Skip to content

Commit b57a8bc

Browse files
committed
flush mode helpers
1 parent 84df4e0 commit b57a8bc

4 files changed

Lines changed: 68 additions & 42 deletions

File tree

include/openPMD/IO/AbstractIOHandler.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,64 @@ enum class FlushLevel
8181
CreateOrOpenFiles
8282
};
8383

84+
namespace flush_level
85+
{
86+
inline constexpr auto global_flushpoint(FlushLevel fl)
87+
{
88+
switch (fl)
89+
{
90+
case FlushLevel::UserFlush:
91+
return true;
92+
case FlushLevel::InternalFlush:
93+
case FlushLevel::SkeletonOnly:
94+
case FlushLevel::CreateOrOpenFiles:
95+
return false;
96+
}
97+
return false; // unreachable
98+
}
99+
// same as global_flushpoint for now, but we will soon introduce
100+
// immediate_flush
101+
inline constexpr auto write_datasets(FlushLevel fl)
102+
{
103+
switch (fl)
104+
{
105+
case FlushLevel::UserFlush:
106+
return true;
107+
case FlushLevel::InternalFlush:
108+
case FlushLevel::SkeletonOnly:
109+
case FlushLevel::CreateOrOpenFiles:
110+
return false;
111+
}
112+
return false; // unreachable
113+
}
114+
inline constexpr auto write_attributes(FlushLevel fl)
115+
{
116+
switch (fl)
117+
{
118+
case FlushLevel::UserFlush:
119+
case FlushLevel::InternalFlush:
120+
return true;
121+
case FlushLevel::SkeletonOnly:
122+
case FlushLevel::CreateOrOpenFiles:
123+
return false;
124+
}
125+
return false; // unreachable
126+
}
127+
inline constexpr auto flush_hierarchy(FlushLevel fl)
128+
{
129+
switch (fl)
130+
{
131+
case FlushLevel::UserFlush:
132+
case FlushLevel::InternalFlush:
133+
case FlushLevel::SkeletonOnly:
134+
return true;
135+
case FlushLevel::CreateOrOpenFiles:
136+
return false;
137+
}
138+
return false; // unreachable
139+
}
140+
} // namespace flush_level
141+
84142
enum class OpenpmdStandard
85143
{
86144
v_1_0_0,

src/IO/ADIOS/ADIOS2File.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,25 +1035,16 @@ void ADIOS2File::flush_impl(
10351035
drainedUniquePtrPuts.swap(m_uniquePtrPuts);
10361036
}
10371037

1038-
if (readOnly(m_mode))
1038+
if (readOnly(m_mode) || flush_level::write_datasets(level))
10391039
{
1040-
level = FlushLevel::UserFlush;
1041-
}
1042-
1043-
switch (level)
1044-
{
1045-
case FlushLevel::UserFlush:
10461040
performPutGets(*this, eng);
10471041
m_updateSpans.clear();
10481042
m_buffer.clear();
10491043
m_alreadyEnqueued.clear();
10501044
drainedUniquePtrPuts.clear();
1051-
1052-
break;
1053-
1054-
case FlushLevel::InternalFlush:
1055-
case FlushLevel::SkeletonOnly:
1056-
case FlushLevel::CreateOrOpenFiles:
1045+
}
1046+
else
1047+
{
10571048
/*
10581049
* Tasks have been given to ADIOS2, but we don't flush them
10591050
* yet. So, move everything to m_alreadyEnqueued to avoid
@@ -1070,7 +1061,6 @@ void ADIOS2File::flush_impl(
10701061
"wrong time.");
10711062
}
10721063
m_buffer.clear();
1073-
break;
10741064
}
10751065
}
10761066

src/Iteration.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,9 @@ void Iteration::flushFileBased(
278278
s.openIteration(i, *this);
279279
}
280280

281-
switch (flushParams.flushLevel)
281+
if (flush_level::flush_hierarchy(flushParams.flushLevel))
282282
{
283-
case FlushLevel::CreateOrOpenFiles:
284-
break;
285-
case FlushLevel::SkeletonOnly:
286-
case FlushLevel::InternalFlush:
287-
case FlushLevel::UserFlush:
288283
flush(flushParams);
289-
break;
290284
}
291285
}
292286

@@ -301,15 +295,9 @@ void Iteration::flushGroupBased(
301295
IOHandler()->enqueue(IOTask(this, pCreate));
302296
}
303297

304-
switch (flushParams.flushLevel)
298+
if (flush_level::flush_hierarchy(flushParams.flushLevel))
305299
{
306-
case FlushLevel::CreateOrOpenFiles:
307-
break;
308-
case FlushLevel::SkeletonOnly:
309-
case FlushLevel::InternalFlush:
310-
case FlushLevel::UserFlush:
311300
flush(flushParams);
312-
break;
313301
}
314302
}
315303

@@ -324,17 +312,13 @@ void Iteration::flushVariableBased(
324312
IOHandler()->enqueue(IOTask(this, pOpen));
325313
}
326314

327-
switch (flushParams.flushLevel)
315+
if (!flush_level::flush_hierarchy(flushParams.flushLevel))
328316
{
329-
case FlushLevel::CreateOrOpenFiles:
330317
return;
331-
case FlushLevel::SkeletonOnly:
332-
case FlushLevel::InternalFlush:
333-
case FlushLevel::UserFlush:
334-
flush(flushParams);
335-
break;
336318
}
337319

320+
flush(flushParams);
321+
338322
if (!written())
339323
{
340324
/* create iteration path */

src/backend/Attributable.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,9 @@ template void Attributable::seriesFlush_impl<false>(
283283

284284
void Attributable::flushAttributes(internal::FlushParams const &flushParams)
285285
{
286-
switch (flushParams.flushLevel)
286+
if (!flush_level::write_attributes(flushParams.flushLevel))
287287
{
288-
case FlushLevel::SkeletonOnly:
289-
case FlushLevel::CreateOrOpenFiles:
290288
return;
291-
case FlushLevel::InternalFlush:
292-
case FlushLevel::UserFlush:
293-
// pass
294-
break;
295289
}
296290
if (dirty())
297291
{

0 commit comments

Comments
 (0)