subroutine ESMF_StateReconcile(state, vm, rc)
!
! !ARGUMENTS:
type(ESMF_State), intent(inout) :: state
type(ESMF_VM), intent(in), optional :: vm
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Must be called for any {\tt ESMF\_State} which contains ESMF objects
! that have not been created on all the {\tt PET}s of the currently
! running {\tt ESMF\_Component}.
! For example, if a coupler is operating on data
! which was created by another component that ran on only a subset
! of the couplers {\tt PET}s, the coupler must make this call first
! before operating on any data inside that {\tt ESMF\_State}.
! After calling {\tt ESMF\_StateReconcile} all {\tt PET}s will have
! a common view of all objects contained in this {\tt ESMF\_State}.
!
! This call is collective across the specified VM.
!
! The arguments are:
! \begin{description}
! \item[state]
! {\tt ESMF\_State} to reconcile.
! \item[{[vm]}]
! {\tt ESMF\_VM} for this {\tt ESMF\_Component}. By default, it is set to the current vm.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
integer :: localrc
type(ESMF_VM) :: localvm
type(ESMF_AttReconcileFlag) :: lattreconflag
type(ESMF_InfoDescribe) :: idesc
logical, parameter :: profile = .false.
! check input variables
ESMF_INIT_CHECK_DEEP(ESMF_StateGetInit,state,rc)
ESMF_INIT_CHECK_DEEP(ESMF_VMGetInit,vm,rc)
! Initialize return code; assume routine not implemented
if (present(rc)) rc = ESMF_RC_NOT_IMPL
localrc = ESMF_RC_NOT_IMPL
if (present (vm)) then
localvm = vm
else
call ESMF_VMGetCurrent(vm=localvm, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
end if
! Each PET broadcasts the object ID lists and compares them to what
! they get back. Missing objects are sent so they can be recreated
! on the PETs without those objects as "proxy" objects. Eventually
! we might want to hash the ID lists so we can send a single number
! (or short list of numbers) instead of having to build and send the
! list each time.
! Attributes must be reconciled to de-deduplicate Field geometries
lattreconflag = ESMF_ATTRECONCILE_ON
if (profile) then
call ESMF_TraceRegionEnter("ESMF_StateReconcile_driver", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
endif
call ESMF_StateReconcile_driver (state, vm=localvm, &
attreconflag=lattreconflag, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
if (profile) then
call ESMF_TraceRegionExit("ESMF_StateReconcile_driver", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
endif
#if 0
! Log a JSON State representation -----------------------------------------
call idesc%Initialize(createInfo=.true., addObjectInfo=.true., rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=rc)) return
call idesc%Update(state, "", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_LogWrite("InfoDescribe before InfoCacheReassembleFields=", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_LogWrite("state_json_before_reassemble="//ESMF_InfoDump(idesc%info), rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=rc)) return
call idesc%Destroy(rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=rc)) return
#endif
if (profile) then
call ESMF_TraceRegionEnter("ESMF_InfoCacheReassembleFields", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
endif
! Traverse the State hierarchy and fix Field references to a shared geometry
call ESMF_InfoCacheReassembleFields(state, state, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=rc)) return
! Traverse the state hierarchy and remove reconcile-specific attributes
call ESMF_InfoCacheReassembleFieldsFinalize(state, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, rcToReturn=rc)) return
if (profile) then
call ESMF_TraceRegionExit("ESMF_InfoCacheReassembleFields", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, &
rcToReturn=rc)) return
endif
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_StateReconcile