Skip to content

Commit 2e1e687

Browse files
committed
Variable-b. encoding: Allow several (equivalent) iterations per step
This means that a single step can be marked by /data/snapshot to represent iterations 0,10,20,30 at the same time. The underlying data is the same, but the API will treat it as 4 times a different iteration with equivalent content.
1 parent 83e1463 commit 2e1e687

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/ReadIterations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ SeriesIterator::SeriesIterator(Series series) : m_series(std::move(series))
115115
}
116116
}
117117

118-
if (!setCurrentIteration())
118+
if (status == AdvanceStatus::OVER)
119119
{
120120
*this = end();
121121
return;
122122
}
123-
if (status == AdvanceStatus::OVER)
123+
if (!setCurrentIteration())
124124
{
125125
*this = end();
126126
return;

src/Series.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,15 +1240,16 @@ std::optional<std::deque<uint64_t> > Series::readGorVBased(bool do_init)
12401240
}
12411241
}
12421242
case IterationEncoding::variableBased: {
1243-
uint64_t index = 0;
1243+
std::deque<uint64_t> res = {0};
12441244
if (currentSteps.has_value() && !currentSteps.value().empty())
12451245
{
1246-
// variable-based layout can only read one iteration at a time
1247-
// @todo warning or exception if the size is any other than 1?
1248-
index = currentSteps.value().at(0);
1246+
res = {currentSteps.value().begin(), currentSteps.value().end()};
12491247
}
1250-
readSingleIteration(index, "", false);
1251-
return std::deque<uint64_t>{index};
1248+
for (auto it : res)
1249+
{
1250+
readSingleIteration(it, "", false);
1251+
}
1252+
return res;
12521253
}
12531254
}
12541255
throw std::runtime_error("Unreachable!");

test/SerialIOTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5034,7 +5034,8 @@ void iterate_nonstreaming_series(
50345034
auto E_x = iteration.meshes["E"]["x"];
50355035
E_x.resetDataset(
50365036
openPMD::Dataset(openPMD::Datatype::INT, {2, extent}));
5037-
std::vector<int> data(extent, i);
5037+
int value = variableBasedLayout ? 0 : i;
5038+
std::vector<int> data(extent, value);
50385039
E_x.storeChunk(data, {0, 0}, {1, extent});
50395040
bool taskSupportedByBackend = true;
50405041
DynamicMemoryView<int> memoryView;
@@ -5122,9 +5123,10 @@ void iterate_nonstreaming_series(
51225123
iteration.close();
51235124
}
51245125

5126+
int value = variableBasedLayout ? 0 : iteration.iterationIndex;
51255127
for (size_t i = 0; i < extent; ++i)
51265128
{
5127-
REQUIRE(chunk.get()[i] == int(iteration.iterationIndex));
5129+
REQUIRE(chunk.get()[i] == value);
51285130
REQUIRE(chunk2.get()[i] == int(i));
51295131
}
51305132
last_iteration_index = iteration.iterationIndex;

0 commit comments

Comments
 (0)