source: CIVL/examples/mpi/mpiFeature/Test_nonblocking/nonblocking_manytoone_some_widlcards3.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.5 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 if (size < 3)
13 return 0;
14
15 int dat[3] = {rank * size + 1, rank * size + 2, rank * size + 3};
16
17 MPI_Send(dat, 1, MPI_INT, 0, 1, comm);
18 MPI_Send(dat + 1, 1, MPI_INT, 0, 2, comm);
19 MPI_Send(dat + 2, 1, MPI_INT, 0, 3, comm);
20 if (rank == 0) {
21 int ub = 3 * size;
22 int rbuf[ub];
23 MPI_Request reqs[ub];
24 MPI_Status statuses[ub];
25 int oft = 0;
26
27 MPI_Irecv(rbuf + oft, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, comm, reqs + oft);
28 oft++;
29 MPI_Irecv(rbuf + oft, 1, MPI_INT, 0, MPI_ANY_TAG, comm, reqs + oft);
30 oft++;
31 MPI_Irecv(rbuf + oft, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, comm, reqs + oft);
32 oft++;
33 MPI_Irecv(rbuf + oft, 1, MPI_INT, 1, MPI_ANY_TAG, comm, reqs + oft);
34 oft++;
35 MPI_Irecv(rbuf + oft, 1, MPI_INT, 2, MPI_ANY_TAG, comm, reqs + oft);
36 oft++;
37 for (int i = 0; i < ub - 5; i++) {
38 MPI_Irecv(rbuf + oft, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, comm, reqs + oft);
39 oft++;
40 }
41 MPI_Waitall(ub, reqs, statuses);
42 for (int i = 0; i < ub; i++) {
43 int src = statuses[i].MPI_SOURCE;
44 int tag = statuses[i].MPI_TAG;
45
46 assert (rbuf[i] == src * size + tag);
47 }
48 }
49 return 0;
50}
51
52int main() {
53 MPI_Init(NULL, NULL);
54 many_to_one();
55 MPI_Finalize();
56 return 0;
57}
Note: See TracBrowser for help on using the repository browser.