From 700e5c761b67029615c74c6ed045ce4203367ef6 Mon Sep 17 00:00:00 2001 From: Johannes Keller <16795031+jjokella@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:36:37 +0200 Subject: [PATCH] Introduce `cime_run(ntsteps)`, callable for TSMP-PDAF (#36) * PDAF: refactor cime/mct routines - remove commented out debug output - small style changes with the goal of being close to CIME tag `cime5.6.47` * Introduce `cime_run(ntsteps)`, callable for TSMP-PDAF 1. re-introduce `private` statement, this was removed because variables from `cime_comp_mod` had to be used by TSMP-PDAF 2. Add `cime_run` with number of time steps `ntsteps` as input. `ntsteps` is supplied by the TSMP-PDAF interface. 3. Add `stop_alarm` for `cime_run` dependent on `ntsteps`. 4. Note: set `counter` to zero explicitly before each forward simulation while-loop. Without this setting, the `ntsteps`-induced `stop_alarm` for the while-loop was not called in a CLM5-PDAF testcase. --- src/eclm/cime_comp_mod.F90 | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/eclm/cime_comp_mod.F90 b/src/eclm/cime_comp_mod.F90 index 542953c..6215eed 100644 --- a/src/eclm/cime_comp_mod.F90 +++ b/src/eclm/cime_comp_mod.F90 @@ -180,9 +180,7 @@ module cime_comp_mod implicit none -#ifndef USE_PDAF private -#endif public cime_pre_init1, cime_pre_init2, cime_init, cime_run, cime_final public timing_dir, mpicom_GLOID @@ -2188,12 +2186,21 @@ end subroutine cime_init !******************************************************************************* !=============================================================================== +#ifdef USE_PDAF + subroutine cime_run(ntsteps) +#else subroutine cime_run() +#endif use seq_comm_mct, only: atm_layout, lnd_layout, ice_layout, glc_layout, & rof_layout, ocn_layout, wav_layout, esp_layout use shr_string_mod, only: shr_string_listGetIndexF use seq_comm_mct, only: num_inst_driver +#ifdef USE_PDAF + ! TSMP specific + integer, intent(in), optional :: ntsteps + integer :: counter=0 +#endif ! gptl timer lookup variables integer, parameter :: hashcnt=7 integer :: hashint(hashcnt) @@ -2245,6 +2252,19 @@ subroutine cime_run() call t_stopf ('CPL:RUN_LOOP_BSTART') Time_begin = mpi_wtime() Time_bstep = mpi_wtime() + +#ifdef USE_PDAF + ! Check for optional input `ntsteps` + if(.not. present(ntsteps)) then + write(logunit,*) 'ERROR: ntsteps input not present, but needed for TSMP-PDAF ;' + call shr_sys_abort(subname// & + ' missing ntsteps input that is needed for TSMP-PDAF') + end if + + ! Explicitly set `counter` to zero before loop + counter = 0 +#endif + do while ( .not. stop_alarm) call t_startf('CPL:RUN_LOOP', hashint(1)) @@ -4088,6 +4108,18 @@ subroutine cime_run() call t_drvstopf ('CPL:BARRIERALARM',cplrun=.true.) endif +#ifdef USE_PDAF + ! TSMP specific stop condition: + counter = counter + 1 + if (present(ntsteps) .and. counter == ntsteps) then + if (iamroot_CPLID) then + write(logunit,*) ' ' + write(logunit,103) subname,' NOTE: Stopping from TSMP-PDAF alarm ntsteps' + write(logunit,*) ' ' + endif + stop_alarm = .true. + end if +#endif enddo ! driver run loop !|----------------------------------------------------------