ESCOMP / ESCOMP/CTSM

Crash with shallow bedrock in FATES non-SP

Open
#4,159 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Fortran
Stars
352
Forks
361
Avg merge
2d 21h
Merged PRs (30d)
7

Description

### Brief summary of bug

As part of my testing of #3927, I'm adding some (probably temporary) tests at Hui's ALP2 site. These tests replicate Hui's setup exactly, which includes `use_bedrock = .true.`. This worked fine in SP mode, but it causes a crash when I try to run in no-comp/fixed-biogeography mode.

### General bug information

**CTSM version you are using:** ctsm5.4.028

**Does this bug cause significantly incorrect results in the model's science?** No

**Configurations affected:** Non-SP FATES runs with `use_bedrock` true and any site/gridcell with `zbedrock` shallower than the deepest decomp layer.

### Important output or errors that show the problem

```
At line 1538 of file /glade/work/samrabin/ctsm_hui_moss/src/utils/clmfates_interfaceMod.F90
Fortran runtime error: Index '20' of dimension 1 of array 'this...%litt_flux_lab_c_si' outside of expected range (6:1)

Error termination. Backtrace:
#0 0x781b9f in __clmfatesinterfacemod_MOD_updateclitterfluxes
at /glade/work/samrabin/ctsm_hui_moss/src/utils/clmfates_interfaceMod.F90:1538
#1 0x1c2bdb1 in __cncstateupdate1mod_MOD_cstateupdate1
at /glade/work/samrabin/ctsm_hui_moss/src/biogeochem/CNCStateUpdate1Mod.F90:202
#2 0x1c70242 in __cndrivermod_MOD_cndrivernoleaching
at /glade/work/samrabin/ctsm_hui_moss/src/biogeochem/CNDriverMod.F90:626
#3 0xd647c0 in __cnvegetationfacade_MOD_ecosystemdynamicspredrainage
at /glade/work/samrabin/ctsm_hui_moss/src/biogeochem/CNVegetationFacade.F90:1057
#4 0x6ebf34 in __clm_driver_MOD_clm_drv
at /glade/work/samrabin/ctsm_hui_moss/src/main/clm_driver.F90:1112
#5 0x6691ff in modeladvance
at /glade/work/samrabin/ctsm_hui_moss/src/cpl/nuopc/lnd_comp_nuopc.F90:913
```

Here's the failing line (note that line number is different from the one in the error message):
https://github.com/ESCOMP/CTSM/blob/a96fb3f836afe2284a618c740a9fa3977a558313/src/utils/clmfates_interfaceMod.F90#L1514-L1517

That line of code is not reached in SP mode, which explains why I only started seeing the error at higher complexity.

### Details of bug
`litt_flux_lab_c_si` is allocated in FATES, in `allocate_bcout()`. It's set to the value passed in to the third argument of that subroutine, which in the subroutine definition is given the dummy variable name `nlevdecomp_in`. The subroutine is called in CLM's `CLMFatesInterfaceMod` here, where you can see it's actually set to `col%nbedrock`, not `nlevdecomp`:
https://github.com/ESCOMP/CTSM/blob/a96fb3f836afe2284a618c740a9fa3977a558313/src/utils/clmfates_interfaceMod.F90#L985-L990

My error won't happen, then, unless `nlevdecomp` is less than `col%nbedrock`. It happens in my run because the `fsurdat` file for this site specifies `zbedrock = 0.4`, which results in `col%nbedrock` = 6. Since `nlevdecomp` is 20, it triggers the crash.

Contributor guide

Open the contributing guide

Research direction

Start in src/utils/clmfates_interfaceMod.F90, especially the allocation call around lines 985-990 and the failing litter-flux access around lines 1514-1517. Reproduce a non-SP FATES run with use_bedrock enabled and zbedrock shallower than the deepest decomposition layer. Done means the shallow-bedrock case completes without an out-of-bounds access.

Written by the indexing model from the issue text.

Assessment

Tech stack
fortran
Domain
hpc
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.