MAPL_TileMaskGet Subroutine

public subroutine MAPL_TileMaskGet(GRID, mask, RC)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Grid), intent(inout) :: GRID
integer, pointer :: mask(:)
integer, intent(out), optional :: RC

Calls

proc~~mapl_tilemaskget~~CallsGraph proc~mapl_tilemaskget FileIOSharedMod::MAPL_TileMaskGet ESMF_DELayoutGet ESMF::ESMF_DELayoutGet proc~mapl_tilemaskget->ESMF_DELayoutGet ESMF_DistGridGet ESMF::ESMF_DistGridGet proc~mapl_tilemaskget->ESMF_DistGridGet ESMF_GridGet ESMF::ESMF_GridGet proc~mapl_tilemaskget->ESMF_GridGet ESMF_VMBarrier ESMF::ESMF_VMBarrier proc~mapl_tilemaskget->ESMF_VMBarrier ESMF_VMGet ESMF::ESMF_VMGet proc~mapl_tilemaskget->ESMF_VMGet interface~mapl_allocnodearray MAPL_Shmem::MAPL_AllocNodeArray proc~mapl_tilemaskget->interface~mapl_allocnodearray interface~mapl_am_i_root MAPL_CommsMod::MAPL_Am_I_Root proc~mapl_tilemaskget->interface~mapl_am_i_root interface~mapl_assert MAPL_ErrorHandlingMod::MAPL_Assert proc~mapl_tilemaskget->interface~mapl_assert interface~mapl_broadcasttonodes MAPL_Shmem::MAPL_BroadcastToNodes proc~mapl_tilemaskget->interface~mapl_broadcasttonodes interface~mapl_commsallgatherv MAPL_CommsMod::MAPL_CommsAllGatherV proc~mapl_tilemaskget->interface~mapl_commsallgatherv interface~mapl_commsgatherv MAPL_CommsMod::MAPL_CommsGatherV proc~mapl_tilemaskget->interface~mapl_commsgatherv interface~mapl_sort MAPL_SortMod::MAPL_Sort proc~mapl_tilemaskget->interface~mapl_sort interface~mapl_syncsharedmemory MAPL_Shmem::MAPL_SyncSharedMemory proc~mapl_tilemaskget->interface~mapl_syncsharedmemory proc~mapl_distgridget mapl_MaplGrid::MAPL_DistGridGet proc~mapl_tilemaskget->proc~mapl_distgridget proc~mapl_gridget mapl_MaplGrid::MAPL_GridGet proc~mapl_tilemaskget->proc~mapl_gridget proc~mapl_return MAPL_ErrorHandlingMod::MAPL_Return proc~mapl_tilemaskget->proc~mapl_return proc~mapl_verify MAPL_ErrorHandlingMod::MAPL_Verify proc~mapl_tilemaskget->proc~mapl_verify proc~mapl_distgridget->ESMF_DistGridGet proc~mapl_distgridget->proc~mapl_verify proc~mapl_gridget->ESMF_GridGet proc~mapl_gridget->proc~mapl_return proc~mapl_gridget->proc~mapl_verify ESMF_AttributeGet ESMF::ESMF_AttributeGet proc~mapl_gridget->ESMF_AttributeGet proc~mapl_gridhasde mapl_MaplGrid::MAPL_GridHasDE proc~mapl_gridget->proc~mapl_gridhasde at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_ThrowMod::MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception proc~mapl_gridhasde->ESMF_DELayoutGet proc~mapl_gridhasde->ESMF_DistGridGet proc~mapl_gridhasde->ESMF_GridGet proc~mapl_gridhasde->proc~mapl_return proc~mapl_gridhasde->proc~mapl_verify

Source Code

  subroutine MAPL_TileMaskGet(grid, mask, rc)
    type (ESMF_Grid),             intent(INout) :: GRID
    integer, pointer                            :: mask(:)
    integer,           optional , intent(  OUT) :: RC

