Skip to content

Commit b62f2e7

Browse files
Fix Iteration::open(), needed for correct use of Span API (#1794)
* Shortcut zero-size storeChunk calls without breaking collectivity * Fix the documentation * Fix: Iteration::open() should access files * Revert "Fix the documentation" This reverts commit dfc8cea.
1 parent 0ecd76c commit b62f2e7

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed

include/openPMD/RecordComponent.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ namespace internal
8181
* Ignored otherwise.
8282
*/
8383
Attribute m_constantValue{-1};
84-
/**
85-
* The same std::string that the parent class would pass as parameter to
86-
* RecordComponent::flush().
87-
* This is stored only upon RecordComponent::flush() if
88-
* AbstractIOHandler::flushLevel is set to FlushLevel::SkeletonOnly
89-
* (for use by the Span<T>-based overload of
90-
* RecordComponent::storeChunk()).
91-
* @todo Merge functionality with ownKeyInParent?
92-
*/
93-
std::string m_name;
9484
/**
9585
* True if this component is an empty dataset, i.e. its extent is zero
9686
* in at least one dimension.
@@ -109,7 +99,6 @@ namespace internal
10999
BaseRecordComponentData::reset();
110100
m_chunks = std::queue<IOTask>();
111101
m_constantValue = -1;
112-
m_name = std::string();
113102
m_isEmpty = false;
114103
m_hasBeenExtended = false;
115104
}

include/openPMD/RecordComponent.tpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "openPMD/auxiliary/ShareRawInternal.hpp"
3030
#include "openPMD/auxiliary/TypeTraits.hpp"
3131
#include "openPMD/auxiliary/UniquePtr.hpp"
32+
#include "openPMD/backend/Attributable.hpp"
3233

3334
#include <memory>
3435
#include <type_traits>
@@ -111,18 +112,10 @@ RecordComponent::storeChunk(Offset o, Extent e, F &&createBuffer)
111112
"using storeChunk() (see RecordComponent::resetDataset()).");
112113
}
113114
Parameter<Operation::CREATE_DATASET> dCreate(rc.m_dataset.value());
114-
dCreate.name = rc.m_name;
115+
dCreate.name = Attributable::get().m_writable.ownKeyWithinParent;
115116
IOHandler()->enqueue(IOTask(this, dCreate));
116117
}
117118

118-
if (size == 0)
119-
{
120-
// Don't forward this operation to the backend as it might create ugly
121-
// zero-blocks in ADIOS2
122-
setDirtyRecursive(true);
123-
return DynamicMemoryView<T>();
124-
}
125-
126119
Parameter<Operation::GET_BUFFER_VIEW> getBufferView;
127120
getBufferView.offset = o;
128121
getBufferView.extent = e;
@@ -136,7 +129,10 @@ RecordComponent::storeChunk(Offset o, Extent e, F &&createBuffer)
136129
// type shared_ptr<T> or shared_ptr<T[]>
137130
auto data = std::forward<F>(createBuffer)(size);
138131
out.ptr = static_cast<void *>(data.get());
139-
storeChunk(std::move(data), std::move(o), std::move(e));
132+
if (size > 0)
133+
{
134+
storeChunk(std::move(data), std::move(o), std::move(e));
135+
}
140136
}
141137
setDirtyRecursive(true);
142138
return DynamicMemoryView<T>{std::move(getBufferView), size, *this};

include/openPMD/backend/Writable.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class Writable final
8989
friend class ParticleSpecies;
9090
friend class Series;
9191
friend class Record;
92+
friend class RecordComponent;
9293
friend class AbstractIOHandlerImpl;
9394
friend class ADIOS2IOHandlerImpl;
9495
friend class detail::ADIOS2File;

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,17 @@ void ADIOS2IOHandlerImpl::getBufferView(
12991299
auto file = refreshFileFromParent(writable, /* preferParentFile = */ false);
13001300
detail::ADIOS2File &ba = getFileData(file, IfFileNotOpen::ThrowError);
13011301

1302+
if (std::any_of(
1303+
parameters.extent.begin(), parameters.extent.end(), [](auto val) {
1304+
return val == 0;
1305+
}))
1306+
{
1307+
// Refuse empty operations, ADIOS2 creates ugly zero blocks for them,
1308+
// tell the frontend to do sth about it instead
1309+
parameters.out->backendManagedBuffer = false;
1310+
return;
1311+
}
1312+
13021313
std::string name = nameOfVariable(writable);
13031314
switch (m_useSpanBasedPutByDefault)
13041315
{

src/Iteration.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,21 @@ Iteration &Iteration::open()
161161
it.m_closed = CloseStatus::Open;
162162
runDeferredParseAccess();
163163
}
164-
if (getStepStatus() == StepStatus::OutOfStep)
164+
switch (getStepStatus())
165165
{
166+
case StepStatus::OutOfStep:
166167
beginStep(/* reread = */ false);
167168
setStepStatus(StepStatus::DuringStep);
169+
break;
170+
case StepStatus::DuringStep:
171+
case StepStatus::NoStep: {
172+
auto end = begin;
173+
++end;
174+
s.flush_impl(begin, end, {FlushLevel::CreateOrOpenFiles});
168175
}
169-
IOHandler()->flush(internal::defaultFlushParams);
176+
break;
177+
}
178+
// IOHandler()->flush(internal::defaultFlushParams);
170179
return *this;
171180
}
172181

src/RecordComponent.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ void RecordComponent::flush(
262262
auto &rc = get();
263263
if (flushParams.flushLevel == FlushLevel::SkeletonOnly)
264264
{
265-
rc.m_name = name;
266265
return;
267266
}
268267
if (access::readOnly(IOHandler()->m_frontendAccess))

0 commit comments

Comments
 (0)