NGEET / fates

repository for the Functionally Assembled Terrestrial Ecosystem Simulator (FATES)
Other
105 stars 92 forks source link

reduce usage of patch structures with leaflayer memory #951

Open rgknox opened 2 years ago

rgknox commented 2 years ago

Below is a list of some large arrays (that use nlevleaf) on the patch structure, and a description of how the memory is used. Note that the first 6 arrays are calculated in one location and used in another location, which demands a genuine need to remember the values. But the other 16 really don't need to be remembered. One or two we just don't use, a couple can be recreated from other arrays on demand, and most of them are used in history diagnostics. If we move the calls to update history diagnostic arrays to the location where these arrays are defined, then we don't need to have these arrays on the patch structure.

Also, we can avoid the memory and computation costs of reading/writing these large arrays if we add in a namelist switch that defines if we want leaf-layer output included in history. The majority of users do not need such high density output.

Also, the allocations that we do need could save space by using dynamic allocations that use "numpft" instead of "maxpft". maxpft is always 16, but many users have only 1 pft. Our global tests only use 12.

cpatch%ed_parsun_z(ican,ipft,ileaf)  - used in photosynthesis
cpatch%ed_parsha_z(ican,ipft,ileaf)  - used in photosynthesis
cpatch%f_sun(ican,ipft,ileaf) - used in photosynthesis
cpatch%elai_profile(ican,ipft,ileaf)  - used in photosynthesis and radiation
cpatch%esai_profile(ican,ipft,ileaf)  - used in photosynthesis and radiation
cpatch%canopy_area_profile(ican,ipft,ileaf) - used in radiation and photosynthesis

tlai_profile(ican,ipft,ileaf)  - used to calculate TLAI, but doesn’t need to be an array
tsai_profile(ican,ipft,ileaf)  - used to calculate TSAI, but doesn’t need to be an array
layer_height_profile(ican,ipft,ileaf) - DOES NOTHING
cpatch%ed_laisun_z(ican,ipft,ileaf)  - redundant with f_sun and elai_profile
cpatch%ed_laisha_z(ican,ipft,ileaf)  - redundant with f_sun and elai_profile
cpatch%fabd_sun_z(ican,ipft,ileaf) - only history
cpatch%fabd_sha_z(ican,ipft,ileaf) - only history
cpatch%fabi_sun_z(ican,ipft,ileaf) - only history
cpatch%fabi_sha_z(ican,ipft,ileaf) - only history
cpatch%parprof_dir_z(ican,ileaf) - only history
cpatch%parprof_dif_z(ican,ileaf) - only history 
cpatch%nrmlzd_parprof_pft_dir_z(nrad,ican,ipft,ileaf) - ONLY in radiation, can be local
cpatch%nrmlzd_parprof_pft_dif_z(nrad,ican,ipft,ileaf) - ONLY in radiation, can be local
cpatch%nrmlzd_parprof_dir_z(nrad,ican,ileaf) - ONLY in radiation, can be local
cpatch%nrmlzd_parprof_dif_z(nrad,ican,ileaf) - ONLY in radiation, can be local
cpatch%psn_z   -  ONLY photosynthesis, can be local array
rgknox commented 2 years ago

Proposed name of namelist switch:

fates_history_density_level = integer

1 - fastest, no high frequency (sub-daily) history writing, only variables that are updated daily 2 - typical, include high frequency history output (sub-daily), but no large arrays such as those with leaf-layer 3 - slowest, include history output that is written at high frequency and those variables with large arrays

We could also in the future extend this. For instance, if we want no multi-dimensional arrays in the daily dynamics history output (ie faster than fastest), then we could use code zero.