source: CIVL/examples/mpi/simple/bcastgather1.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: 866 bytes
Line 
1/* Good broadcast followed by gather.
2 */
3#include<mpi.h>
4#include<assert.h>
5#include<stdlib.h>
6
7#define COUNT 5
8#ifdef _CIVL
9$input double a[COUNT];
10#else
11double a[COUNT];
12#endif
13double buf1[COUNT];
14double *buf2;
15int nprocs;
16int rank;
17
18void main() {
19 int argc;
20 char **argv;
21 int i;
22
23 MPI_Init(&argc, &argv);
24 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
25 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
26 if (rank == 0) {
27 for (i=0; i<COUNT; i++)
28 buf1[i] = a[i];
29 }
30 MPI_Bcast(&buf1[0], COUNT, MPI_DOUBLE, 0, MPI_COMM_WORLD);
31 if (rank == 1)
32 buf2 = (double*)malloc(nprocs*COUNT*sizeof(double));
33 else
34 buf2= (double*)NULL;
35 MPI_Gather(&buf1[0], COUNT, MPI_DOUBLE,
36 buf2, COUNT, MPI_DOUBLE,
37 1, MPI_COMM_WORLD);
38 if (rank == 1) {
39 for (i=0; i<nprocs*COUNT; i++)
40 assert(buf2[i]==a[i%COUNT]);
41 free(buf2);
42 }
43 MPI_Finalize();
44}
Note: See TracBrowser for help on using the repository browser.