ESMF_ReconcileZapProxies Subroutine

private subroutine ESMF_ReconcileZapProxies(state, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_State), intent(inout) :: state
integer, intent(out), optional :: rc

Calls

proc~~esmf_reconcilezapproxies~~CallsGraph proc~esmf_reconcilezapproxies ESMF_ReconcileZapProxies esmf_stateremove esmf_stateremove proc~esmf_reconcilezapproxies->esmf_stateremove interface~esmf_containerget~2 ESMF_ContainerGet proc~esmf_reconcilezapproxies->interface~esmf_containerget~2 proc~esmf_isproxy ESMF_IsProxy proc~esmf_reconcilezapproxies->proc~esmf_isproxy proc~esmf_logfounderror ESMF_LogFoundError proc~esmf_reconcilezapproxies->proc~esmf_logfounderror proc~esmf_stateitemget ESMF_StateItemGet proc~esmf_reconcilezapproxies->proc~esmf_stateitemget proc~esmf_containergetfield ESMF_ContainerGetField interface~esmf_containerget~2->proc~esmf_containergetfield proc~esmf_containergetfieldlist ESMF_ContainerGetFieldList interface~esmf_containerget~2->proc~esmf_containergetfieldlist proc~esmf_containergetfieldlistall ESMF_ContainerGetFieldListAll interface~esmf_containerget~2->proc~esmf_containergetfieldlistall proc~esmf_isproxy->proc~esmf_logfounderror c_esmc_isproxy c_esmc_isproxy proc~esmf_isproxy->c_esmc_isproxy proc~esmf_logseterror ESMF_LogSetError proc~esmf_isproxy->proc~esmf_logseterror esmf_breakpoint esmf_breakpoint proc~esmf_logfounderror->esmf_breakpoint proc~esmf_logrc2msg ESMF_LogRc2Msg proc~esmf_logfounderror->proc~esmf_logrc2msg proc~esmf_logwrite ESMF_LogWrite proc~esmf_logfounderror->proc~esmf_logwrite proc~esmf_stateitemget->proc~esmf_logfounderror esmf_arrayget esmf_arrayget proc~esmf_stateitemget->esmf_arrayget esmf_fieldbundleget esmf_fieldbundleget proc~esmf_stateitemget->esmf_fieldbundleget esmf_fieldget esmf_fieldget proc~esmf_stateitemget->esmf_fieldget interface~esmf_arraybundleget ESMF_ArrayBundleGet proc~esmf_stateitemget->interface~esmf_arraybundleget interface~esmf_routehandleget ESMF_RouteHandleGet proc~esmf_stateitemget->interface~esmf_routehandleget proc~esmf_stateitemget->proc~esmf_logseterror

Called by

proc~~esmf_reconcilezapproxies~~CalledByGraph proc~esmf_reconcilezapproxies ESMF_ReconcileZapProxies proc~esmf_reconcileinitialize ESMF_ReconcileInitialize proc~esmf_reconcileinitialize->proc~esmf_reconcilezapproxies proc~esmf_statereconcile_driver ESMF_StateReconcile_driver proc~esmf_statereconcile_driver->proc~esmf_reconcileinitialize proc~esmf_statereconcile ESMF_StateReconcile proc~esmf_statereconcile->proc~esmf_statereconcile_driver

Source Code

    subroutine ESMF_ReconcileZapProxies(state, rc)
!
! !ARGUMENTS:
      type(ESMF_State), intent(inout)         :: state
      integer,          intent(out), optional :: rc
