Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: attribute_writing_ranks in HDf5 #1581

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/5_write_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
*/
#include <openPMD/openPMD.hpp>

#include <openPMD/auxiliary/Environment.hpp>

#include <mpi.h>

#include <iostream>
#include <memory>
#include <sstream>
#include <vector> // std::vector

using std::cout;
Expand Down Expand Up @@ -59,6 +62,19 @@ stripe_count = -1
chunks = "auto"
)";

#if 1
subfiling_config =
[]() {
std::stringstream res;
res << "attribute_writing_ranks = ["
<< auxiliary::getEnvString("RANKS", "0") << "]";
auto res_str = res.str();
std::cout << "RETURNING: '" << res_str << "'" << std::endl;
return res_str;
}() +
subfiling_config;
#endif

// open file for writing
Series series = Series(
"../samples/5_parallel_write.h5",
Expand Down
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
10 changes: 9 additions & 1 deletion src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
MPI_Comm_rank(communicator, &rank);
auto throw_error = []() {
throw error::BackendConfigSchema(
{"adios2", "attribute_writing_ranks"},
{"attribute_writing_ranks"},
"Type must be either an integer or an array of integers.");
};
if (attribute_writing_ranks.is_array())
Expand Down Expand Up @@ -190,6 +190,8 @@ template <typename Callback>
void ADIOS2IOHandlerImpl::init(
json::TracingJSON cfg, Callback &&callbackWriteAttributesFromRank)
{
std::cout << "Initializing ADIOS2 with config:\n"
<< cfg.json() << std::endl;
// allow overriding through environment variable
m_engineType =
auxiliary::getEnvString("OPENPMD_ADIOS2_ENGINE", m_engineType);
Expand All @@ -208,6 +210,12 @@ void ADIOS2IOHandlerImpl::init(
groupTableViaEnv == 0 ? UseGroupTable::No : UseGroupTable::Yes;
}

// Backend-independent options with backend-dependent implementations
if (cfg.json().contains("attribute_writing_ranks"))
{
callbackWriteAttributesFromRank(cfg["attribute_writing_ranks"].json());
}

if (cfg.json().contains("adios2"))
{
m_config = cfg["adios2"];
Expand Down
Loading
Loading