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

FORTLINK: Guess if Unknown #1126

Merged
merged 3 commits into from
Jul 14, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Tools/CMake/AMReX_Defines.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ function ( set_amrex_defines )
set(FORTLINK "UNDERSCORE")
message(STATUS "Fortran name mangling scheme: ${FORTLINK} (lower case, append underscore)")
else ()
message(AUTHOR_WARNING "Fortran to C mangling not compatible with AMReX code")
# now we have to guess
if (CMAKE_Fortran_COMPILER_ID MATCHES XL) # old IBM prior to XLClang
set(FORTLINK "LOWERCASE")
else ()
set(FORTLINK "UNDERSCORE")
endif()
message(WARNING "Fortran to C mangling not compatible with AMReX code, assuming '${FORTLINK}'")
endif ()

Copy link
Member Author

@ax3l ax3l Jul 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JBlaschke can you add this line to your code to find out what FortranCInterface_GLOBAL_SUFFIX is in your case please?

Suggested change
message(WARNING "+++++++++ FortranCInterface_GLOBAL_PREFIX='${FortranCInterface_GLOBAL_PREFIX}' ++++++++++++++++")
message(WARNING "+++++++++ FortranCInterface_GLOBAL_SUFFIX='${FortranCInterface_GLOBAL_SUFFIX}' ++++++++++++++++")
message(WARNING "+++++++++ FortranCInterface_GLOBAL_CASE='${FortranCInterface_GLOBAL_CASE}' ++++++++++++++++")

