Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'rljacob/fix-extra-read' (PR #4523)
Make drv_resume a logical and set it to FALSE to prevent read of restart immediately after it is written.
Introduce drv_resume_file to use where a filename is really needed.

Also add a log message for the real restart read and make the seq_io_read_avs log messages more informative.

Fixes #4513
  • Loading branch information
rljacob committed Sep 15, 2021
2 parents 5341618 + 31c32e4 commit 44d5343
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
34 changes: 21 additions & 13 deletions driver-mct/main/cime_comp_mod.F90
Expand Up @@ -1377,6 +1377,7 @@ end subroutine cime_pre_init2

subroutine cime_init()

103 format( 5A )
104 format( A, i10.8, i8)

!-----------------------------------------------------------------------------
Expand Down Expand Up @@ -2316,6 +2317,10 @@ subroutine cime_init()

call seq_diag_zero_mct(mode='all')
if (read_restart .and. iamin_CPLID) then
if (iamroot_CPLID) then
write(logunit,103) subname,' Reading restart file ',trim(rest_file)
call shr_sys_flush(logunit)
end if
call seq_rest_read(rest_file, infodata, &
atm, lnd, ice, ocn, rof, glc, wav, esp, iac, &
fractions_ax, fractions_lx, fractions_ix, fractions_ox, &
Expand Down Expand Up @@ -2416,7 +2421,8 @@ subroutine cime_run()
integer :: hashint(hashcnt)
! Driver pause/resume
logical :: drv_pause ! Driver writes pause restart file
character(len=CL) :: drv_resume ! Driver resets state from restart file
logical :: drv_resume ! Driver resets state from restart file
character(len=CL) :: drv_resume_file ! The restart (resume) file
character(len=CL), pointer :: resume_files(:) ! Component resume files

type(ESMF_Time) :: etime_curr ! Current model time
Expand All @@ -2441,6 +2447,7 @@ subroutine cime_run()

call t_startf ('CPL:cime_run_init')
hashint = 0
drv_resume=.FALSE.

call seq_infodata_putData(infodata,atm_phase=1,lnd_phase=1,ocn_phase=1,ice_phase=1)
call seq_timemgr_EClockGetData( EClock_d, stepno=begstep)
Expand Down Expand Up @@ -3116,7 +3123,7 @@ subroutine cime_run()
!----------------------------------------------------------
!| Write driver restart file
!----------------------------------------------------------
call cime_run_write_restart(drv_pause, restart_alarm, drv_resume)
call cime_run_write_restart(drv_pause, restart_alarm, drv_resume_file)

!----------------------------------------------------------
!| Write history file, only AVs on CPLID
Expand Down Expand Up @@ -3348,7 +3355,7 @@ subroutine cime_run()
WAVID(ewi), component_get_iamroot_compid(wav(ewi)))
end do
! Here we pass 1 as num_inst_driver as num_inst_driver is used inside
call seq_resume_store_comp('x', drv_resume, 1, &
call seq_resume_store_comp('x', drv_resume_file, 1, &
driver_id, iamroot_CPLID)
call component_run(Eclock_e, esp, esp_run, infodata, &
comp_prognostic=esp_prognostic, comp_num=comp_num_esp, &
Expand Down Expand Up @@ -3402,26 +3409,27 @@ subroutine cime_run()
end if
call seq_resume_get_files('x', resume_files)
if (associated(resume_files)) then
drv_resume = resume_files(driver_id)
drv_resume_file = resume_files(driver_id)
end if
end if

!----------------------------------------------------------
!| RESUME (read restart) if signaled
!----------------------------------------------------------
if (len_trim(drv_resume) > 0) then
if (drv_resume) then
if (iamroot_CPLID) then
write(logunit,103) subname,' Reading restart (resume) file ',trim(drv_resume)
write(logunit,103) subname,' Reading restart (resume) file ',trim(drv_resume_file)
call shr_sys_flush(logunit)
end if
if (iamin_CPLID) then
call seq_rest_read(drv_resume, infodata, &
call seq_rest_read(drv_resume_file, infodata, &
atm, lnd, ice, ocn, rof, glc, wav, esp, iac, &
fractions_ax, fractions_lx, fractions_ix, fractions_ox, &
fractions_rx, fractions_gx, fractions_wx, fractions_zx)
end if
! Clear the resume file so we don't try to read it again
drv_resume = ' '
drv_resume = .FALSE.
drv_resume_file = ' '
end if

!----------------------------------------------------------
Expand Down Expand Up @@ -4914,15 +4922,15 @@ end subroutine cime_run_write_history

!----------------------------------------------------------------------------------

subroutine cime_run_write_restart(drv_pause, write_restart, drv_resume)
subroutine cime_run_write_restart(drv_pause, write_restart, drv_resume_file)

!----------------------------------------------------------
! Write driver restart file
!----------------------------------------------------------

logical , intent(in) :: drv_pause
logical , intent(in) :: write_restart
character(len=*), intent(inout) :: drv_resume ! Driver resets state from restart file
character(len=*), intent(inout) :: drv_resume_file ! Driver resets state from restart file

103 format( 5A )
104 format( A, i10.8, i8)
Expand All @@ -4941,17 +4949,17 @@ subroutine cime_run_write_restart(drv_pause, write_restart, drv_resume)
atm, lnd, ice, ocn, rof, glc, wav, esp, iac, &
fractions_ax, fractions_lx, fractions_ix, fractions_ox, &
fractions_rx, fractions_gx, fractions_wx, fractions_zx, &
trim(cpl_inst_tag), drv_resume)
trim(cpl_inst_tag), drv_resume_file)

if (iamroot_CPLID) then
write(logunit,103) ' Restart filename: ',trim(drv_resume)
write(logunit,103) ' Restart filename: ',trim(drv_resume_file)
call shr_sys_flush(logunit)
endif

if (drv_threading) call seq_comm_setnthreads(nthreads_GLOID)
call t_drvstopf ('CPL:RESTART',cplrun=.true.)
else
drv_resume = ''
drv_resume_file = ' '
endif
end if

Expand Down
10 changes: 5 additions & 5 deletions driver-mct/main/seq_io_mod.F90
Expand Up @@ -1745,7 +1745,7 @@ subroutine seq_io_read_avs(filename,gsmap,AVS,dname,pre)
call shr_mpi_bcast(exists,mpicom,'seq_io_read_avs exists')
if (exists) then
rcode = pio_openfile(cpl_io_subsystem, pioid, cpl_pio_iotype, trim(filename),pio_nowrite)
if(iam==0) write(logunit,*) subname,' open file ',trim(filename)
if(iam==0) write(logunit,*) subname,' open file ',trim(filename),' for ',trim(dname)
call pio_seterrorhandling(pioid,PIO_BCAST_ERROR)
rcode = pio_get_att(pioid,pio_global,"file_version",lversion)
call pio_seterrorhandling(pioid,PIO_INTERNAL_ERROR)
Expand Down Expand Up @@ -1847,7 +1847,7 @@ end subroutine seq_io_read_avs
!===============================================================================
!BOP ===========================================================================
!
! !IROUTINE: seq_io_read_avs - read AV from netcdf file
! !IROUTINE: seq_io_read_avscomp - read AV from netcdf file
!
! !DESCRIPTION:
! Read AV from netcdf file
Expand Down Expand Up @@ -1890,7 +1890,7 @@ subroutine seq_io_read_avscomp(filename, comp, flow, dname, pre)
character(CL) :: lversion
character(CL) :: name1
character(CL) :: lpre
character(*),parameter :: subName = '(seq_io_read_avs) '
character(*),parameter :: subName = '(seq_io_read_avscomp) '
!-------------------------------------------------------------------------------
!
!-------------------------------------------------------------------------------
Expand All @@ -1915,10 +1915,10 @@ subroutine seq_io_read_avscomp(filename, comp, flow, dname, pre)
ng = mct_gsmap_gsize(gsmap)

if (iam==0) inquire(file=trim(filename),exist=exists)
call shr_mpi_bcast(exists,mpicom,'seq_io_read_avs exists')
call shr_mpi_bcast(exists,mpicom,'seq_io_read_avscomp exists')
if (exists) then
rcode = pio_openfile(cpl_io_subsystem, pioid, cpl_pio_iotype, trim(filename),pio_nowrite)
if(iam==0) write(logunit,*) subname,' open file ',trim(filename)
if(iam==0) write(logunit,*) subname,' open file ',trim(filename),' for ',trim(dname)
call pio_seterrorhandling(pioid,PIO_BCAST_ERROR)
rcode = pio_get_att(pioid,pio_global,"file_version",lversion)
call pio_seterrorhandling(pioid,PIO_INTERNAL_ERROR)
Expand Down

0 comments on commit 44d5343

Please sign in to comment.