main
|
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:
548 bytes
|
| Line | |
|---|
| 1 | #include <assert.h>
|
|---|
| 2 | #include <mpi.h>
|
|---|
| 3 |
|
|---|
| 4 | struct Pair {
|
|---|
| 5 | double 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 | double mynum = rank < nprocs/2.0 ? rank : nprocs - rank - 1;
|
|---|
| 15 | struct Pair mypair = { mynum, rank }, result;
|
|---|
| 16 | MPI_Reduce(&mypair, &result, 1, MPI_DOUBLE_INT, MPI_MAXLOC,
|
|---|
| 17 | 0, MPI_COMM_WORLD);
|
|---|
| 18 | if (rank == 0) {
|
|---|
| 19 | assert(result.val == (nprocs-1)/2);
|
|---|
| 20 | assert(result.rank == (nprocs-1)/2);
|
|---|
| 21 | }
|
|---|
| 22 | MPI_Finalize();
|
|---|
| 23 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.