@@ -38,34 +38,28 @@ public static void main(String args[]) throws MPIException {
38
38
j );
39
39
40
40
/*
41
- * rank is the Buffer passed into iSend to send to rank j.
41
+ * rank is the Buffer passed into sendRecv to send to rank j.
42
42
* rank is populated with myRank, which is the data to send off
43
- * peer is the Buffer received from rank j from iRecv
43
+ * peer is the Buffer received from rank j to current rank
44
44
*/
45
45
IntBuffer rank = MPI .newIntBuffer (1 );
46
46
IntBuffer peer = MPI .newIntBuffer (1 );
47
47
rank .put (0 , myRank );
48
48
49
49
/*
50
- * To avoid deadlocks, use non-blocking communication iSend and iRecv
51
- * This will allow the program to progress, in the event that
52
- * two ranks both send to each other at the same time and could
53
- * potentially cause deadlock. The ranks can send their requests
54
- * without halting the program and immediately
50
+ * To avoid deadlocks, use combined sendRecv operation.
51
+ * This performs a send and recv as a combined atomic operation
52
+ * and allow MPI to efficiently handle the requests internally.
55
53
*/
56
- Request sendReq = MPI .COMM_WORLD .iSend (rank , 1 , MPI .INT , j , myRank );
57
- Request recvReq = MPI .COMM_WORLD .iRecv (peer , 1 , MPI .INT , j , j );
58
- sendReq .waitFor ();
59
- recvReq .waitFor ();
54
+ MPI .COMM_WORLD .sendRecv (rank , 1 , MPI .INT , j , myRank , peer , 1 , MPI .INT , j , j );
60
55
}
61
56
} else if (myRank > i ) {
62
57
IntBuffer rank = MPI .newIntBuffer (1 );
63
58
IntBuffer peer = MPI .newIntBuffer (1 );
64
59
rank .put (0 , myRank );
65
60
66
61
/* receive from and reply to rank i */
67
- MPI .COMM_WORLD .iRecv (peer , 1 , MPI .INT , i , i ).waitFor ();
68
- MPI .COMM_WORLD .iSend (rank , 1 , MPI .INT , i , myRank ).waitFor ();
62
+ MPI .COMM_WORLD .sendRecv (rank , 1 , MPI .INT , i , myRank , peer , 1 , MPI .INT , i , i );
69
63
}
70
64
}
71
65
0 commit comments