source: CIVL/examples/mpi/mpiFeature/Test_nonblocking/nonblocking_manytoone_order.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.1 KB
Line 
1#include "mpi.h"
2#include "assert.h"
3
4int 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[4] = {rank, rank + 1, rank + 2, rank + 3};
15 MPI_Request reqs[4];
16
17 for (int i = 0; i < 4; i++)
18 MPI_Isend(dat + i, 1, MPI_INT, 0, i, comm, reqs + i);
19 MPI_Waitall(4, reqs, MPI_STATUS_IGNORE);
20 } else {
21 int ub = 4 * (size - 1);
22 int dat[ub];
23 MPI_Request reqs[ub];
24 MPI_Status statuses[ub];
25
26 for (int i = 1; i < size; i++)
27 for (int j = 0; j < 4; j++)
28 MPI_Irecv(dat + (i-1) * 4 + j, 1, MPI_INT, i, j, comm, reqs + (i-1) * 4 + j);
29 MPI_Waitall(ub, reqs, statuses);
30 for (int i = 1; i < size; i++)
31 for (int j = 0; j < 4; j++) {
32 int idx = (i-1)*4 + j;
33 int src = statuses[idx].MPI_SOURCE;
34 int tag = statuses[idx].MPI_TAG;
35
36 assert (dat[idx] == i + j && src == i && j == tag);
37 }
38 }
39 return 0;
40}
41
42int main() {
43 MPI_Init(NULL, NULL);
44 many_to_one();
45 MPI_Finalize();
46 return 0;
47}
Note: See TracBrowser for help on using the repository browser.