Function utils::initMPI
Defined in File MPIUtils.hpp
Function Documentation
-
inline void utils::initMPI(int *argc, char ***argv)
Initialize MPI, if this build was compiled with SLUG_MPI.
A no-op when SLUG_MPI is not defined. Requests MPI_THREAD_FUNNELED, since MPI is only ever called from a single thread, outside any active OpenMP parallel region (see mpiBarrier()’s own callers). MPI_THREAD_FUNNELED itself only constrains which thread may call MPI – but the next level down, MPI_THREAD_SINGLE, is a stronger promise from this process to the MPI implementation that it will never be multithreaded at all, not just that MPI calls are confined to one thread; an implementation that could only actually provide MPI_THREAD_SINGLE gives no guarantee that it behaves correctly once this build (if also compiled with OpenMP) goes on to spawn worker threads regardless, even ones that never call MPI themselves. Since this build cannot un-compile its own OpenMP support at this point, the next best thing is forcing OpenMP down to a single thread for the rest of the run, so the “no threads beyond this one” promise MPI_THREAD_SINGLE actually implies is still honored in practice – slower than intended, but correct, rather than silently relying on a implementation-specific tolerance the standard itself does not promise.
Also caches this process’s own rank and the total number of ranks, which mpiRank(), mpiSize() and isIORank() then return without making any further MPI call – so they are safe to call from any thread, and after finalizeMPI(), as well.
- Parameters:
argc – Address of main()’s own argc
argv – Address of main()’s own argv