Skip to content

MPI005 blocking-send-before-receive ​

warning opt-in

Every rank does a blocking mpi_send and then the matching mpi_recv: a deadlock for large messages.

Why ​

mpi_send may block until the matching receive starts (always for messages above the eager limit, which depends on the MPI library and the network). When all ranks send first and receive after, as in a halo exchange written send-then-recv, every rank waits in mpi_send for a receive that is never posted: the code works on small cases and hangs on large ones. Use mpi_sendrecv, or non-blocking calls completed by mpi_waitall. Reported when the send and the receive are not in rank-dependent branches.

Reported ​

fortran
call mpi_send(sbuf, n, MPI_REAL8, right, 0, comm, ierr)
call mpi_recv(rbuf, n, MPI_REAL8, left, 0, comm, status, ierr)

Preferred ​

fortran
call mpi_sendrecv(sbuf, n, MPI_REAL8, right, 0, rbuf, n, MPI_REAL8, left, 0, comm, status, ierr)

Suppressing ​

For one occurrence, with the reason on the same line (or alone on the line before the statement):

fortran
! fobis: ignore[MPI005] <why this occurrence is fine>

For the whole project, ignore = MPI005 in the fobos [lint] section.

References ​

Sections of the shipped knowledge packs behind this rule:

  • mpi:cheatsheet#avoid-deadlock (fobis kb show mpi:cheatsheet#avoid-deadlock)
  • mpi:overview#point-to-point-ch-3-and-deadlock (fobis kb show mpi:overview#point-to-point-ch-3-and-deadlock)