chem: add scalar guards for p_hcl and p_ch3cl in add_anthropogenics t… - #2387
AlphaBetaGammaChi wants to merge 3 commits into
Conversation
…o prevent SIGSEGV in non-halogen mechanisms
|
The regression results: |
…from uninitialized loop indices In WRF 4.8, area=(dx/mapfac_mx(i,j))*(dy/mapfac_my(i,j)) was placed at subroutine entry before loop indices i and j are initialized. On modern compilers (e.g. GCC 13 on aarch64/x86_64 with -O3), this causes an immediate SIGSEGV out-of-bounds memory access. Restores the safe area=dx*dx calculation.
|
@dudhia Without this, the model can abort as it has been shown - using array indices outside do loops. If it needs to be that accurate, there are other ways to fix it. |
|
I introduced area=(dx/mapfac_mx(i,j))*(dy/mapfac_my(i,j)) And I could achievemass-balancee closure with it. Using does not provide mass-balance closure, as it is a less accurate area calculation. |
|
@saneku Can you move the area calculation to a do loop where the accurate area information is needed? For example area can be defined inside the i,j do loop that begins on line 455, for example. Or you can declare a local 2D array to store the area array to be used later? |
|
I agree with @weiwangncar. The map-factor-aware area calculation should be preserved, but moved inside the i,j loops, where the indices are defined: ! For volcanic ash transport, vash variables are in mixing ratio here. The area argument should then be removed from the preceding diagnostic message. Its format should also be changed from 2f15.3 to f15.3: |
|
@AlphaBetaGammaChi Would you like to make this change in this PR? |
|
@weiwangncar and @AlphaBetaGammaChi i have noticed that this correction is already implemented in |
|
@saneku Thanks for the alert. We will review PR-2353 and close this one afterwards. |
|
Hi @weiwangncar, Thank you! Just to flag: PR #2353 addresses the Without those guards, any CRI-MECH run ( Would it be possible to either:
Happy to proceed either way! |
|
@AlphaBetaGammaChi I suggest to go with your proposal #1. Thanks for the reminder for the other fix. |
Fixes a runtime SIGSEGV crash during
emissions_driverwhen running chemical mechanisms that do not include anthropogenic chlorine (such as CRI-MECH withemiss_opt = 19oremiss_opt = 20).Cause
In
chem/module_emissions_anthropogenics.F, assignments forp_hclandp_ch3clwere placed in the generic anthropogenic emissions loop withoutparam_first_scalarbounds checks.For mechanisms where
e_hclande_ch3clare not present in the package, referencingchem(..., p_hcl)andemis_ant(..., p_e_hcl)causes an invalid memory reference and crashes on timestep 1: