Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix history and restart frequency, new features to scripts #610

Merged
merged 11 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions cice.setup
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,6 @@ EOF
set bfbcomp = "$bfbcomp_tmp"
endif

set fbfbcomp = ${spval}
if ($bfbcomp != ${spval}) then
set fbfbcomp = ${machcomp}_${bfbcomp}
endif

#------------------------------------------------------------
# Parse pesx with strict checking, limit pes for machine

Expand Down Expand Up @@ -751,7 +746,14 @@ EOF
endif

set testname_noid = ${spval}

# create case for test cases

set fbfbcomp = ${spval}
if ($bfbcomp != ${spval}) then
set fbfbcomp = ${machcomp}_${bfbcomp}
endif

if (${docase} == 0) then
set soptions = ""
# Create sorted array and remove duplicates and "none"
Expand All @@ -768,6 +770,31 @@ EOF
set testname_base = "${machcomp}_${test}_${grid}_${pesx}${soptions}.${testid}"
set testname = "${tsdir}/${testname_base}"
set case = ${testname}

if (${dosuite} == 1) then
# Add -s flags in cice.setup to bfbcomp name
# Parse bfbcomp test_grid_pes and sets
# Add sets_base and sort unique
# Create fbfbcomp string that should be consistent with base casename
set bfbcomp_regex="\(.*_[0-9x]*\)_\(.*\)"
set bfbcomp_test_grid_pes=`echo ${bfbcomp} | sed "s/${bfbcomp_regex}/\1/"`
set bfbcomp_sets=`echo ${bfbcomp} | sed "s/${bfbcomp_regex}/\2/" | sed 's/_/,/g' `
set bfbcomp_sets="${bfbcomp_sets},${sets_base}"
set bfbcomp_soptions = ""
# Create sorted array and remove duplicates and "none"
set bfbcomp_setsarray = `echo ${bfbcomp_sets} | sed 's/,/ /g' | fmt -1 | sort -u`
if ("${bfbcomp_setsarray}" != "") then
foreach field (${bfbcomp_setsarray})
if (${field} != "none") then
set bfbcomp_soptions = ${bfbcomp_soptions}"_"${field}
endif
end
endif
set fbfbcomp = ${spval}
if ($bfbcomp != ${spval}) then
set fbfbcomp = ${machcomp}_${bfbcomp_test_grid_pes}${bfbcomp_soptions}
endif
endif
endif

if (-d ${case}) then
Expand Down Expand Up @@ -891,6 +918,9 @@ EOF
echo "ICE_PES = ${task}x${thrd}"
echo "ICE_GRID = ${grid} (${ICE_DECOMP_NXGLOB}x${ICE_DECOMP_NYGLOB}) blocksize=${ICE_DECOMP_BLCKX}x${ICE_DECOMP_BLCKY}x${ICE_DECOMP_MXBLCKS}"
echo "ICE_DECOMP = ${ICE_DECOMP_DECOMP} ${ICE_DECOMP_DSHAPE}"
if ($fbfbcomp != ${spval}) then
echo "ICE_BFBCOMP = ${fbfbcomp}"
endif

#------------------------------------------------------------
# Copy in and update cice.settings and ice_in files
Expand Down
97 changes: 59 additions & 38 deletions cicecore/cicedynB/general/ice_init.F90
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module ice_init
ice_ic ! method of ice cover initialization
! 'default' => latitude and sst dependent
! 'none' => no ice
! note: restart = .true. overwrites
! filename => read file

public :: input_data, init_state, set_state_var

