source: CIVL/examples/mpi/collective/reduce.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.4 KB
RevLine 
[b12731c]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;
[01e3bb5]11 double sum[2], val[2]; int calc, knt=1;
[b12731c]12 ierr = MPI_Init(&argc, &argv);
13 ierr = MPI_Comm_size(WCOMM, &npes);
14 ierr = MPI_Comm_rank(WCOMM, &mype);
15
[01e3bb5]16 val[0] = (double)mype;
17 val[1] = (double)mype;
[b12731c]18#ifdef OPERATOR
19 if(mype%2)
[01e3bb5]20 ierr = MPI_Reduce(val, sum, knt, MPI_DOUBLE, MPI_SUM, 0, WCOMM);
[b12731c]21 else
[01e3bb5]22 ierr = MPI_Reduce(val, sum, knt, MPI_DOUBLE, MPI_MAX, 0, WCOMM);
[b12731c]23#elif defined ORDER
24 if(mype !== 2)
[01e3bb5]25 ierr = MPI_Reduce(val, sum, knt, MPI_DOUBLE, MPI_SUM, 0, WCOMM);
[b12731c]26#elif defined TYPE
27 if(mype%2)
[01e3bb5]28 ierr = MPI_Reduce(val, sum, knt, MPI_DOUBLE, MPI_SUM, 0, WCOMM);
[b12731c]29 else
[01e3bb5]30 ierr = MPI_Reduce(val, sum, knt, MPI_INT, MPI_SUM, 0, WCOMM);
[b12731c]31#elif defined ROOT
[01e3bb5]32 ierr = MPI_Reduce(val, sum, knt, MPI_DOUBLE, MPI_SUM, mype, WCOMM);
33#elif defined COUNT
34 knt = 2-(mype%2);
35 ierr = MPI_Reduce(val, sum, knt, MPI_DOUBLE, MPI_SUM, 0, WCOMM);
[b12731c]36#else
[01e3bb5]37 ierr = MPI_Reduce(val, sum, knt, MPI_DOUBLE, MPI_SUM, 0, WCOMM);
[b12731c]38#endif
39
40 calc = ((npes - 1) * npes) / 2;
41 if(mype == 0){
[01e3bb5]42 printf(" PE: %d sum=%5.0f calc=%d\n", mype, sum[0], calc);
[b12731c]43#ifdef _CIVL
[626a547]44#ifndef OPERATOR
[01e3bb5]45 $assert(sum[0] == calc);
[626a547]46#endif
[b12731c]47#endif
48 }
49 ierr = MPI_Finalize();
50}
Note: See TracBrowser for help on using the repository browser.