program ESMF_StateReconcileEx
!EOC
!==============================================================================
!
! !PROGRAM: ESMF_StateReconcileEx - State reconciliation
!
! !DESCRIPTION:
!
! This program shows examples of using the State Reconcile function
!-----------------------------------------------------------------------------
#include "ESMF.h"
! ESMF Framework module
use ESMF
use ESMF_TestMod
use ESMF_StateReconcileEx_Mod
implicit none
! Local variables
integer :: rc, petCount
type(ESMF_State) :: state
!BOC
! ... other local variables ...
type(ESMF_GridComp) :: comp
!EOC
type(ESMF_VM) :: vm
integer :: finalrc, result
character(ESMF_MAXSTR) :: testname
character(ESMF_MAXSTR) :: failMsg
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
write(failMsg, *) "Example failure"
write(testname, *) "Example ESMF_StateReconcileEx"
! ------------------------------------------------------------------------------
! ------------------------------------------------------------------------------
finalrc = ESMF_SUCCESS
call ESMF_Initialize(vm=vm, defaultlogfilename="StateReconcileEx.Log", &
logkindflag=ESMF_LOGKIND_MULTI, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
! verify that this example can run on the given petCount
call ESMF_VMGet(vm, petCount=petCount, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
if (petCount<4) then
print *, "This test must run on at least 4 PETs."
finalrc = ESMF_FAILURE
goto 20
endif
!BOC
comp = ESMF_GridCompCreate(name="MyComp", petList=[0,1], rc=rc)
!EOC
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!BOE
! Here {\tt comp} is created to execute on two PETs: 0 and 1.
!
! Next the Component {\tt SetServices} method is called to register the
! custom component method(s).
!EOE
!BOC
call ESMF_GridCompSetServices(comp, userRoutine=SetServices, rc=rc)
!EOC
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!BOE
! Now a State is created that can be passed in when the registered Component
! method is called.
!EOE
!BOC
state = ESMF_StateCreate(rc=rc)
!EOC
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!BOE
! The {\tt state} object is used as the Component's {\tt exportState}.
!EOE
!BOC
call ESMF_GridCompInitialize(comp, exportState=state, rc=rc)
!EOC
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!BOE
! Once control of execution has returned from the pevious
! {\tt ESMF\_GridCompInitialize()} call, the {\tt state} object is in an
! inconsistent state across the PETs of the current (main program) context.
! This is because Fields were added on PETs 0 and 1, but not on the remaining
! PETs (2 and 3). This situation can easliy be observed by writing the current
! {\tt state} to the ESMF log.
!EOE
!BOC
call ESMF_StateLog(state, prefix="Before Reconcile:", rc=rc)
!EOC
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!BOE
! To reconcile {\tt state} across all of the PETs, use the
! {\tt ESMF\_StateReconcile()} method.
!EOE
!BOC
call ESMF_StateReconcile(state, rc=rc)
!EOC
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!BOE
! The output of {\tt state} to the ESMF log shows that the object is now
! consistent across all PETs. I.e. {\tt state} contains identical items on
! all of the PETs.
!EOE
!BOC
call ESMF_StateLog(state, prefix="After Reconcile:", rc=rc)
!EOC
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!-------------------------------------------------------------------------
call ESMF_StateDestroy (state, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
call ESMF_GridCompDestroy (comp, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
20 continue
! IMPORTANT: ESMF_STest() prints the PASS string and the # of processors in the log
! file that the scripts grep for.
call ESMF_STest((finalrc.eq.ESMF_SUCCESS), testname, failMsg, result, ESMF_SRCLINE)
call ESMF_Finalize(rc=rc)
if (rc.NE.ESMF_SUCCESS) finalrc = ESMF_FAILURE
if (finalrc.EQ.ESMF_SUCCESS) then
print *, "PASS: ESMF_StateReconcileEx.F90"
else
print *, "FAIL: ESMF_StateReconcileEx.F90"
end if
!BOC
end program ESMF_StateReconcileEx