NOAA-GFDL / FMS

GFDL's Flexible Modeling System
Other
87 stars 128 forks source link

Build Error with GNU + fms_r8 + Debug Flags #1531

Closed mathomp4 closed 2 weeks ago

mathomp4 commented 1 month ago

Describe the bug

In trying to build FMS 2024.01 with GNU 13.2 and Open MPI 4.1.6 with -DCMAKE_BUILD_TYPE=Debug I ran into an error:

[ 85%] Building Fortran object CMakeFiles/fms_r8_f.dir/coupler/coupler_types.F90.o
/discover/swdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/coupler/coupler_types.F90:4207:37:

 4207 |         var%bc(n)%field(m)%id_rest = fms_io_register_restart_field(rest_file,&
      |                                     1
Error: There is no specific function for the generic 'register_restart_field' at (1)
/discover/swdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/coupler/coupler_types.F90:4175:37:

 4175 |         var%bc(n)%field(m)%id_rest = fms_io_register_restart_field(bc_rest_files(f),&
      |                                     1
Error: There is no specific function for the generic 'register_restart_field' at (1)
/discover/swdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/coupler/coupler_types.F90:4120:37:

 4120 |         var%bc(n)%field(m)%id_rest = fms_io_register_restart_field(rest_file,&
      |                                     1
Error: There is no specific function for the generic 'register_restart_field' at (1)
/discover/swdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/coupler/coupler_types.F90:4086:37:

 4086 |         var%bc(n)%field(m)%id_rest = fms_io_register_restart_field(bc_rest_files(f),&
      |                                     1
Error: There is no specific function for the generic 'register_restart_field' at (1)
gmake[4]: *** [CMakeFiles/fms_r8_f.dir/build.make:231: CMakeFiles/fms_r8_f.dir/coupler/coupler_types.F90.o] Error 1
gmake[4]: Leaving directory '/gpfsm/dswdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/build'
gmake[3]: *** [CMakeFiles/Makefile2:198: CMakeFiles/fms_r8_f.dir/all] Error 2
gmake[3]: Leaving directory '/gpfsm/dswdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/build'
gmake[2]: *** [Makefile:136: all] Error 2
gmake[2]: Leaving directory '/gpfsm/dswdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/build'
make[1]: *** [GNUmakefile:981: FMS.install] Error 2
make[1]: Leaving directory '/gpfsm/dswdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src'

Note that building without a -DCMAKE_BUILD_TYPE (aka Release) does not have this error.

To Reproduce

I built FMS with:

cmake -B build -S . -DCMAKE_INSTALL_PREFIX=$(prefix)/FMS -DCMAKE_PREFIX_PATH=$(prefix) -D32BIT=ON -D64BIT=ON -DFPIC=ON -DCONSTANTS=GEOS -DNetCDF_ROOT=$(prefix) -DNetCDF_INCLUDE_DIR=$(prefix)/include/netcdf -DUSE_DEPRECATED_IO=ON -DCMAKE_BUILD_TYPE=Debug

inside of ESMA-Baselibs. I do not think the netCDF stuff matters for this (see error above), so it should be reproducible...I hope.

Expected behavior

I expect FMS to build. 😄

System Environment Describe the system environment, include:

Additional context

I believe this might be related to #1417 that @climbfuji filed last year. Why? Well, #1417 produced this error:

Error: There is no specific function for the generic 'register_restart_field' at (1)

which is quite familiar.

So, I went into my build and did make install VERBOSE=1 and what I saw was this:

[ 56%] Building Fortran object CMakeFiles/fms_r8_f.dir/coupler/coupler_types.F90.o
/usr/local/other/gcc/13.2.0/bin/gfortran -DENABLE_QUAD_PRECISION 
 -DGEOS_CONSTANTS -DHAVE_GETTID -DINTERNAL_FILE_NML -Duse_deprecated_io 
-Duse_libMPI -Duse_netCDF 
-I/discover/swdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/include 
-I/discover/swdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/fms 
...lots of includes...
-I/discover/swdev/gmao_SIteam/MPI/openmpi/4.1.6-SLES15/gcc-13.2.0/lib 
-fcray-pointer -fconvert=big-endian -ffree-line-length-none 
-fno-range-check -fbacktrace -O0 -g -fcheck=bounds 
-ffpe-trap=invalid,zero,overflow,underflow -Jinclude_r8 -fPIC 
-fallow-argument-mismatch -w -pthread 
-c /discover/swdev/gmao_SIteam/Baselibs/ESMA-Baselibs-8.0.2/src/FMS/coupler/coupler_types.F90 
-o CMakeFiles/fms_r8_f.dir/coupler/coupler_types.F90.o

As you'll note, this is building fms_r8 and there is something missing here:

-fdefault-real-8 -fdefault-double-8

Much like what @climbfuji saw in https://github.com/NOAA-GFDL/FMS/issues/1417#issuecomment-1822033644, I think this code:

https://github.com/NOAA-GFDL/FMS/blob/98e2ebdd1b443b4ba47e41b8ece676b457e15b23/CMakeLists.txt#L357-L366

is overwriting the REAL64 flags in CMake, and so we end up with the same issue.

I'm trying to test a possible patch now.

mathomp4 commented 1 month ago

Oh. Huh. Actually r8_flags never appears anywhere in the source code. So I guess it can't be due to the REAL64 flags not being appended. Hmm.