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