diff --git a/include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp b/include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp index e1190b3d71..3b214b64cb 100644 --- a/include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp +++ b/include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp @@ -43,6 +43,8 @@ class ParallelHDF5IOHandlerImpl : public HDF5IOHandlerImpl MPI_Comm m_mpiComm; MPI_Info m_mpiInfo; + + std::future flush(internal::ParsedFlushParams &); }; // ParallelHDF5IOHandlerImpl #else class ParallelHDF5IOHandlerImpl diff --git a/src/IO/HDF5/HDF5IOHandler.cpp b/src/IO/HDF5/HDF5IOHandler.cpp index 01c929c429..5ca6fb8f6d 100644 --- a/src/IO/HDF5/HDF5IOHandler.cpp +++ b/src/IO/HDF5/HDF5IOHandler.cpp @@ -2939,51 +2939,14 @@ HDF5IOHandlerImpl::getFile(Writable *writable) return std::make_optional(std::move(res)); } -#define OPENPMD_HAVE_HDF5_INDEPENDENT_STORES openPMD_HAVE_MPI - std::future HDF5IOHandlerImpl::flush(internal::ParsedFlushParams ¶ms) { -#if OPENPMD_HAVE_HDF5_INDEPENDENT_STORES - std::optional old_value; -#endif + auto res = AbstractIOHandlerImpl::flush(); + if (params.backendConfig.json().contains("hdf5")) { auto hdf5_config = params.backendConfig["hdf5"]; - if (hdf5_config.json().contains("independent_stores")) - { - auto independent_stores_json = hdf5_config["independent_stores"]; -#if OPENPMD_HAVE_HDF5_INDEPENDENT_STORES - if (!independent_stores_json.json().is_boolean()) - { - throw error::BackendConfigSchema( - {"hdf5", "independent_stores"}, "Requires boolean value."); - } - bool independent_stores = - independent_stores_json.json().get(); - old_value = std::make_optional(); - herr_t status = - H5Pget_dxpl_mpio(m_datasetTransferProperty, &*old_value); - VERIFY( - status >= 0, - "[HDF5] Internal error: Failed to query the global data " - "transfer mode before flushing."); - H5FD_mpio_xfer_t new_value = independent_stores - ? H5FD_MPIO_INDEPENDENT - : H5FD_MPIO_COLLECTIVE; - status = H5Pset_dxpl_mpio(m_datasetTransferProperty, new_value); - VERIFY( - status >= 0, - "[HDF5] Internal error: Failed to set the local data " - "transfer mode before flushing."); -#else - std::cerr << "[Warning] HDF5 backend option " - "`hdf5.independent_stores` was specified, but " - "HDF5 has no MPI support. Will ignore." - << std::endl; -#endif - } - if (auto shadow = hdf5_config.invertShadow(); shadow.size() > 0) { switch (hdf5_config.originallySpecifiedAs) @@ -3003,18 +2966,6 @@ std::future HDF5IOHandlerImpl::flush(internal::ParsedFlushParams ¶ms) } } } - auto res = AbstractIOHandlerImpl::flush(); - -#if OPENPMD_HAVE_HDF5_INDEPENDENT_STORES - if (old_value.has_value()) - { - herr_t status = H5Pset_dxpl_mpio(m_datasetTransferProperty, *old_value); - VERIFY( - status >= 0, - "[HDF5] Internal error: Failed to reset the global data " - "transfer mode after flushing."); - } -#endif return res; } diff --git a/src/IO/HDF5/ParallelHDF5IOHandler.cpp b/src/IO/HDF5/ParallelHDF5IOHandler.cpp index 2ab6606667..aef9619553 100644 --- a/src/IO/HDF5/ParallelHDF5IOHandler.cpp +++ b/src/IO/HDF5/ParallelHDF5IOHandler.cpp @@ -20,6 +20,8 @@ */ #include "openPMD/IO/HDF5/ParallelHDF5IOHandler.hpp" #include "openPMD/Error.hpp" +#include "openPMD/IO/FlushParametersInternal.hpp" +#include "openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp" #include "openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp" #include "openPMD/auxiliary/Environment.hpp" #include "openPMD/auxiliary/JSON_internal.hpp" @@ -356,6 +358,55 @@ ParallelHDF5IOHandlerImpl::~ParallelHDF5IOHandlerImpl() m_openFileIDs.erase(file); } } + +std::future +ParallelHDF5IOHandlerImpl::flush(internal::ParsedFlushParams ¶ms) +{ + std::optional old_value; + if (params.backendConfig.json().contains("hdf5")) + { + auto hdf5_config = params.backendConfig["hdf5"]; + + if (hdf5_config.json().contains("independent_stores")) + { + auto independent_stores_json = hdf5_config["independent_stores"]; + if (!independent_stores_json.json().is_boolean()) + { + throw error::BackendConfigSchema( + {"hdf5", "independent_stores"}, "Requires boolean value."); + } + bool independent_stores = + independent_stores_json.json().get(); + old_value = std::make_optional(); + herr_t status = + H5Pget_dxpl_mpio(m_datasetTransferProperty, &*old_value); + VERIFY( + status >= 0, + "[HDF5] Internal error: Failed to query the global data " + "transfer mode before flushing."); + H5FD_mpio_xfer_t new_value = independent_stores + ? H5FD_MPIO_INDEPENDENT + : H5FD_MPIO_COLLECTIVE; + status = H5Pset_dxpl_mpio(m_datasetTransferProperty, new_value); + VERIFY( + status >= 0, + "[HDF5] Internal error: Failed to set the local data " + "transfer mode before flushing."); + } + } + auto res = HDF5IOHandlerImpl::flush(params); + + if (old_value.has_value()) + { + herr_t status = H5Pset_dxpl_mpio(m_datasetTransferProperty, *old_value); + VERIFY( + status >= 0, + "[HDF5] Internal error: Failed to reset the global data " + "transfer mode after flushing."); + } + + return res; +} #else #if openPMD_HAVE_MPI