Expand All @@ -67,8 +67,8 @@ subroutine input_data
n_doc, n_dic, n_don, n_fed, n_fep, &
max_nstrm
use ice_calendar, only: year_init, month_init, day_init, sec_init, &
istep0, histfreq, histfreq_n, &
dumpfreq, dumpfreq_n, diagfreq, &
istep0, histfreq, histfreq_n, histfreq_base, &
dumpfreq, dumpfreq_n, diagfreq, dumpfreq_base, &
npt, dt, ndtd, days_per_year, use_leap_years, &
write_ic, dump_last, npt_unit
use ice_arrays_column, only: oceanmixed_ice
Expand Down Expand Up @@ -167,6 +167,7 @@ subroutine input_data
print_global, print_points, latpnt, lonpnt, &
debug_forcing, histfreq, histfreq_n, hist_avg, &
history_dir, history_file, history_precision, cpl_bgc, &
histfreq_base, dumpfreq_base, &
conserv_check, debug_model, debug_model_step, &
debug_model_i, debug_model_j, debug_model_iblk, debug_model_task, &
year_init, month_init, day_init, sec_init, &
Expand Down Expand Up @@ -285,6 +286,7 @@ subroutine input_data
histfreq(4) = 'm' ! output frequency option for different streams
histfreq(5) = 'y' ! output frequency option for different streams
histfreq_n(:) = 1 ! output frequency
histfreq_base = 'zero' ! output frequency reference date
hist_avg = .true. ! if true, write time-averages (not snapshots)
history_format = 'default' ! history file format
history_dir = './' ! write to executable dir for default
Expand All @@ -296,6 +298,7 @@ subroutine input_data
incond_file = 'iceh_ic'! file prefix
dumpfreq='y' ! restart frequency option
dumpfreq_n = 1 ! restart frequency
dumpfreq_base = 'init' ! restart frequency reference date
dump_last = .false. ! write restart on last time step
restart_dir = './' ! write to executable dir for default
restart_file = 'iced' ! restart file name prefix
Expand Down Expand Up @@ -452,8 +455,8 @@ subroutine input_data
#ifndef CESMCOUPLED
runid = 'unknown' ! run ID used in CESM and for machine 'bering'
runtype = 'initial' ! run type: 'initial', 'continue'
restart = .false. ! if true, read restart files for initialization
use_restart_time = .true. ! if true, use time info written in file
restart = .false. ! if true, read ice state from restart file
use_restart_time = .false. ! if true, use time info written in file
#endif

! extra tracers
Expand Down Expand Up @@ -625,6 +628,7 @@ subroutine input_data
call broadcast_scalar(histfreq(n), master_task)
enddo
call broadcast_array(histfreq_n, master_task)
call broadcast_scalar(histfreq_base, master_task)
call broadcast_scalar(hist_avg, master_task)
call broadcast_scalar(history_dir, master_task)
call broadcast_scalar(history_file, master_task)
Expand All @@ -636,6 +640,7 @@ subroutine input_data
call broadcast_scalar(incond_file, master_task)
call broadcast_scalar(dumpfreq, master_task)
call broadcast_scalar(dumpfreq_n, master_task)
call broadcast_scalar(dumpfreq_base, master_task)
call broadcast_scalar(dump_last, master_task)
call broadcast_scalar(restart_file, master_task)
call broadcast_scalar(restart, master_task)
Expand Down Expand Up @@ -844,42 +849,46 @@ subroutine input_data
write(nu_diag,*) ' '
endif

if (trim(runtype) == 'continue' .and. .not.restart) then
if (my_task == master_task) &
write(nu_diag,*) subname//' WARNING: runtype=continue, setting restart=.true.'
if (trim(runtype) == 'continue') then
if (my_task == master_task) then
write(nu_diag,*) subname//'NOTE: runtype=continue, setting restart=.true.'
if (.not. use_restart_time) &
write(nu_diag,*) subname//'NOTE: runtype=continue, setting use_restart_time=.true.'
write(nu_diag,*) ' '
endif
restart = .true.
endif

if (trim(runtype) /= 'continue' .and. restart .and. &
(ice_ic == 'none' .or. ice_ic == 'default')) then
if (my_task == master_task) &
write(nu_diag,*) subname//' WARNING: runtype ne continue and ice_ic=none|default, setting restart=.false.'
restart = .false.
endif

if (trim(runtype) /= 'continue' .and. (ice_ic == 'none' .or. ice_ic == 'default')) then
if (my_task == master_task) &
write(nu_diag,*) subname//' WARNING: ice_ic = none or default, setting restart flags to .false.'
restart = .false.
restart_iso = .false.
restart_aero = .false.
restart_fsd = .false.
restart_age = .false.
restart_fy = .false.
restart_lvl = .false.
restart_pond_cesm = .false.
restart_pond_lvl = .false.
restart_pond_topo = .false.
use_restart_time = .true.
elseif (trim(runtype) == 'initial') then
if (ice_ic == 'none' .or. ice_ic == 'default') then
if (my_task == master_task) then
write(nu_diag,*) subname//'NOTE: ice_ic = none or default, setting restart flags to .false.'
if (.not. use_restart_time) &
write(nu_diag,*) subname//'NOTE: ice_ic = none or default, setting use_restart_time=.false.'
write(nu_diag,*) ' '
endif
use_restart_time = .false.
restart = .false.
restart_iso = .false.
restart_aero = .false.
restart_fsd = .false.
restart_age = .false.
restart_fy = .false.
restart_lvl = .false.
restart_pond_cesm = .false.
restart_pond_lvl = .false.
restart_pond_topo = .false.
! tcraig, OK to leave as true, needed for boxrestore case
! restart_ext = .false.
endif

