Resolve the communicator a new decomposition will run on and register it with the process-wide lifecycle bookkeeping.
With comm present the caller (e.g. mpi4py) already owns MPI and SELF
calls neither MPI_Init nor MPI_Finalize. Without it SELF falls back to
MPI_COMM_WORLD, initializing MPI only if nobody else has yet.
Shared by the CPU and GPU DomainDecomposition Init implementations so the two cannot drift apart.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(out) | :: | mpiComm | |||
| logical, | intent(out) | :: | ownsMpi | |||
| integer, | intent(in), | optional | :: | comm |
subroutine AcquireMPI(mpiComm,ownsMpi,comm)
!! Resolve the communicator a new decomposition will run on and register it
!! with the process-wide lifecycle bookkeeping.
!!
!! With `comm` present the caller (e.g. mpi4py) already owns MPI and SELF
!! calls neither MPI_Init nor MPI_Finalize. Without it SELF falls back to
!! MPI_COMM_WORLD, initializing MPI only if nobody else has yet.
!!
!! Shared by the CPU and GPU DomainDecomposition Init implementations so the
!! two cannot drift apart.
implicit none
integer,intent(out) :: mpiComm
logical,intent(out) :: ownsMpi
integer,intent(in),optional :: comm
! Local
integer :: ierror
logical :: mpiIsInitialized
call MPI_Initialized(mpiIsInitialized,ierror)
if(present(comm)) then
! The caller (e.g. mpi4py) owns the MPI lifecycle and provides the communicator.
if(.not. mpiIsInitialized) then
error stop __FILE__//" : A communicator was provided but MPI is not initialized."// &
" Initialize MPI (e.g. via mpi4py or MPI_Init) before creating a mesh with an external communicator."
endif
mpiComm = comm
else
mpiComm = MPI_COMM_WORLD
if(.not. mpiIsInitialized) then
print*,__FILE__," : Initializing MPI"
call mpi_init(ierror)
selfInitializedMpi = .true.
endif
endif
nLiveDecomps = nLiveDecomps+1
ownsMpi = selfInitializedMpi
endsubroutine AcquireMPI