Skip to content

Commit

Permalink
Reset Iterations after closing
Browse files Browse the repository at this point in the history
Not yet complete
  • Loading branch information
franzpoeschel committed Nov 21, 2023
1 parent 7d38a13 commit 47da1e9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
3 changes: 3 additions & 0 deletions include/openPMD/IO/IOTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "openPMD/backend/Attribute.hpp"
#include "openPMD/backend/ParsePreference.hpp"

#include <any>
#include <map>
#include <memory>
#include <string>
Expand Down Expand Up @@ -209,6 +210,8 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::CLOSE_FILE>
Parameter &operator=(Parameter &&) = default;
Parameter &operator=(Parameter const &) = default;

std::any keep_this_data_alive;

std::unique_ptr<AbstractParameter> to_heap() && override
{
return std::unique_ptr<AbstractParameter>(
Expand Down
2 changes: 2 additions & 0 deletions include/openPMD/Iteration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ class Iteration : public Attributable
*
*/
void runDeferredParseAccess();

Iteration resetIteration();
}; // Iteration

extern template float Iteration::time<float>() const;
Expand Down
16 changes: 16 additions & 0 deletions src/Iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,22 @@ void Iteration::linkHierarchy(Writable &w)
Attributable::linkHierarchy(w);
meshes.linkHierarchy(this->writable());
particles.linkHierarchy(this->writable());
meshes.writable().ownKeyWithinParent = {"meshes"};
particles.writable().ownKeyWithinParent = {"particles"};
}

Iteration Iteration::resetIteration()
{
Iteration copied = *this;
auto parent = writable().parent;

setData(std::make_shared<internal::IterationData>());
meshes = {};
particles = {};
writable().written = true;

this->linkHierarchy(*parent);
return copied;
}

void Iteration::runDeferredParseAccess()
Expand Down
6 changes: 4 additions & 2 deletions src/ReadIterations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,10 @@ void SeriesIterator::deactivateDeadIteration(iteration_index_t index)
{
case IterationEncoding::fileBased: {
Parameter<Operation::CLOSE_FILE> param;
data.series->IOHandler()->enqueue(
IOTask(&data.series->iterations[index], std::move(param)));
Iteration resetted = data.series->iterations[index].resetIteration();
auto writable = &resetted.writable();
param.keep_this_data_alive = std::move(resetted);
data.series->IOHandler()->enqueue(IOTask(writable, std::move(param)));
data.series->IOHandler()->flush({FlushLevel::UserFlush});
}
break;
Expand Down
15 changes: 12 additions & 3 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,10 @@ void Series::flushFileBased(
internal::CloseStatus::ClosedInFrontend)
{
Parameter<Operation::CLOSE_FILE> fClose;
IOHandler()->enqueue(IOTask(&it->second, std::move(fClose)));
Iteration resetted = it->second.resetIteration();
auto writable = &resetted.writable();
fClose.keep_this_data_alive = std::move(resetted);
IOHandler()->enqueue(IOTask(writable, std::move(fClose)));
it->second.get().m_closed =
internal::CloseStatus::ClosedInBackend;
}
Expand Down Expand Up @@ -838,7 +841,10 @@ void Series::flushFileBased(
internal::CloseStatus::ClosedInFrontend)
{
Parameter<Operation::CLOSE_FILE> fClose;
IOHandler()->enqueue(IOTask(&it->second, std::move(fClose)));
Iteration resetted = it->second.resetIteration();
auto writable = &resetted.writable();
fClose.keep_this_data_alive = std::move(resetted);
IOHandler()->enqueue(IOTask(writable, std::move(fClose)));
it->second.get().m_closed =
internal::CloseStatus::ClosedInBackend;
}
Expand Down Expand Up @@ -1876,7 +1882,10 @@ AdvanceStatus Series::advance(
if (itData.m_closed != internal::CloseStatus::ClosedTemporarily)
{
Parameter<Operation::CLOSE_FILE> fClose;
IOHandler()->enqueue(IOTask(&iteration, std::move(fClose)));
Iteration resetted = iteration.resetIteration();
auto writable = &resetted.writable();
fClose.keep_this_data_alive = std::move(resetted);
IOHandler()->enqueue(IOTask(writable, std::move(fClose)));
}
itData.m_closed = internal::CloseStatus::ClosedInBackend;
break;
Expand Down
4 changes: 2 additions & 2 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6833,13 +6833,13 @@ void varying_pattern(std::string const &file_ending)
REQUIRE(it.getAttribute("my_step").get<int>() == int(step));
}

helper::listSeries(series, true, std::cout);

for (auto i : {0, 8000, 10000, 100000, 2000000})
{
auto it = series.iterations[i];
REQUIRE(it.getAttribute("my_step").get<int>() == i);
}

helper::listSeries(series, true, std::cout);
}
}

Expand Down

0 comments on commit 47da1e9

Please sign in to comment.