source: CIVL/examples/mpi/simple/reduce.c@ bb03188

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 651 bytes
Line 
1/* Good broadcasts.
2 */
3#include<mpi.h>
4#include<assert.h>
5
6int nprocs;
7int myrank;
8
9#define count 10
10
11void main() {
12 int argc;
13 char **argv;
14 double x[count];
15 double y[count];
16 int root;
17 int i;
18
19 MPI_Init(&argc, &argv);
20 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
21 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
22 root = nprocs-1; // just to be different
23 for (i=0; i<count; i++)
24 x[i]=myrank;
25 MPI_Reduce(&x[0], &y[0], count, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
26 for (i=0; i<count; i++)
27 assert(x[i]==myrank);
28 if (myrank == root) {
29 for (i=0; i<count; i++)
30 assert(y[i]==nprocs*(nprocs-1)/2);
31 }
32 MPI_Finalize();
33}
Note: See TracBrowser for help on using the repository browser.