ESMF_StateReconcileEx Program

Uses

  • program~~esmf_statereconcileex~~UsesGraph program~esmf_statereconcileex ESMF_StateReconcileEx module~esmf ESMF program~esmf_statereconcileex->module~esmf module~esmf_statereconcileex_mod ESMF_StateReconcileEx_Mod program~esmf_statereconcileex->module~esmf_statereconcileex_mod module~esmf_testmod ESMF_TestMod program~esmf_statereconcileex->module~esmf_testmod

Calls

program~~esmf_statereconcileex~~CallsGraph program~esmf_statereconcileex ESMF_StateReconcileEx esmf_gridcompsetservices esmf_gridcompsetservices program~esmf_statereconcileex->esmf_gridcompsetservices esmf_statecreate esmf_statecreate program~esmf_statereconcileex->esmf_statecreate esmf_statedestroy esmf_statedestroy program~esmf_statereconcileex->esmf_statedestroy esmf_statelog esmf_statelog program~esmf_statereconcileex->esmf_statelog interface~esmf_vmget ESMF_VMGet program~esmf_statereconcileex->interface~esmf_vmget proc~esmf_finalize ESMF_Finalize program~esmf_statereconcileex->proc~esmf_finalize proc~esmf_gridcompcreate ESMF_GridCompCreate program~esmf_statereconcileex->proc~esmf_gridcompcreate proc~esmf_gridcompdestroy ESMF_GridCompDestroy program~esmf_statereconcileex->proc~esmf_gridcompdestroy proc~esmf_gridcompinitialize ESMF_GridCompInitialize program~esmf_statereconcileex->proc~esmf_gridcompinitialize proc~esmf_initialize ESMF_Initialize program~esmf_statereconcileex->proc~esmf_initialize proc~esmf_statereconcile ESMF_StateReconcile program~esmf_statereconcileex->proc~esmf_statereconcile proc~esmf_stest ESMF_STest program~esmf_statereconcileex->proc~esmf_stest

Variables

Type Attributes Name Initial
character(len=ESMF_MAXSTR) :: failMsg
character(len=ESMF_MAXSTR) :: testname
integer :: finalrc
integer :: petCount
integer :: rc
integer :: result
type(ESMF_GridComp) :: comp
type(ESMF_State) :: state
type(ESMF_VM) :: vm

Source Code

  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