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

HDF5 does not build with CMake and NAG Fortran compiler and MPI #5168

Closed
hakostra opened this issue Dec 6, 2024 · 4 comments
Closed

HDF5 does not build with CMake and NAG Fortran compiler and MPI #5168

hakostra opened this issue Dec 6, 2024 · 4 comments
Assignees

Comments

@hakostra
Copy link

hakostra commented Dec 6, 2024

Describe the bug
I have an issue building the HDF5 library with the NAG Fortran compiler nagfor. Details on the system is given below.

In a build-subdirectory, I execute: FC=nagfor cmake -DBUILD_TESTING=OFF -DHDF5_BUILD_FORTRAN=ON -DHDF5_ENABLE_PARALLEL=ON -DHDF5_BUILD_EXAMPLES=OFF .., and this fails:

-- Detecting NAG Fortran directory
-- Detecting NAG Fortran directory - /opt/nag/NAG/lib/NAG_Fortran
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - failed
-- Check for working Fortran compiler: /opt/nag/NAG/bin/nagfor
-- Check for working Fortran compiler: /opt/nag/NAG/bin/nagfor - broken
CMake Error at /usr/share/cmake-3.28/Modules/CMakeTestFortranCompiler.cmake:59 (message):
  The Fortran compiler

    "/opt/nag/NAG/bin/nagfor"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/home/hakostra/tmp/hdf5-autotools-cmake/hdf5/build/CMakeFiles/CMakeScratch/TryCompile-PUg7rn'
    
    Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_3641b/fast
    /usr/bin/gmake  -f CMakeFiles/cmTC_3641b.dir/build.make CMakeFiles/cmTC_3641b.dir/build
    gmake[1]: Entering directory '/home/hakostra/tmp/hdf5-autotools-cmake/hdf5/build/CMakeFiles/CMakeScratch/TryCompile-PUg7rn'
    Building Fortran object CMakeFiles/cmTC_3641b.dir/testFortranCompiler.f.o
    /opt/nag/NAG/bin/nagfor   -PIC -c /home/hakostra/tmp/hdf5-autotools-cmake/hdf5/build/CMakeFiles/CMakeScratch/TryCompile-PUg7rn/testFortranCompiler.f -o CMakeFiles/cmTC_3641b.dir/testFortranCompiler.f.o
    NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7220
    Obsolescent: /home/hakostra/tmp/hdf5-autotools-cmake/hdf5/build/CMakeFiles/CMakeScratch/TryCompile-PUg7rn/testFortranCompiler.f, line 2: Fixed source form
    [NAG Fortran Compiler normal termination, 1 warning]
    Linking Fortran executable cmTC_3641b
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_3641b.dir/link.txt --verbose=1
    /opt/nag/NAG/bin/nagfor -Wl,-rpath -Wl,/opt/nag/mpich/mpich-4.2.3/install/lib -Wl,--enable-new-dtags   CMakeFiles/cmTC_3641b.dir/testFortranCompiler.f.o -o cmTC_3641b 
    NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7220
    gcc: error: unrecognized command-line option ‘-rpath’
    gmake[1]: *** [CMakeFiles/cmTC_3641b.dir/build.make:99: cmTC_3641b] Error 1
    gmake[1]: Leaving directory '/home/hakostra/tmp/hdf5-autotools-cmake/hdf5/build/CMakeFiles/CMakeScratch/TryCompile-PUg7rn'
    gmake: *** [Makefile:127: cmTC_3641b/fast] Error 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  config/cmake/HDFUseFortran.cmake:16 (enable_language)
  config/cmake/HDF5UseFortran.cmake:17 (include)
  CMakeLists.txt:1130 (include)


-- Configuring incomplete, errors occurred!

So CMake believe the nagfor does not work (trust me, it does) and it refuse to continue. The reason nagfor fails is that it is given invalid flags.

I have digged a bit around in the CMake lists for HDF5, and in the main CMakeLists.txt there is the lines:

# Parallel IO usage requires MPI to be Linked and Included
if (H5_HAVE_PARALLEL)
  set (LINK_LIBS ${LINK_LIBS} ${MPI_C_LIBRARIES})
  if (MPI_C_LINK_FLAGS)
    set (CMAKE_EXE_LINKER_FLAGS "${MPI_C_LINK_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
  endif ()
endif ()

I believe what happens is that the MPI_C_LINK_FLAGS, which works for gcc, is applied to the nagfor Fortran tests that are executed by include (CheckFortranSourceRuns), CMake believe the Fortran compiler does not run and stop. As far as I know no Fortran executables are linked by HDF5 and CMAKE_EXE_LINKER_FLAGS is only ever actually used on C executables, so the behavior is not wrong per se, but the resulting outcome is that I'm not able to proceed building HDF5.

Expected behavior
On this system, Autotools works and build HDF5 just fine with MPI and Fortran wrappers. When autotools are removed from HDF5 there will be no ways to build Fortran wrappers with the NAG compiler.

Platform (please complete the following information)

  • HDF5 version (if building from a maintenance branch, please include the commit hash) develop 945fb3c
  • OS and version: Linux Mint 22 (Ubuntu 24.04 based)
  • Compiler and version: nagfor 7.2 build 7220 and gcc 14.2
  • Build system (e.g. CMake, Autotools) and version: CMake version 3.28.3
  • Any configure options you specified
  • MPI library and version (parallel HDF5): MPICH 4.2.3

Additional context
Ref. issue #5040, issue #5039 and PR #4961

@brtnfld
Copy link
Collaborator

brtnfld commented Dec 6, 2024

Out of curiosity, what compiler did you use to build mpich? What is NAG? We usually recommend using the mpi compile wrappers since they will contain all the necessary links and includes.

I don't think we've ever checked enabled parallel with NAG. Can you enable tests and check if all the fortran tests pass with your autotools build? I'm just wondering if it works.

@hakostra
Copy link
Author

hakostra commented Dec 9, 2024

I used the same compilers to build MPICH as I attempted to use for HDF5. For autotools, I set FC and CC to the MPICH compiler wrappers, but for CMake I do not see any difference (mpicc vs gcc and mpifort vs nagfor). Setting FC to mpifort over nagfor does not change anyting wrt. CMake - same error.

Just now, I also compiled the tests with autotools, and ran make test, and all tests build and pass (from same develop branch commit as mentioned in first post).

Edit: Discovered I did a mistake in my testing, I will follow up with a new post later.

@hakostra hakostra changed the title HDF5 does not build with CMake and NAG Fortran compiler HDF5 does not build with CMake and NAG Fortran compiler and MPI Dec 9, 2024
@hakostra
Copy link
Author

A follow-up: Everything works when using the compiler wrappers mpicc and mpifort as @brtnfld suggest! Thanks for the hint!

I tested building HDF5 both with and without MPI, and did a ctest as well. All tests pass, both Fortran-related and others, besides t_shapesame that hanged until I killed it after 30 minutes. This test does not use Fortran and I do not think we can blame this compiler for that.

I look forward to version 2.0, and hope the removal of autotools (CMake is so much better...) makes it easier to spend time efficiently on improving the library!

@brtnfld
Copy link
Collaborator

brtnfld commented Dec 10, 2024

@hakostra, thank you for following up and testing it. We plan on adding testing with NAG and MPI soon. I'm glad we could help.

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