Skip to content

Commit

Permalink
Move this to the ParallelIOHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jun 17, 2024
1 parent 4ac3f29 commit b62a1c9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 51 deletions.
2 changes: 2 additions & 0 deletions include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ParallelHDF5IOHandlerImpl : public HDF5IOHandlerImpl

MPI_Comm m_mpiComm;
MPI_Info m_mpiInfo;

std::future<void> flush(internal::ParsedFlushParams &);
}; // ParallelHDF5IOHandlerImpl
#else
class ParallelHDF5IOHandlerImpl
Expand Down
53 changes: 2 additions & 51 deletions src/IO/HDF5/HDF5IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2938,51 +2938,14 @@ HDF5IOHandlerImpl::getFile(Writable *writable)
return std::make_optional(std::move(res));
}

#define OPENPMD_HAVE_HDF5_INDEPENDENT_STORES openPMD_HAVE_MPI

std::future<void> HDF5IOHandlerImpl::flush(internal::ParsedFlushParams &params)
{
#if OPENPMD_HAVE_HDF5_INDEPENDENT_STORES
std::optional<H5FD_mpio_xfer_t> 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<bool>();
old_value = std::make_optional<H5FD_mpio_xfer_t>();
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)
Expand All @@ -3002,18 +2965,6 @@ std::future<void> HDF5IOHandlerImpl::flush(internal::ParsedFlushParams &params)
}
}
}
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;
}
Expand Down
51 changes: 51 additions & 0 deletions src/IO/HDF5/ParallelHDF5IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -356,6 +358,55 @@ ParallelHDF5IOHandlerImpl::~ParallelHDF5IOHandlerImpl()
m_openFileIDs.erase(file);
}
}

std::future<void>
ParallelHDF5IOHandlerImpl::flush(internal::ParsedFlushParams &params)
{
std::optional<H5FD_mpio_xfer_t> 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<bool>();
old_value = std::make_optional<H5FD_mpio_xfer_t>();
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
Expand Down

0 comments on commit b62a1c9

Please sign in to comment.