Skip to content

Commit

Permalink
PRE for multi instance cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Aug 4, 2017
1 parent d1c35de commit 27ecb70
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 71 deletions.
50 changes: 32 additions & 18 deletions scripts/lib/CIME/SystemTests/pre.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,40 @@ def run_phase(self): # pylint: disable=arguments-differ
else:
pause_comps = pause_comps.split(':')

multi_coupler = self._case.get_value("MULTI_COUPLER")

for comp in pause_comps:
if comp == "cpl":
if multi_coupler:
ninst = self._case.get_value("NINST_MAX")
else:
ninst = 1
else:
ninst = self._case.get_value("NINST_{}".format(comp.upper()))
comp_name = self._case.get_value('COMP_{}'.format(comp.upper()))
rname = '*.{}.r.*'.format(comp_name)
restart_files_1 = glob.glob(os.path.join(rundir1, rname))
expect((len(restart_files_1) > 0), "No case1 restart files for {}".format(comp))
restart_files_2 = glob.glob(os.path.join(rundir2, rname))
expect((len(restart_files_2) > len(restart_files_1)),
"No pause (restart) files found in case2 for {}".format(comp))
# Do cprnc of restart files.
rfile1 = restart_files_1[len(restart_files_1) - 1]
# rfile2 has to match rfile1 (same time string)
parts = os.path.basename(rfile1).split(".")
glob_str = "*.{}".format(".".join(parts[len(parts)-4:]))
restart_files_2 = glob.glob(os.path.join(rundir2, glob_str))
expect((len(restart_files_2) == 1),
"Missing case2 restart file, {}", glob_str)
rfile2 = restart_files_2[0]
ok = cprnc(comp, rfile1, rfile2, self._case, rundir2)[0]
logger.warning("CPRNC result for {}: {}".format(os.path.basename(rfile1), "PASS" if (ok == should_match) else "FAIL"))
compare_ok = compare_ok and (should_match == ok)
for index in range(1,ninst+1):
if ninst == 1:
rname = '*.{}.r.*'.format(comp_name)
else:
rname = '*.{}_{:04d}.r.*'.format(comp_name, index)

restart_files_1 = glob.glob(os.path.join(rundir1, rname))
expect((len(restart_files_1) > 0), "No case1 restart files for {}".format(comp))
restart_files_2 = glob.glob(os.path.join(rundir2, rname))
expect((len(restart_files_2) > len(restart_files_1)),
"No pause (restart) files found in case2 for {}".format(comp))
# Do cprnc of restart files.
rfile1 = restart_files_1[len(restart_files_1) - 1]
# rfile2 has to match rfile1 (same time string)
parts = os.path.basename(rfile1).split(".")
glob_str = "*.{}".format(".".join(parts[len(parts)-4:]))
restart_files_2 = glob.glob(os.path.join(rundir2, glob_str))
expect((len(restart_files_2) == 1),
"Missing case2 restart file, {}", glob_str)
rfile2 = restart_files_2[0]
ok = cprnc(comp, rfile1, rfile2, self._case, rundir2)[0]
logger.warning("CPRNC result for {}: {}".format(os.path.basename(rfile1), "PASS" if (ok == should_match) else "FAIL"))
compare_ok = compare_ok and (should_match == ok)

expect(compare_ok,
"Not all restart files {}".format("matched" if should_match else "failed to match"))
2 changes: 1 addition & 1 deletion scripts/lib/CIME/case_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _build_usernl_files(case, model, comp):
ninst = case.get_value("NINST_{}".format(model))
nlfile = "user_nl_{}".format(comp)
model_nl = os.path.join(model_dir, nlfile)
if ninst > 1:
if ninst > 1 and not comp.endswith("esp"):
for inst_counter in xrange(1, ninst+1):
inst_nlfile = "{}_{:04d}".format(nlfile, inst_counter)
if not os.path.exists(inst_nlfile):
Expand Down
25 changes: 13 additions & 12 deletions src/components/data_comps/desp/desp_comp_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module desp_comp_mod
use seq_timemgr_mod, only: seq_timemgr_EClockGetData
use seq_timemgr_mod, only: seq_timemgr_RestartAlarmIsOn
use seq_comm_mct, only: seq_comm_inst, seq_comm_name, seq_comm_suffix
use seq_comm_mct, only: num_inst_cpl


implicit none
private
Expand Down Expand Up @@ -99,8 +101,6 @@ module desp_comp_mod

subroutine desp_comp_init(EClock, espid, mpicom_in, phase, read_restart, &
esp_present, esp_prognostic)
use pio, only: iosystem_desc_t
use shr_pio_mod, only: shr_pio_getiosys, shr_pio_getiotype

! !INPUT/OUTPUT PARAMETERS:

