source: CIVL/examples/mpi/collective/BcastReduce2.c@ 2261cec

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 2261cec 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: 636 bytes
Line 
1#include <mpi.h>
2#include <assert.h>
3#include <stdio.h>
4
5int main(int argc, char * argv[]) {
6 int nprocs, rank;
7 int num;
8 int recv;
9
10 MPI_Init(&argc, &argv);
11 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
12 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
13 if(rank == 0) num = 3;
14 MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
15 MPI_Allreduce(&num, &recv, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
16 MPI_Reduce(&recv, &num, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
17 MPI_Allreduce(&num, &recv, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
18 printf("recv = %d\n", recv);
19 assert(recv == (3*nprocs*nprocs + 3*(nprocs-1)));
20 MPI_Finalize();
21 return 0;
22}
Note: See TracBrowser for help on using the repository browser.