init_comm Subroutine

private subroutine init_comm(comm, total_procs, rank, is_rank0, comm_in)

Initialise a communicator and associated variables

Defaults to using MPI_COMM_WORLD, but can be set to another communicator comm_in.

Arguments

Type IntentOptional Attributes Name
integer, intent(out) :: comm

Communicator to initialise

integer, intent(out) :: total_procs

Total number of processors in communicator

integer, intent(out) :: rank

This processor's rank

logical, intent(out) :: is_rank0

True if this processor's rank is zero

integer, intent(inout), optional :: comm_in

Communicator to use instead of MPI_COMM_WORLD: if this is MPI_COMM_NULL, this is also initialised to MPI_COMM_WORLD


Contents

Source Code


Source Code

  subroutine init_comm(comm, total_procs, rank, is_rank0, comm_in)
    !> Communicator to initialise
    integer, intent(out) :: comm
    !> Total number of processors in communicator
    integer, intent(out) :: total_procs
    !> This processor's rank
    integer, intent(out) :: rank
    !> True if this processor's rank is zero
    logical, intent(out) :: is_rank0
    !> Communicator to use instead of `MPI_COMM_WORLD`: if this is
    !> `MPI_COMM_NULL`, this is also initialised to `MPI_COMM_WORLD`
    integer, intent(inout), optional :: comm_in

    integer :: ierror

    if (present(comm_in)) then
      if (comm_in == mp_comm_null) then
        comm_in = mpi_comm_world
      end if
      comm = comm_in
    else
      comm = mpi_comm_world
    end if

!$OMP MASTER
    call time_message(.false., time_mp_other, ' MPI Overheads')
!$OMP END MASTER

    call mpi_comm_size(comm, total_procs, ierror)
    call mpi_comm_rank(comm, rank, ierror)
    is_rank0 = (rank == 0)

!$OMP MASTER
    call time_message(.false., time_mp_other, ' MPI Overheads')
!$OMP END MASTER
  end subroutine init_comm