source: CIVL/examples/mpi/collective/BcastReduce_bad.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: 867 bytes
Line 
1/* A bad example shows how CIVL catches the misusage of MPI collective
2 routines. In this example, even processes and odd processes calls
3 different MPI collective routines. */
4#include <mpi.h>
5#include <assert.h>
6
7int main(int argc, char * argv[]) {
8 int nprocs, rank;
9 int num;
10 int recv;
11
12 MPI_Init(&argc, &argv);
13 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
14 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
15 if(rank == 0) num = 3;
16 MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
17
18 if(rank%2 == 0)
19 MPI_Reduce(&num, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
20 else
21 MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
22 if(rank == 0) num = recv;
23 if(rank%2 == 0)
24 MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
25 else
26 MPI_Reduce(&num, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
27 assert(num == 3 * nprocs);
28 MPI_Finalize();
29 return 0;
30}
Note: See TracBrowser for help on using the repository browser.