source: CIVL/examples/mpi/simple/allgather_inplace.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: 699 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
23 recvbuf = (double*)malloc(COUNT*nprocs*sizeof(double));
24 for (int i = 0; i < COUNT; i++)
25 recvbuf[myrank * COUNT + i] = myrank * COUNT + i;
26
27 MPI_Allgather(MPI_IN_PLACE, COUNT, MPI_DOUBLE,
28 recvbuf, COUNT, MPI_DOUBLE,
29 MPI_COMM_WORLD);
30 for (i=0; i<nprocs*COUNT; i++) {
31 assert(recvbuf[i] == 1.0*i);
32 }
33 free(recvbuf);
34 MPI_Finalize();
35}
Note: See TracBrowser for help on using the repository browser.