source: CIVL/examples/mpi/simple/gather.c

main
Last change on this file 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: 789 bytes
Line 
1/* Good scatter.
2 */
3#include<mpi.h>
4#include<assert.h>
5#include<stdlib.h>
6
7#define COUNT 10
8
9int nprocs;
10int myrank;
11int root;
12
13void main() {
14 int argc;
15 char **argv;
16 double *recvbuf = (double*)NULL;
17 double sendbuf[COUNT];
18 int i;
19
20 MPI_Init(&argc, &argv);
21 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
22 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
23 root = nprocs - 1; // to be different
24 for (i=0; i<COUNT; i++)
25 sendbuf[i]=myrank*COUNT+i;
26 if (myrank == root) {
27 recvbuf = (double*)malloc(COUNT*nprocs*sizeof(double));
28 }
29 MPI_Gather(&sendbuf[0], COUNT, MPI_DOUBLE,
30 recvbuf, COUNT, MPI_DOUBLE,
31 root, MPI_COMM_WORLD);
32 if (myrank == root) {
33 for (i=0; i<nprocs*COUNT; i++) {
34 assert(recvbuf[i] == 1.0*i);
35 }
36 free(recvbuf);
37 }
38 MPI_Finalize();
39}
Note: See TracBrowser for help on using the repository browser.