@@ -4901,8 +4901,10 @@ void serial_iterator(std::string const &file)
49014901 Series readSeries (file, Access::READ_ONLY);
49024902
49034903 size_t last_iteration_index = 0 ;
4904+ size_t numberOfIterations = 0 ;
49044905 for (auto iteration : readSeries.readIterations ())
49054906 {
4907+ ++numberOfIterations;
49064908 auto E_x = iteration.meshes [" E" ][" x" ];
49074909 REQUIRE (E_x.getDimensionality () == 1 );
49084910 REQUIRE (E_x.getExtent ()[0 ] == extent);
@@ -4915,6 +4917,7 @@ void serial_iterator(std::string const &file)
49154917 last_iteration_index = iteration.iterationIndex ;
49164918 }
49174919 REQUIRE (last_iteration_index == 9 );
4920+ REQUIRE (numberOfIterations == 10 );
49184921}
49194922
49204923TEST_CASE (" serial_iterator" , " [serial][adios2]" )
@@ -6178,11 +6181,12 @@ TEST_CASE("deferred_parsing", "[serial]")
61786181 }
61796182}
61806183
6181- // @todo merge this back with the chaotic_stream test of PR #949
6182- // (bug noticed while working on that branch)
6183- void no_explicit_flush (std::string filename)
6184+ void chaotic_stream (std::string filename, bool variableBased)
61846185{
6185- std::vector<uint64_t > sampleData{5 , 9 , 1 , 3 , 4 , 6 , 7 , 8 , 2 , 0 };
6186+ /*
6187+ * We will write iterations in the following order.
6188+ */
6189+ std::vector<uint64_t > iterations{5 , 9 , 1 , 3 , 4 , 6 , 7 , 8 , 2 , 0 };
61866190 std::string jsonConfig = R"(
61876191{
61886192 "adios2": {
@@ -6193,16 +6197,31 @@ void no_explicit_flush(std::string filename)
61936197 }
61946198})" ;
61956199
6200+ bool weirdOrderWhenReading{};
6201+
61966202 {
61976203 Series series (filename, Access::CREATE, jsonConfig);
6198- for (uint64_t currentIteration = 0 ; currentIteration < 10 ;
6199- ++currentIteration)
6204+ /*
6205+ * When using ADIOS2 steps, iterations are read not by logical order
6206+ * (iteration index), but by order of writing.
6207+ */
6208+ weirdOrderWhenReading = series.backend () == " ADIOS2" &&
6209+ series.iterationEncoding () != IterationEncoding::fileBased;
6210+ if (variableBased)
6211+ {
6212+ if (series.backend () != " ADIOS2" )
6213+ {
6214+ return ;
6215+ }
6216+ series.setIterationEncoding (IterationEncoding::variableBased);
6217+ }
6218+ for (auto currentIteration : iterations)
62006219 {
62016220 auto dataset =
62026221 series.writeIterations ()[currentIteration]
62036222 .meshes [" iterationOrder" ][MeshRecordComponent::SCALAR];
62046223 dataset.resetDataset ({determineDatatype<uint64_t >(), {10 }});
6205- dataset.storeChunk (sampleData , {0 }, {10 });
6224+ dataset.storeChunk (iterations , {0 }, {10 });
62066225 // series.writeIterations()[ currentIteration ].close();
62076226 }
62086227 }
@@ -6212,19 +6231,27 @@ void no_explicit_flush(std::string filename)
62126231 size_t index = 0 ;
62136232 for (const auto &iteration : series.readIterations ())
62146233 {
6215- REQUIRE (iteration.iterationIndex == index);
6234+ if (weirdOrderWhenReading)
6235+ {
6236+ REQUIRE (iteration.iterationIndex == iterations[index]);
6237+ }
6238+ else
6239+ {
6240+ REQUIRE (iteration.iterationIndex == index);
6241+ }
62166242 ++index;
62176243 }
6218- REQUIRE (index == 10 );
6244+ REQUIRE (index == iterations. size () );
62196245 }
62206246}
62216247
6222- TEST_CASE (" no_explicit_flush " , " [serial]" )
6248+ TEST_CASE (" chaotic_stream " , " [serial]" )
62236249{
62246250 for (auto const &t : testedFileExtensions ())
62256251 {
6226- no_explicit_flush (" ../samples/no_explicit_flush_filebased_%T." + t);
6227- no_explicit_flush (" ../samples/no_explicit_flush." + t);
6252+ chaotic_stream (" ../samples/chaotic_stream_filebased_%T." + t, false );
6253+ chaotic_stream (" ../samples/chaotic_stream." + t, false );
6254+ chaotic_stream (" ../samples/chaotic_stream_vbased." + t, true );
62286255 }
62296256}
62306257
@@ -6405,7 +6432,25 @@ void append_mode(
64056432 }
64066433
64076434 writeSomeIterations (
6408- write.writeIterations (), std::vector<uint64_t >{4 , 3 });
6435+ write.writeIterations (), std::vector<uint64_t >{4 , 3 , 10 });
6436+ write.flush ();
6437+ }
6438+ {
6439+ Series write (filename, Access::APPEND, jsonConfig);
6440+ if (variableBased)
6441+ {
6442+ write.setIterationEncoding (IterationEncoding::variableBased);
6443+ }
6444+ if (write.backend () == " ADIOS1" )
6445+ {
6446+ REQUIRE_THROWS_AS (
6447+ write.flush (), error::OperationUnsupportedInBackend);
6448+ // destructor will be noisy now
6449+ return ;
6450+ }
6451+
6452+ writeSomeIterations (
6453+ write.writeIterations (), std::vector<uint64_t >{7 , 1 , 11 });
64096454 write.flush ();
64106455 }
64116456 {
@@ -6415,27 +6460,28 @@ void append_mode(
64156460 // in variable-based encodings, iterations are not parsed ahead of
64166461 // time but as they go
64176462 unsigned counter = 0 ;
6463+ uint64_t iterationOrder[] = {0 , 1 , 2 , 3 , 4 , 10 , 7 , 11 };
64186464 for (auto const &iteration : read.readIterations ())
64196465 {
6420- REQUIRE (iteration.iterationIndex == counter);
6466+ REQUIRE (iteration.iterationIndex == iterationOrder[ counter] );
64216467 ++counter;
64226468 }
6423- REQUIRE (counter == 5 );
6469+ REQUIRE (counter == 8 );
64246470 // Cannot do listSeries here because the Series is already drained
64256471 REQUIRE_THROWS_AS (helper::listSeries (read), error::WrongAPIUsage);
64266472 }
64276473 else
64286474 {
6429- REQUIRE (read.iterations .size () == 5 );
6475+ REQUIRE (read.iterations .size () == 8 );
6476+ /*
6477+ * Roadmap: for now, reading this should work by ignoring the last
6478+ * duplicate iteration.
6479+ * After merging https://github.com/openPMD/openPMD-api/pull/949, we
6480+ * should see both instances when reading.
6481+ * Final goal: Read only the last instance.
6482+ */
6483+ helper::listSeries (read);
64306484 }
6431- /*
6432- * Roadmap: for now, reading this should work by ignoring the last
6433- * duplicate iteration.
6434- * After merging https://github.com/openPMD/openPMD-api/pull/949, we
6435- * should see both instances when reading.
6436- * Final goal: Read only the last instance.
6437- */
6438- helper::listSeries (read);
64396485 }
64406486#if 100000000 * ADIOS2_VERSION_MAJOR + 1000000 * ADIOS2_VERSION_MINOR + \
64416487 10000 * ADIOS2_VERSION_PATCH + 100 * ADIOS2_VERSION_TWEAK >= \
0 commit comments