diff --git a/include/openPMD/IO/ADIOS/ADIOS2File.hpp b/include/openPMD/IO/ADIOS/ADIOS2File.hpp index 147e79d2ee..6595a9baa2 100644 --- a/include/openPMD/IO/ADIOS/ADIOS2File.hpp +++ b/include/openPMD/IO/ADIOS/ADIOS2File.hpp @@ -67,6 +67,7 @@ struct BufferedGet : BufferedAction { std::string name; Parameter param; + std::optional stepSelection; void run(ADIOS2File &) override; }; diff --git a/src/IO/ADIOS/ADIOS2File.cpp b/src/IO/ADIOS/ADIOS2File.cpp index f313869d1f..71800bdfc6 100644 --- a/src/IO/ADIOS/ADIOS2File.cpp +++ b/src/IO/ADIOS/ADIOS2File.cpp @@ -146,7 +146,7 @@ void BufferedGet::run(ADIOS2File &ba) ba.m_IO, ba.getEngine(), ba.m_file, - ba.stepSelection()); + this->stepSelection); } void BufferedPut::run(ADIOS2File &ba) diff --git a/src/IO/ADIOS/ADIOS2IOHandler.cpp b/src/IO/ADIOS/ADIOS2IOHandler.cpp index 67a18f7c11..c91ff6b272 100644 --- a/src/IO/ADIOS/ADIOS2IOHandler.cpp +++ b/src/IO/ADIOS/ADIOS2IOHandler.cpp @@ -1079,6 +1079,9 @@ void ADIOS2IOHandlerImpl::readDataset( detail::BufferedGet bg; bg.name = nameOfVariable(writable); bg.param = parameters; + // need to store the current step selection for deferred reads as the step + // selection might change again before flushing + bg.stepSelection = ba.stepSelection(); ba.enqueue(std::move(bg)); m_dirty.emplace(std::move(file)); } @@ -1521,7 +1524,6 @@ Random-access for variable-encoding in ADIOS2 is currently experimental. Support for modifiable attributes is currently not implemented yet, meaning that attributes such as /data/time will show useless values. Use Access::READ_LINEAR to retrieve those values if needed. -The following modifiable attributes have been found: )"; }; if (!modifiable_flag) diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index 0b050384fb..40aba2c8c1 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -5901,6 +5901,31 @@ void variableBasedSeries(std::string const &file) REQUIRE( readSeries.getAttribute("some_global").get() == "attribute"); + if (access == Access::READ_RANDOM_ACCESS) + { + std::vector> load_E_x( + readSeries.snapshots().size()); + // std::vector> load_E_y( + // readSeries.snapshots().size()); + + for (auto &[idx, iteration] : readSeries.snapshots()) + { + iteration.open(); + load_E_x[idx] = iteration.meshes["E"]["x"].loadChunk(); + // TODO: Changing dimensionality seems to not work in ADIOS2 + // with ReadRandomAccess + // https://github.com/ornladios/ADIOS2/issues/4474 + // load_E_y[idx] = iteration.meshes["E"]["y"].loadChunk(); + } + readSeries.flush(); + for (size_t i = 0; i < load_E_x.size(); ++i) + { + for (size_t j = 0; j < extent; ++j) + { + REQUIRE(load_E_x[i].get()[j] == int(i)); + } + } + } for (auto iteration : readSeries.readIterations()) { if (access == Access::READ_LINEAR) @@ -5999,6 +6024,35 @@ void variableBasedSeries(std::string const &file) iteration.iterationIndex); } REQUIRE(last_iteration_index == (is_adios2 ? 9 : 0)); + if (access == Access::READ_RANDOM_ACCESS) + { + // should be able to reopen Iterations closed previously + // should be able to read multiple Iterations at once + + std::vector> load_E_x( + readSeries.snapshots().size()); + + // std::vector> load_E_y( + // readSeries.snapshots().size()); + + for (auto &[idx, iteration] : readSeries.snapshots()) + { + iteration.open(); + load_E_x[idx] = iteration.meshes["E"]["x"].loadChunk(); + // Changing dimensionality seems to not work in ADIOS2 + // with ReadRandomAccess + // https://github.com/ornladios/ADIOS2/issues/4474 + // load_E_y[idx] = iteration.meshes["E"]["y"].loadChunk(); + } + readSeries.flush(); + for (size_t i = 0; i < load_E_x.size(); ++i) + { + for (size_t j = 0; j < extent; ++j) + { + REQUIRE(load_E_x[i].get()[j] == int(i)); + } + } + } }; std::string jsonConfig = R"(