subroutine ESMF_DistGridGetNumIds(distgrid, numIds, rc)
type(ESMF_DistGrid), intent(in) :: distgrid
integer, intent(out) :: numIds
integer, intent(out), optional :: rc
type(ESMF_DELayout) :: delayout
integer :: localDeCount,lDE,numDEIDs
integer :: localrc
! Get delayout from distgrid
call ESMF_DistGridGet(distgrid, delayout=delayout, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Get local number of DEs
call ESMF_DELayoutGet(delayout, localDECount=localDECount, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Iterate summing number of DEs
numIds=0
do lDE=0,localDECount-1
call ESMF_DistGridGet(distgrid,localDe=lDE, &
elementCount=numDEIds, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
numIds=numIds+numDEIds
enddo
end subroutine ESMF_DistGridGetNumIds