source: CIVL/examples/mpi/simple/allgather.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: 664 bytes
Line 
1/* Good Allgather.
2 */
3#include<mpi.h>
4#include<assert.h>
5#include<stdlib.h>
6
7#define COUNT 10
8
9int nprocs;
10int myrank;
11
12void main() {
13 int argc;
14 char **argv;
15 double *recvbuf = (double*)NULL;
16 double sendbuf[COUNT];
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 for (i=0; i<COUNT; i++)
23 sendbuf[i]=myrank*COUNT+i;
24 recvbuf = (double*)malloc(COUNT*nprocs*sizeof(double));
25 MPI_Allgather(&sendbuf[0], COUNT, MPI_DOUBLE,
26 recvbuf, COUNT, MPI_DOUBLE,
27 MPI_COMM_WORLD);
28 for (i=0; i<nprocs*COUNT; i++) {
29 assert(recvbuf[i] == 1.0*i);
30 }
31 free(recvbuf);
32 MPI_Finalize();
33}
Note: See TracBrowser for help on using the repository browser.