source: CIVL/examples/mpi/mpiFeature/Test_nonblocking/nonblocking_manytoone_anyorder_mix.cvl

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[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 int nd = $choose_int(2);
28
29 if (nd)
30 MPI_Irecv(dat + i, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, comm, reqs + i);
31 else {
32 MPI_Recv(dat + i, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, comm, statuses + i);
33 reqs[i] = MPI_REQUEST_NULL;
34 }
35 }
36 MPI_Waitall(ub, reqs, statuses);
37 for (int i = 0; i < ub; i++) {
38 int src = statuses[i].MPI_SOURCE;
39 int tag = statuses[i].MPI_TAG;
40
41 assert (dat[i] == src + tag);
42 }
43 }
44 return 0;
45}
46
47int main() {
48 MPI_Init(NULL, NULL);
49 many_to_one();
50 MPI_Finalize();
51 return 0;
52}
Note: See TracBrowser for help on using the repository browser.