From 33ce70c0f4ea8e6c3ea29bc50bcccc341ec5b001 Mon Sep 17 00:00:00 2001 From: likeuclinux Date: Tue, 4 Feb 2025 19:45:13 -0500 Subject: [PATCH] Fix access violation crash (#2137) TYPE: bug fix KEYWORDS: crash, access violation error SOURCE: Charlie Li, software developer from lakes environmental, Canada DESCRIPTION OF CHANGES: Problem: WRF crashed for access violation frequently, due to the change made in PR https://github.com/wrf-model/WRF/pull/1991 when namelist.input has sf_urban_physics = 0 and bl_pbl_physics = 1. Because those arrays from urban models are always available, but their memories are not available if the urban option is not turned on. This causes the access violation in module_bl_ysu.F Solution: The fix is actually using v4.5 logic to check on the flag 'flag_bep' before using the arrays. LIST OF MODIFIED FILES: phys/module_bl_ysu.F TESTS CONDUCTED: The Jenkins tests are all passing. RELEASE NOTE: This PR fixes a access violation error when a PGI compiler is used with urban variables in module_bl_ysu.F when urban option is turned off and the memories of those arrays are not available. --- phys/module_bl_ysu.F | 47 +++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/phys/module_bl_ysu.F b/phys/module_bl_ysu.F index 403532e094..fd071f5d7a 100644 --- a/phys/module_bl_ysu.F +++ b/phys/module_bl_ysu.F @@ -353,27 +353,34 @@ subroutine ysu(u3d,v3d,t3d,qv3d,qc3d,qi3d,p3d,p3di,pi3d, & present(b_v_bep) .and. present(b_t_bep) .and. present(b_q_bep) .and. & present(b_e_bep) .and. present(dlg_bep) .and. present(dl_u_bep) .and. & present(sf_bep) .and. present(vl_bep) .and. present(frc_urb2d)) then - do k = kts, kte - do i = its,ite - a_u_hv(i,k) = a_u_bep(i,k,j) - a_v_hv(i,k) = a_v_bep(i,k,j) - a_t_hv(i,k) = a_t_bep(i,k,j) - a_q_hv(i,k) = a_q_bep(i,k,j) - a_e_hv(i,k) = a_e_bep(i,k,j) - b_u_hv(i,k) = b_u_bep(i,k,j) - b_v_hv(i,k) = b_v_bep(i,k,j) - b_t_hv(i,k) = b_t_bep(i,k,j) - b_q_hv(i,k) = b_q_bep(i,k,j) - b_e_hv(i,k) = b_e_bep(i,k,j) - dlg_hv(i,k) = dlg_bep(i,k,j) - dl_u_hv(i,k) = dl_u_bep(i,k,j) - vlk_hv(i,k) = vl_bep(i,k,j) - sfk_hv(i,k) = sf_bep(i,k,j) + + ! following v4.5 logic to fix access violation + if(flag_bep) then + + do k = kts, kte + do i = its,ite + a_u_hv(i,k) = a_u_bep(i,k,j) + a_v_hv(i,k) = a_v_bep(i,k,j) + a_t_hv(i,k) = a_t_bep(i,k,j) + a_q_hv(i,k) = a_q_bep(i,k,j) + a_e_hv(i,k) = a_e_bep(i,k,j) + b_u_hv(i,k) = b_u_bep(i,k,j) + b_v_hv(i,k) = b_v_bep(i,k,j) + b_t_hv(i,k) = b_t_bep(i,k,j) + b_q_hv(i,k) = b_q_bep(i,k,j) + b_e_hv(i,k) = b_e_bep(i,k,j) + dlg_hv(i,k) = dlg_bep(i,k,j) + dl_u_hv(i,k) = dl_u_bep(i,k,j) + vlk_hv(i,k) = vl_bep(i,k,j) + sfk_hv(i,k) = sf_bep(i,k,j) + enddo enddo - enddo - do i = its, ite - frcurb_hv(i) = frc_urb2d(i,j) - enddo + do i = its, ite + frcurb_hv(i) = frc_urb2d(i,j) + enddo + + endif + endif do i = its, ite