From 0b841f4a507523ec1f701164a8ec33d3587bc064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Wed, 20 Dec 2023 15:46:25 +0100 Subject: [PATCH] Read attribute_writing_ranks parameter also from HDF5 --- include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp | 1 + src/IO/HDF5/ParallelHDF5IOHandler.cpp | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp b/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp index 9fee9978f0..0662f6afa7 100644 --- a/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp +++ b/include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp @@ -116,6 +116,7 @@ class HDF5IOHandlerImpl : public AbstractIOHandlerImpl */ std::optional m_communicator; #endif + bool m_writeAttributesFromThisRank = true; json::TracingJSON m_config; std::optional m_buffered_dataset_config; diff --git a/src/IO/HDF5/ParallelHDF5IOHandler.cpp b/src/IO/HDF5/ParallelHDF5IOHandler.cpp index ecdbc8ab89..865245e316 100644 --- a/src/IO/HDF5/ParallelHDF5IOHandler.cpp +++ b/src/IO/HDF5/ParallelHDF5IOHandler.cpp @@ -70,7 +70,7 @@ std::future 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 */ { @@ -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() == rank) + { + m_writeAttributesFromThisRank = true; + break; + } + } + } + else if (attribute_writing_ranks.is_number()) + { + m_writeAttributesFromThisRank = + attribute_writing_ranks.get() == rank; + } + else + { + throw_error(); + } + } + #if H5_VERSION_GE(1, 10, 1) auto const hdf5_spaced_allocation = auxiliary::getEnvString("OPENPMD_HDF5_PAGED_ALLOCATION", "ON");