Skip to content

Commit

Permalink
Variable-b. encoding: Allow several (equivalent) iterations per step
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
franzpoeschel committed Feb 21, 2022
1 parent 2790983 commit 2b71817
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/ReadIterations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ SeriesIterator::SeriesIterator(Series series) : m_series(std::move(series))
}
}

if (!setCurrentIteration())
if (status == AdvanceStatus::OVER)
{
*this = end();
return;
}
if (status == AdvanceStatus::OVER)
if (!setCurrentIteration())
{
*this = end();
return;
Expand Down
13 changes: 7 additions & 6 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,15 +1240,16 @@ std::optional<std::deque<uint64_t> > Series::readGorVBased(bool do_init)
}
}
case IterationEncoding::variableBased: {
uint64_t index = 0;
std::deque<uint64_t> res = {0};
if (currentSteps.has_value() && !currentSteps.value().empty())
{
// variable-based layout can only read one iteration at a time
// @todo warning or exception if the size is any other than 1?
index = currentSteps.value().at(0);
res = {currentSteps.value().begin(), currentSteps.value().end()};
}
readSingleIteration(index, "", false);
return std::deque<uint64_t>{index};
for (auto it : res)
{
readSingleIteration(it, "", false);
}
return res;
}
}
throw std::runtime_error("Unreachable!");
Expand Down
6 changes: 4 additions & 2 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5031,7 +5031,8 @@ void iterate_nonstreaming_series(
auto E_x = iteration.meshes["E"]["x"];
E_x.resetDataset(
openPMD::Dataset(openPMD::Datatype::INT, {2, extent}));
std::vector<int> data(extent, i);
int value = variableBasedLayout ? 0 : i;
std::vector<int> data(extent, value);
E_x.storeChunk(data, {0, 0}, {1, extent});
bool taskSupportedByBackend = true;
DynamicMemoryView<int> memoryView;
Expand Down Expand Up @@ -5119,9 +5120,10 @@ void iterate_nonstreaming_series(
iteration.close();
}

int value = variableBasedLayout ? 0 : iteration.iterationIndex;
for (size_t i = 0; i < extent; ++i)
{
REQUIRE(chunk.get()[i] == int(iteration.iterationIndex));
REQUIRE(chunk.get()[i] == value);
REQUIRE(chunk2.get()[i] == int(i));
}
last_iteration_index = iteration.iterationIndex;
Expand Down

0 comments on commit 2b71817

Please sign in to comment.