NCAR / wrf_hydro_nwm_public

WRF-Hydro model code
https://ral.ucar.edu/projects/wrf_hydro
Other
181 stars 139 forks source link

Bug: Optimization -O0 Causes erroneous arithmetic operation SIGFPE #650

Closed scrasmussen closed 2 years ago

scrasmussen commented 2 years ago

Expected Behavior

Run without SIGFPE.

Current Behavior

When optimization is -O0 then both statements of an if statement are calculated, causing the STEPWTD variable to be used in the remainder mod function, but in certain codeflows this will be zero. This causes a SIGFPE, a floating-point exception from an erroneous arithmetic operation, at LandModel/phys/module_sf_noahmpdrv.F:1878

IF(noah_lsm%RUNOFF_OPTION.EQ.5.AND.MOD(ITIME,STEPWTD).EQ.0)THEN

Possible Solution

Initialize with STEPWTD = 1 to avoid SIGFPE. The variable STEPWTD gets set in this line:

STEPWTD = max(STEPWTD,1)

This line doesn't get run with certain namelist options, but since the minimum value of STEPWTD should be one, STEPWTD can be initialized as one to fix the bug and void any other side-effects.

Steps to Reproduce (for bugs)

Turn optimization flag in macros file to -O0. Setting RUNOFF_OPTION = 3 in namelist.hrldas should be enough.

Your Environment

Version of the code used: 08.12.2022 Trunk
Operating System and version: Linux
Compiler and version: GNU 12.1.0
Other relevant information: Cheyenne