@@ -38,34 +38,28 @@ public static void main(String args[]) throws MPIException {
3838 j );
3939
4040 /*
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.
4242 * 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
4444 */
4545 IntBuffer rank = MPI .newIntBuffer (1 );
4646 IntBuffer peer = MPI .newIntBuffer (1 );
4747 rank .put (0 , myRank );
4848
4949 /*
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.
5553 */
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 );
6055 }
6156 } else if (myRank > i ) {
6257 IntBuffer rank = MPI .newIntBuffer (1 );
6358 IntBuffer peer = MPI .newIntBuffer (1 );
6459 rank .put (0 , myRank );
6560
6661 /* 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 );
6963 }
7064 }
7165
0 commit comments