mpi_runtime Module

Owns the single call to MPI_Init / MPI_Finalize for any executable that includes this module, and exposes the world communicator together with the local rank and total rank count. It runs at any mpirun -np N (and at -np 1, where the rank/size queries degenerate cleanly).

This module uses only the lowest-common-denominator MPI features (Init, Finalize, Comm_rank, Comm_size, Allreduce, COMM_WORLD). The Fortran 2008 mpi_f08 module gives us type-safe handles on every implementation that provides it; MS-MPI on Windows does not ship mpi_f08 yet, so we fall back to the legacy mpi module when CFD_SOLVER_LEGACY_MPI is defined at preprocess time (set via -DCFD_SOLVER_LEGACY_MPI on the Windows CI job). The call-site code is identical either way because mpi_world() and the named constants resolve to the handle type of whichever module is in scope.



Variables

Type Visibility Attributes Name Initial
integer, private, save :: g_my_rank = -1

Cached identity values, populated by mpi_runtime_init.

integer, private, save :: g_n_ranks = -1
logical, private, save :: g_initialised = .false.

Functions

public pure function mpi_runtime_is_initialised() result(yes)

True after mpi_runtime_init and before mpi_runtime_finalize.

Arguments

None

Return Value logical

public function my_rank() result(r)

Local rank in MPI_COMM_WORLD. Aborts if called before init.

Arguments

None

Return Value integer

public function n_ranks() result(n)

Size of MPI_COMM_WORLD. Aborts if called before init.

Arguments

None

Return Value integer

public function mpi_world() result(comm)

Return the world communicator handle. Convenience accessor so call sites never reference MPI_COMM_WORLD directly. Always call this function at the point of use rather than caching the return value, so the call site stays correct once sub-communicators are introduced.

Arguments

None

Return Value integer

public pure function mpi_proc_null_value() result(v)

Expose MPI_PROC_NULL as a value so callers that don't use mpi* themselves can compare against it.

Arguments

None

Return Value integer


Subroutines

public subroutine mpi_runtime_init()

Initialise the MPI library and cache rank/size.

Read more…

Arguments

None

public subroutine mpi_runtime_finalize()

Finalise the MPI library. Idempotent: a second call is a no-op.

Arguments

None

public subroutine parallel_fatal(message)

Abort the entire MPI world with a diagnostic message.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: message