HDF5 2.0 has breaking changes - cmake doesn't set the `HDF5_IS_PARALLEL` variable anymore

Detection of MPI support in HDF5 worked with HDF5<2.0.0. With the recent release of HDF5 2.0.0 ( ​Release of HDF5 2.0.0 (Newsletter #207) - The HDF Group - ensuring long-term access and usability of HDF data and supporting users of HDF technologies ), CMake appears to be unable to detect MPI support in HDF5 properly.

You can find the source and cmake configuration file below, and here is the command I’ve tried:
$ mkdir build && cd build && cmake .. && make && mpirun -np 2 test_hdf5_mpi

The configuration works, the code compiles and runs with openmpi 5.0.7, hdf5 1.14.6 with MPI support, Cmake 3.26.5 and GCC 15.2.0.

$ mkdir build && cd build && cmake .. && make && mpirun -np 2 test_hdf5_mpi
-- The C compiler identification is GNU 8.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found MPI_C: /softs/openmpi/5.0.7-gnu-slurm/lib/libmpi.so (found version "3.1") 
-- Found MPI: TRUE (found version "3.1")  
-- Found HDF5: /softs/hdf5/1.14.6-mpi-gnu/lib/libhdf5.so;/usr/lib64/libz.so;/usr/lib64/libdl.so;/usr/lib64/libm.so (found version "1.14.6") found components: C 
-- Configuring done (0.8s)
-- Generating done (0.0s)
-- Build files have been written to: /home/cadiou/tmp/build
[ 50%] Building C object CMakeFiles/test_hdf5_mpi.dir/test.c.o
[100%] Linking C executable test_hdf5_mpi
[100%] Built target test_hdf5_mpi
[1] Parallel HDF5 appears to be working.
[0] Parallel HDF5 appears to be working.

The configuration fails with openmpi 5.0.9, hdf5 2.0.0 with MPI support, Cmake 4.2.1 and GCC 15.2.1:

$ mkdir build && cd build && cmake .. && make && mpirun -np 2 test_hdf5_mpi
-- The C compiler identification is GNU 15.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found MPI_C: /usr/lib/libmpi.so (found version "3.1")
-- Found MPI: TRUE (found version "3.1")
-- Found ZLIB: /usr/lib/libz.so (found version "1.3.1")
-- Found HDF5: hdf5-shared (found version "2.0.0") found components: C
CMake Error at CMakeLists.txt:13 (message):
  Found HDF5, but it is NOT built with MPI support


-- Configuring incomplete, errors occurred!

# file: test.c

#include <mpi.h>
#include <hdf5.h>
#include <stdio.h>

int main(int argc, char **argv)
{
    MPI_Init(&argc, &argv);

    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    hid_t fapl = H5Pcreate(H5P_FILE_ACCESS);
    if (fapl < 0) {
        if (rank == 0) fprintf(stderr, "H5Pcreate failed\n");
        MPI_Abort(MPI_COMM_WORLD, 1);
    }

    herr_t status = H5Pset_fapl_mpio(fapl, MPI_COMM_WORLD, MPI_INFO_NULL);
    if (status < 0) {
        if (rank == 0) fprintf(stderr, "H5Pset_fapl_mpio failed (no parallel HDF5?)\n");
        MPI_Abort(MPI_COMM_WORLD, 2);
    }

    printf("[%d] Parallel HDF5 appears to be working.\n", rank);

    H5Pclose(fapl);
    MPI_Finalize();
    return 0;
}
# file: CMakeLists.txt

cmake_minimum_required(VERSION 3.18)
project(test_hdf5_mpi C)

# MPI is required
find_package(MPI REQUIRED)

set( HDF5_PREFER_PARALLEL ON )

# HDF5 with explicit parallel requirement
find_package(HDF5 REQUIRED COMPONENTS C)

if (NOT HDF5_IS_PARALLEL)
    message(FATAL_ERROR "Found HDF5, but it is NOT built with MPI support")
endif()

add_executable(test_hdf5_mpi test.c)

target_link_libraries(test_hdf5_mpi
    MPI::MPI_C
    HDF5::HDF5
)

target_include_directories(test_hdf5_mpi PRIVATE ${HDF5_INCLUDE_DIRS})

Note that, one of the breaking changes in HDF5 2.0.0 is a renaming of HDF5_ENABLE_PARALLEL to HDF5_PROVIDES_PARALLEL (see PR #5716). It seems like the following diff fixes FindHDF5.cmake:

686c686
<         set(HDF5_IS_PARALLEL ${HDF5_ENABLE_PARALLEL})
---
>         set(HDF5_IS_PARALLEL ${HDF5_PROVIDES_PARALLEL})
1 Like