locate_batch_slot Subroutine

public pure subroutine locate_batch_slot(self, slot, segment, local_index)

global slot から (segment, segment 内 index) を求める。O(nsegments) で、slot ごとの表を持たない。

Type Bound

batch_injection_layout_type

Arguments

Type IntentOptional Attributes Name
class(batch_injection_layout_type), intent(in) :: self
integer(kind=i32), intent(in) :: slot

1..total_slots の global slot。

integer(kind=i32), intent(out) :: segment

slot が属する segment。

integer(kind=i32), intent(out) :: local_index

slot が属する segment。 segment 内の 1 始まり index。


Source Code

  pure subroutine locate_batch_slot(self, slot, segment, local_index)
    class(batch_injection_layout_type), intent(in) :: self
    integer(i32), intent(in) :: slot
    integer(i32), intent(out) :: segment, local_index
    integer(i32) :: band, active, offset, rank_in_round, g

    band = 1_i32
    do while (self%band_last_slot(band) < slot)
      band = band + 1_i32
    end do
    active = count(self%segment_end - self%segment_begin + 1_i32 >= self%band_length(band))
    offset = slot - self%band_last_slot(band - 1_i32) - 1_i32
    local_index = self%band_length(band - 1_i32) + offset/active + 1_i32
    rank_in_round = mod(offset, active) + 1_i32
    segment = 0_i32
    do g = 1_i32, self%nsegments
      if (self%segment_end(g) - self%segment_begin(g) + 1_i32 < self%band_length(band)) cycle
      rank_in_round = rank_in_round - 1_i32
      if (rank_in_round == 0_i32) then
        segment = g
        return
      end if
    end do
  end subroutine locate_batch_slot