Skip to content

MPI006 any-source-order-dependent-sum ​

info opt-in

Messages received from MPI_ANY_SOURCE are summed in arrival order: the result is not reproducible.

Why ​

With MPI_ANY_SOURCE the messages are processed in the order they arrive, which changes from run to run. Floating-point addition is not associative, so a sum accumulated in that order changes in its last bits each run, and regression tests at round-off level fail randomly. Receive from each source in a fixed order, or store the contributions by status%MPI_SOURCE and sum them in rank order.

Reported ​

fortran
do k = 1, nproc - 1
  call mpi_recv(part, 1, MPI_REAL8, MPI_ANY_SOURCE, 0, comm, status, ierr)
  total = total + part
end do

Preferred ​

fortran
do k = 1, nproc - 1
  call mpi_recv(parts(k), 1, MPI_REAL8, k, 0, comm, status, ierr)
end do
total = total + sum(parts)       ! fixed order

Suppressing ​

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

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

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

References ​

Sections of the shipped knowledge packs behind this rule:

  • hpc-practice:gpu-practice#floating-point-reproducibility (fobis kb show hpc-practice:gpu-practice#floating-point-reproducibility)