MPI004 collective-in-rank-branch
warning enabled by defaultAn MPI collective is called inside a branch that depends on the rank.
Why
Every process of the communicator must call a collective (mpi_bcast, mpi_allreduce, mpi_barrier, ...), in the same order. Called inside if (rank == 0), the other ranks never reach it and the program hangs, or matches it with a different collective and computes garbage. Move the collective out of the branch; if the branch selects exactly the members of a sub-communicator passed to the call, suppress with a reason. Not reported when every branch of the construct (an else or case default included) calls the same collectives in the same order: every rank reaches them. The rank variables are those filled by mpi_comm_rank anywhere in the project.
Reported
if (myrank == 0) then
read(u, *) dt
call mpi_bcast(dt, 1, MPI_REAL8, 0, comm, ierr)
end ifPreferred
if (myrank == 0) read(u, *) dt
call mpi_bcast(dt, 1, MPI_REAL8, 0, comm, ierr)Suppressing
For one occurrence, with the reason on the same line (or alone on the line before the statement):
! fobis: ignore[MPI004] <why this occurrence is fine>For the whole project, ignore = MPI004 in the fobos [lint] section.
References
Sections of the shipped knowledge packs behind this rule:
mpi:ch06-collective#anti-patterns(fobis kb show mpi:ch06-collective#anti-patterns)mpi:ch06-collective#key-concepts(fobis kb show mpi:ch06-collective#key-concepts)