! Local variables

    integer                               :: STATUS
    integer, pointer                      :: tileIndex(:)
    integer                               :: gcount(2), lcount(2)
    integer                               :: gsize, lsize
    integer                               :: gridRank
    integer                               :: n
    type (ESMF_DistGrid)                  :: distGrid

    integer,               allocatable    :: AL(:,:)
    integer,               allocatable    :: AU(:,:)
    integer, allocatable, dimension(:)    :: recvcounts, displs
    integer                               :: de, deId
    integer                               :: nDEs
    integer                               :: sendcount

    integer                               :: I
    integer                               :: I1, IN
    integer, allocatable                  :: var(:)
    type (ESMF_DELayout)                  :: layout

    type(ESMF_VM) :: vm
    logical :: amIRoot

    call ESMF_GridGet(grid, dimCount=gridRank, distGrid=distGrid, rc=status)
    _VERIFY(STATUS)
    _ASSERT(gridRank == 1, 'gridRank must be 1')

    call MAPL_GridGet(grid, globalCellCountPerDim=gcount, &
         localCellCountPerDim=lcount, RC=STATUS)
    _VERIFY(STATUS)

    gsize = gcount(1)
    lsize = lcount(1)

    call ESMF_DistGridGet(distgrid, localDe=0, elementCount=n, rc=status)
    _ASSERT(lsize == n, ' inconsistent lsize')

    allocate(tileIndex(lsize), stat=status)
    _VERIFY(STATUS)

    call ESMF_DistGridGet(distgrid, localDe=0, seqIndexList=tileIndex, rc=status)
    _VERIFY(STATUS)

    call ESMF_DistGridGet(distGRID, delayout=layout, rc=STATUS)
    _VERIFY(STATUS)
    call ESMF_DELayoutGet(layout, vm=vm, rc=status)
    _VERIFY(STATUS)
    call ESMF_VmGet(vm, localPet=deId, petCount=nDEs, rc=status)
    _VERIFY(STATUS)

    amIRoot = MAPL_AM_I_Root(vm)

    call ESMF_VmBarrier(vm, rc=status)
    _VERIFY(STATUS)

    if (.not. MAPL_ShmInitialized) then
       allocate(mask(gsize), stat=status)
       _VERIFY(STATUS)
    else
       call MAPL_AllocNodeArray(mask,(/gsize/),rc=STATUS)
       _VERIFY(STATUS)
    end if

    allocate (AL(gridRank,0:nDEs-1),  stat=status)
    _VERIFY(STATUS)
    allocate (AU(gridRank,0:nDEs-1),  stat=status)
    _VERIFY(STATUS)

    call MAPL_DistGridGet(distgrid, &
         minIndex=AL, maxIndex=AU, rc=status)
    _VERIFY(STATUS)

    allocate (recvcounts(0:nDEs-1), displs(0:nDEs), stat=status)
    _VERIFY(STATUS)

    if (.not. MAPL_ShmInitialized .or. amIRoot) then
       allocate(VAR(0:gsize-1), stat=status)
       _VERIFY(STATUS)
    else
       allocate(VAR(0), stat=status)
       _VERIFY(STATUS)
    end if

    displs(0) = 0
    do I = 0,nDEs-1
       de = I
       I1 = AL(1,I)
       IN = AU(1,I)

       recvcounts(I) = (IN - I1 + 1)
       if (de == deId) then
          sendcount = recvcounts(I)      ! Count I will send
       endif

       displs(I+1) = displs(I) + recvcounts(I)
    enddo

#ifdef NEW
    _FAIL( 'unsupported code block') !ALT this section is questionable
    do I = 0,nDEs-1
       de = I
       I1 = AL(1,I)
       IN = AU(1,I)
       var(I1:IN) = -9999
       if (de == deId) then
          var(I1:IN) = tileindex
       endif
       do II=I1,IN
          mmax=var(II)
          call MAPL_CommsAllReduceMax(vm, mmax, var(II), 1, rc=status)
          _VERIFY(STATUS)
       enddo
    end do
#else
    if (MAPL_ShmInitialized) then
       call MAPL_CommsGatherV(layout, tileindex, sendcount, &
                              var, recvcounts, displs, MAPL_Root, status)
       _VERIFY(STATUS)
    else
       call MAPL_CommsAllGatherV(layout, tileindex, sendcount, &
                                 var, recvcounts, displs, status)
       _VERIFY(STATUS)
    endif
#endif

    if (.not. MAPL_ShmInitialized .or. amIRoot) then
       do I = 0,nDEs-1
          mask(displs(I)+1:displs(I+1)) = I
       end do
       call MAPL_SORT(var,MASK)
    end if

! clean up

    deallocate(var)
    deallocate (recvcounts, displs)
    deallocate (AU)
    deallocate (AL)
    deallocate(tileIndex)

! mask is deallocated in the caller routine
       call MAPL_BroadcastToNodes(MASK, N=gsize, ROOT=MAPL_Root, rc=status)
       _VERIFY(STATUS)

    call MAPL_SyncSharedMemory(rc=status)
    _VERIFY(STATUS)

    _RETURN(ESMF_SUCCESS)
  end subroutine MAPL_TileMaskGet