
Programming Using the
Message-Passing
Paradigm IV
Dr. Cem Özdo
˘
gan
LOGIK
Overlapping
Communication with
Computation
Non-Blocking
Communication Operations
Collective
Communication and
Computation
Operations
Broadcast
Reduction
Gather
Scatter
All-to-All
8.7
Non-Blocking Communication Operations IV
•
Avoiding Deadlocks; by using non-blocking communication
operations we can remove most of the deadlocks
associated with their blocking counterparts.
•
For example, the following piece of code is not safe.
1 i n t a [ 1 0] , b[ 1 0 ] , myrank ;
2 MPI_Status sta t u s ;
3 . . .
4 MPI_Comm_rank (MPI_COMM_WORLD, &myrank ) ;
5 i f ( myrank == 0) {
6 MPI_Send( a , 10 , MPI_INT , 1 , 1 , MPI_COMM_WORLD) ;
7 MPI_Send( b , 10 , MPI_INT , 1 , 2 , MPI_COMM_WORLD) ;
8 }
9 else i f ( myrank == 1) {
10 MPI_Recv ( b , 10 , MPI_INT , 0 , 2 , &sta tus , MPI_COMM_WORLD ) ;
11 MPI_Recv ( a , 10 , MPI_INT , 0 , 1 , &sta tus , MPI_COMM_WORLD ) ;
12 }
13 . . .
•
However, if we replace either the send or receive
operations with their non-blocking counterparts, then the
code will be s afe, and will c orrectly run on any MPI
implementation.