MAPL_GenericRunChildren Subroutine

public recursive subroutine MAPL_GenericRunChildren(GC, IMPORT, EXPORT, CLOCK, RC)

Arguments

Type IntentOptional Attributes Name
type(ESMF_GridComp), intent(inout) :: GC
type(ESMF_State), intent(inout) :: IMPORT
type(ESMF_State), intent(inout) :: EXPORT
type(ESMF_Clock), intent(inout) :: CLOCK
integer, intent(out), optional :: RC

Calls

proc~~mapl_genericrunchildren~~CallsGraph proc~mapl_genericrunchildren MAPL_GenericRunChildren ESMF_CplCompRun ESMF_CplCompRun proc~mapl_genericrunchildren->ESMF_CplCompRun ESMF_GridCompGet ESMF_GridCompGet proc~mapl_genericrunchildren->ESMF_GridCompGet ESMF_GridCompRun ESMF_GridCompRun proc~mapl_genericrunchildren->ESMF_GridCompRun ESMF_UserCompGetInternalState ESMF_UserCompGetInternalState proc~mapl_genericrunchildren->ESMF_UserCompGetInternalState interface~mapl_getobjectfromgc MAPL_GetObjectFromGC proc~mapl_genericrunchildren->interface~mapl_getobjectfromgc interface~mapl_timeroff MAPL_TimerOff proc~mapl_genericrunchildren->interface~mapl_timeroff interface~mapl_timeron MAPL_TimerOn proc~mapl_genericrunchildren->interface~mapl_timeron none~get_child_export_state MAPL_MetaComp%get_child_export_state proc~mapl_genericrunchildren->none~get_child_export_state none~get_child_gridcomp MAPL_MetaComp%get_child_gridcomp proc~mapl_genericrunchildren->none~get_child_gridcomp none~get_child_import_state MAPL_MetaComp%get_child_import_state proc~mapl_genericrunchildren->none~get_child_import_state none~get_num_children~3 CompositeComponent%get_num_children proc~mapl_genericrunchildren->none~get_num_children~3 proc~mapl_return MAPL_Return proc~mapl_genericrunchildren->proc~mapl_return proc~mapl_verify MAPL_Verify proc~mapl_genericrunchildren->proc~mapl_verify none~get_export_state MaplGenericComponent%get_export_state none~get_child_export_state->none~get_export_state none~get_ith_child MAPL_MetaComp%get_ith_child none~get_child_export_state->none~get_ith_child none~get_gridcomp MaplGenericComponent%get_gridcomp none~get_child_gridcomp->none~get_gridcomp none~get_child_gridcomp->none~get_ith_child none~get_import_state MaplGenericComponent%get_import_state none~get_child_import_state->none~get_import_state none~get_child_import_state->none~get_ith_child none~get_num_children~5 ConcreteComposite%get_num_children none~get_num_children~3->none~get_num_children~5 at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception none~is_threading_active MaplGenericComponent%is_threading_active none~get_export_state->none~is_threading_active proc~get_current_thread get_current_thread none~get_export_state->proc~get_current_thread none~get_gridcomp->none~is_threading_active none~get_gridcomp->proc~get_current_thread none~get_import_state->none~is_threading_active none~get_import_state->proc~get_current_thread none~get_child~26 MAPL_MetaComp%get_child none~get_ith_child->none~get_child~26 none~get_child_by_index CompositeComponent%get_child_by_index none~get_child~26->none~get_child_by_index none~get_child_by_name CompositeComponent%get_child_by_name none~get_child~26->none~get_child_by_name