if (trim(runtype) == 'initial' .and. .not.(restart) .and. &
ice_ic /= 'none' .and. ice_ic /= 'default') then
! restart_ext = .false.
else
if (my_task == master_task) then
write(nu_diag,*) subname//'NOTE: ice_ic /= none or default, setting restart=.true.'
write(nu_diag,*) ' '
endif
restart = .true.
endif
else
if (my_task == master_task) then
write(nu_diag,*) subname//' ERROR: runtype, restart, ice_ic are inconsistent:'
write(nu_diag,*) subname//' ERROR: runtype=',trim(runtype), ' restart=',restart, ' ice_ic=',trim(ice_ic)
write(nu_diag,*) subname//' ERROR: Please review user guide'
write(nu_diag,*) subname//' ERROR: runtype unknown = ',trim(runtype)
endif
abort_list = trim(abort_list)//":1"
endif
Expand Down Expand Up @@ -1120,6 +1129,16 @@ subroutine input_data
abort_list = trim(abort_list)//":22"
endif

if(histfreq_base /= 'init' .and. histfreq_base /= 'zero') then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you check these in ice_calendar.F90, do you need to do them here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't, but I think it's reasonable to trap them during the initialization for efficiency. I think it's also proper to have the if loop in the calendar operate only on valid values.

write (nu_diag,*) subname//' ERROR: bad value for histfreq_base, allowed values: init, zero'
abort_list = trim(abort_list)//":24"
endif

if(dumpfreq_base /= 'init' .and. dumpfreq_base /= 'zero') then
write (nu_diag,*) subname//' ERROR: bad value for dumpfreq_base, allowed values: init, zero'
abort_list = trim(abort_list)//":25"
endif

