create_comm_from_handle Function

private function create_comm_from_handle(fhandle) result(comm)

Builds an OWNED comm_t from a caller’s Fortran MPI communicator handle.

Under the legacy mpi module a communicator already IS this integer, so no conversion is needed – but the duplication still is. See the mpi_f08 backend for the full rationale: the result owns its communicator, so finalize frees pic-mpi’s copy and never the caller’s.

COLLECTIVE over the communicator fhandle names, because MPI_Comm_dup is: every rank in that communicator must call this, together.

A handle naming MPI_COMM_NULL returns an invalid comm_t and makes no MPI call.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: fhandle

Return Value type(comm_t)


Calls

proc~~create_comm_from_handle~3~~CallsGraph proc~create_comm_from_handle~3 create_comm_from_handle mpi_comm_dup mpi_comm_dup proc~create_comm_from_handle~3->mpi_comm_dup proc~create_comm_from_mpi~3 create_comm_from_mpi proc~create_comm_from_handle~3->proc~create_comm_from_mpi~3 proc~create_null_comm~3 create_null_comm proc~create_comm_from_handle~3->proc~create_null_comm~3 mpi_comm_rank mpi_comm_rank proc~create_comm_from_mpi~3->mpi_comm_rank mpi_comm_size mpi_comm_size proc~create_comm_from_mpi~3->mpi_comm_size

Called by

proc~~create_comm_from_handle~3~~CalledByGraph proc~create_comm_from_handle~3 create_comm_from_handle interface~comm_from_handle~3 comm_from_handle interface~comm_from_handle~3->proc~create_comm_from_handle~3

Variables

Type Visibility Attributes Name Initial
integer, private :: dup_comm
integer(kind=int32), private :: ierr

Source Code

   function create_comm_from_handle(fhandle) result(comm)
   !! Builds an OWNED comm_t from a caller's Fortran MPI communicator handle.
   !!
   !! Under the legacy `mpi` module a communicator already IS this integer,
   !! so no conversion is needed -- but the duplication still is. See the
   !! mpi_f08 backend for the full rationale: the result owns its
   !! communicator, so `finalize` frees pic-mpi's copy and never the
   !! caller's.
   !!
   !! COLLECTIVE over the communicator `fhandle` names, because MPI_Comm_dup
   !! is: every rank in that communicator must call this, together.
   !!
   !! A handle naming MPI_COMM_NULL returns an invalid comm_t and makes no
   !! MPI call.
      integer, intent(in) :: fhandle
      type(comm_t) :: comm
      integer :: dup_comm
      integer(int32) :: ierr

      if (fhandle == MPI_COMM_NULL) then
         comm = create_null_comm()
         return
      end if

      call MPI_Comm_dup(fhandle, dup_comm, ierr)
      comm = create_comm_from_mpi(dup_comm)

   end function create_comm_from_handle