From 15ce4d4d66eda33dfac741b8e8604dc98dc90c84 Mon Sep 17 00:00:00 2001 From: Philippe Blain Date: Mon, 15 Aug 2022 15:22:16 -0400 Subject: [PATCH] ice_calendar: zero-initialize 'nstreams' 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. --- cicecore/shared/ice_calendar.F90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cicecore/shared/ice_calendar.F90 b/cicecore/shared/ice_calendar.F90 index 7684fef67..284af2085 100644 --- a/cicecore/shared/ice_calendar.F90 +++ b/cicecore/shared/ice_calendar.F90 @@ -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