source: CIVL/examples/mpi/collective/allreduce.c@ 4f4a0fd

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

added more examples

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

  • Property mode set to 100644
File size: 596 bytes
Line 
1#include <mpi.h>
2#include <stdio.h>
3#ifdef _CIVL
4#include<civlc.cvh>
5#endif
6
7#define WCOMM MPI_COMM_WORLD
8
9int main(int argc, char **argv){
10 int npes, mype, ierr;
11 double sum, val; int calc, knt=1;
12 ierr = MPI_Init(&argc, &argv);
13 ierr = MPI_Comm_size(WCOMM, &npes);
14 ierr = MPI_Comm_rank(WCOMM, &mype);
15
16 val = (double)mype;
17 ierr = MPI_Allreduce(&val, &sum, knt, MPI_DOUBLE, MPI_SUM, WCOMM);
18
19 calc = ((npes - 1) * npes) / 2;
20 printf(" PE: %d sum=%5.0f calc=%d\n", mype, sum, calc);
21#ifdef _CIVL
22 $assert(sum == calc);
23#endif
24 ierr = MPI_Finalize();
25}
Note: See TracBrowser for help on using the repository browser.