Skip to content

Commit 358d239

Browse files
ADIOS2 bugfix: Always use CurrentStep() in mode::Read (#1749)
* Always use CurrentStep() in mode::Read * Remove manual step counting m_currentStep only necessary for SetStepSelection, it seems * Clean up logic that is no longer needed * Add test
1 parent 45708ca commit 358d239

3 files changed

Lines changed: 19 additions & 36 deletions

File tree

examples/10_streaming_write.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ int main()
2222
}
2323

2424
// open file for writing
25+
// use QueueFullPolicy = Discard in order to create a situation where from
26+
// the reader's perspective steps are skipped. This tests the bug reported
27+
// in https://github.com/openPMD/openPMD-api/issues/1747.
2528
Series series = Series("electrons.sst", Access::CREATE, R"(
2629
{
2730
"adios2": {
2831
"engine": {
2932
"parameters": {
30-
"DataTransport": "WAN"
33+
"DataTransport": "WAN",
34+
"QueueFullPolicy": "Discard"
3135
}
3236
}
3337
}

include/openPMD/IO/ADIOS/ADIOS2File.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class ADIOS2File
407407

408408
size_t currentStep();
409409
void setStepSelection(std::optional<size_t>);
410-
[[nodiscard]] std::optional<size_t> stepSelection() const;
410+
[[nodiscard]] std::optional<size_t> const &stepSelection() const;
411411

412412
[[nodiscard]] detail::AdiosAttributes const &attributes() const
413413
{
@@ -431,13 +431,9 @@ class ADIOS2File
431431
std::optional<adios2::Engine> m_engine; //! ADIOS engine
432432

433433
/*
434-
* Not all engines support the CurrentStep() call, so we have to
435-
* implement this manually.
436-
* Note: We don't use a std::optional<size_t> here since the currentStep
437-
* is always being counted.
434+
* Used for selecting steps in adios2::Mode::ReadRandomAccesss.
438435
*/
439-
size_t m_currentStep = 0;
440-
bool useStepSelection = false;
436+
std::optional<size_t> m_stepSelection;
441437
std::optional<size_t> m_max_steps_bp5 = std::make_optional<size_t>(100);
442438

443439
/*

src/IO/ADIOS/ADIOS2File.cpp

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ size_t ADIOS2File::currentStep()
363363
{
364364
return *step_selection;
365365
}
366-
else if (nonpersistentEngine(m_impl->m_engineType))
366+
else if (m_mode == adios2::Mode::ReadRandomAccess)
367367
{
368-
return m_currentStep;
368+
return 0;
369369
}
370370
else
371371
{
@@ -381,28 +381,12 @@ void ADIOS2File::setStepSelection(std::optional<size_t> step)
381381
"ADIOS2 backend: Cannot only use random-access step selections "
382382
"when reading without streaming mode.");
383383
}
384-
if (!step.has_value())
385-
{
386-
m_currentStep = 0;
387-
useStepSelection = false;
388-
}
389-
else
390-
{
391-
m_currentStep = *step;
392-
useStepSelection = true;
393-
}
384+
m_stepSelection = step;
394385
}
395386

396-
std::optional<size_t> ADIOS2File::stepSelection() const
387+
std::optional<size_t> const &ADIOS2File::stepSelection() const
397388
{
398-
if (useStepSelection)
399-
{
400-
return {m_currentStep};
401-
}
402-
else
403-
{
404-
return std::nullopt;
405-
}
389+
return m_stepSelection;
406390
}
407391

408392
void ADIOS2File::configure_IO_Read()
@@ -1172,7 +1156,6 @@ void ADIOS2File::flush_impl(ADIOS2FlushParams flushParams, bool writeLatePuts)
11721156
}
11731157
engine.EndStep();
11741158
engine.BeginStep();
1175-
// ++m_currentStep; // think we should keep this as the logical step
11761159
m_uniquePtrPuts.clear();
11771160
uncommittedAttributes.clear();
11781161
m_updateSpans.clear();
@@ -1257,14 +1240,14 @@ AdvanceStatus ADIOS2File::advance(AdvanceMode mode)
12571240
uncommittedAttributes.clear();
12581241
m_updateSpans.clear();
12591242
streamStatus = StreamStatus::OutsideOfStep;
1260-
++m_currentStep;
12611243
return AdvanceStatus::OK;
12621244
}
12631245
case AdvanceMode::BEGINSTEP: {
12641246
adios2::StepStatus adiosStatus{};
1247+
auto &engine = getEngine();
12651248

12661249
auto check_bp5 = [&]() -> bool {
1267-
std::string engineType = getEngine().Type();
1250+
std::string engineType = engine.Type();
12681251
std::transform(
12691252
engineType.begin(),
12701253
engineType.end(),
@@ -1273,7 +1256,7 @@ AdvanceStatus ADIOS2File::advance(AdvanceMode mode)
12731256
return engineType == "bp5writer";
12741257
};
12751258

1276-
if (this->m_currentStep == 0)
1259+
if (engine.CurrentStep() == 0)
12771260
{
12781261
int max_steps_from_env =
12791262
auxiliary::getEnvNum("OPENPMD_BP5_GROUPENCODING_MAX_STEPS", -1);
@@ -1293,7 +1276,7 @@ AdvanceStatus ADIOS2File::advance(AdvanceMode mode)
12931276
if (this->m_impl->m_handler->m_encoding ==
12941277
IterationEncoding::groupBased &&
12951278
this->m_max_steps_bp5.has_value() &&
1296-
this->m_currentStep >= *this->m_max_steps_bp5 &&
1279+
engine.CurrentStep() >= *this->m_max_steps_bp5 &&
12971280
(this->m_mode == adios2::Mode::Write ||
12981281
this->m_mode == adios2::Mode::Append) &&
12991282
check_bp5())
@@ -1329,7 +1312,7 @@ Be aware of the performance implications described above.)");
13291312

13301313
if (streamStatus != StreamStatus::DuringStep)
13311314
{
1332-
adiosStatus = getEngine().BeginStep();
1315+
adiosStatus = engine.BeginStep();
13331316
}
13341317
else
13351318
{
@@ -1403,7 +1386,7 @@ ADIOS2File::availableVariablesPrefixed(std::string const &prefix)
14031386
ADIOS2File::AttributeMap_t const &ADIOS2File::availableVariables()
14041387
{
14051388
return m_variables.availableVariables(
1406-
currentStep(), useStepSelection, m_IO);
1389+
currentStep(), stepSelection().has_value(), m_IO);
14071390
}
14081391

14091392
void ADIOS2File::markActive(Writable *writable)

0 commit comments

Comments
 (0)