Skip to content

v12: Fixes for Flang 22#1220

Open
mathomp4 wants to merge 4 commits intofeature/v12-remove-mom5from
feature/fixes-for-flang
Open

v12: Fixes for Flang 22#1220
mathomp4 wants to merge 4 commits intofeature/v12-remove-mom5from
feature/fixes-for-flang

Conversation

@mathomp4
Copy link
Member

@mathomp4 mathomp4 commented Mar 11, 2026

This PR has fixes for Flang 22

NOTE: I am keeping this draft for now. I'm going to test if this is zero-diff for v12. It should be, but I want to be safe. There is a small chance that my using nint() for the access-array-with-reals could be different if ifort does an int(). It is int() which what the compilers do.

I'll also probably want to consult with @biljanaorescanin and @gmao-rreichle as flang found issues in the rasterizing code. Again mostly access-arrays-with-reals. → Testing with remap_restarts shows it is zero-diff here as well. Nice.


This pull request primarily focuses on improving type safety and compatibility in several Fortran routines across the GEOS physics grid components. The most significant changes are the consistent application of int() to ensure integer indices, enhancements to file handling for robustness, and improved compiler compatibility checks. Below are the most important changes grouped by theme:

Type Safety and Indexing Improvements:

  • Replaced direct use of potentially non-integer indices with int() in multiple routines, including wind and stress calculations in gw_convect.F90, vegetation tile handling in carbon regridding routines, and turbulence height assignment, ensuring indices are always integers and preventing potential runtime errors. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

File Handling Robustness:

  • Updated file size retrieval in mkMITAquaRaster.F90 from manual fstat calls to Fortran's inquire statement with error checking, improving reliability and error reporting when opening grid files. Also changed file size variables to use INT64 for large file support. [1] [2] [3] [4]

Compiler Compatibility Enhancements:

  • Refined conditional compilation checks for ftell external declaration to support both gfortran and flang, increasing portability across compilers in several restart and utility programs. [1] [2] [3] [4] [5] [6]

Minor Codebase Cleanups:

  • Removed unnecessary dependency on FMS::fms from the GEOSmoist_GridComp CMake configuration, streamlining build dependencies.
  • Added missing declaration for iargc in cv_SaltRestart.F90, resolving a potential undeclared variable issue.

These changes collectively improve the reliability, maintainability, and portability of the GEOS physics grid component codebase.

@mathomp4 mathomp4 self-assigned this Mar 11, 2026
@mathomp4 mathomp4 added 0 diff The changes in this pull request have verified to be zero-diff with the target branch. Non 0-diff The changes in this pull request are non-zero-diff labels Mar 11, 2026
Copy link
Contributor

@gmao-rreichle gmao-rreichle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mathomp4 : Thanks for putting together this PR and checking in about any land impact.

The only mods I see in the rasterization code are in mkMITAquaRaster.F90, which is for the coupled model and about which I know nothing. To be safe, @biljanaorescanin can test the creation of coupled-model bcs.

I see some changes in mk_restarts, which all look innocuous. To be safe, @biljanaorescanin can test the remap_restarts package. Note that some of the mk_restart files that are touched in this PR may be slated for removal. We may (or may not) still be waiting for the v12 GCM to make it to develop so we can clean up old code that goes with "regrid.pl", which is no longer supported in the v12 GCM. ‎ And I can never remember which mk_restart programs are used only by "regrid.pl" (but not by the new "remap_restart" python package). @weiyuan-jiang would know.

@mathomp4 mathomp4 removed the Non 0-diff The changes in this pull request are non-zero-diff label Mar 12, 2026
@mathomp4
Copy link
Member Author

@gmao-rreichle I can say this is zero-diff to stock v12 as of today as far as the model is concerned. So I believe using int() is the safe option.

I'll try remap_restarts now as well sparing @biljanaorescanin from needing to do that. :)

@gmao-rreichle
Copy link
Contributor

I'll try remap_restarts now as well sparing @biljanaorescanin from needing to do that. :)

Thanks, @mathomp4. Just in case the info got lost, we have a set of tests for remap_restarts:
https://github.com/GEOS-ESM/GEOS_Util/tree/main/pre/remap_restart/tests

@mathomp4
Copy link
Member Author

@gmao-rreichle I can say this is zero-diff to stock v12 as of today as far as the model is concerned. So I believe using int() is the safe option.

I'll try remap_restarts now as well sparing @biljanaorescanin from needing to do that. :)

Update. I did a remap from C180 CS Ocean v12 Land to C48 MERRA2 Ocean NL3 Land and both this PR and stock v12 are identical. I think we are good

@mathomp4
Copy link
Member Author

I'll try remap_restarts now as well sparing @biljanaorescanin from needing to do that. :)

Thanks, @mathomp4. Just in case the info got lost, we have a set of tests for remap_restarts: GEOS-ESM/GEOS_Util@main/pre/remap_restart/tests

Oh yeah. @weiyuan-jiang recently fixed that for us. Let me try that...

@mathomp4 mathomp4 added the Non 0-diff The changes in this pull request are non-zero-diff label Mar 12, 2026
@mathomp4
Copy link
Member Author

@gmao-rreichle So, huh. Exactly one restart is not identical. The gocart_internal_rst from the f522Toc360 case in 9 points on earth:

