Skip to content

Commit

Permalink
ice_calendar: zero-initialize 'nstreams' (CICE-Consortium#752)
Browse files Browse the repository at this point in the history
The variable ice_calendar::nstreams, which corresponds to the number of
output history streams to use for the run, is initialized in
ice_history::init_hist depending on the number of non-'x' elements in
'histfreq' in the namelist.

However, the code does use 'nstreams' before ice_history::init_hist is
called, in ice_calendar::calendar when called from
ice_calendar::init_calendar. Both 'init_calendar' and 'init_hist' are
called from CICE_InitMod::cice_init, in that order, such that the loop
that initializes 'write_history' in 'calendar' uses 'nstreams'
uninitialized.

'calendar' ends up being called at least once more during 'cice_init', from
ice_calendar::advance_timestep, at which point 'nstreams' is correctly
defined and 'write_history' is thus correctly initialized, before its
first use in 'accum_hist'.

To avoid using 'nstreams' uninitialized in the first call to 'calendar'
from 'init_calendar', initialize it to zero in 'init_calendar' before
calling 'calendar'.

This issue was discovered by compiling using the '-init=huge' flag of
the Intel compiler.
  • Loading branch information
phil-blain authored and dabail10 committed Oct 4, 2022
1 parent 32f20db commit d485554
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cicecore/shared/ice_calendar.F90
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ subroutine init_calendar
dt_dyn = dt/real(ndtd,kind=dbl_kind) ! dynamics et al timestep
force_restart_now = .false.

! initialize nstreams to zero (will be initialized from namelist in 'init_hist')
! this avoids using it uninitialzed in 'calendar' below
nstreams = 0

#ifdef CESMCOUPLED
! calendar_type set by coupling
#else
Expand Down

0 comments on commit d485554

Please sign in to comment.