Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix for GCC 14. Always allocate NH arrays #104

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

mathomp4
Copy link
Member

@mathomp4 mathomp4 commented Oct 23, 2024

This fixes issue with GCC 14 with Debugging flags.

Testing with Intel shows this is zero-diff when running hydrostatic v11.

Also, as expected, in v12, GCC 14 Debug runs just fine since that is non-hydrostatic by default.


Testing with GCC 14 with Debugging on found a bug when running as hydrostatic:

Error termination. Backtrace:
At line 505 of file /discover/nobackup/mathomp4/SystemTests/builds/AGCM_GNU/CURRENT/GEOSgcm/src/Components/@GEOSgcm_GridComp/GEOSagcm_GridComp/GEOSsuperdyn_GridComp/@FVdycoreCubed_GridComp/@fvdycore/model/dyn_core.F90
Fortran runtime error: Index '2' of dimension 3 of array 'w' outside of expected range (1:1)

This is on the call to c_sw:

do k=1,npz
call c_sw(delpc(isd,jsd,k), delp(isd,jsd,k), ptc(isd,jsd,k), &
pt(isd,jsd,k), u(isd,jsd,k), v(isd,jsd,k), &
w(isd:,jsd:,k), uc(isd,jsd,k), vc(isd,jsd,k), &
ua(isd,jsd,k), va(isd,jsd,k), omga(isd,jsd,k), &
ut(isd,jsd,k), vt(isd,jsd,k), divgd(isd,jsd,k), &
flagstruct%nord, dt2, hydrostatic, .true., bd, &
gridstruct, flagstruct)
enddo

The current code for allocating w is:

    if ( Atm%flagstruct%hydrostatic ) then
       !Note length-one initialization if hydrostatic = .true.
       allocate (    Atm%w(isd:isd, jsd:jsd  ,1) )
       allocate ( Atm%delz(isd:isd, jsd:jsd  ,1) )
       allocate (  Atm%ze0(is:is, js:js  ,1) )
    else
       allocate (    Atm%w(isd:ied, jsd:jed  ,npz  ) )
       allocate ( Atm%delz(isd:ied, jsd:jed  ,npz) )
       if( Atm%flagstruct%hybrid_z ) then
          allocate (  Atm%ze0(is:ie, js:je ,npz+1) )
       else
          allocate (  Atm%ze0(is:is, js:js  ,1) )
       endif
       !         allocate ( mono(isd:ied, jsd:jed, npz))
    endif

The issue is that because I was running hydrostatic, w is w(1,1,1). But the call to c_sw is do k = 1, npz and when it gets to the second loop, boom.

So, the simple fix is to just always allocate these arrays. It is wasteful, but solves the issue.

NOTE 1: As I'm not sure how to test the hybrid_z bits of this, I've kept it as is. I suppose it should probably always be allocated as well

NOTE 2: From my reading of the current mothership fvdycore (which we have diverged from, but share a common ancestor), they could have the same issue there (see https://github.com/NOAA-GFDL/GFDL_atmos_cubed_sphere/blob/44e20a7d45ac1d2c3b84a6ffaa0c88b4cc3d5175/model/fv_arrays.F90#L1546-L1563 and https://github.com/NOAA-GFDL/GFDL_atmos_cubed_sphere/blob/44e20a7d45ac1d2c3b84a6ffaa0c88b4cc3d5175/model/dyn_core.F90#L440-L448). For that reason, I mention @bensonr as this might be seen by them if/when they test with GCC 14. (Though if they don't see it, I guess that says something interesting too!)

@mathomp4 mathomp4 added the 0 diff The changes in this pull request have verified to be zero-diff with the target branch. label Oct 23, 2024
@mathomp4 mathomp4 requested a review from wmputman October 23, 2024 15:20
@mathomp4 mathomp4 self-assigned this Oct 23, 2024
@mathomp4 mathomp4 marked this pull request as ready for review October 23, 2024 16:41
@mathomp4 mathomp4 merged commit c038dc3 into geos/main Oct 23, 2024
10 checks passed
@mathomp4 mathomp4 deleted the hotfix/mathomp4/gcc-14-array-fix branch October 23, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 diff The changes in this pull request have verified to be zero-diff with the target branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant