AcquireMPI Subroutine

public 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.

Arguments

TypeIntentOptionalAttributesName
integer, intent(out) :: mpiComm
logical, intent(out) :: ownsMpi
integer, intent(in), optional :: comm

Calls

proc~~acquirempi~~CallsGraph proc~acquirempi AcquireMPI mpi_initialized mpi_initialized proc~acquirempi->mpi_initialized mpi_init mpi_init proc~acquirempi->mpi_init

Called by

proc~~acquirempi~~CalledByGraph proc~acquirempi AcquireMPI proc~init_domaindecomposition_t Init_DomainDecomposition_t proc~init_domaindecomposition_t->proc~acquirempi proc~init_domaindecomposition Init_DomainDecomposition proc~init_domaindecomposition->proc~acquirempi

Contents

Source Code


Source Code

  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