Skip to content

MPI002 isend-buffer-modified-before-completion ​

warning enabled by default

The buffer of a pending mpi_isend is written before the request is completed.

Why ​

A non-blocking send may read its buffer at any time until mpi_wait/mpi_test completes the request. Writing the buffer in between changes what is sent, depending on timing: the receiver gets old values, new values, or a mix, and the run is not reproducible. Complete the request before reusing the buffer, or double-buffer.

Reported ​

fortran
call mpi_isend(halo, n, MPI_REAL8, dst, 0, comm, req, ierr)
halo = q(1:n)               ! the send may still be reading halo
call mpi_wait(req, MPI_STATUS_IGNORE, ierr)

Preferred ​

fortran
call mpi_isend(halo, n, MPI_REAL8, dst, 0, comm, req, ierr)
call mpi_wait(req, MPI_STATUS_IGNORE, ierr)
halo = q(1:n)

Suppressing ​

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

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

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

References ​

Sections of the shipped knowledge packs behind this rule:

  • mpi:ch03-point-to-point#anti-patterns (fobis kb show mpi:ch03-point-to-point#anti-patterns)
  • mpi:cheatsheet#tells-smells (fobis kb show mpi:cheatsheet#tells-smells)