comm_env_global_comm Function

public function comm_env_global_comm() result(comm)

Return the cached global (world) communicator.

Use this instead of pic_mpi_lib::comm_world() from inside per-step code: comm_world() does an MPI_Comm_dup on every call, and that dup is collective on MPI_COMM_WORLD. Calling it from a routine that runs on only some ranks (e.g. the I/O client send path, which compute ranks hit but the I/O server does not) deadlocks. comm_global is duplicated exactly once by comm_env_init on every rank, so handing it out is free.

Arguments

None

Return Value type(comm_t)


Calls

proc~~comm_env_global_comm~~CallsGraph proc~comm_env_global_comm comm_env_global_comm comm_world comm_world proc~comm_env_global_comm->comm_world

Source Code

   function comm_env_global_comm() result(comm)
      !! Return the cached global (world) communicator.
      !!
      !! Use this instead of `pic_mpi_lib::comm_world()` from inside
      !! per-step code: `comm_world()` does an `MPI_Comm_dup` on every
      !! call, and that dup is collective on `MPI_COMM_WORLD`.  Calling
      !! it from a routine that runs on only some ranks (e.g. the I/O
      !! client send path, which compute ranks hit but the I/O server
      !! does not) deadlocks.  `comm_global` is duplicated exactly once
      !! by `comm_env_init` on every rank, so handing it out is free.
      type(comm_t) :: comm
      if (cached_rank >= 0) then
         comm = comm_global
      else
         comm = comm_world()
      end if
   end function comm_env_global_comm