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

Potential issue with Where statements in debug mode #1614

Closed
JosephMouallem opened this issue Nov 19, 2024 · 2 comments
Closed

Potential issue with Where statements in debug mode #1614

JosephMouallem opened this issue Nov 19, 2024 · 2 comments

Comments

@JosephMouallem
Copy link

Hi all,

I am encountering issues with where statements when running SHiELD/MOM6 in debug mode.
For example, the model performs a division by zero and crashes in xgrid.F90 when computing the inverse area, where grid%area>0 so not sure how the division by zero is happening in this context:

FMS/exchange/xgrid.F90

Lines 1973 to 1976 in 23df6d7

if(grid%on_this_pe) then
grid%area_inv = 0.0_r8_kind;
where (grid%area>0.0_r8_kind) grid%area_inv = 1.0_r8_kind/grid%area
endif

A similar issue arises in the monin obukhov routine:

where (mask_1)
rzeta = 1.0_lkind/zeta
zeta_0 = zeta/z_z0
zeta_t = zeta/z_zt
zeta_q = zeta/z_zq
end where

I am using the standard SHiELD template and compile flags: https://github.com/NOAA-GFDL/SHiELD_build/blob/main/site/intel.mk.

These issues are specific to DEBUG mode; everything works fine when compiling in REPRO mode.

@bensonr
Copy link
Contributor

bensonr commented Nov 25, 2024

There are some nuances with respect to where statements and the order things are evaluated leading to FPEs when you would expect to be protected against them. Whether you hit them or not is completely up to how the compiler is implemented.

@J-Lentz
Copy link
Contributor

J-Lentz commented Dec 30, 2024

Closing because this isn't an issue with FMS per se.

Floating point exceptions are enabled by the main program due to -fpe0 and -ftrapuv in the debug-mode mkmf flags, while optimization of FMS code causes speculative execution of divide-by-zero cases in the where statement without regard for the mask condition. Possible solutions are to add -fp-speculation=safe to the FMS build flags or to build FMS in debug mode when linking it with a debug-mode main program.

@J-Lentz J-Lentz closed this as completed Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants