Fix problems uncovered by adding the -nan compilation flag for the Nag compiler
- Dominant language
- Fortran
- Stars
- 352
- Forks
- 361
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
### Brief summary of bug
@cacraigucar, on behalf of the CAM group, has requested that we start adding the -nan compilation flag when building with the Nag compiler, which initializes variables to NaN, helping catch a variety of issues. However, this currently causes runtime failures in CTSM; we should resolve these so that we can add this useful compilation flag.
### General bug information
**CTSM version you are using:** What is about to become ctsm5.1.dev123, but with ccs_config_cesm0.0.63 (we will use ccs_config_cesm0.0.64 in dev123, which is the same as ccs_config_cesm0.0.63 but backs out the addition of the -nan flag because of this and possibly other issues currently encountered when using this flag).
**Does this bug cause significantly incorrect results in the model's science?** No?
**Configurations affected:** Compilations with the Nag compiler when trying to add the -nan flag.
### Details of bug
Most / all Nag cases fail at runtime. From spot-checking a couple, I see the same error in both:
```
*** Arithmetic exception: Floating invalid operation - aborting
/home/sacks/ctsm_code/ctsm/src/main/surfrdUtilsMod.F90, line 67: Error occurred in SURFRDUTILSMOD:CHECK_SUMS_EQUAL_1
/home/sacks/ctsm_code/ctsm/src/main/surfrdUtilsMod.F90, line 438: Called by SURFRDUTILSMOD:COLLAPSE_CROP_TYPES
/home/sacks/ctsm_code/ctsm/src/main/surfrdMod.F90, line 839: Called by SURFRDMOD:SURFRD_VEG_ALL
/home/sacks/ctsm_code/ctsm/src/main/surfrdMod.F90, line 192: Called by SURFRDMOD:SURFRD_GET_DATA
/home/sacks/ctsm_code/ctsm/src/main/clm_initializeMod.F90, line 243: Called by CLM_INITIALIZEMOD:INITIALIZE2
/home/sacks/ctsm_code/ctsm/src/cpl/nuopc/lnd_comp_nuopc.F90, line 659: Called by LND_COMP_NUOPC:INITIALIZEREALIZE
/home/sacks/ctsm_code/ctsm/components/cmeps/cime_config/../cesm/driver/esmApp.F90, line 128: Called by ESMAPP
```
At a glance, I can't see the reason this error is appearing when we add the -nan flag, but the relevant part of collapse_crop_types has some complex whole-array operations, and it's possible they are responsible for this issue. A first attempt at fixing this could be to rewrite that whole-array operation with an explicit loop.
### Important details of your setup / configuration so we can reproduce the bug
One test that exhibits this issue is `SMS_Ld5_D_P48x1.f10_f10_mg37.IHistClm51Bgc.izumi_nag.clm-decStart`, from ctsm5.1.dev123 but with ccs_config changed to ccs_config_cesm0.0.63.
@slevisconsulting - FYI, because you are probably the one most familiar with this collapse_crop_types code.
Contributor guide
Assessment
This issue has not been assessed yet.