subroutine ESMF_ReconcileInitialize (state, vm, &
siwrap, nitems_all, rc)
!
! !ARGUMENTS:
type (ESMF_State), intent(inout) :: state
type (ESMF_VM), intent(in) :: vm
type (ESMF_StateItemWrap), pointer :: siwrap(:) ! intent(out)
integer, pointer :: nitems_all(:) ! intent(out)
integer, intent(out) :: rc
!
! !DESCRIPTION:
!
! The arguments are:
! \begin{description}
! \item[state]
! {\tt ESMF\_State} to collect information from.
! \item[rc]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!EOPI
integer :: localrc
integer :: memstat
integer :: nitems_local(1)
integer :: mypet, npets
logical, parameter :: profile = .false.
localrc = ESMF_RC_NOT_IMPL
if (associated (siwrap) .or. associated (nitems_all)) then
if (ESMF_LogFoundError(ESMF_RC_ARG_BAD, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
end if
call ESMF_VMGet(vm, localPet=mypet, petCount=npets, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
! Brute force removal of all existing proxies from the State
! to handle the re-reconcile case. If State items were removed
! between reconciles, there should be no proxies for them.
!
! TODO: Consider maintaining a flag in the state. Perform
! a communication step to see if any removals have taken place.
! Conditionally zap the proxies depending on whether it is actually
! needed.
if (profile) then
call ESMF_TraceRegionEnter("ESMF_ReconcileZapProxies", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
endif
call ESMF_ReconcileZapProxies (state, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
if (profile) then
call ESMF_TraceRegionExit("ESMF_ReconcileZapProxies", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
endif
! Obtain local PET item list
siwrap => null ()
call ESMF_ContainerGet (state%statep%stateContainer, &
itemList=siwrap, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
if (associated (siwrap)) then
nitems_local(1) = size (siwrap)
else
nitems_local(1) = 0
end if
! All PETs send their item counts to all the other PETs for recv array sizing.
allocate (nitems_all(0:npets-1), stat=memstat)
if (ESMF_LogFoundAllocError(memstat, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
if (profile) then
call ESMF_TraceRegionEnter("ESMF_VMAllGather", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
endif
call ESMF_VMAllGather (vm, &
sendData=nitems_local, recvData=nitems_all, &
count=1, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
if (profile) then
call ESMF_TraceRegionExit("ESMF_VMAllGather", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
endif
end subroutine ESMF_ReconcileInitialize