NOAA-EMC / GFDL_atmos_cubed_sphere

The GFDL atmos_cubed_sphere dynamical core code
Other
2 stars 27 forks source link

Passing unallocated array dtdt (dtdt_m) to subroutine Lagrangian_to_Eulerian #29

Closed climbfuji closed 3 years ago

climbfuji commented 4 years ago

This affects the non-CCPP option only.

Subroutine Lagrangian_to_Eulerian expects the array dtdt (or dtdt_m internally) to be allocated: fv_mapz.F90, around line 200:

real, intent(inout)::   dtdt(is:ie,js:je,km)

In fv_dynamics.F90, however, this array is only allocated under certain conditions:

if ( idiag%id_mdt > 0 .and. (.not. do_adiabatic_init) ) then
       allocate ( dtdt_m(is:ie,js:je,npz) )
...

This can go very wrong and lead to model crashes or data corruption (luckily, it hasn't on the platforms and for the compilers we have been using so far; but we have seen similar cases leading to model crashes in the physics). A simple solution is to always allocate the array or make it an automatic array so that it gets allocated only once and only reset every time. Or make the variable declaration in Lagrangian_to_Eulerian an assumed-size declaration, in which case passing an unallocated object should be allowed:

real, intent(inout)::   dtdt(:,:,:)

This affects the non-CCPP option only. For CCPP the corresponding array is a member of the CCPP_interstitial data type and is always allocated.

junwang-noaa commented 3 years ago

Dom, is this issue resolved?

climbfuji commented 3 years ago

No, this is still an issue and needs to be addressed. The solution, however, will be easy now that we can remove the IPD related code - as soon as that is done and only the CCPP version remains, the array will always be allocated.