Variable Position Baseline Value Test Value Absolute Difference Relative Difference
MSA [70,815,269] 4.395786306569255e-13 4.395786577619798e-13 2.710505e-20 6.166145e-08
NO3an1 [28,762,280] 1.58500955416141e-11 1.585009901106105e-11 3.469447e-18 2.188912e-07
NO3an2 [34,1107,268] 3.073211986542174e-13 3.073212257592717e-13 2.710505e-20 8.819780e-08
du004 [34,2119,86] 1.501894136547424e-17 1.501894301983546e-17 1.654361e-24 1.101517e-07
du005 [5,2086,67] 1.183363202218857e-38 1.183363342348704e-38 1.401298e-45 1.184166e-07
du005 [6,2086,67] 1.181040129624699e-38 1.181040269754546e-38 1.401298e-45 1.186495e-07
ss002 [29,799,42] 1.24064102632708e-13 1.240640890801809e-13 1.355253e-20 1.092381e-07
ss002 [32,799,42] 8.102980634562551e-13 8.102980092461465e-13 5.421011e-20 6.690144e-08
ss005 [26,2118,273] 1.084696985447259e-28 1.084696744706016e-28 2.407412e-35 2.219433e-07

Per internet this number: 1.401298e-45 is "exactly one float32 ULP at the smallest denormal, meaning some of these differences are literally 1 bit in the mantissa".

So I think this means there was a slight rounding difference somewhere.

@mathomp4
Copy link
Member Author

Per a suggestion from @tclune I'm doing a test now where I undo this change and run the tester again. If those are identical, then the difference is something between the v12 @weiyuan-jiang used for the Baselines (which is more of a "stock v12" than the "development v12" I started from)

@mathomp4
Copy link
Member Author

Per a suggestion from @tclune I'm doing a test now where I undo this change and run the tester again. If those are identical, then the difference is something between the v12 @weiyuan-jiang used for the Baselines (which is more of a "stock v12" than the "development v12" I started from)

This is confirmed. The difference is due to something that changed in v12 not in my PR. Phew. Now what was the change? I dunno, but I didn't do it! 😄

@mathomp4 mathomp4 removed the Non 0-diff The changes in this pull request are non-zero-diff label Mar 12, 2026
@mathomp4
Copy link
Member Author

I've removed the non-zero-diff label as this seems to be very zero-diff! Huzzah!

@mathomp4 mathomp4 marked this pull request as ready for review March 12, 2026 16:11
@mathomp4 mathomp4 requested review from a team as code owners March 12, 2026 16:11
@gmao-rreichle
Copy link
Contributor

This is confirmed. The difference is due to something that changed in v12 not in my PR. Phew. Now what was the change?

@mathomp4 @biljanaorescanin @weiyuan-jiang : Do we know if the non-zero-diff might also apply to "develop"? Matt tested this on the "v12" branch, but that doesn't mean it's not present in develop (v11). We don't always test for zero-diff of remap_restarts, and such a non-zero-diff change in remap_restarts might well have slipped through the cracks on develop.

@biljanaorescanin
Copy link
Contributor

biljanaorescanin commented Mar 12, 2026

Last week when I tested develop GCM v11 only thing different was AKand BK in fvcore that was missed to be rebased but today my tests are failing for many diff variables in many different restarts.
I will have to talk with @mathomp4 and see what happened in between. If tests use wrong rebase or what.
It could be that rebase was done for GCM v12 and we still compare and want to run for GCM v11 as well so that could explain all the differences...

@gmao-rreichle
Copy link
Contributor

Last week when I tested develop GCM v11 only thing different was AKand BK in fvcore that was missed to be rebased but today my tests are failing for many diff variables in many different restarts. I will have to talk with @mathomp4 and see what happened in between. If tests use wrong rebase or what. It could be that rebase was done for GCM v12 and we still compare and want to run for GCM v11 as well so that could explain all the differences...

@biljanaorescanin : Are you talking about the routine nightly tests here or about testing remap_restarts?

@biljanaorescanin
Copy link
Contributor

biljanaorescanin commented Mar 12, 2026

Last week when I tested develop GCM v11 only thing different was AKand BK in fvcore that was missed to be rebased but today my tests are failing for many diff variables in many different restarts. I will have to talk with @mathomp4 and see what happened in between. If tests use wrong rebase or what. It could be that rebase was done for GCM v12 and we still compare and want to run for GCM v11 as well so that could explain all the differences...

@biljanaorescanin : Are you talking about the routine nightly tests here or about testing remap_restarts?

Running test_remap_restarts.py package from what you get with develop GCM v11.
Actually, when I read @mathomp4 comments that is definitely it ( baseline is now v12 for restarts package) since he gets zero diff.

@mathomp4
Copy link
Member Author

Running test_remap_restarts.py package from what you get with develop GCM v11. Actually, when I read @mathomp4 comments that is definitely it ( baseline is now v12 for restarts package) since he gets zero diff.

Yes. At the moment the test script will target v12. If needed, we could create a v11 baseline for v11 testing?

@weiyuan-jiang
Copy link
Contributor

The difference is only on fvcore and related restarts like moist. It is zero-diff for catch, lake, landice. @gmao-rreichle

@gmao-rreichle
Copy link
Contributor

Running test_remap_restarts.py package from what you get with develop GCM v11.
Actually, when I read @mathomp4 comments that is definitely it ( baseline is now v12 for restarts package) since he gets zero diff.

The difference is only on fvcore and related restarts like moist. It is zero-diff for catch, lake, landice. @gmao-rreichle

@mathomp4 , @sdrabenh : I approved the PR, based on Matt's finding that it's zero-diff. We will have to follow up, though, on the non-zero diff results for remap_restarts that happened before this PR.

@weiyuan-jiang , @biljanaorescanin : I'm getting a bit lost what we are and aren't seeing here in terms of non-zero diff results. It doesn't really matter that the non-zero-diff results are only in restarts related to fvcore and moist. Remap_restarts as a whole must be zero-diff, not just catch-related restarts. If there are any non-zero diff results, we need to explain, evaluate, and document the non-zero-diff change. Let's discuss at our next LDAS tagup.

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.

4 participants