source: CIVL/examples/mpi/mpiFeature/Test_nonblocking/nonblocking_sendrecv_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.2 KB
Line 
1#include "mpi.h"
2#include "assert.h"
3
4#ifndef TAG
5#define TAG 0
6#endif
7
8#ifndef WILDCARD
9#define SRC 0
10#else
11#define SRC MPI_ANY_SOURCE
12#endif
13
14int main(int argc, char *argv[]) {
15 int numtasks, rank;
16
17 MPI_Init(&argc,&argv);
18 MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
19 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20
21 if (numtasks < 2) {
22 MPI_Finalize();
23 return 0;
24 }
25
26 MPI_Comm comm = MPI_COMM_WORLD;
27 MPI_Request reqs[4];
28
29 if (rank == 0) {
30 int dat[4] = {1,2,3,4};
31
32 MPI_Isend(dat, 1, MPI_INT, 1, TAG, comm, reqs);
33 MPI_Isend(dat + 1, 1, MPI_INT, 1, TAG, comm, reqs + 1);
34 MPI_Isend(dat + 2, 1, MPI_INT, 1, TAG, comm, reqs + 2);
35 MPI_Isend(dat + 3, 1, MPI_INT, 1, TAG, comm, reqs + 3);
36 MPI_Waitall(4, reqs, MPI_STATUS_IGNORE);
37 } else if (rank == 1) {
38 int rbuf[4];
39
40 MPI_Irecv(rbuf, 1, MPI_INT, SRC, TAG, comm, reqs);
41 MPI_Irecv(rbuf + 1, 1, MPI_INT, SRC, TAG, comm, reqs + 1);
42 MPI_Irecv(rbuf + 2, 1, MPI_INT, SRC, TAG, comm, reqs + 2);
43 MPI_Irecv(rbuf + 3, 1, MPI_INT, SRC, TAG, comm, reqs + 3);
44 MPI_Waitall(4, reqs, MPI_STATUS_IGNORE);
45 assert (rbuf[0] == 1 && rbuf[1] == 2 && rbuf[2] == 3 && rbuf[3] == 4);
46 }
47 MPI_Finalize();
48}
Note: See TracBrowser for help on using the repository browser.