What's the full cmake output (including compiler identifications) if you add this? I fear the picked up C compiler and Fortran compiler might truly be incompatible. If that is the case, we might better error out with a meaningful message here instead of guessing and causing a hard to debug runtime error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Axel -- I don't think your thesis matches reality :( another beautiful theory slain by and ugly fact. Here is the full cmake output:

blaschke@NERSCs-MBP  ◰³ py3  ~/S/amrex  ➦ 52909b777  dist  cmake -DENABLE_PARTICLES=ON -DENABLE_AMRDATA=ON -DENABLE_EB=ON -DENABLE_OMP=ON -DBUILD_SHARED_LIBS=ON \
                                                                -DCMAKE_INSTALL_PREFIX="." \
                                                                -DCMAKE_C_COMPILER=(which gcc-8) -DCMAKE_CXX_COMPILER=(which g++-8) -DCMAKE_Fortran_COMPILER=(which gfortran-8) ..
- The C compiler identification is GNU 8.4.0
- The CXX compiler identification is GNU 8.4.0
- Checking whether C compiler has -isysroot
- Checking whether C compiler has -isysroot - yes
- Checking whether C compiler supports OSX deployment target flag
- Checking whether C compiler supports OSX deployment target flag - yes
- Check for working C compiler: /usr/local/bin/gcc-8
- Check for working C compiler: /usr/local/bin/gcc-8 - works
- Detecting C compiler ABI info
- Detecting C compiler ABI info - done
- Detecting C compile features
- Detecting C compile features - done
- Checking whether CXX compiler has -isysroot
- Checking whether CXX compiler has -isysroot - yes
- Checking whether CXX compiler supports OSX deployment target flag
- Checking whether CXX compiler supports OSX deployment target flag - yes
- Check for working CXX compiler: /usr/local/bin/g++-8
- Check for working CXX compiler: /usr/local/bin/g++-8 - works
- Detecting CXX compiler ABI info
- Detecting CXX compiler ABI info - done
- Detecting CXX compile features
- Detecting CXX compile features - done
- CMake version: 3.17.3
- AMReX installation directory: /Users/blaschke/Science/amrex/dist
- Building AMReX with DIM = 3
- Configuring AMReX with the following options enabled:
-    BUILD_SHARED_LIBS
-    ENABLE_FORTRAN
-    ENABLE_DP
-    ENABLE_MPI
-    ENABLE_OMP
-    ENABLE_EB
-    ENABLE_LINEAR_SOLVERS
-    ENABLE_AMRDATA
-    ENABLE_PARTICLES
-    ENABLE_DP_PARTICLES
- The Fortran compiler identification is GNU 8.4.0
- Checking whether Fortran compiler has -isysroot
- Checking whether Fortran compiler has -isysroot - yes
- Checking whether Fortran compiler supports OSX deployment target flag
- Checking whether Fortran compiler supports OSX deployment target flag - yes
- Check for working Fortran compiler: /usr/local/bin/gfortran-8
- Check for working Fortran compiler: /usr/local/bin/gfortran-8 - works
- Detecting Fortran compiler ABI info
- Detecting Fortran compiler ABI info - done
- Checking whether /usr/local/bin/gfortran-8 supports Fortran 90
- Checking whether /usr/local/bin/gfortran-8 supports Fortran 90 - yes
- Detecting Fortran/C Interface
ailed to compile
- Fortran name mangling scheme: CASE (no append underscore)
- Found OpenMP_C: -fopenmp (found version "4.5")
- Found OpenMP_CXX: -fopenmp (found version "4.5")
- Found OpenMP_Fortran: -fopenmp (found version "4.5")
- Found OpenMP: TRUE (found version "4.5")
- Found MPI_C: /usr/local/Cellar/mpich/3.3.2_1/lib/libmpi.dylib (found version "3.1")
- Found MPI_CXX: /usr/local/Cellar/mpich/3.3.2_1/lib/libmpicxx.dylib (found version "3.1")
- Found MPI: TRUE (found version "3.1") found components: C CXX
- Looking for pthread.h
- Looking for pthread.h - found
- Performing Test CMAKE_HAVE_LIBC_PTHREAD
- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
- Found Threads: TRUE
- AMReX configuration summary:
-    Build type               = Release
-    Install directory        = /Users/blaschke/Science/amrex/dist
-    C++ compiler             = /usr/local/bin/g++-8
-    Fortran compiler         = /usr/local/bin/gfortran-8
-    C++ defines              = -DAMREX_GIT_VERSION="20.07-37-g52909b777b70" -DAMREX_USE_MPI -DBL_USE_MPI -DAMREX_USE_OMP -DBL_USE_OMP -DAMREX_SPACEDIM=3 -DBL_SPACEDIM=3 -DAMREX_Da
win -DBL_Darwin -DBL_FORT_USE_CASE -DAMREX_USE_EB -DAMREX_PARTICLES
-    Fortran defines          = -DAMREX_GIT_VERSION="20.07-37-g52909b777b70" -DAMREX_USE_MPI -DBL_USE_MPI -DAMREX_USE_OMP -DBL_USE_OMP -DAMREX_SPACEDIM=3 -DBL_SPACEDIM=3 -DAMREX_Da
win -DBL_Darwin -DBL_LANG_FORT -DAMREX_LANG_FORT -DBL_FORT_USE_CASE -DAMREX_USE_EB -DAMREX_PARTICLES
-    C++ flags                = -O3 -DNDEBUG  -fopenmp -Werror=return-type
-    Fortran flags            = -O3 -DNDEBUG -O3  -fimplicit-none -ffixed-line-length-none -ffree-line-length-none
-    C++ include paths        = -I/usr/local/Cellar/mpich/3.3.2_1/include -I/Users/blaschke/Science/amrex/dist/mod_files -I/Users/blaschke/Science/amrex/Src/Base -I/Users/blaschke/
cience/amrex/Src/Boundary -I/Users/blaschke/Science/amrex/Src/AmrCore -I/Users/blaschke/Science/amrex/Src/Amr -I/Users/blaschke/Science/amrex/Src/EB -I/Users/blaschke/Science/amrex
Src/LinearSolvers/MLMG -I/Users/blaschke/Science/amrex/Src/LinearSolvers/Projections -I/Users/blaschke/Science/amrex/Src/Particle -I/Users/blaschke/Science/amrex/Src/Extern/amrdata
-    Fortran include paths    = -I/usr/local/Cellar/mpich/3.3.2_1/include -I/Users/blaschke/Science/amrex/dist/mod_files -I/Users/blaschke/Science/amrex/Src/Base -I/Users/blaschke/
cience/amrex/Src/Boundary -I/Users/blaschke/Science/amrex/Src/AmrCore -I/Users/blaschke/Science/amrex/Src/Amr -I/Users/blaschke/Science/amrex/Src/EB -I/Users/blaschke/Science/amrex
Src/LinearSolvers/MLMG -I/Users/blaschke/Science/amrex/Src/LinearSolvers/Projections -I/Users/blaschke/Science/amrex/Src/Particle -I/Users/blaschke/Science/amrex/Src/Extern/amrdata
-    Link line                = gfortran gcc_ext.10.5 gcc quadmath m /usr/local/Cellar/gcc@8/8.4.0_1/lib/gcc/8/libgomp.dylib ::@(0x7ffbad80b800) /usr/local/Cellar/mpich/3.3.2_1/lib
libmpi.dylib /usr/local/Cellar/mpich/3.3.2_1/lib/libpmpi.dylib /usr/local/Cellar/mpich/3.3.2_1/lib/libmpicxx.dylib ::@
- Configuring done
- Generating done
- Build files have been written to: /Users/blaschke/Science/amrex/dist

(note: I'm using fish -- so -DCMAKE_C_COMPILER=(which gcc-8) is equivalent to -DCMAKE_C_COMPILER=$(which gcc-8))

I think the problem is that cmake -- for reasons that are above my pay grade -- can't figure out the Fortran/C interface:

-- Detecting Fortran/C Interface
Failed to compile

But I also don't know how to coax any information out of cmake RE what it actually tried to do there, and why it failed to compile.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added your warnings, and I get:

CMake Warning at Tools/CMake/AMReX_Defines.cmake:117 (message):
  +++++++++ FortranCInterface_GLOBAL_PREFIX='' ++++++++++++++++
Call Stack (most recent call first):
  Tools/CMake/AMReX_Config.cmake:41 (set_amrex_defines)
  Src/CMakeLists.txt:62 (configure_amrex)


CMake Warning at Tools/CMake/AMReX_Defines.cmake:118 (message):
  +++++++++ FortranCInterface_GLOBAL_SUFFIX='' ++++++++++++++++
Call Stack (most recent call first):
  Tools/CMake/AMReX_Config.cmake:41 (set_amrex_defines)
  Src/CMakeLists.txt:62 (configure_amrex)


CMake Warning at Tools/CMake/AMReX_Defines.cmake:119 (message):
  +++++++++ FortranCInterface_GLOBAL_CASE='' ++++++++++++++++
Call Stack (most recent call first):
  Tools/CMake/AMReX_Config.cmake:41 (set_amrex_defines)
  Src/CMakeLists.txt:62 (configure_amrex)

This means that the FortranCInterface_GLOBAL_PREFIX is empty -- probably not being set because the C/Fortran interface determination fails 😢

Copy link
Member Author

@ax3l ax3l Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for those details. That explains a lot... very empty action there is.
Probably one can spot it here:

There is a try_compile being called which fails:
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.17.3/Modules/FortranCInterface/Detect.cmake#L31-41

According to the docs we can pass --debug-trycompile to the cmake .. call to get more verbose output about this.

cmake \
  -DENABLE_PARTICLES=ON \
  -DENABLE_AMRDATA=ON \
  -DENABLE_EB=ON \
  -DENABLE_OMP=ON \
  -DBUILD_SHARED_LIBS=ON \
  -DCMAKE_INSTALL_PREFIX="." \
  -DCMAKE_C_COMPILER=(which gcc-8) \
  -DCMAKE_CXX_COMPILER=(which g++-8) \
  -DCMAKE_Fortran_COMPILER=(which gfortran-8) \
  --debug-trycompile ..

(Note: -DCMAKE_INSTALL_PREFIX="." looks dangerous, this will at some point interleave temporary build files with install files on make install.)

Maybe we already see more CMake output, but otherwise we should get files in <bindir>/CMakeFiles/CMakeTmp. We should potentially do a

message(FATAL_ERROR "I am outta here")

between the two include() lines https://github.com/AMReX-Codes/amrex/blob/development/Tools/CMake/AMReX_Defines.cmake#L96 to get the latest try_compile files in that temporary directory.

I would be curious why this compile failed for you...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I do this, I get (in the CMakeError.log) this:

ld: warning: ignoring file libmyfort.a, file was built for archive which is not the architecture being linked (x86_64): libmyfort.a

The problem was that my macOS install has howebrew's binutils in the PATH (which comes with the wrong sort of ar util) -- removing this from PATH fixes the problem.

Cheers!

add_amrex_define( BL_FORT_USE_${FORTLINK} ) # Only legacy form
Expand Down