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

atm_gray does not compile on macOS with gfortran #45

Open
gaelforget opened this issue Jun 21, 2021 · 3 comments
Open

atm_gray does not compile on macOS with gfortran #45

gaelforget opened this issue Jun 21, 2021 · 3 comments

Comments

@gaelforget
Copy link
Member

This is the error message I get:

Update AD_CONFIG.h and make ./mitgcmuv
make -f Makefile ./mitgcmuv
gfortran -fdefault-real-8 -fdefault-double-8 -fconvert=big-endian -Wunused -Wuninitialized -O3 -ftree-vectorize -funroll-loops  -c atm_phys_driver.for
atm_phys_driver.for:502:10:

  502 |       use radiation_mod
      |          1
Fatal Error: Cannot open module file 'radiation_mod.mod' for reading at (1): No such file or directory
compilation terminated.
make[1]: *** [atm_phys_driver.o] Error 1

when following the README directions using ../../../tools/genmake2 -mods ../code -of ../../../tools/build_options/darwin_amd64_gfortran on MacOS 11.3 and with gfortran v11

@jm-c
Copy link
Member

jm-c commented Aug 30, 2024

Could it be related to this: MITgcm/MITgcm#850 ?

@mjlosch
Copy link
Member

mjlosch commented Sep 2, 2024

Yes and no.

No: When I add my hack (-x f95), the problem does not go away.
This seems to be fixed-format code, and MITgcm/MITgcm#850 is explicitly about free-format code with an unusual suffix (not f90, but fr9). Here the suffix seems to be for, which gfortran (correctly) interprets as a fixed-format file.

But, atm_gray does not compile on my Mac, either, because the genmake_local by default (retv=1) sets options (-r8)that my gfortran does not recognise, when I set retv=0, I get FFLAGS='-fdefault-real-8 -fdefault-double-8' which works, but then I get @gaelforget's error. I think that the error is related to the dependencies of the modules not properly resolved in the makefile. I need to make sure (by hand) that I first compile the module files (in the right order!) so that they can be used in the compilation. I think that MITgcm/MITgcm#862 may address this.

Yes: without the -x f95 flag, I cannot compile the free format F90-> fr9 module files (but that's not what @gaelforget describes).

Update: with PR MITgcm/MITgcm#862 I still need to compile 3 module files "by hand":

make simple_sat_vapor_pres_mod.o
make gcm_params_mod.o
make monin_obukhov_mod.o

and from then on make works (but not make -j <N>, as described in PR 862), but at the link step I get many error messages like this following:

duplicate symbol '___constants_mod_MOD_constants_init' in:
    constants_mod.o

With the master branch I can modify the Makefile after the make depend step to replace all _mod.f90: ... by _mod.o: ... and the make works (but not make -j <N>). I am not sure if that's the way forward. It should really be _mod.o: *.mod instead of .o.

There seems to be some online "literature" on how to deal with "modern fortran" in Makefiles, e.g. here: https://aoterodelaroza.github.io/devnotes/modern-fortran-makefiles/

@mjlosch
Copy link
Member

mjlosch commented Sep 2, 2024

Another update: PR #858: Generic file endings for f90mkdepend should fix the issue described above for MacOS, except that there's a small modification to a sed-command (additional \|\r$, which means "or remove carriage return at the end of the line) that breaks it again ... should be easy to sort out? The sed command on MacOS follows POSIX and both the OR \| and \r are GNU extensions (according to ChatGPT) that do not work with POSIX standard (on linux I tried with --posix and this fails, too).

After that has been fixed, the issue of gfortran not recognising free-format files that have arbitrary suffixes (e.g. fr9) will also appear here and this is the same issue as MITgcm/MITgcm#850 .

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