tile_indices Function

public pure function tile_indices(dims)

Given input global array size, return start and end index of a parallel 1-d tile that correspond to this image. start and end indices assuming equal tile sizes if we have any remainder, distribute it to the tiles at the end

Arguments

Type IntentOptional AttributesName
integer(kind=ik), intent(in) :: dims

Return Value integer(kind=ik) (2)


Called by

proc~~tile_indices~~CalledByGraph proc~tile_indices tile_indices proc~train_batch train_batch proc~train_batch->proc~tile_indices

Contents

Source Code


Source Code

  pure function tile_indices(dims)
    !! Given input global array size, return start and end index
    !! of a parallel 1-d tile that correspond to this image.
    integer(ik), intent(in) :: dims
    integer(ik) :: tile_indices(2)
    integer(ik) :: offset, tile_size

    tile_size = dims / num_images()

    !! start and end indices assuming equal tile sizes
    tile_indices(1) = (this_image() - 1) * tile_size + 1
    tile_indices(2) = tile_indices(1) + tile_size - 1

    !! if we have any remainder, distribute it to the tiles at the end
    offset = num_images() - mod(dims, num_images())
    if (this_image() > offset) then
      tile_indices(1) = tile_indices(1) + this_image() - offset - 1
      tile_indices(2) = tile_indices(2) + this_image() - offset
    end if

  end function tile_indices