Skip to content

Commit

Permalink
Replace h5xx submodule by FetchContent
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Jan 17, 2025
1 parent 8511931 commit 237c376
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 86 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "libs/h5xx"]
path = libs/h5xx
url = https://github.com/h5md/h5xx.git
82 changes: 66 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2009-2022 The ESPResSo project
# Copyright (C) 2009-2025 The ESPResSo project
# Copyright (C) 2009,2010
# Max-Planck-Institute for Polymer Research, Theory Group
#
Expand Down Expand Up @@ -105,6 +105,11 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/hmenke/espresso-stokesian-dynamics.git
GIT_TAG 862a7537a366f0c32f0c25e46bd107bea590faea
)
FetchContent_Declare(
h5xx
GIT_REPOSITORY https://github.com/h5md/h5xx.git
GIT_TAG 0.9.1
)
FetchContent_Declare(
caliper
GIT_REPOSITORY https://github.com/LLNL/Caliper.git
Expand Down Expand Up @@ -490,23 +495,68 @@ if(ESPRESSO_BUILD_WITH_HDF5)
set(HDF5_FOUND FALSE)
message(FATAL_ERROR "HDF5 parallel version not found.")
endif()
endif()
endif()

# Check for the h5xx submodule and try to check it out if not found or update it
# if found.
if(ESPRESSO_BUILD_WITH_HDF5 AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
# Try to find git
find_package(Git)
if(GIT_FOUND)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/libs/h5xx/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --
libs/h5xx WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
else()
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update -- libs/h5xx
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
if(${HDF5_VERSION} VERSION_GREATER_EQUAL 1.13.0)
message(
WARNING
"Library hdf5 >= 1.13.0 is incompatible with h5xx 0.9.1 on some platforms (https://github.com/fhoefling/h5xx/issues/11)"
)
endif()
endif()
# We need to define our own h5xx target, since the project version we depend
# on is not fully compatible with modern CMake.
FetchContent_GetProperties(h5xx)
if(NOT h5xx_POPULATED)
FetchContent_Populate(h5xx)
endif()
add_library(h5xx INTERFACE)
add_library(hdf5 INTERFACE)
target_link_libraries(hdf5 INTERFACE $<BUILD_INTERFACE:${HDF5_LIBRARIES}>)
target_include_directories(hdf5
INTERFACE $<BUILD_INTERFACE:${HDF5_INCLUDE_DIRS}>)
target_include_directories(h5xx
INTERFACE $<BUILD_INTERFACE:${h5xx_SOURCE_DIR}>)
target_compile_features(h5xx INTERFACE cxx_std_11)
target_compile_definitions(h5xx INTERFACE H5XX_USE_MPI)
add_library(espresso_h5xx_cpp_flags INTERFACE)
add_library(espresso::h5xx_cpp_flags ALIAS espresso_h5xx_cpp_flags)
target_compile_options(
espresso_h5xx_cpp_flags
INTERFACE
$<$<CXX_COMPILER_ID:GNU>:-Wno-terminate>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-exceptions>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-but-set-variable>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-delete-non-abstract-non-virtual-dtor>
)
if(ESPRESSO_BUILD_WITH_CLANG_TIDY)
set(H5XX_CXX_CLANG_TIDY "${ESPRESSO_CXX_CLANG_TIDY}")
set(SKIP_CLANG_TIDY_CHECKS "")
set(SKIP_CLANG_TIDY_CHECKS_CXX "")
# silence hdf5 and h5xx diagnostics
list(APPEND SKIP_CLANG_TIDY_CHECKS "-clang-analyzer-deadcode.DeadStores")
list(APPEND SKIP_CLANG_TIDY_CHECKS
"-clang-analyzer-optin.performance.Padding")
list(APPEND SKIP_CLANG_TIDY_CHECKS
"-clang-diagnostic-unused-but-set-variable")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-clang-diagnostic-exceptions")
list(APPEND SKIP_CLANG_TIDY_CHECKS
"-bugprone-multi-level-implicit-pointer-conversion")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-bugprone-assignment-in-if-condition")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-bugprone-exception-escape")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-bugprone-narrowing-conversions")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-use-auto")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-use-nullptr")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-use-noexcept")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-use-override")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-use-equals-default")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-loop-convert")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-pass-by-value")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-redundant-void-arg")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-readability-else-after-return")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-readability-container-size-empty")
espresso_override_clang_tidy_checks(
H5XX_CXX_CLANG_TIDY "${SKIP_CLANG_TIDY_CHECKS}"
"${SKIP_CLANG_TIDY_CHECKS_CXX}")
endif()
endif()

if(ESPRESSO_BUILD_WITH_SCAFACOS)
Expand Down
29 changes: 7 additions & 22 deletions doc/sphinx/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -886,28 +886,7 @@ external libraries that are downloaded automatically by CMake. When a
network connection cannot be established due to firewall restrictions,
the CMake logic needs editing.

.. _Git submodules without a network connection:

Git submodules without a network connection
"""""""""""""""""""""""""""""""""""""""""""

