source: CIVL/examples/mpi/collective/reduce_maxloc.c

acw/focus-triggers
Last change on this file was 2b25839, checked in by Stephen Siegel <siegel@…>, 4 days ago

Implemented MPI operations MINLOC and MAXLOC and associated datatypes
for collective routines. Still need to do it for point-to-point, if
they are ever used in that way. Still need to think more deeply
about how to handle structs in general for MPI.
Found additional uses of deprecated $state and deleted them.
Added further complex and collective examples. Still need to make
them into JUnit tests.

  • Property mode set to 100644
File size: 528 bytes
Line 
1#include <assert.h>
2#include <mpi.h>
3
4struct Pair {
5 int val;
6 int rank;
7};
8
9int main(void) {
10 MPI_Init(NULL, NULL);
11 int rank, nprocs;
12 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
13 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
14 int mynum = rank < nprocs/2 ? rank : nprocs - rank - 1;
15 struct Pair mypair = { mynum, rank }, result;
16 MPI_Reduce(&mypair, &result, 1, MPI_2INT, MPI_MAXLOC, 0, MPI_COMM_WORLD);
17 if (rank == 0) {
18 assert(result.val == (nprocs-1)/2);
19 assert(result.rank == (nprocs-1)/2);
20 }
21 MPI_Finalize();
22}
Note: See TracBrowser for help on using the repository browser.