Skip to content

Commit 7f96a13

Browse files
committed
Move flushing from storeChunk to resetDataset
1 parent e3a0136 commit 7f96a13

6 files changed

Lines changed: 37 additions & 38 deletions

File tree

include/openPMD/RecordComponent.tpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,22 @@ RecordComponent::storeChunk(Offset o, Extent e, F &&createBuffer)
8585
{
8686
verifyChunk<T>(o, e);
8787

88-
/*
89-
* The openPMD backend might not yet know about this dataset.
90-
* Flush the openPMD hierarchy to the backend without flushing any actual
91-
* data yet.
92-
*/
93-
seriesFlush_impl</* flush_entire_series = */ false>(
94-
{FlushLevel::SkeletonOnly});
95-
9688
size_t size = 1;
9789
for (auto ext : e)
9890
{
9991
size *= ext;
10092
}
93+
10194
/*
10295
* Flushing the skeleton does not create datasets,
10396
* so we might need to do it now.
10497
*/
105-
if (!written())
98+
auto &rc = get();
99+
if (!rc.m_dataset.has_value())
106100
{
107-
auto &rc = get();
108-
if (!rc.m_dataset.has_value())
109-
{
110-
throw error::WrongAPIUsage(
111-
"[RecordComponent] Must specify dataset type and extent before "
112-
"using storeChunk() (see RecordComponent::resetDataset()).");
113-
}
114-
Parameter<Operation::CREATE_DATASET> dCreate(rc.m_dataset.value());
115-
dCreate.name = Attributable::get().m_writable.ownKeyWithinParent;
116-
IOHandler()->enqueue(IOTask(this, dCreate));
101+
throw error::WrongAPIUsage(
102+
"[RecordComponent] Must specify dataset type and extent before "
103+
"using storeChunk() (see RecordComponent::resetDataset()).");
117104
}
118105

119106
Parameter<Operation::GET_BUFFER_VIEW> getBufferView;

include/openPMD/backend/Attributable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ OPENPMD_protected
421421
/** @} */
422422

423423
template <bool flush_entire_series>
424-
void seriesFlush_impl(internal::FlushParams const &);
424+
void seriesFlush_impl(internal::FlushParams const &, bool flush_io_handler);
425425

426426
void flushAttributes(internal::FlushParams const &);
427427

src/RecordComponent.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "openPMD/Dataset.hpp"
2323
#include "openPMD/DatatypeHelpers.hpp"
2424
#include "openPMD/Error.hpp"
25+
#include "openPMD/IO/AbstractIOHandler.hpp"
2526
#include "openPMD/IO/Format.hpp"
2627
#include "openPMD/Series.hpp"
2728
#include "openPMD/auxiliary/Environment.hpp"
@@ -237,10 +238,15 @@ RecordComponent &RecordComponent::resetDataset(Dataset d)
237238
auto &rc = get();
238239
auto cleanup = defer([&rc, this]() {
239240
if (rc.m_dataset.has_value() &&
240-
rc.m_dataset->dtype != Datatype::UNDEFINED)
241+
rc.m_dataset->dtype != Datatype::UNDEFINED &&
242+
IOHandler()->m_seriesStatus != internal::SeriesStatus::Parsing)
241243
{
244+
// TODO: try getting flush_io_handler = false to run
242245
seriesFlush_impl</* flush_entire_series = */ false>(
243-
{FlushLevel::SkeletonOnly});
246+
{FlushLevel::SkeletonOnly}, /* flush_io_handler = */ true);
247+
Parameter<Operation::CREATE_DATASET> dCreate(rc.m_dataset.value());
248+
dCreate.name = Attributable::get().m_writable.ownKeyWithinParent;
249+
IOHandler()->enqueue(IOTask(this, dCreate));
244250
}
245251
});
246252
if (written())

src/backend/Attributable.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,15 @@ OpenpmdStandard Attributable::openPMDStandard() const
271271
}
272272

273273
template <bool flush_entire_series>
274-
void Attributable::seriesFlush_impl(internal::FlushParams const &flushParams)
274+
void Attributable::seriesFlush_impl(
275+
internal::FlushParams const &flushParams, bool flush_io_handler)
275276
{
276-
writable().seriesFlush<flush_entire_series>(flushParams);
277+
writable().seriesFlush<flush_entire_series>(flushParams, flush_io_handler);
277278
}
278-
template void
279-
Attributable::seriesFlush_impl<true>(internal::FlushParams const &flushParams);
280-
template void
281-
Attributable::seriesFlush_impl<false>(internal::FlushParams const &flushParams);
279+
template void Attributable::seriesFlush_impl<true>(
280+
internal::FlushParams const &flushParams, bool flush_io_handler);
281+
template void Attributable::seriesFlush_impl<false>(
282+
internal::FlushParams const &flushParams, bool flush_io_handler);
282283

283284
void Attributable::flushAttributes(internal::FlushParams const &flushParams)
284285
{

src/backend/BaseRecord.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121
#include "openPMD/backend/BaseRecord.hpp"
22+
#include "openPMD/IO/AbstractIOHandler.hpp"
2223
#include "openPMD/backend/MeshRecordComponent.hpp"
2324
#include "openPMD/backend/PatchRecordComponent.hpp"
2425

src/backend/Writable.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,20 @@ Writable::~Writable()
5252
}
5353

5454
template <bool flush_entire_series>
55-
void Writable::seriesFlush(std::string backendConfig)
55+
void Writable::seriesFlush(std::string backendConfig, bool flush_io_handler)
5656
{
5757
seriesFlush<flush_entire_series>(
58-
internal::FlushParams{FlushLevel::UserFlush, std::move(backendConfig)});
58+
internal::FlushParams{FlushLevel::UserFlush, std::move(backendConfig)},
59+
flush_io_handler);
5960
}
60-
template void Writable::seriesFlush<true>(std::string backendConfig);
61-
template void Writable::seriesFlush<false>(std::string backendConfig);
61+
template void
62+
Writable::seriesFlush<true>(std::string backendConfig, bool flush_io_handler);
63+
template void
64+
Writable::seriesFlush<false>(std::string backendConfig, bool flush_io_handler);
6265

6366
template <bool flush_entire_series>
64-
void Writable::seriesFlush(internal::FlushParams const &flushParams)
67+
void Writable::seriesFlush(
68+
internal::FlushParams const &flushParams, bool flush_io_handler)
6569
{
6670
Attributable impl;
6771
impl.setData({attributable, [](auto const *) {}});
@@ -103,10 +107,10 @@ void Writable::seriesFlush(internal::FlushParams const &flushParams)
103107
return {series.iterations.begin(), series.iterations.end()};
104108
}
105109
}();
106-
series.flush_impl(begin, end, flushParams);
110+
series.flush_impl(begin, end, flushParams, flush_io_handler);
107111
}
108-
template void
109-
Writable::seriesFlush<true>(internal::FlushParams const &flushParams);
110-
template void
111-
Writable::seriesFlush<false>(internal::FlushParams const &flushParams);
112+
template void Writable::seriesFlush<true>(
113+
internal::FlushParams const &flushParams, bool flush_io_handler);
114+
template void Writable::seriesFlush<false>(
115+
internal::FlushParams const &flushParams, bool flush_io_handler);
112116
} // namespace openPMD

0 commit comments

Comments
 (0)