* ``ESPRESSO_BUILD_WITH_HDF5``: when cloning |es|, the :file:`libs/h5xx` folder
will be a git submodule containing a :file:`.git` subfolder. To prevent CMake
from updating this submodule with git, delete the corresponding command with:

.. code-block:: bash
sed -i '/execute_process(COMMAND ${GIT_EXECUTABLE} submodule update -- libs\/h5xx/,+1 d' CMakeLists.txt
When installing a release version of |es|, no network communication
is needed for HDF5.

.. _CMake subprojects without a network connection:

CMake subprojects without a network connection
""""""""""""""""""""""""""""""""""""""""""""""

Several libraries are downloaded and included into the CMake project using
External libraries are downloaded and included into the CMake project using
`FetchContent <https://cmake.org/cmake/help/latest/module/FetchContent.html>`__.
The repository URLs can be found in the ``GIT_REPOSITORY`` field of the
corresponding ``FetchContent_Declare()`` commands. The ``GIT_TAG`` field
Expand All @@ -921,6 +900,12 @@ the clone. You can automate this task by adapting the following commands:
sed -ri 's|GIT_REPOSITORY +.+/walberla.git|GIT_REPOSITORY /work/username/walberla|' CMakeLists.txt
* ``ESPRESSO_BUILD_WITH_HDF5``

.. code-block:: bash
sed -ri 's|GIT_REPOSITORY +.+h5xx.git|GIT_REPOSITORY /work/username/h5xx|' CMakeLists.txt
* ``ESPRESSO_BUILD_WITH_STOKESIAN_DYNAMICS``

.. code-block:: bash
Expand Down
23 changes: 19 additions & 4 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#
# Copyright (C) 2018-2025 The ESPResSo project
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

add_library(Random123 INTERFACE)
target_include_directories(
Random123 SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/Random123-1.09/include)
target_compile_definitions(Random123 INTERFACE R123_USE_MULHILO64_C99)

add_library(h5xx INTERFACE)
target_include_directories(h5xx SYSTEM
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/h5xx)
1 change: 0 additions & 1 deletion libs/h5xx
Submodule h5xx deleted from 89d8d4
25 changes: 14 additions & 11 deletions src/core/io/writer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2016-2022 The ESPResSo project
# Copyright (C) 2016-2025 The ESPResSo project
#
# This file is part of ESPResSo.
#
Expand All @@ -18,14 +18,17 @@
#

if(ESPRESSO_BUILD_WITH_HDF5)
target_link_libraries(espresso_core PUBLIC ${HDF5_LIBRARIES}
Boost::filesystem h5xx)
target_include_directories(espresso_core PUBLIC ${CMAKE_CURRRENT_SOURCE_DIR}
${HDF5_INCLUDE_DIRS})

target_compile_definitions(espresso_core PUBLIC H5XX_USE_MPI)

target_sources(
espresso_core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/h5md_core.cpp
${CMAKE_CURRENT_SOURCE_DIR}/h5md_specification.cpp)
add_library(espresso_hdf5 STATIC h5md_core.cpp h5md_specification.cpp)
add_library(espresso::hdf5 ALIAS espresso_hdf5)
if(ESPRESSO_BUILD_WITH_CLANG_TIDY)
set_target_properties(espresso_hdf5 PROPERTIES CXX_CLANG_TIDY
"${H5XX_CXX_CLANG_TIDY}")
endif()
target_include_directories(espresso_hdf5 PRIVATE ${CMAKE_SOURCE_DIR}/src/core)
target_link_libraries(
espresso_hdf5
PRIVATE h5xx hdf5 espresso::cpp_flags espresso::h5xx_cpp_flags MPI::MPI_CXX
Boost::mpi Boost::filesystem espresso::utils espresso::config
espresso::instrumentation)
target_link_libraries(espresso_core PRIVATE espresso_hdf5)
endif()
29 changes: 16 additions & 13 deletions src/core/io/writer/h5md_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@

#include <utils/Vector.hpp>

#include <boost/array.hpp>
#include <boost/filesystem.hpp>
#include <boost/mpi/collectives.hpp>
#include <boost/multi_array.hpp>

#include <mpi.h>

Expand Down Expand Up @@ -71,7 +74,7 @@ static void extend_dataset(h5xx::dataset &dataset,
auto const rank = static_cast<h5xx::dataspace>(dataset).rank();
auto extents = static_cast<h5xx::dataspace>(dataset).extents();
/* Extend the dataset for another timestep */
for (int i = 0; i < rank; i++) {
for (auto i = 0u; i < rank; i++) {
extents[i] += change_extent[i];
}
H5Dset_extent(dataset.hid(), extents.data()); // extend all dims is collective
Expand Down Expand Up @@ -151,11 +154,11 @@ void File::create_groups() {

static std::vector<hsize_t> create_dims(hsize_t rank, hsize_t data_dim) {
switch (rank) {
case 3:
return std::vector<hsize_t>{0, 0, data_dim};
case 2:
return std::vector<hsize_t>{0, data_dim};
case 1:
case 3ul:
return std::vector<hsize_t>{0ul, 0ul, data_dim};
case 2ul:
return std::vector<hsize_t>{0ul, data_dim};
case 1ul:
return std::vector<hsize_t>{data_dim};
default:
throw std::runtime_error(
Expand All @@ -164,13 +167,13 @@ static std::vector<hsize_t> create_dims(hsize_t rank, hsize_t data_dim) {
}

static std::vector<hsize_t> create_chunk_dims(hsize_t rank, hsize_t data_dim) {
hsize_t chunk_size = (rank > 1) ? 1000 : 1;
hsize_t chunk_size = (rank > 1ul) ? 1000ul : 1ul;
switch (rank) {
case 3:
return {1, chunk_size, data_dim};
case 2:
return {1, chunk_size};
case 1:
case 3ul:
return {1ul, chunk_size, data_dim};
case 2ul:
return {1ul, chunk_size};
case 1ul:
return {chunk_size};
default:
throw std::runtime_error(
Expand Down Expand Up @@ -200,7 +203,7 @@ void File::load_file(const std::string &file_path) {
static void write_attributes(h5xx::file &h5md_file) {
auto h5md_group = h5xx::group(h5md_file, "h5md");
h5xx::write_attribute(h5md_group, "version",
boost::array<hsize_t, 2>{{1, 1}});
boost::array<hsize_t, 2>{{1ul, 1ul}});
auto h5md_creator_group = h5xx::group(h5md_group, "creator");
h5xx::write_attribute(h5md_creator_group, "name", "ESPResSo");
h5xx::write_attribute(h5md_creator_group, "version", ESPRESSO_VERSION);
Expand Down
4 changes: 1 addition & 3 deletions src/core/io/writer/h5md_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CORE_IO_WRITER_H5MD_CORE_HPP
#define CORE_IO_WRITER_H5MD_CORE_HPP
#pragma once

#include "BoxGeometry.hpp"
#include "ParticleRange.hpp"
Expand Down Expand Up @@ -293,4 +292,3 @@ struct left_backupfile : public std::exception {

} /* namespace H5md */
} /* namespace Writer */
#endif
3 changes: 2 additions & 1 deletion src/core/io/writer/h5md_specification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

#include "h5md_specification.hpp"
#include "h5md_core.hpp"
#include "hdf5.h"

#include <hdf5.h>

#include <utility>

Expand Down
17 changes: 13 additions & 4 deletions src/core/io/writer/h5md_specification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CORE_IO_WRITER_H5MD_SPECIFICATION_HPP
#define CORE_IO_WRITER_H5MD_SPECIFICATION_HPP

#pragma once

// guard for hdf5.h
#if not defined(_H5public_H)
#ifdef OMPI_SKIP_MPICXX
#undef OMPI_SKIP_MPICXX
#endif
#ifdef MPICH_SKIP_MPICXX
#undef MPICH_SKIP_MPICXX
#endif
#endif // not defined(_H5public_H)
#include <H5public.h>

#include <h5xx/h5xx.hpp>

Expand Down Expand Up @@ -73,5 +84,3 @@ struct H5MD_Specification {

} // namespace H5md
} // namespace Writer

#endif
18 changes: 14 additions & 4 deletions src/script_interface/h5md/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2022 The ESPResSo project
# Copyright (C) 2020-2025 The ESPResSo project
#
# This file is part of ESPResSo.
#
Expand All @@ -18,7 +18,17 @@
#

if(ESPRESSO_BUILD_WITH_HDF5)
target_sources(
espresso_script_interface PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/initialize.cpp
${CMAKE_CURRENT_SOURCE_DIR}/h5md.cpp)
add_library(espresso_si_hdf5 STATIC initialize.cpp h5md.cpp)
add_library(espresso::si_hdf5 ALIAS espresso_si_hdf5)
if(ESPRESSO_BUILD_WITH_CLANG_TIDY)
set_target_properties(espresso_si_hdf5 PROPERTIES CXX_CLANG_TIDY
"${H5XX_CXX_CLANG_TIDY}")
endif()
target_include_directories(espresso_si_hdf5 PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_link_libraries(
espresso_si_hdf5
PRIVATE h5xx hdf5 espresso::hdf5 espresso::cpp_flags
espresso::h5xx_cpp_flags espresso::core espresso::config
espresso::utils espresso::instrumentation)
target_link_libraries(espresso_script_interface PRIVATE espresso_si_hdf5)
endif()
4 changes: 1 addition & 3 deletions src/script_interface/h5md/h5md.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ESPRESSO_SRC_SCRIPT_INTERFACE_H5MD_H5MD_HPP
#define ESPRESSO_SRC_SCRIPT_INTERFACE_H5MD_H5MD_HPP
#pragma once

#include "config/config.hpp"

Expand Down Expand Up @@ -86,4 +85,3 @@ class H5md : public AutoParameters<H5md> {
} // namespace ScriptInterface

#endif // H5MD
#endif
1 change: 0 additions & 1 deletion testsuite/python/h5md.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ def test_bonds(self):
self.assertEqual(bond[1], i + 1)

def test_script(self):
assert sys.argv[0] == __file__
# case #1: running a pypresso script
with open(sys.argv[0], 'r') as f:
ref = f.read()
Expand Down

0 comments on commit 237c376

Please sign in to comment.