Skip to content

FIX: runtime errors when compiled with flang #193

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

Merged
merged 3 commits into from
Jun 25, 2025

Conversation

tacaswell
Copy link
Collaborator

This fixes the run-time issue when complied with flang on windows noted in #135 (comment)

The first commit is adding explicit declarations of variables which seems like good practice (but is unrelated to the problem).

The second commit fixes the problem we identified with incorrect results when complied with flang.

The third commit fixes structurally similar issues that we have not disocvered as bugs yet (presumably because they would have only shown up on windows when compiled with flang which we otherwise abandoned work on due to the first issue!)


The root of the problem is that with both gfortran and flang the implemenattion of ACOSD in the source was not actually being used (I had a version of this with lots of print statements and without the EXTERNAL lines the ACOSD logs did not come out). It seems that there is a bug in flang's ACOSD intrinsic (?! 🤯 I could not sort out exactly what it was doing as wrong result was not just the radian version of the right result). By adding the EXTERNAL flag the linker picks the version in the source which works.

I could also see eliminating ACOSD (and friends) all together and working in radians in the code, but that would be a bigger (and riskier) change. I could also see removing the local local version of the degree sub-routines and sorting out which versions of flang they work correctly in, but that is a bigger project than I want to take on right now.


It seems in the last year CF has started to provide gfortran so this is a bit moot (sorry @briantoby , I incorrectly assumed we had moved to pulling gfortran for windows from the defaults channel), and my attempts to test with this branch on windows with flang failed with compiler errors (I think it is picking the wrong version of flang that does not play nice with visual studio). The pixi.lock file in https://github.com/tacaswell/GSAS-II/tree/clang-works compiles and is the branch I used to verify that this fixes the problem.

@tacaswell tacaswell changed the title Win fortran FIX: runtime errors when compiled with flang Jun 20, 2025
@briantoby briantoby merged commit d457fcf into AdvancedPhotonSource:main Jun 25, 2025
12 checks passed
@briantoby briantoby mentioned this pull request Jun 25, 2025
@tacaswell tacaswell deleted the win_fortran branch June 25, 2025 21:48
@tacaswell
Copy link
Collaborator Author

tacaswell commented Jun 25, 2025

llvm/llvm-project#145593

This uncovered a bug in flang! There is an open PR upstream to fix it.

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

Successfully merging this pull request may close these issues.

2 participants