Source Code

   recursive subroutine MAPL_GenericRunChildren ( GC, IMPORT, EXPORT, CLOCK, RC)

      !ARGUMENTS:
      type(ESMF_GridComp), intent(INOUT) :: GC     ! Gridded component
      type(ESMF_State),    intent(INOUT) :: IMPORT ! Import state
      type(ESMF_State),    intent(INOUT) :: EXPORT ! Export state
      type(ESMF_Clock),    intent(INOUT) :: CLOCK  ! The clock
      integer, optional,   intent(  OUT) :: RC     ! Error code:

      !EOPI

      ! ErrLog Variables


      character(len=ESMF_MAXSTR)    :: IAm
      character(len=ESMF_MAXSTR)    :: comp_name
      integer                       :: status
      integer                       :: userRC

      ! Local derived type aliases

      type (MAPL_MetaComp),pointer :: STATE

      character(len=ESMF_MAXSTR)       :: CHILD_NAME
      integer                          :: I, J
      integer                          :: NC
      integer                          :: PHASE
      integer                          :: NUMPHASES
      integer                          :: MAXPHASES
      type (MAPL_MetaPtr), allocatable :: CHLDMAPL(:)
      type(ESMF_GridComp), pointer :: gridcomp
      type(ESMF_State), pointer :: child_import_state
      type(ESMF_State), pointer :: child_export_state

      !=============================================================================

      ! Begin...

      _UNUSED_DUMMY(IMPORT)
      _UNUSED_DUMMY(EXPORT)

      ! Get the target components name and set-up traceback handle.
      ! -----------------------------------------------------------

      Iam = "MAPL_GenericRunChildren"
      call ESMF_GridCompGet( GC, NAME=comp_name, RC=status )
      _VERIFY(status)
      Iam = trim(comp_name) // trim(Iam)

      ! Retrieve the pointer to the internal state. It comes in a wrapper.
      ! ------------------------------------------------------------------

      call MAPL_InternalStateGet ( GC, STATE, RC=status)
      _VERIFY(status)

!@ call MAPL_TimerOn (STATE,"GenRunTot")

      ! Run the children
      ! ----------------

      NC = STATE%get_num_children()
      allocate(CHLDMAPL(NC), stat=status)
      MAXPHASES = 0
      do I=1,NC
         gridcomp => STATE%GET_CHILD_GRIDCOMP(I)
         call MAPL_GetObjectFromGC(gridcomp, CHLDMAPL(I)%PTR, RC=status)
         _VERIFY(status)
         MAXPHASES = MAX(MAXPHASES, SIZE(CHLDMAPL(I)%PTR%PHASE_RUN))
      end do

      do PHASE = 1, MAXPHASES
         do I=1,NC
            NUMPHASES = SIZE(CHLDMAPL(I)%PTR%PHASE_RUN)
            if (PHASE .le. NUMPHASES) then
               gridcomp => STATE%GET_CHILD_GRIDCOMP(I)
               call ESMF_GridCompGet( gridcomp, NAME=CHILD_NAME, RC=status )
               _VERIFY(status)

               call MAPL_TimerOn (STATE,trim(CHILD_NAME))
               child_import_state => STATE%get_child_import_state(i)
               child_export_state => STATE%get_child_export_state(i)

               call ESMF_GridCompRun (gridcomp, &
                    importState=child_import_state, &
                    exportState=child_export_state, &
                    clock=CLOCK, PHASE=CHLDMAPL(I)%PTR%PHASE_RUN(PHASE), &
                    userRC=userRC, _RC )
               _VERIFY(userRC)

                call MAPL_TimerOff(STATE,trim(CHILD_NAME))
            end if

            !ALT question for Max - if user wants to run particular phase only, when should we run couplers
            if (PHASE == NUMPHASES) then
               do J=1,NC
                  if(STATE%CCcreated(I,J)) then
                     child_export_state => STATE%get_child_export_state(i)
                     child_import_state => STATE%get_child_import_state(j)
                     call ESMF_CplCompRun (STATE%CCS(I,J), &
                          importState=child_export_state, &
                          exportState=child_import_state, &
                          clock=CLOCK, userRC=userRC, _RC)
                     _VERIFY(userRC)
                  endif
               enddo
            end if
         enddo
      enddo
      deallocate(CHLDMAPL)

!@ call MAPL_TimerOff(STATE,"GenRunTot")

      _RETURN(ESMF_SUCCESS)

   end subroutine MAPL_GenericRunChildren