Skip to content

Parallel Fortran high-level build omits MPI_Fortran_MODULE_DIR and globally applies MPI_C_LINK_FLAGS #6581

Open

Description

@mathomp4

Describe the bug

A parallel HDF5 build with Fortran and the high-level Fortran library fails with an OpenMPI installation whose mpi.mod is located in CMake's MPI_Fortran_MODULE_DIR but not in MPI_Fortran_INCLUDE_DIRS.

The high-level Fortran targets add MPI_Fortran_INCLUDE_DIRS but omit MPI_Fortran_MODULE_DIR, so compilation fails because mpi.mod cannot be found.

The same configuration also copies MPI_C_LINK_FLAGS into global CMAKE_EXE_LINKER_FLAGS, despite already linking MPI::MPI_C. This applies C MPI-wrapper flags to Fortran linker invocations. In this environment, that propagates a raw -pthread flag to NAG Fortran, which does not accept it.

Expected behavior

A parallel HDF5 build with HDF5_BUILD_FORTRAN=ON and HDF5_BUILD_HL_LIB=ON should locate the MPI Fortran modules discovered by CMake and should not apply C-specific MPI wrapper linker flags globally to Fortran links.

Platform (please complete the following information)

  • HDF5 version: develop, commit 2888f82e837 (Add release page for 2.2.0)
  • OS and version: SLES 15 on NASA Discover
  • C compiler: GCC 12.3.0, via OpenMPI mpicc
  • Fortran compiler: NAG Fortran 7.2 build 7238, via OpenMPI mpif90
  • Build system: CMake 4.3.0, Ninja 1.12.0
  • MPI library: OpenMPI 4.1.6, built with GCC 12.3.0 and NAG Fortran 7.2.7238
  • Configure options:
  cmake -S . -B build -G Ninja \
    -DCMAKE_C_COMPILER=mpicc \
    -DCMAKE_Fortran_COMPILER=mpif90 \
    -DHDF5_ENABLE_PARALLEL=ON \
    -DHDF5_BUILD_FORTRAN=ON \
    -DHDF5_BUILD_HL_LIB=ON \
    -DHDF5_BUILD_CPP_LIB=OFF \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_TESTING=OFF \
    -DHDF5_BUILD_EXAMPLES=OFF \
    -DHDF5_ENABLE_Z_LIB_SUPPORT=OFF

Additional context

CMake 4.3 currently has a separate issue with FortranCInterface_VERIFY() and NAG Fortran 7.2. A minimal reproducer has been reported to Kitware. I applied a temporary local guard for that unrelated CMake failure in order to complete this HDF5 build and isolate the issues described above.

With the proposed HDF5 changes and that temporary CMake workaround, HDF5 develop builds successfully in this configuration.

I have a branch with a fix for this here:

develop...mathomp4:hdf5:fix-mpi-fortran-module-dir

I didn't want to make a PR until you all thought it was a good idea.

AI assistance disclosure

GPT-5.6 Terra (Codex) assisted with diagnosing the build configuration and drafting the proposed changes. I independently built and verified the result.

Activity

  1. jhendersonHDF commented on Jul 30, 2026

    @jhendersonHDF
    Collaborator

    @mathomp4 The change to CMAKE_EXE_LINKER_FLAGS looks reasonable to me; it seems that line has been there in one form or another since CMake support was added 16 years ago (ae06433), so very likely an outdated piece of logic by this point. As for the Fortran modules change, to me it would make sense to just add MPI_Fortran_MODULE_DIR to MPI_Fortran_INCLUDE_DIRS in the appropriate places to simplify things, but I'd be happy with the changes either way.

  2. added theissue type on Aug 4, 2026
  3. moved this from To be triaged to On-Deck in HDF5 - TRIAGE & TRACKon Aug 4, 2026
  4. updated Priority P2 - Medium and Effort Small on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Fields

Priority

P2 - Medium

Effort

Small

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions