mpi_shared_counter_type Derived Type

type, public :: mpi_shared_counter_type

rank 0 が保持する 64 bit カウンタを全 rank が fetch-and-add で取り合う、バッチ粒子 slot pool の claim 窓口。 claim は OpenMP の critical 区間から呼ぶ前提で、MPI は MPI_THREAD_SERIALIZED 以上を要求する。 非 MPI build や 1 rank では rank 内のカウンタに落ちる。


Components

Type Visibility Attributes Name Initial
logical, public :: active = .false.
logical, public :: distributed = .false.
logical, public :: hosts_window = .false.

この rank が窓を持つ(rank 0)。remote の fetch-and-add は窓を持つ rank の MPI 進行で処理される。

logical, public :: prefetch_pending = .false.

次の chunk の fetch-and-add を先に発行してある(結果は prefetch_result)。

integer(kind=i64), public :: local_value = 0_i64

Type-Bound Procedures

procedure, public :: init => shared_counter_init

  • private subroutine shared_counter_init(self, ctx)

    rank 0 に 1 要素の RMA 窓を作り、全 rank で passive-target lock を張る(collective)。

    Arguments

    Type IntentOptional Attributes Name
    class(mpi_shared_counter_type), intent(inout) :: self
    type(mpi_context), intent(in) :: ctx

procedure, public :: reset => shared_counter_reset

  • private subroutine shared_counter_reset(self, ctx)

    カウンタを 0 に戻す(collective)。前バッチの claim が全て終わってから呼ぶ。

    Arguments

    Type IntentOptional Attributes Name
    class(mpi_shared_counter_type), intent(inout) :: self
    type(mpi_context), intent(in) :: ctx

procedure, public :: claim => shared_counter_claim

  • private subroutine shared_counter_claim(self, count, first)

    count 個を確保し、確保前のカウンタ値(0 始まりの先頭 slot)を返す。

    Arguments

    Type IntentOptional Attributes Name
    class(mpi_shared_counter_type), intent(inout) :: self
    integer(kind=i64), intent(in) :: count
    integer(kind=i64), intent(out) :: first

procedure, public :: progress => shared_counter_progress

  • private subroutine shared_counter_progress(self)

    窓を持つ rank が MPI の進行エンジンを回し、他 rank から届いた fetch-and-add を処理する。 passive-target RMA は target が MPI を呼ばないと進まないので、rank 0 の粒子ループから定期的に呼ぶ。

    Arguments

    Type IntentOptional Attributes Name
    class(mpi_shared_counter_type), intent(inout) :: self

procedure, public :: complete_prefetch => shared_counter_complete_prefetch

  • private subroutine shared_counter_complete_prefetch(self)

    先行発行した fetch-and-add があれば完了させて捨てる(barrier の前に呼ぶ)。

    Arguments

    Type IntentOptional Attributes Name
    class(mpi_shared_counter_type), intent(inout) :: self

procedure, public :: destroy => shared_counter_destroy

  • private subroutine shared_counter_destroy(self)

    RMA 窓を解放する(collective。init した全 rank が呼ぶ)。

    Arguments

    Type IntentOptional Attributes Name
    class(mpi_shared_counter_type), intent(inout) :: self

Source Code

  type, public :: mpi_shared_counter_type
    logical :: active = .false.
    logical :: distributed = .false.
    !> この rank が窓を持つ(rank 0)。remote の fetch-and-add は窓を持つ rank の MPI 進行で処理される。
    logical :: hosts_window = .false.
    !> 次の chunk の fetch-and-add を先に発行してある(結果は `prefetch_result`)。
    logical :: prefetch_pending = .false.
    integer(i64) :: local_value = 0_i64
#ifdef USE_MPI
    integer :: win = MPI_WIN_NULL
#endif
  contains
    procedure :: init => shared_counter_init
    procedure :: reset => shared_counter_reset
    procedure :: claim => shared_counter_claim
    procedure :: progress => shared_counter_progress
    procedure :: complete_prefetch => shared_counter_complete_prefetch
    procedure :: destroy => shared_counter_destroy
  end type mpi_shared_counter_type