MCSclimate / MCT

Model Coupling Tookit
Other
43 stars 18 forks source link

make fails with GNU 10 compilers #63

Closed andreapiacentini closed 3 years ago

andreapiacentini commented 3 years ago

Good morning, I am compiling the git master version of MCT on a Mac Os X (Mojave) under Brew. Brew has recently updated gnu compilers to version 10 (as Ubuntu has done on the linux side since version 20.10).

Polymorphic fortran API's are not accepted anymore by default and they require the -fallow-argument-mismatch option for gfortran (or mpifort, mpif90 and similar wrappers).

The configure should be able to detect the gnu compiler version and add this option (unfortunately not recognised by previous gnu compilers, therefore the test on the version is needed), otherwise make fails on

mpicc -c -DSYSDARWIN -DCPRINTEL -g -O2  -I. -I../ get_zeits.c
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_mpif.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_realkinds.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_stdio.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_mpif90.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_dropdead.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_chars.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_flow.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_ioutil.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_mpout.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_die.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_IndexBin_char.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_IndexBin_integer.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_IndexBin_logical.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_mall.F90
mpif90 -c  -I. -I../ -DSYSDARWIN -DCPRINTEL -O2  -g -O2   m_String.F90
m_String.F90:478:17:

  457 |   call MPI_bcast(ln,1,MP_INTEGER,root,comm,ier)
      |                 2
......
  478 |   call MPI_bcast(Str%c(1),ln,MP_CHARACTER,root,comm,ier)
      |                 1
Error: Type mismatch between actual argument at (1) and actual argument at (2) (CHARACTER(1)/INTEGER(4)).
make[1]: *** [m_String.o] Error 1
make: *** [subdirs] Error 2

Thank you very much A.P.

ndkeen commented 3 years ago

I also hit this issue and got around with -fallow-argument-mismatch.

Note I then hit another issue which I was able to avoid with -fallow-invalid-boz

integer, parameter :: gen_hash_key_offset = z'000053db'

But then ran into a link issue.

https://github.com/E3SM-Project/E3SM/issues/3954

rljacob commented 3 years ago

Confirmed with latest MCT on Cori.nersc.gov using gnu 10.1.0.

rljacob commented 3 years ago

This discussion suggests its an MPI issues https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91731 So adding that flag is the only way to fix it within MCT.

andreapiacentini commented 3 years ago

Unfortunately the -fallow-argument-mismatch option is not accepted by gfortran <10 The same issue has been dealt with (and extended to NAG compilers) by NetCDF (similar problem of polymorphic calls) in their https://github.com/Unidata/netcdf-fortran/blob/master/configure.ac Cf. lines 307 - 350 @rljacob could you please try to insert the corresponding section in the MCT autoconf files (in the main configure or, perhaps, in the fortran configuration in the m4 directory) ? Thanks

andreapiacentini commented 3 years ago

Hi @rljacob Please find here attached a modified configure.ac (requires autoreconf for generating a new configure) capable of detecting the appropriate mismatch flags. It also addresses another issue: passing mpifort (the open-mpi wrapper for whatever fortran is behind), the test looking for ifort in FC gives a false positive. Even if there are separate variables for MPIFC and FC, OASIS only knows the mpi wrapper command and passes it to FC as well. As a partial fix, you'll see that we check beforehand if the wrapped compiler is GNU, before checking for ifort in the FC string. Cheers Andrea configure.ac.zip

rljacob commented 3 years ago

Thanks for this! I don't see the fix for ifort.

andreapiacentini commented 3 years ago

look for the variable IS_GNU. It takes a yes/no value when AC_PROG_FC tests for the compilers in the provided list. If the compiler is detected as gnu, we skip the test elif echo $FC | grep ifort >/dev/null 2>&1; then (the elif order has changed) so that the the appropriate options are selected even if we set FC=mpifort for the open-mpi wrapper of the gnu compiler in the OASIS Makefile. It's a pretty specific workaround for the way configure is invoked from the OASIS makefile (there is no difference between MPIFC and FC). I've got oneapi on my machine (since this morning) and I didn't notice any problem with it (but I did not check carefully what mpi-serial does). Let me know if you want me to have a better look tomorrow. A.

rljacob commented 3 years ago

Ok I understand now. Setting FC to the mpi wrapper should be supported so that's a good fix for any users.

rljacob commented 3 years ago

@andreapiacentini please test this PR https://github.com/MCSclimate/MCT/pull/64