source: CIVL/examples/mpi/collective/BcastReduce_bad.c@ 7dbb0db

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 7dbb0db was 4ccacf8, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

added some more MPI collective tests.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@2106 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 675 bytes
Line 
1#include <mpi.h>
2#include <assert.h>
3
4int main(int argc, char * argv[]) {
5 int nprocs, rank;
6 int num;
7 int recv;
8
9 MPI_Init(&argc, &argv);
10 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
11 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
12 if(rank == 0) num = 3;
13 MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
14
15 if(rank%2)
16 MPI_Reduce(&num, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
17 else
18 MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
19 if(rank == 0) num = recv;
20 if(rank%2)
21 MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
22 else
23 MPI_Reduce(&num, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
24 assert(num == 3 * nprocs);
25 MPI_Finalize();
26 return 0;
27}
Note: See TracBrowser for help on using the repository browser.