!
! !DESCRIPTION:
!   All top-level proxy objects (regardless of type) are identified and removed
!   from {\tt state}. Information about the zapped proxies is kept in the State
!   for later handling during the companion method ESMF_ReconcileZappedProxies().
!
!   The arguments are:
!   \begin{description}
!   \item[state]
!     The State from which to zap proxies.
!   \item[{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOPI
      integer                             :: localrc, i
      type(ESMF_StateClass),      pointer :: stypep
      type(ESMF_StateItemWrap),   pointer :: itemList(:)
      character(len=ESMF_MAXSTR)          :: thisname
      type(ESMF_FieldType),       pointer :: fieldp
      type(ESMF_FieldBundleType), pointer :: fbpthis
#ifdef RECONCILE_ZAP_LOG_on
      character(len=160)                  :: msgString
#endif

      ! Initialize return code; assume routine not implemented
      if (present(rc)) rc = ESMF_RC_NOT_IMPL
      localrc = ESMF_RC_NOT_IMPL

      stypep => state%statep

#ifdef RECONCILE_ZAP_LOG_on
      call ESMF_VMLogGarbageInfo(prefix="ZapProxies bef: ", &
        logMsgFlag=ESMF_LOGMSG_DEBUG, rc=localrc)
#endif

      itemList => null ()
      call ESMF_ContainerGet(container=stypep%stateContainer, itemList=itemList, &
        rc=localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, &
        rcToReturn=rc)) return

      stypep%zapFlag => null()
          
      if (associated(itemList)) then
        allocate(stypep%zapFlag(size(itemList)))
        stypep%zapFlag = .false.
        ! Zap all proxies
        do i=1, size(itemList)
          ! First ensure the proxyFlag for the current object in the local
          ! State is set correctly. Each object internally (in Base) knows
          ! if it was created as a proxy or not. However, the local State
          ! might not correctly track this if the proxy object was created
          ! under a different State and then copied over into this State.
          ! This can happen e.g. under NUOPC when Fields or FieldBuindles
          ! from a smaller VM are shared with a larger VM. Then on the extra
          ! PETs the sharing protocol creates proxies using a temporary State
          ! which then are copied into the actual import/exportState seen in
          ! a later Reconcile.
          ! The only use cases are Field and FieldBundle objects under State.
          if (itemList(i)%si%otype==ESMF_STATEITEM_FIELD) then
            fieldp => itemList(i)%si%datap%fp%ftypep
            call ESMF_StateItemGet(itemList(i)%si, name=thisname, rc=localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, &
              rcToReturn=rc)) return

#ifdef RECONCILE_ZAP_LOG_on
write(msgString,*) "ESMF_ReconcileZapProxies Field proxyFlag(old): "//&
  trim(thisname), itemList(i)%si%proxyFlag
call ESMF_LogWrite(msgString, ESMF_LOGMSG_DEBUG, rc=localrc)
#endif

            ! determine proxyFlag from Base level
            itemList(i)%si%proxyFlag = ESMF_IsProxy(fieldp%base, rc=localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
              ESMF_CONTEXT,  &
              rcToReturn=rc)) return

#ifdef RECONCILE_ZAP_LOG_on
write(msgString,*) "ESMF_ReconcileZapProxies Field proxyFlag(new): "//&
  trim(thisname), itemList(i)%si%proxyFlag
call ESMF_LogWrite(msgString, ESMF_LOGMSG_DEBUG, rc=localrc)
#endif

          else if (itemList(i)%si%otype==ESMF_STATEITEM_FIELDBUNDLE) then
            fbpthis => itemList(i)%si%datap%fbp%this
            call ESMF_StateItemGet(itemList(i)%si, name=thisname, rc=localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, &
              rcToReturn=rc)) return

#ifdef RECONCILE_ZAP_LOG_on
write(msgString,*) "ESMF_ReconcileZapProxies FieldBundle proxyFlag(old): "//&
  trim(thisname), itemList(i)%si%proxyFlag
call ESMF_LogWrite(msgString, ESMF_LOGMSG_DEBUG, rc=localrc)
#endif

            ! determine proxyFlag from Base level
            itemList(i)%si%proxyFlag = ESMF_IsProxy(fbpthis%base, rc=localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
              ESMF_CONTEXT,  &
              rcToReturn=rc)) return

#ifdef RECONCILE_ZAP_LOG_on
write(msgString,*) "ESMF_ReconcileZapProxies FieldBundle proxyFlag(new): "//&
  trim(thisname), itemList(i)%si%proxyFlag
call ESMF_LogWrite(msgString, ESMF_LOGMSG_DEBUG, rc=localrc)
#endif

          endif
          ! Now the local State proxyFlag is consistent and can be used to
          ! determine whether the current object needs to be zapped or not.
          if (itemList(i)%si%proxyFlag) then
            stypep%zapFlag(i) = .true.  ! keep record about zapping
            call ESMF_StateItemGet(itemList(i)%si, name=thisname, rc=localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, &
              rcToReturn=rc)) return
            ! Remove proxy object from state using its name. This is safe b/c
            ! a state only allows items with unique names.
            call ESMF_StateRemove (state, itemNameList=(/thisname/), rc=localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, ESMF_CONTEXT, &
              rcToReturn=rc)) return
#ifdef RECONCILE_ZAP_LOG_on
write(msgString,*) "ESMF_ReconcileZapProxies zapping from State: "//&
  trim(thisname)
call ESMF_LogWrite(msgString, ESMF_LOGMSG_DEBUG, rc=localrc)
#endif
          end if
        end do
      endif

      stypep%zapList => itemList ! hang on for ESMF_ReconcileZappedProxies()

#ifdef RECONCILE_ZAP_LOG_on
      call ESMF_VMLogGarbageInfo(prefix="ZapProxies aft: ", &
        logMsgFlag=ESMF_LOGMSG_DEBUG, rc=localrc)
#endif

      if (present(rc)) rc = ESMF_SUCCESS
    end subroutine ESMF_ReconcileZapProxies