Skip to content

Commit

Permalink
Avoid infinite loops if there is no stream active
Browse files Browse the repository at this point in the history
The backends will explicitly report in their status if it is currently
random-accessing. The frontend will then fall back to stepping linearly.
  • Loading branch information
franzpoeschel committed Mar 25, 2021
1 parent 9e9cc88 commit 6bb3c8a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions include/openPMD/IO/AbstractIOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ class AbstractIOHandlerImpl
* The return status code shall be stored as parameters.status.
*/
virtual void
advance( Writable *, Parameter< Operation::ADVANCE > & )
{}
advance( Writable *, Parameter< Operation::ADVANCE > & parameters )
{
*parameters.status = AdvanceStatus::RANDOMACCESS;
}

/** Close an openPMD group.
*
Expand Down
5 changes: 3 additions & 2 deletions include/openPMD/Streaming.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ namespace openPMD
*/
enum class AdvanceStatus : unsigned char
{
OK, /* stream goes on */
OVER /* stream is over */
OK, /* stream goes on */
OVER, /* stream is over */
RANDOMACCESS /* there is no stream, it will never be over */
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2534,7 +2534,7 @@ namespace detail
m_IO.DefineAttribute< bool_representation >(
ADIOS2Defaults::str_usesstepsAttribute, 0 );
flush( /* writeAttributes = */ false );
return AdvanceStatus::OK;
return AdvanceStatus::RANDOMACCESS;
}

m_IO.DefineAttribute< bool_representation >(
Expand Down
6 changes: 4 additions & 2 deletions src/ReadIterations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ SeriesIterator::SeriesIterator( Series series )
Iteration::BeginStepStatus::AvailableIterations_t
availableIterations;
std::tie( status, availableIterations ) = it->second.beginStep();
if( availableIterations.has_value() )
if( availableIterations.has_value()
&& status != AdvanceStatus::RANDOMACCESS )
{
m_iterationsInCurrentStep = availableIterations.get();
if( !m_iterationsInCurrentStep.empty() )
Expand Down Expand Up @@ -188,7 +189,8 @@ SeriesIterator & SeriesIterator::operator++()
AdvanceStatus status;
Iteration::BeginStepStatus::AvailableIterations_t availableIterations;
std::tie( status, availableIterations ) = currentIteration.beginStep();
if( availableIterations.has_value() )
if( availableIterations.has_value()
&& status != AdvanceStatus::RANDOMACCESS )
{
m_iterationsInCurrentStep = availableIterations.get();
}
Expand Down

0 comments on commit 6bb3c8a

Please sign in to comment.