source: CIVL/examples/mpi/collective/BcastReduce.c@ 75982de

1.23 2.0 main test-branch
Last change on this file since 75982de was ec2d23f2, checked in by Ziqing Luo <ziqing@…>, 11 years ago

add new tests

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

  • Property mode set to 100644
File size: 507 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 MPI_Reduce(&num, &recv, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
15 if(rank == 0) num = recv;
16 MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
17 assert(num == 3 * nprocs);
18 MPI_Finalize();
19 return 0;
20}
Note: See TracBrowser for help on using the repository browser.