NCAR / ccpp-physics

GFS physics for CCPP
Other
58 stars 145 forks source link

Uninitialized variables in module_mp_thompson.F90 #891

Closed SamuelTrahanNOAA closed 2 years ago

SamuelTrahanNOAA commented 2 years ago

Description

In module_mp_thompson.F90, the min_rand variable is used but never uninitialized. If you initialize min_rand=0, the scheme passes that point, but fails later due to a temperature of 4.821964740593585E+036. That likely indicates uninitialized memory or out-of-bounds array access elsewhere.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

You can see this plainly in the source code, but if you want the Intel compiler to tell you, do this.

  1. In the ufs-weather-model tests/ directory, make a conf file with this:
    
    COMPILE | -DAPP=ATM -DDEBUG=ON  -DCCPP_SUITES=FV3_RAP,FV3_RAP_sfcdiff,FV3_HRRR,FV3_RRFS_v1beta,FV3_RRFS_v1nssl -D32BIT=ON                     |                                         | fv3 |

RUN | regional_spp_sppt_shum_skeb | | fv3 |


2. Run that regression test.
3. Witness the stack trace on Hera using the Intel compiler.
4. Initialize the min_rand to 0
5. Rerun the regression test
6. The test passes that point, but fails later due to a temperature of 4.821964740593585E+036.

## Output

If you run the regression test as described above, you'll see this:

35: forrtl: error (182): floating invalid - possible uninitialized real/complex variable. 35: Image PC Routine Line Source
35: fv3.exe 000000000AE8A8EE Unknown Unknown Unknown 35: libpthread-2.17.s 00002B05702DE630 Unknown Unknown Unknown 35: fv3.exe 0000000009416FD7 module_mp_thompso 1295 module_mp_thompson.F90 35: fv3.exe 0000000009754A84 mp_thompson_mp_mp 635 mp_thompson.F90 35: fv3.exe 00000000071CA248 ccpp_fv3_hrrr_phy 12648 ccpp_FV3_HRRR_physics_cap.F90 35: fv3.exe 0000000006B44C37 ccpp_static_api_m 662 ccpp_static_api.F90 35: fv3.exe 0000000006B37E60 ccpp_driver_mp_cc 188 CCPP_driver.F90 35: libiomp5.so 00002B056E9EEA43 kmp_invoke_micr Unknown Unknown 35: libiomp5.so 00002B056E9B1CDA Unknown Unknown Unknown 35: libiomp5.so 00002B056E9B35B6 kmp_fork_call Unknown Unknown


The error is here:
     if (rand_perturb_on .ne. 0) then
        if (MOD(rand_perturb_on,2) .ne. 0) rand1 = rand_pert(i,1)
        m = RSHIFT(ABS(rand_perturb_on),1)
        if (MOD(m,2) .ne. 0) rand2 = rand_pert(i,1)*2.
        m = RSHIFT(ABS(rand_perturb_on),2)
  ==>   if (MOD(m,2) .ne. 0) rand3 = 0.25*(rand_pert(i,1)+ABS(min_rand))  <==
        m = RSHIFT(ABS(rand_perturb_on),3)
     endif
SamuelTrahanNOAA commented 2 years ago

I have submitted a PR with a temporary solution to avoid this broken code holding up other development: remove the regression test.

https://github.com/ufs-community/ufs-weather-model/pull/1151

ligiabernardet commented 2 years ago

Can this issue be closed?