Expand All @@ -120,8 +120,6 @@ subroutine desp_comp_init(EClock, espid, mpicom_in, phase, read_restart, &
integer(IN) :: shrloglev ! original log level
integer(IN) :: nunit ! unit number

type(iosystem_desc_t), pointer :: iosystem

character(len=CL) :: fileName ! generic file name

character(len=CL) :: rest_file ! restart filename
Expand Down Expand Up @@ -223,8 +221,7 @@ subroutine desp_comp_init(EClock, espid, mpicom_in, phase, read_restart, &
! Initialize PIO
!------------------------------------------------------------------------

iosystem => shr_pio_getiosys(trim(inst_name))
call shr_strdata_pioinit(SDESP, iosystem, shr_pio_getiotype(trim(inst_name)))
call shr_strdata_pioinit(SDESP, COMPID)

!------------------------------------------------------------------------
! Validate mode
Expand Down Expand Up @@ -353,7 +350,7 @@ subroutine desp_comp_run(EClock, case_name, pause_sig, atm_resume, &
character(len=CL), intent(inout) :: ice_resume(num_inst_ice)
character(len=CL), intent(inout) :: glc_resume(num_inst_glc)
character(len=CL), intent(inout) :: wav_resume(num_inst_wav)
character(len=CL), intent(inout) :: cpl_resume
character(len=CL), intent(inout) :: cpl_resume(num_inst_cpl)

!--- local ---
integer(IN) :: CurrentYMD ! model date
Expand Down Expand Up @@ -393,7 +390,7 @@ subroutine desp_comp_run(EClock, case_name, pause_sig, atm_resume, &
ice_resume(:) = ' '
glc_resume(:) = ' '
wav_resume(:) = ' '
cpl_resume = ' '
cpl_resume(:) = ' '

!--------------------------------------------------------------------------
! Reset shr logging to my log file
Expand Down Expand Up @@ -477,8 +474,8 @@ subroutine desp_comp_run(EClock, case_name, pause_sig, atm_resume, &
varname = 'T'
case('drv')
call get_restart_filenames(ind, cpl_resume, errcode)
allocate(rfilenames(1))
rfilenames(1) = cpl_resume
allocate(rfilenames(size(cpl_resume)))
rfilenames = cpl_resume
varname = 'x2oacc_ox_Foxx_swnet'
case default
call shr_sys_abort(subname//'Unrecognized ind')
Expand Down Expand Up @@ -613,7 +610,7 @@ end subroutine desp_comp_final

subroutine get_restart_filenames_a(comp_ind, filenames, retcode)
use seq_comm_mct, only: ATMID, LNDID, OCNID, ICEID, GLCID, ROFID
use seq_comm_mct, only: WAVID, CPLID, seq_comm_suffix
use seq_comm_mct, only: WAVID, CPLID, seq_comm_suffix, cpl_inst_tag, num_inst_cpl
use shr_file_mod, only: shr_file_getUnit, shr_file_freeUnit

! Dummy arguments
Expand Down Expand Up @@ -660,7 +657,11 @@ subroutine get_restart_filenames_a(comp_ind, filenames, retcode)
rpointer_name = rpprefix//comp_names(comp_ind)

do ind = 1, num_inst
rpointer_name = rpprefix//comp_names(comp_ind)//trim(seq_comm_suffix(ids(ind)))
if (num_inst_cpl > 1) then
rpointer_name = rpprefix//comp_names(comp_ind)//trim(cpl_inst_tag)
else
rpointer_name = rpprefix//comp_names(comp_ind)//trim(seq_comm_suffix(ids(ind)))
endif
if (my_task == master_task) then
inquire(file=rpointer_name, EXIST=file_exists)
! POP decided to not follow the convention
Expand Down
10 changes: 4 additions & 6 deletions src/drivers/mct/main/cime_comp_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module cime_comp_mod
use seq_comm_mct, only: seq_comm_iamin, seq_comm_name, seq_comm_namelen
use seq_comm_mct, only: seq_comm_init, seq_comm_setnthreads, seq_comm_getnthreads
use seq_comm_mct, only: seq_comm_getinfo => seq_comm_setptrs
use seq_comm_mct, only: seq_comm_petlist
use seq_comm_mct, only: seq_comm_petlist, cpl_inst_tag

! clock & alarm routines and variables
use seq_timemgr_mod, only: seq_timemgr_type
Expand Down Expand Up @@ -534,8 +534,6 @@ module cime_comp_mod
logical :: iamin_CPLALLROFID ! pe associated with CPLALLROFID
logical :: iamin_CPLALLWAVID ! pe associated with CPLALLWAVID

! suffix for log and timing files if multi coupler driver
character(len=seq_comm_namelen) :: cpl_inst_tag

!----------------------------------------------------------------------------
! complist: list of comps on this pe
Expand Down Expand Up @@ -589,7 +587,7 @@ module cime_comp_mod

subroutine cime_pre_init1()
use shr_pio_mod, only : shr_pio_init1, shr_pio_init2

use seq_comm_mct, only: num_inst_cpl
!----------------------------------------------------------
!| Initialize MCT and MPI communicators and IO
!----------------------------------------------------------
Expand All @@ -598,7 +596,7 @@ subroutine cime_pre_init1()
logical :: comp_iamin(num_inst_total)
character(len=seq_comm_namelen) :: comp_name(num_inst_total)
integer :: i, it
integer :: num_inst_cpl, cpl_id
integer :: cpl_id
integer :: cpl_comm

call mpi_init(ierr)
Expand Down Expand Up @@ -4068,7 +4066,7 @@ subroutine cime_comp_barriers(mpicom, timer)
end subroutine cime_comp_barriers

subroutine cime_cpl_init(comm_in, comm_out, num_inst_cpl, id)

use seq_comm_mct, only : cpl_inst_iamin
!-----------------------------------------------------------------------
!
! Initialize multiple coupler instances, if requested
Expand Down
Loading

0 comments on commit 27ecb70

Please sign in to comment.