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:
975 bytes
|
| Line | |
|---|
| 1 | #include "mpi.h"
|
|---|
| 2 | #include "assert.h"
|
|---|
| 3 |
|
|---|
| 4 | int many_to_one () {
|
|---|
| 5 | int size;
|
|---|
| 6 | int rank;
|
|---|
| 7 | MPI_Comm comm = MPI_COMM_WORLD;
|
|---|
| 8 | MPI_Datatype type = MPI_INT;
|
|---|
| 9 |
|
|---|
| 10 | MPI_Comm_size (comm, &size);
|
|---|
| 11 | MPI_Comm_rank (comm, &rank);
|
|---|
| 12 |
|
|---|
| 13 | if (rank != 0) {
|
|---|
| 14 | int dat[3] = {rank, rank + 1, rank + 2};
|
|---|
| 15 | MPI_Request reqs[3];
|
|---|
| 16 |
|
|---|
| 17 | for (int i = 0; i < 3; i++)
|
|---|
| 18 | MPI_Isend(dat + i, 1, MPI_INT, 0, i, comm, reqs + i);
|
|---|
| 19 | MPI_Waitall(3, reqs, MPI_STATUS_IGNORE);
|
|---|
| 20 | } else {
|
|---|
| 21 | int ub = 3 * (size - 1);
|
|---|
| 22 | int dat[ub];
|
|---|
| 23 | MPI_Request reqs[ub];
|
|---|
| 24 | MPI_Status statuses[ub];
|
|---|
| 25 |
|
|---|
| 26 | for (int i = 0; i < ub; i++)
|
|---|
| 27 | MPI_Irecv(dat + i, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, comm, reqs + i);
|
|---|
| 28 | MPI_Waitall(ub, reqs, statuses);
|
|---|
| 29 | for (int i = 0; i < ub; i++) {
|
|---|
| 30 | int src = statuses[i].MPI_SOURCE;
|
|---|
| 31 | int tag = statuses[i].MPI_TAG;
|
|---|
| 32 |
|
|---|
| 33 | assert (dat[i] == src + tag);
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | return 0;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | int main() {
|
|---|
| 40 | MPI_Init(NULL, NULL);
|
|---|
| 41 | many_to_one();
|
|---|
| 42 | MPI_Finalize();
|
|---|
| 43 | return 0;
|
|---|
| 44 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.