From b971f1cfc51c87fd3e08386de71863cec0739abd Mon Sep 17 00:00:00 2001 From: dutta-alankar Date: Tue, 14 Jul 2026 17:41:39 +0200 Subject: [PATCH 1/5] Fix parallel HDF5 detection when found via CMake config package find_package(HDF5) can resolve through the HDF5-provided CMake config package (config mode), which does not set HDF5_IS_PARALLEL. The previous 'if(NOT HDF5_IS_PARALLEL)' check then wrongly failed for a genuinely parallel HDF5 build. Detect parallel support robustly: prefer imported targets (hdf5::hdf5 / HDF5::HDF5), fall back to the FindHDF5 module, and determine parallelism from HDF5_IS_PARALLEL/HDF5_C_IS_PARALLEL, 'h5cc -showconfig', or an H5Pset_fapl_mpio compile+link probe. --- CMakeLists.txt | 60 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fad0058b..a9d563af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,12 +113,66 @@ if(Idefix_HDF5) PUBLIC src/output/xdmf.cpp PUBLIC src/output/xdmf.hpp ) - find_package(HDF5 REQUIRED) - target_link_libraries(idefix "${HDF5_LIBRARIES}") + # Prefer imported targets (matches older working behavior), then fall back. + find_package(HDF5 QUIET COMPONENTS C) + if(NOT HDF5_FOUND) + find_package(HDF5 REQUIRED MODULE COMPONENTS C) + endif() + + set(_idefix_hdf5_link_items "${HDF5_LIBRARIES}") + if(TARGET hdf5::hdf5) + set(_idefix_hdf5_link_items hdf5::hdf5) + elseif(TARGET HDF5::HDF5) + set(_idefix_hdf5_link_items HDF5::HDF5) + endif() + + target_link_libraries(idefix ${_idefix_hdf5_link_items}) message(STATUS "Found HDF5 include directories: ${HDF5_INCLUDE_DIRS}") target_include_directories(idefix PUBLIC "${HDF5_INCLUDE_DIRS}") if(Idefix_MPI) - if(NOT HDF5_IS_PARALLEL) + include(CheckCSourceCompiles) + + # Some CMake/HDF5 combinations do not reliably set HDF5_IS_PARALLEL + # (e.g. when HDF5 is found via its CMake config package rather than the + # FindHDF5 module). Combine metadata checks with a compile+link probe for + # the MPI-IO symbols to reliably detect parallel HDF5. + set(_idefix_hdf5_is_parallel FALSE) + if(HDF5_IS_PARALLEL OR HDF5_C_IS_PARALLEL) + set(_idefix_hdf5_is_parallel TRUE) + endif() + + if(NOT _idefix_hdf5_is_parallel AND DEFINED HDF5_C_COMPILER_EXECUTABLE) + execute_process( + COMMAND ${HDF5_C_COMPILER_EXECUTABLE} -showconfig + OUTPUT_VARIABLE _idefix_hdf5_showconfig + ERROR_QUIET + ) + if(_idefix_hdf5_showconfig MATCHES "Parallel HDF5:[ \t]*yes") + set(_idefix_hdf5_is_parallel TRUE) + endif() + endif() + + set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS} ${MPI_C_INCLUDE_DIRS}) + set(CMAKE_REQUIRED_LIBRARIES ${_idefix_hdf5_link_items} MPI::MPI_C) + check_c_source_compiles( + "#include + #include + int main(void) { + hid_t plist = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_mpio(plist, MPI_COMM_WORLD, MPI_INFO_NULL); + H5Pclose(plist); + return 0; + }" + IDEFIX_HDF5_HAS_MPI_IO + ) + unset(CMAKE_REQUIRED_INCLUDES) + unset(CMAKE_REQUIRED_LIBRARIES) + + if(IDEFIX_HDF5_HAS_MPI_IO) + set(_idefix_hdf5_is_parallel TRUE) + endif() + + if(NOT _idefix_hdf5_is_parallel) message(FATAL_ERROR "Parallel HDF5 required for Idefix_MPI but the found HDF5 library does not support it") endif() endif() From 0fd1a387585550888883263085c9520401d9b2f8 Mon Sep 17 00:00:00 2001 From: dutta-alankar Date: Tue, 14 Jul 2026 17:41:40 +0200 Subject: [PATCH 2/5] Silence unused-variable warnings with [[maybe_unused]] Mark variables that are unused in some build configurations as [[maybe_unused]]: the MPI buffer index locals in Axis::ExchangeMPI and tot_dim in the DIMENSIONS==2 branch of Xdmf::Write. --- src/fluid/boundary/axis.cpp | 4 ++-- src/output/xdmf.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fluid/boundary/axis.cpp b/src/fluid/boundary/axis.cpp index 45ea49ea..3e9c60b9 100644 --- a/src/fluid/boundary/axis.cpp +++ b/src/fluid/boundary/axis.cpp @@ -392,8 +392,8 @@ void Axis::ExchangeMPI(int side) { idfx::pushRegion("Axis::ExchangeMPI"); #ifdef WITH_MPI // Load the buffers with data - int ibeg,iend,jbeg,jend,kbeg,kend,offset; - int ny; + [[maybe_unused]] int ibeg,iend,jbeg,jend,kbeg,kend,offset; + [[maybe_unused]] int ny; Buffer bufferSend = this->bufferSend; IdefixArray1D map = this->mapVars; IdefixArray4D Vc = this->Vc; diff --git a/src/output/xdmf.cpp b/src/output/xdmf.cpp index 4e7ff684..f0881900 100644 --- a/src/output/xdmf.cpp +++ b/src/output/xdmf.cpp @@ -295,7 +295,7 @@ int Xdmf::Write() { #if DIMENSIONS == 1 [[maybe_unused]] int tot_dim = 1; #elif DIMENSIONS == 2 - int tot_dim = 2; + [[maybe_unused]] int tot_dim = 2; #elif DIMENSIONS == 3 [[maybe_unused]] int tot_dim = 3; #endif From 9cba84bbbd41196b7d53c288fa59123f74752457 Mon Sep 17 00:00:00 2001 From: Alankar Dutta Date: Wed, 15 Jul 2026 11:50:28 +0200 Subject: [PATCH 3/5] Apply suggestions from code review Minor Co-pilot suggested fixes Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- CMakeLists.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9d563af..ca6ca585 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,7 +143,7 @@ if(Idefix_HDF5) if(NOT _idefix_hdf5_is_parallel AND DEFINED HDF5_C_COMPILER_EXECUTABLE) execute_process( - COMMAND ${HDF5_C_COMPILER_EXECUTABLE} -showconfig + COMMAND "${HDF5_C_COMPILER_EXECUTABLE}" -showconfig OUTPUT_VARIABLE _idefix_hdf5_showconfig ERROR_QUIET ) @@ -152,6 +152,9 @@ if(Idefix_HDF5) endif() endif() + set(_idefix_saved_required_includes "${CMAKE_REQUIRED_INCLUDES}") + set(_idefix_saved_required_libraries "${CMAKE_REQUIRED_LIBRARIES}") + set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS} ${MPI_C_INCLUDE_DIRS}) set(CMAKE_REQUIRED_LIBRARIES ${_idefix_hdf5_link_items} MPI::MPI_C) check_c_source_compiles( @@ -165,8 +168,11 @@ if(Idefix_HDF5) }" IDEFIX_HDF5_HAS_MPI_IO ) - unset(CMAKE_REQUIRED_INCLUDES) - unset(CMAKE_REQUIRED_LIBRARIES) + + set(CMAKE_REQUIRED_INCLUDES "${_idefix_saved_required_includes}") + set(CMAKE_REQUIRED_LIBRARIES "${_idefix_saved_required_libraries}") + unset(_idefix_saved_required_includes) + unset(_idefix_saved_required_libraries) if(IDEFIX_HDF5_HAS_MPI_IO) set(_idefix_hdf5_is_parallel TRUE) From 3fdab2df53b30ba876e3774c11ca518531e28922 Mon Sep 17 00:00:00 2001 From: dutta-alankar Date: Wed, 15 Jul 2026 11:53:54 +0200 Subject: [PATCH 4/5] Minor typo fix --- src/fluid/showConfig.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fluid/showConfig.hpp b/src/fluid/showConfig.hpp index f3a14430..0f8b64ed 100644 --- a/src/fluid/showConfig.hpp +++ b/src/fluid/showConfig.hpp @@ -60,7 +60,7 @@ void Fluid::ShowConfig() { << ": Ohmic resistivity ENABLED with user-defined resistivity function." << std::endl; if(!ohmicDiffusivityFunc) { - IDEFIX_ERROR("No user-defined Ihmic resistivity function has been enrolled."); + IDEFIX_ERROR("No user-defined Ohmic resistivity function has been enrolled."); } } else { IDEFIX_ERROR("Unknown Ohmic resistivity mode"); From d6196044eb4ba46325c4857bd6f27b0926dcea08 Mon Sep 17 00:00:00 2001 From: dutta-alankar Date: Sat, 15 Aug 2026 01:31:58 +0200 Subject: [PATCH 5/5] [ENH] refactor of parallel hdf5 detection --- CMakeLists.txt | 52 ++-------------------------- cmake/CheckHdf5ParallelSupport.cmake | 50 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 49 deletions(-) create mode 100644 cmake/CheckHdf5ParallelSupport.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ca6ca585..1b2c05ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ include(ReplaceIdefixSource) include(AddIdefixSource) include(SetIdefixProperty) include(SetRequiredBuildSettingsForGCC8) +include(CheckHdf5ParallelSupport) #Idefix requires Cuda Lambdas (experimental) if(Kokkos_ENABLE_CUDA) @@ -130,55 +131,8 @@ if(Idefix_HDF5) message(STATUS "Found HDF5 include directories: ${HDF5_INCLUDE_DIRS}") target_include_directories(idefix PUBLIC "${HDF5_INCLUDE_DIRS}") if(Idefix_MPI) - include(CheckCSourceCompiles) - - # Some CMake/HDF5 combinations do not reliably set HDF5_IS_PARALLEL - # (e.g. when HDF5 is found via its CMake config package rather than the - # FindHDF5 module). Combine metadata checks with a compile+link probe for - # the MPI-IO symbols to reliably detect parallel HDF5. - set(_idefix_hdf5_is_parallel FALSE) - if(HDF5_IS_PARALLEL OR HDF5_C_IS_PARALLEL) - set(_idefix_hdf5_is_parallel TRUE) - endif() - - if(NOT _idefix_hdf5_is_parallel AND DEFINED HDF5_C_COMPILER_EXECUTABLE) - execute_process( - COMMAND "${HDF5_C_COMPILER_EXECUTABLE}" -showconfig - OUTPUT_VARIABLE _idefix_hdf5_showconfig - ERROR_QUIET - ) - if(_idefix_hdf5_showconfig MATCHES "Parallel HDF5:[ \t]*yes") - set(_idefix_hdf5_is_parallel TRUE) - endif() - endif() - - set(_idefix_saved_required_includes "${CMAKE_REQUIRED_INCLUDES}") - set(_idefix_saved_required_libraries "${CMAKE_REQUIRED_LIBRARIES}") - - set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS} ${MPI_C_INCLUDE_DIRS}) - set(CMAKE_REQUIRED_LIBRARIES ${_idefix_hdf5_link_items} MPI::MPI_C) - check_c_source_compiles( - "#include - #include - int main(void) { - hid_t plist = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_mpio(plist, MPI_COMM_WORLD, MPI_INFO_NULL); - H5Pclose(plist); - return 0; - }" - IDEFIX_HDF5_HAS_MPI_IO - ) - - set(CMAKE_REQUIRED_INCLUDES "${_idefix_saved_required_includes}") - set(CMAKE_REQUIRED_LIBRARIES "${_idefix_saved_required_libraries}") - unset(_idefix_saved_required_includes) - unset(_idefix_saved_required_libraries) - - if(IDEFIX_HDF5_HAS_MPI_IO) - set(_idefix_hdf5_is_parallel TRUE) - endif() - - if(NOT _idefix_hdf5_is_parallel) + CheckHdf5ParallelSupport("${_idefix_hdf5_link_items}") + if(NOT IDEFIX_HDF5_IS_PARALLEL) message(FATAL_ERROR "Parallel HDF5 required for Idefix_MPI but the found HDF5 library does not support it") endif() endif() diff --git a/cmake/CheckHdf5ParallelSupport.cmake b/cmake/CheckHdf5ParallelSupport.cmake new file mode 100644 index 00000000..aae651a1 --- /dev/null +++ b/cmake/CheckHdf5ParallelSupport.cmake @@ -0,0 +1,50 @@ +include(CheckCSourceCompiles) + +# Check whether the HDF5 library found by find_package(HDF5) supports parallel +# (MPI-IO) access, and store the result in IDEFIX_HDF5_IS_PARALLEL in the +# caller's scope. +# +# Usage: CheckHdf5ParallelSupport() +# where is the list of HDF5 targets/libraries to link against. +# +# Some CMake/HDF5 combinations do not reliably set HDF5_IS_PARALLEL (e.g. when +# HDF5 is found via its CMake config package rather than the FindHDF5 module). +# Combine metadata checks with a compile+link probe for the MPI-IO symbols to +# reliably detect parallel HDF5. +function(CheckHdf5ParallelSupport hdf5_link_items) + set(_idefix_hdf5_is_parallel FALSE) + if(HDF5_IS_PARALLEL OR HDF5_C_IS_PARALLEL) + set(_idefix_hdf5_is_parallel TRUE) + endif() + + if(NOT _idefix_hdf5_is_parallel AND DEFINED HDF5_C_COMPILER_EXECUTABLE) + execute_process( + COMMAND "${HDF5_C_COMPILER_EXECUTABLE}" -showconfig + OUTPUT_VARIABLE _idefix_hdf5_showconfig + ERROR_QUIET + ) + if(_idefix_hdf5_showconfig MATCHES "Parallel HDF5:[ \t]*yes") + set(_idefix_hdf5_is_parallel TRUE) + endif() + endif() + + set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS} ${MPI_C_INCLUDE_DIRS}) + set(CMAKE_REQUIRED_LIBRARIES ${hdf5_link_items} MPI::MPI_C) + check_c_source_compiles( + "#include + #include + int main(void) { + hid_t plist = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_mpio(plist, MPI_COMM_WORLD, MPI_INFO_NULL); + H5Pclose(plist); + return 0; + }" + IDEFIX_HDF5_HAS_MPI_IO + ) + + if(IDEFIX_HDF5_HAS_MPI_IO) + set(_idefix_hdf5_is_parallel TRUE) + endif() + + set(IDEFIX_HDF5_IS_PARALLEL ${_idefix_hdf5_is_parallel} PARENT_SCOPE) +endfunction()