Skip to content

Commit

Permalink
Turn attribute_writing_ranks into global option
Browse files Browse the repository at this point in the history
New concept: global options with backend-specific implementation
  • Loading branch information
franzpoeschel committed Feb 14, 2024
1 parent 283b2fe commit 685e4f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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 @@ -178,6 +178,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 @@ -196,6 +198,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
15 changes: 15 additions & 0 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,21 @@ namespace
template <typename TracingJSON>
void Series::parseJsonOptions(TracingJSON &options, ParsedInput &input)
{
constexpr std::array
backend_independent_options_with_backend_specific_implementation = {
"attribute_writing_ranks"};

for (auto const &opt :
backend_independent_options_with_backend_specific_implementation)
{
// Suppress warnings for these options: The backends might or might not
// take those hints
if (options.json().contains(opt))
{
options[opt];
}
}

auto &series = get();
getJsonOption<bool>(
options, "defer_iteration_parsing", series.m_parseLazily);
Expand Down
3 changes: 2 additions & 1 deletion test/ParallelIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,9 +1173,10 @@ doshuffle = "BLOSC_BITSHUFFLE"

std::string writeConfigBP4 =
R"END(
attribute_writing_ranks = 0
[adios2]
unused = "parameter"
attribute_writing_ranks = 0
)END"
#if openPMD_HAS_ADIOS_2_9
"use_group_table = true"
Expand Down

0 comments on commit 685e4f0

Please sign in to comment.