Skip to content

Commit

Permalink
Read attribute_writing_ranks parameter also from HDF5
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 28, 2024
1 parent 1e80500 commit 267d1f6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class HDF5IOHandlerImpl : public AbstractIOHandlerImpl
*/
std::optional<MPI_Comm> m_communicator;
#endif
bool m_writeAttributesFromThisRank = true;

json::TracingJSON m_config;
std::optional<nlohmann::json> m_buffered_dataset_config;
Expand Down
40 changes: 39 additions & 1 deletion src/IO/HDF5/ParallelHDF5IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ std::future<void> ParallelHDF5IOHandler::flush(internal::ParsedFlushParams &)

ParallelHDF5IOHandlerImpl::ParallelHDF5IOHandlerImpl(
AbstractIOHandler *handler, MPI_Comm comm, json::TracingJSON config)
: HDF5IOHandlerImpl{handler, std::move(config), /* do_warn_unused_params = */ false}
: HDF5IOHandlerImpl{handler, config, /* do_warn_unused_params = */ false}
, m_mpiComm{comm}
, m_mpiInfo{MPI_INFO_NULL} /* MPI 3.0+: MPI_INFO_ENV */
{
Expand All @@ -81,6 +81,44 @@ ParallelHDF5IOHandlerImpl::ParallelHDF5IOHandlerImpl(
m_fileAccessProperty = H5Pcreate(H5P_FILE_ACCESS);
m_fileCreateProperty = H5Pcreate(H5P_FILE_CREATE);

if (config.json().contains("attribute_writing_ranks"))
{
auto const &attribute_writing_ranks =
config["attribute_writing_ranks"].json();
int rank = 0;
MPI_Comm_rank(comm, &rank);
auto throw_error = []() {
throw error::BackendConfigSchema(
{"attribute_writing_ranks"},
"Type must be either an integer or an array of integers.");
};
if (attribute_writing_ranks.is_array())
{
m_writeAttributesFromThisRank = false;
for (auto const &val : attribute_writing_ranks)
{
if (!val.is_number())
{
throw_error();
}
if (val.get<int>() == rank)
{
m_writeAttributesFromThisRank = true;
break;
}
}
}
else if (attribute_writing_ranks.is_number())
{
m_writeAttributesFromThisRank =
attribute_writing_ranks.get<int>() == rank;
}
else
{
throw_error();
}
}

#if H5_VERSION_GE(1, 10, 1)
auto const hdf5_spaced_allocation =
auxiliary::getEnvString("OPENPMD_HDF5_PAGED_ALLOCATION", "ON");
Expand Down

0 comments on commit 267d1f6

Please sign in to comment.