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 Nov 1, 2021
1 parent e89336c commit 49b75ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/ReadIterations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ SeriesIterator::SeriesIterator( Series series )
}
}

if( !setCurrentIteration() )
if( status == AdvanceStatus::OVER )
{
*this = end();
return;
}
if( status == AdvanceStatus::OVER )
if( !setCurrentIteration() )
{
*this = end();
return;
Expand Down
18 changes: 9 additions & 9 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,17 +1135,17 @@ SeriesInterface::readGorVBased( bool do_init )
return auxiliary::Option< std::deque< uint64_t > >();
}
}
case IterationEncoding::variableBased:
{
uint64_t index = 0;
case IterationEncoding::variableBased: {
std::deque< uint64_t > res = { 0 };
if( currentSteps.has_value() && !currentSteps.get().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.get().at( 0 );
res = { currentSteps.get().begin(), currentSteps.get().end() };
}
for( auto it : res )
{
readSingleIteration( it, "", false );
}
readSingleIteration( index, "", false );
return std::deque< uint64_t >{ index };
return res;
}
}
throw std::runtime_error( "Unreachable!" );
Expand Down Expand Up @@ -1605,7 +1605,7 @@ SeriesInternal::~SeriesInternal()
* needlessly flushed a second time. Otherwise, error messages can get
* very confusing.
*/
if( get().m_lastFlushSuccessful )
if( series.m_lastFlushSuccessful )
{
flush();
flushStep( /* doFlush = */ true );
Expand Down
8 changes: 5 additions & 3 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4172,7 +4172,8 @@ 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 = E_x.storeChunk< int >(
Expand Down Expand Up @@ -4252,10 +4253,11 @@ 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( chunk2.get()[ i ] == int(i) );
REQUIRE( chunk.get()[ i ] == value );
REQUIRE( chunk2.get()[ i ] == int( i ) );
}
last_iteration_index = iteration.iterationIndex;
}
Expand Down

0 comments on commit 49b75ee

Please sign in to comment.