if (.not.(trim(dumpfreq) == 'y' .or. trim(dumpfreq) == 'Y' .or. &
trim(dumpfreq) == 'm' .or. trim(dumpfreq) == 'M' .or. &
trim(dumpfreq) == 'd' .or. trim(dumpfreq) == 'D' .or. &
Expand Down Expand Up @@ -1681,6 +1700,7 @@ subroutine input_data
write(nu_diag,1021) ' numax = ', numax
write(nu_diag,1033) ' histfreq = ', histfreq(:)
write(nu_diag,1023) ' histfreq_n = ', histfreq_n(:)
write(nu_diag,1031) ' histfreq_base = ', trim(histfreq_base)
write(nu_diag,1011) ' hist_avg = ', hist_avg
if (.not. hist_avg) write(nu_diag,1031) ' History data will be snapshots'
write(nu_diag,1031) ' history_dir = ', trim(history_dir)
Expand All @@ -1693,6 +1713,7 @@ subroutine input_data
endif
write(nu_diag,1031) ' dumpfreq = ', trim(dumpfreq)
write(nu_diag,1021) ' dumpfreq_n = ', dumpfreq_n
write(nu_diag,1031) ' dumpfreq_base = ', trim(dumpfreq_base)
write(nu_diag,1011) ' dump_last = ', dump_last
write(nu_diag,1011) ' restart = ', restart
write(nu_diag,1031) ' restart_dir = ', trim(restart_dir)
Expand Down
22 changes: 14 additions & 8 deletions cicecore/cicedynB/infrastructure/comm/mpi/ice_exit.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module ice_exit

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

subroutine abort_ice(error_message, file, line)
subroutine abort_ice(error_message, file, line, doabort)

! This routine aborts the ice model and prints an error message.

Expand All @@ -31,10 +31,10 @@ subroutine abort_ice(error_message, file, line)
use mpi ! MPI Fortran module
#endif

character (len=*), intent(in),optional :: error_message
character (len=*), intent(in),optional :: file
integer (kind=int_kind), intent(in), optional :: &
line ! line number
character (len=*), intent(in),optional :: error_message ! error message
character (len=*), intent(in),optional :: file ! file
integer (kind=int_kind), intent(in), optional :: line ! line number
logical (kind=log_kind), intent(in), optional :: doabort ! abort flag

! local variables

Expand All @@ -43,8 +43,12 @@ subroutine abort_ice(error_message, file, line)
ierr, & ! MPI error flag
error_code ! return code
#endif
logical (log_kind) :: ldoabort ! local doabort flag
character(len=*), parameter :: subname='(abort_ice)'

ldoabort = .true.
if (present(doabort)) ldoabort = doabort

#if (defined CESMCOUPLED)
call flush_fileunit(nu_diag)
call icepack_warnings_flush(nu_diag)
Expand All @@ -54,7 +58,7 @@ subroutine abort_ice(error_message, file, line)
if (present(line)) write (nu_diag,*) subname,' line number ',line
if (present(error_message)) write (nu_diag,*) subname,' error = ',trim(error_message)
call flush_fileunit(nu_diag)
call shr_sys_abort(subname//trim(error_message))
if (ldoabort) call shr_sys_abort(subname//trim(error_message))
#else
call flush_fileunit(nu_diag)
call icepack_warnings_flush(nu_diag)
Expand All @@ -65,8 +69,10 @@ subroutine abort_ice(error_message, file, line)
if (present(error_message)) write (ice_stderr,*) subname,' error = ',trim(error_message)
call flush_fileunit(ice_stderr)
error_code = 128
call MPI_ABORT(MPI_COMM_WORLD, error_code, ierr)
stop
if (ldoabort) then
call MPI_ABORT(MPI_COMM_WORLD, error_code, ierr)
stop
endif
#endif

end subroutine abort_ice
Expand Down
18 changes: 11 additions & 7 deletions cicecore/cicedynB/infrastructure/comm/serial/ice_exit.F90
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,29 @@ module ice_exit

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

subroutine abort_ice(error_message,file,line)
subroutine abort_ice(error_message,file,line,doabort)

! This routine aborts the ice model and prints an error message.

character (len=*), intent(in),optional :: error_message
character (len=*), intent(in),optional :: file
integer (kind=int_kind), intent(in), optional :: &
line ! line number
character (len=*), intent(in),optional :: error_message ! error message
character (len=*), intent(in),optional :: file ! file
integer (kind=int_kind), intent(in), optional :: line ! line number
logical (kind=log_kind), intent(in), optional :: doabort ! abort flag

logical (kind=log_kind) :: ldoabort ! local doabort
character(len=*), parameter :: subname='(abort_ice)'

ldoabort = .true.
if (present(doabort)) ldoabort = doabort

#ifdef CESMCOUPLED
call icepack_warnings_flush(nu_diag)
write(nu_diag,*) ' '
write(nu_diag,*) subname, 'ABORTED: '
if (present(file)) write (nu_diag,*) subname,' called from ',trim(file)
if (present(line)) write (nu_diag,*) subname,' line number ',line
if (present(error_message)) write (nu_diag,*) subname,' error = ',trim(error_message)
call shr_sys_abort(subname//trim(error_message))
if (ldoabort) call shr_sys_abort(subname//trim(error_message))
#else
call icepack_warnings_flush(nu_diag)
write(nu_diag,*) ' '
Expand All @@ -51,7 +55,7 @@ subroutine abort_ice(error_message,file,line)
if (present(line)) write (nu_diag,*) subname,' line number ',line
if (present(error_message)) write (nu_diag,*) subname,' error = ',trim(error_message)
call flush_fileunit(nu_diag)
stop
if (ldoabort) stop
#endif

end subroutine abort_ice
Expand Down
20 changes: 15 additions & 5 deletions cicecore/drivers/unittest/bcstchk/bcstchk.F90
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,32 @@ program bcstchk
write(6,*) 'BCSTCHK COMPLETED SUCCESSFULLY'
else
write(6,*) 'BCSTCHK FAILED'
call abort_ice(subname//' ERROR: BCSTCHK FAILED',file=__FILE__,line=__LINE__)
endif
endif

! Test abort_ice, regardless of test outcome
! Set doabort to false to support code coverage stats, aborted runs don't seem to generate
! gcov statistics

call flush_fileunit(6)
call ice_barrier()
if (my_task == master_task) then
write(6,*) ' '
write(6,*) '=========================================================='
write(6,*) ' '
write(6,*) 'NOTE: We are testing the abort now so you should see an abort to follow'
write(6,*) 'The BCSTCHK passed, so please ignore the abort'
write(6,*) ' '
call abort_ice(subname//' Test abort ',file=__FILE__,line=__LINE__, doabort=.false.)
endif

! Test abort_ice, regardless of test outcome
call flush_fileunit(6)
call ice_barrier()
call abort_ice(subname//' Test abort ',file=__FILE__,line=__LINE__)

if (my_task == master_task) write(6,*) subname,'This line should not be written'
if (my_task == master_task) then
write(6,*) ' '
write(6,*) 'BCSTCHK done'
write(6,*) ' '
endif

call end_run()

Expand Down
Loading