comm_t Derived Type

type, public :: comm_t

MPI communicator wrapper type

Provides object-oriented interface to MPI communicators with type-bound procedures for common operations. Automatically caches rank and size information for efficient access.


Inherits

type~~comm_t~2~~InheritsGraph type~comm_t~2 comm_t MPI_Comm MPI_Comm type~comm_t~2->MPI_Comm m_comm

Components

Type Visibility Attributes Name Initial
logical, private :: is_valid = .false.

Validity flag

type(MPI_Comm), private :: m_comm = MPI_COMM_NULL

Internal MPI communicator

integer(kind=int32), private :: m_rank = -1

Cached rank in this communicator

integer(kind=int32), private :: m_size = -1

Cached size of this communicator


Type-Bound Procedures

procedure, public :: barrier => comm_barrier

Synchronization barrier

  • private subroutine comm_barrier(this)

    Blocks until all processes in the communicator have called barrier

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this

procedure, public :: discard_leader => comm_discard_leader

Create communicator without leader

  • private function comm_discard_leader(this) result(new_comm)

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this

    Return Value type(comm_t)

procedure, public :: discard_to => comm_discard_to

Create communicator with first N ranks

  • private function comm_discard_to(this, num_ranks) result(new_comm)

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this
    integer, intent(in) :: num_ranks

    Return Value type(comm_t)

procedure, public :: duplicate => comm_duplicate

Duplicate communicator

  • private function comm_duplicate(this) result(new_comm)

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this

    Return Value type(comm_t)

procedure, public :: finalize => comm_finalize

Free communicator resources

  • private subroutine comm_finalize(this)

    Frees the MPI communicator resources

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(inout) :: this

procedure, public :: get => comm_get

Get underlying MPI_Comm

  • private function comm_get(this) result(mpi_comm_out)

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this

    Return Value type(MPI_Comm)

procedure, public :: is_null => comm_is_null

Check if communicator is null

  • private pure function comm_is_null(this) result(is_null)

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this

    Return Value logical

procedure, public :: leader => comm_leader

Check if this rank is leader (rank 0)

  • private pure function comm_leader(this) result(is_leader)

    Returns true if the calling process has rank 0

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this

    Return Value logical

procedure, public :: rank => comm_rank

Get rank in communicator

  • private pure function comm_rank(this) result(rank)

    Returns the 0-indexed rank of the calling process

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this

    Return Value integer

procedure, public :: size => m_size_func

Get size of communicator

  • private pure function m_size_func(this) result(size)

    Returns the number of processes in the communicator

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this

    Return Value integer

procedure, public :: split => comm_split_shared

Split into shared memory communicators

  • private function comm_split_shared(this) result(new_comm)

    Creates a new communicator containing only processes that share memory with each other (typically processes on the same node)

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this

    Return Value type(comm_t)

procedure, public :: split_by => comm_split_by_color

Split communicator by color

  • private function comm_split_by_color(this, color) result(new_comm)

    Partitions the communicator into disjoint subgroups based on color. Processes with the same color end up in the same new communicator.

    Arguments

    Type IntentOptional Attributes Name
    class(comm_t), intent(in) :: this
    integer, intent(in) :: color

    Return Value type(comm_t)

Source Code

   type :: comm_t
      !! MPI communicator wrapper type
      !!
      !! Provides object-oriented interface to MPI communicators with
      !! type-bound procedures for common operations. Automatically caches
      !! rank and size information for efficient access.
      private
      type(MPI_Comm) :: m_comm = MPI_COMM_NULL !! Internal MPI communicator
      integer(int32) :: m_rank = -1 !! Cached rank in this communicator
      integer(int32) :: m_size = -1 !! Cached size of this communicator
      logical :: is_valid = .false. !! Validity flag
   contains
      procedure :: rank => comm_rank !! Get rank in communicator
      procedure :: size => m_size_func !! Get size of communicator
      procedure :: leader => comm_leader !! Check if this rank is leader (rank 0)
      procedure :: is_null => comm_is_null !! Check if communicator is null
      procedure :: get => comm_get !! Get underlying MPI_Comm

      procedure :: barrier => comm_barrier !! Synchronization barrier

      procedure :: split => comm_split_shared !! Split into shared memory communicators
      procedure :: split_by => comm_split_by_color !! Split communicator by color
      procedure :: discard_leader => comm_discard_leader !! Create communicator without leader
      procedure :: discard_to => comm_discard_to !! Create communicator with first N ranks
      procedure :: duplicate => comm_duplicate !! Duplicate communicator

      procedure :: finalize => comm_finalize !! Free communicator resources
   end type comm_t