subroutine computeAreaMesh(mesh, vm, petNo, petCnt, area, rc)
type(ESMF_Mesh) :: mesh
type(ESMF_VM) :: VM
integer :: petNo,petCnt
real (ESMF_KIND_R8), pointer :: area(:)
integer :: rc
real (ESMF_KIND_R8), pointer :: localArea(:)
integer :: localrc
integer :: localElemCount,i
integer (ESMF_KIND_I4) :: localCount(1)
integer (ESMF_KIND_I4),pointer :: globalCount(:),globalDispl(:)
integer :: totalCount
! Get local size of mesh areas
call ESMF_MeshGet(mesh, numOwnedElements=localElemCount, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! allocate space for areas
allocate(localArea(localElemCount))
! Get local Areas
call ESMF_MeshGetElemArea(mesh, areaList=localArea, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Allocate List of counts
allocate(globalCount(petCnt))
! Get List of counts
localCount(1)=localElemCount
call ESMF_VMGather(vm,localCount,globalCount,count=1,rootPet=0,rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Calculate Displacements
allocate(globalDispl(petCnt))
if (petNo==0) then
globalDispl(1)=0
do i=2,petCnt
globalDispl(i)=globalDispl(i-1)+globalCount(i-1)
enddo
else
globalDispl=0
endif
! Sum size
if (petNo==0) then
totalCount=0
do i=1,petCnt
totalCount=totalCount+globalCount(i)
enddo
else
totalCount=1 ! Because I'm not sure what happens
! if array is not allocated in VM
endif
! Allocate final area list
allocate(area(totalCount))
! Gather all areas
call ESMF_VMGatherV(vm,sendData=localArea, sendCount=localElemCount,&
recvData=area,recvCounts=globalCount,recvOffsets=globalDispl,&
rootPet=0, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Get rid of helper variables
deallocate(localArea)
deallocate(globalCount)
deallocate(globalDispl)
if (petNo .ne. 0) deallocate(area)
end subroutine computeAreaMesh