[Mpi-comments] non-blocking communication deadlock possible?

Andreas Hehn hehn at phys.ethz.ch
Wed Dec 10 05:15:28 CST 2014


Dear MPI comments readers,

I am not 100% sure if the following piece of code could cause a deadlock
in a standard-compliant MPI implementation or not.

#include <mpi.h>

int main(int argc, char** argv) {
  MPI_Status s[2];
  int num;

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD,&num);

  double ds=5.4; // to send
  double dr;     // to receive
  int tag=99;

  MPI_Request r[2];
  if(num==0) {
    MPI_Isend(&ds,1,MPI_DOUBLE,1,tag,MPI_COMM_WORLD,&r[0]);
    MPI_Irecv (&dr,1,MPI_DOUBLE,1,tag,MPI_COMM_WORLD,&r[1]);
  }
  else {
    MPI_Isend(&ds,1,MPI_DOUBLE,0,tag,MPI_COMM_WORLD,&r[0]);
    MPI_Irecv (&dr,1,MPI_DOUBLE,0,tag,MPI_COMM_WORLD,&r[1]);
  }

  MPI_Waitall(2,r,s);

  MPI_Finalize();
  return 0;
}

It is not entirely clear to me if the order of MPI_Isend and MPI_Irecv
matters (as it does for blocking communication). Both function calls
should return immediately according to section 3.7 of the standard -
even if MPI_Isend uses synchronous send.
So at this point there shouldn't be any problem.
However, will MPI_Waitall() return for any order of the filed requests?
The standard says it is equivalent to MPI_Wait() for the number of
requests in "some arbitrary order" (line 28 of page 59).
I suppose this means MPI_Waitall() is not supposed to mind the order of
the requests in any way. Therefore it could not deadlock.
Is this correct and is the line of argument sufficient to exclude the
possibility of a deadlock?

Best regards,

Andreas Hehn



More information about the mpi-comments mailing list