acw/focus-triggers
|
Last change
on this file was 2b25839, checked in by Stephen Siegel <siegel@…>, 5 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:
532 bytes
|
| Line | |
|---|
| 1 | #include <assert.h>
|
|---|
| 2 | #include <mpi.h>
|
|---|
| 3 |
|
|---|
| 4 | struct Pair {
|
|---|
| 5 | int val;
|
|---|
| 6 | int rank;
|
|---|
| 7 | };
|
|---|
| 8 |
|
|---|
| 9 | int 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;
|
|---|
| 15 | if (mynum < 0) mynum = -mynum;
|
|---|
| 16 | struct Pair mypair = { mynum, rank }, result;
|
|---|
| 17 | MPI_Reduce(&mypair, &result, 1, MPI_2INT, MPI_MINLOC, 0, MPI_COMM_WORLD);
|
|---|
| 18 | if (rank == 0) {
|
|---|
| 19 | assert(result.val == 0);
|
|---|
| 20 | assert(result.rank == (nprocs - nprocs%2)/2);
|
|---|
| 21 | }
|
|---|
| 22 | MPI_Finalize();
|
|---|
| 23 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.