source: CIVL/examples/mpi/collective/allreduce.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: 1.5 KB
RevLine 
[5d951df]1/* This example shows misusage of MPI collective routines. With a
2 * macro TYPE or TYPE2, this example shows inconsistency of MPI
3 * datatypes of collective calls. With a macro OPERATOR, this example
4 * shows inconsistency of MPI operators of collective calls.
5 **/
[b12731c]6#include <mpi.h>
7#include <stdio.h>
8#ifdef _CIVL
9#include<civlc.cvh>
10#endif
11
12#define WCOMM MPI_COMM_WORLD
13
14int main(int argc, char **argv){
15 int npes, mype, ierr;
16 double sum, val; int calc, knt=1;
[5d951df]17
[b12731c]18 ierr = MPI_Init(&argc, &argv);
19 ierr = MPI_Comm_size(WCOMM, &npes);
[5d951df]20 ierr = MPI_Comm_rank(WCOMM, &mype);
[b12731c]21 val = (double)mype;
[626a547]22
23#ifdef TYPE
24 if(mype%2)
25 ierr = MPI_Allreduce(&val, &sum, knt, MPI_DOUBLE, MPI_SUM, WCOMM);
26 else
27 ierr = MPI_Allreduce(&val, &sum, knt, MPI_INT, MPI_SUM, WCOMM);
[5d951df]28#elif defined TYPE2
29 if(mype%2)
30 ierr = MPI_Allreduce(&val, &sum, knt, MPI_DOUBLE, MPI_SUM, WCOMM);
31 else {
32 int sum, val;
33
34 ierr = MPI_Allreduce(&val, &sum, knt, MPI_INT, MPI_SUM, WCOMM);
35 }
[626a547]36#elif defined OPERATOR
37 if(mype%2)
38 ierr = MPI_Allreduce(&val, &sum, knt, MPI_DOUBLE, MPI_SUM, WCOMM);
39 else
[e077e59]40 ierr = MPI_Allreduce(&val, &sum, knt, MPI_DOUBLE, MPI_MAX, WCOMM);
[626a547]41#else
[b12731c]42 ierr = MPI_Allreduce(&val, &sum, knt, MPI_DOUBLE, MPI_SUM, WCOMM);
[626a547]43#endif
[b12731c]44
45 calc = ((npes - 1) * npes) / 2;
46 printf(" PE: %d sum=%5.0f calc=%d\n", mype, sum, calc);
47#ifdef _CIVL
[626a547]48#ifndef OPERATOR
[b12731c]49 $assert(sum == calc);
[626a547]50#endif
[b12731c]51#endif
52 ierr = MPI_Finalize();
53}
Note: See TracBrowser for help on using the repository browser.