Use of uninitialized values in `fv_mapz_mod.cs_profile` when `iv == -3`
Closed this issue · 5 comments
Describe the bug
Debugging the source of non-reproducibility for a configuration of SHiELD turned up the use of uninitialized values in a local array in the cs_profile
subroutine of the fv_mapz
module. The issue occurs only when iv == -3
, which corresponds to one of two possible modes for use when remapping the vertical velocity, the other being iv == -2
. I have verified this with additional means, but the issue can be identified by inspecting the lines of code clipped below, considering the case when iv == -3
:
GFDL_atmos_cubed_sphere/model/fv_mapz.F90
Lines 1988 to 2071 in e94dc4b
The issue specifically stems from the local
gam
array, which is declared in line 1988 without any initial assignment. When iv == -3
it gets values for level 1
in line 2025 and levels 2
through km - 1
(inclusive) in line 2034, but is not assigned values for level km
prior to being used in line 2068. This leads to undefined / non-reproducible behavior at runtime.
To Reproduce
Run SHiELD in non-hydrostatic mode with fv_core_nml.kord_wz
less than zero and abs(fv_core_nml.kord_wz) > 7
, e.g. fv_core_nml.kord_wz = -9
. This tells the model to use iv == -3
and cs_profile
when remapping the vertical velocity:
GFDL_atmos_cubed_sphere/model/fv_mapz.F90
Lines 411 to 424 in e94dc4b
Expected behavior
I would expect values to be defined for gam(:,km)
when iv == -3
prior to it being used in line 2068.
System Environment
Describe the system environment, include:
- OS: Ubuntu 20.04
- Compiler(s): GNU version 10.5
- MPI type, and version: MPICH 3.3.2
- netCDF Version: netCDF-C 4.7.3; netCDF-Fortran 4.5.2
- Configure options: 64bit
@spencerkclark you are correct. gam(i,km) was incorrectly not specified in the iv .eq. -2
branch. I believe it should be specified the same way as in the interior (gam(i,k) = d4(i) / bet
). This is an oversight on my part.
@laurenchilutti I haven't been assigned an issue before. Should I test the code and submit a patch? Thanks.
@lharris4 I did not look closely before assigning this - I had thought this was a PR and I was adding you as a reviewer. Please disregard the assignment.
@laurenchilutti Thank you.