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

compilation fails with gfortran 12.1.0 #23

Open
jornbr opened this issue Jul 22, 2022 · 5 comments
Open

compilation fails with gfortran 12.1.0 #23

jornbr opened this issue Jul 22, 2022 · 5 comments

Comments

@jornbr
Copy link

jornbr commented Jul 22, 2022

With gfortran 12.1.0 a large number of errors like one below are reported. Compilation thus does not succeed.

.../GSW-Fortran/modules/gsw_mod_check_data.f90:781:30:

781 | "C_from_SP", 6.1638e-10_r8, (/ &
| 1
Error: The rank of the element in the structure constructor at (1) does not match that of the component (1/2)

It seems that this gfortran release does not like 1D data to be assigned to a 2D array. This is not a problem for earlier gfortran releases, nor for intel fortran. I'm not sure whether gfortran 12 is overly strict in its interpretation of the Fortran standards here, or the others are too lenient...

@jornbr
Copy link
Author

jornbr commented Aug 17, 2022

Just to add that gfortran 10.4.0 and 11.3.0 are also affected by this. gfortran 9.5.0 is ok.

@bolding
Copy link
Contributor

bolding commented Aug 17, 2022

I've found a fix - but it is quite tedious to implement. So before proceeding I have the following questions:

  1. Shall we wait and see if gfortran is fixed?

  2. Is the file gsw_mod_check_data.f90 auto generated - or created in an editor?

The fix is to explicit put a reshape in for all 2d arrays when they are part of a type. There is more than 200 places to fix. So if the file is auto generated the issue should be fixed during the generation. If not auto generated some clever search and replace might do the most of the work.

@jornbr
Copy link
Author

jornbr commented Aug 22, 2022

Since this problem did not occur with any gfortran version from before May 2022, nor with ifort, it looked like it could be a gfortran bug. However, it is not: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106684. Thus the code would need a fix. Use of reshape as mentioned above is an option, and the bugzilla thread also mentions an alternative at the very bottom.

bolding added a commit to bolding/GSW-Fortran that referenced this issue Aug 23, 2022
versions of gfortran (10.4.0, 11.3.0 and 12.1.0) fails

For a discussion of the Fortran issue see:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106684

For a discussion on how it is resolved see:
TEOS-10#23
@bolding
Copy link
Contributor

bolding commented Aug 23, 2022

Code similar to this

image

fails.

There at least two solutions:

  1. explicitly add a reshape to the array argument of the initialsation
  2. explicitly specify the variables of the type during initialisation

The double reshape is more error prone so the 2. method have been chosen resulting in code similar to:
image

And this solution is also more in line with how the simple variables are initialized.

The new code has been checked on gfortran (9.4.0, 10.3.0, 11.2.0 and 12.0.1) on Linux Mint (Ubuntu). The old code fails with 10.3.0, 11.2.0 and 12.0.1.

@bolding
Copy link
Contributor

bolding commented Aug 24, 2022

The pull request has been extended to include a Github Actions file - that - upon a git push - will compile GSW-Fortran and run the test programs gsw_check_functions.x and gsw_poly_check.x on the Github infrastructure.

Results can be inspected here - https://github.com/TEOS-10/GSW-Fortran/actions.

At present gfortran version 9, 10 and 11 are checked using Ubuntu.

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

2 participants