source: CIVL/examples/mpi/mpiFeature/Test_nonblocking/nonblocking_sendrecv_3pingpong.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.3 KB
Line 
1#include "mpi.h"
2#include "assert.h"
3
4int main(int argc, char *argv[]) {
5 int numtasks, rank, next, prev, buf[2], tag1=1, tag2=2;
6 MPI_Request reqs[4];
7 MPI_Status stats[4];
8
9 MPI_Init(&argc,&argv);
10 MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
11 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
12
13 MPI_Request req1, req2;
14 int rbuf[2];
15 MPI_Comm comm = MPI_COMM_WORLD;
16
17 if (rank == 0) {
18 MPI_Irecv(rbuf, 1, MPI_INT, 1, 0, comm, &req1);
19 MPI_Irecv(rbuf + 1, 1, MPI_INT, 2, 0, comm, &req2);
20 MPI_Wait(&req1, MPI_STATUS_IGNORE);
21 rbuf[0]++;
22 MPI_Send(rbuf, 1, MPI_INT, 2, 0, comm);
23 MPI_Wait(&req2, MPI_STATUS_IGNORE);
24 assert (rbuf[1] == 3);
25 rbuf[1]++;
26 MPI_Send(rbuf + 1, 1, MPI_INT, 1, 0, comm);
27 } else if (rank == 1) {
28 MPI_Irecv(rbuf, 1, MPI_INT, 0, 0, comm, &req1);
29 MPI_Send(&rank, 1, MPI_INT, 0, 0, comm);
30 MPI_Wait(&req1, MPI_STATUS_IGNORE);
31 rbuf[0]++;
32 MPI_Send(rbuf, 1, MPI_INT, 2, 0, comm);
33 } else if (rank == 2) {
34 MPI_Irecv(rbuf, 1, MPI_INT, 0, 0, comm, &req1);
35 MPI_Irecv(rbuf + 1, 1, MPI_INT, 1, 0, comm, &req2);
36 MPI_Wait(&req1, MPI_STATUS_IGNORE);
37 rbuf[0]++;
38 MPI_Send(rbuf, 1, MPI_INT, 0, 0, comm);
39 MPI_Wait(&req2, MPI_STATUS_IGNORE);
40 assert (rbuf[1] == 5);
41 }
42 MPI_Finalize();
43}
Note: See TracBrowser for help on using the repository browser.