Skip to content

Commit

Permalink
Fix flushStep() logic
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 18, 2024
1 parent 41d950a commit 9412493
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/openPMD/Iteration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class Iteration : public Attributable
void flushFileBased(
std::string const &, IterationIndex_t, internal::FlushParams const &);
void flushGroupBased(IterationIndex_t, internal::FlushParams const &);
void flushVariableBased(IterationIndex_t, internal::FlushParams const &);
void flushVariableBased(internal::FlushParams const &);
void flush(internal::FlushParams const &);
void deferParseAccess(internal::DeferredParseAccess);
/*
Expand Down
24 changes: 23 additions & 1 deletion src/IO/AbstractIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "openPMD/IO/AbstractIOHandlerImpl.hpp"

#include "openPMD/auxiliary/Environment.hpp"
#include "openPMD/auxiliary/TypeTraits.hpp"
#include "openPMD/backend/Writable.hpp"

#include <iostream>
Expand Down Expand Up @@ -301,7 +302,28 @@ std::future<void> AbstractIOHandlerImpl::flush()
"] WRITE_ATT: (",
parameter.dtype,
") ",
parameter.name);
parameter.name,
"=",
[&]() {
return std::visit(
[&](auto const &val) {
using dtype = std::remove_cv_t<
std::remove_reference_t<decltype(val)>>;
if constexpr (
auxiliary::IsArray_v<dtype> ||
auxiliary::IsVector_v<dtype>)
{
return vec_as_string(val);
}
else
{
std::stringstream res;
res << val;
return res.str();
}
},
parameter.resource);
});
writeAttribute(i.writable, parameter);
break;
}
Expand Down
20 changes: 1 addition & 19 deletions src/Iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ void Iteration::flushGroupBased(
}
}

void Iteration::flushVariableBased(
IterationIndex_t i, internal::FlushParams const &flushParams)
void Iteration::flushVariableBased(internal::FlushParams const &flushParams)
{
setDirty(true);

Expand All @@ -305,23 +304,6 @@ void Iteration::flushVariableBased(
flush(flushParams);
break;
}

// @todo maybe dont repeat this upon each invocation
{
/*
* In v-based encoding, the snapshot attribute must always be written.
* Reason: Even in backends that don't support changing attributes,
* variable-based iteration encoding can be used to write one single
* iteration. Then, this attribute determines which iteration it is.
*/
Parameter<Operation::WRITE_ATT> wAttr;
wAttr.changesOverSteps =
Parameter<Operation::WRITE_ATT>::ChangesOverSteps::IfPossible;
wAttr.name = "snapshot";
wAttr.resource = (unsigned long long)i;
wAttr.dtype = Datatype::ULONGLONG;
IOHandler()->enqueue(IOTask(this, wAttr));
}
}

void Iteration::flush(internal::FlushParams const &flushParams)
Expand Down
14 changes: 11 additions & 3 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,16 +1521,16 @@ void Series::flushGorVBased(
"Iterations must be the same backend object as the "
"Iterations themselves.");
}
series.m_currentlyActiveIterations.emplace(it->first);
}
series.m_currentlyActiveIterations.emplace(it->first);
switch (iterationEncoding())
{
using IE = IterationEncoding;
case IE::groupBased:
it->second.flushGroupBased(it->first, flushParams);
break;
case IE::variableBased:
it->second.flushVariableBased(it->first, flushParams);
it->second.flushVariableBased(flushParams);
break;
default:
throw std::runtime_error(
Expand Down Expand Up @@ -2636,8 +2636,16 @@ void Series::flushStep(bool doFlush)
* one IO step.
*/
Parameter<Operation::WRITE_ATT> wAttr;
/*
* In v-based encoding, the snapshot attribute must always be written.
* Reason: Even in backends that don't support changing attributes,
* variable-based iteration encoding can be used to write one single
* iteration. Then, this attribute determines which iteration it is.
*/
wAttr.changesOverSteps =
Parameter<Operation::WRITE_ATT>::ChangesOverSteps::Yes;
iterationEncoding() == IterationEncoding::variableBased
? Parameter<Operation::WRITE_ATT>::ChangesOverSteps::IfPossible
: Parameter<Operation::WRITE_ATT>::ChangesOverSteps::Yes;
wAttr.name = "snapshot";
wAttr.resource = std::vector<unsigned long long>{
series.m_currentlyActiveIterations.begin(),
Expand Down

0 comments on commit 9412493

Please sign in to comment.