Skip to content

Commit 04982dd

Browse files
committed
Cache m_is_bp5
1 parent 2caf62c commit 04982dd

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

include/openPMD/IO/ADIOS/ADIOS2File.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ class ADIOS2File
229229
* on chosen ADIOS2 engine and can not be explicitly overridden by user.
230230
*/
231231
bool optimizeAttributesStreaming = false;
232+
/*
233+
* Used for a number of BP5-specific optimizations. Written in getEngine().
234+
*/
235+
bool m_is_bp5 = false;
232236

233237
using ParsePreference = Parameter<Operation::OPEN_FILE>::ParsePreference;
234238
ParsePreference parsePreference = ParsePreference::UpFront;

src/IO/ADIOS/ADIOS2File.cpp

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,8 @@ void WriteDataset::call(ADIOS2File &ba, detail::BufferedPut &bp)
109109
std::nullopt,
110110
ba.variables());
111111

112-
// @todo cache this
113-
auto is_bp5 = ba.m_impl->realEngineType() == "bp5" ||
114-
auxiliary::lowerCase(engine.Type()) == "bp5writer";
115112
auto do_defer =
116-
is_bp5 ? adios2::Mode::Sync : adios2::Mode::Deferred;
113+
ba.m_is_bp5 ? adios2::Mode::Sync : adios2::Mode::Deferred;
117114
engine.Put(var, ptr, do_defer);
118115
}
119116
else if constexpr (std::is_same_v<
@@ -185,10 +182,8 @@ struct RunUniquePtrPut
185182
bufferedPut.name,
186183
std::nullopt,
187184
ba.variables());
188-
// @todo cache this
189-
auto is_bp5 = ba.m_impl->realEngineType() == "bp5" ||
190-
auxiliary::lowerCase(engine.Type()) == "bp5writer";
191-
auto do_defer = is_bp5 ? adios2::Mode::Sync : adios2::Mode::Deferred;
185+
auto do_defer =
186+
ba.m_is_bp5 ? adios2::Mode::Sync : adios2::Mode::Deferred;
192187
engine.Put(var, ptr, do_defer);
193188
}
194189

@@ -985,6 +980,14 @@ adios2::Engine &ADIOS2File::getEngine()
985980
{
986981
throw std::runtime_error("[ADIOS2] Failed opening Engine.");
987982
}
983+
984+
m_is_bp5 = m_impl->realEngineType() == "bp5" ||
985+
/* this second check should be sufficient, but we leave the
986+
first check in as a safeguard against renamings in
987+
ADIOS2. Also do a lowerCase transform since the docstring
988+
of `Engine::Type()` claims that the return value is in
989+
lowercase, but for BP5 this does not seem true. */
990+
auxiliary::lowerCase(m_engine->Type()) == "bp5writer";
988991
}
989992
return m_engine.value();
990993
}
@@ -1105,13 +1108,7 @@ void ADIOS2File::flush_impl(ADIOS2FlushParams flushParams, bool writeLatePuts)
11051108
{
11061109
case FlushTarget::Disk:
11071110
case FlushTarget::Disk_Override:
1108-
if (m_impl->realEngineType() == "bp5" ||
1109-
/* this second check should be sufficient, but we leave the
1110-
first check in as a safeguard against renamings in
1111-
ADIOS2. Also do a lowerCase transform since the docstring
1112-
of `Engine::Type()` claims that the return value is in
1113-
lowercase, but for BP5 this does not seem true. */
1114-
auxiliary::lowerCase(engine.Type()) == "bp5writer")
1111+
if (m_is_bp5)
11151112
{
11161113
target = CleanedFlushTarget::Disk;
11171114
}
@@ -1145,10 +1142,8 @@ void ADIOS2File::flush_impl(ADIOS2FlushParams flushParams, bool writeLatePuts)
11451142
m_uniquePtrPuts.clear();
11461143
m_updateSpans.clear();
11471144
break;
1148-
case CleanedFlushTarget::Buffer: { // @todo cache this
1149-
auto is_bp5 = m_impl->realEngineType() == "bp5" ||
1150-
auxiliary::lowerCase(engine.Type()) == "bp5writer";
1151-
if (!is_bp5)
1145+
case CleanedFlushTarget::Buffer: {
1146+
if (!m_is_bp5)
11521147
{
11531148
engine.PerformPuts();
11541149
}
@@ -1261,16 +1256,6 @@ AdvanceStatus ADIOS2File::advance(AdvanceMode mode)
12611256
adios2::StepStatus adiosStatus{};
12621257
auto &engine = getEngine();
12631258

1264-
auto check_bp5 = [&]() -> bool {
1265-
std::string engineType = engine.Type();
1266-
std::transform(
1267-
engineType.begin(),
1268-
engineType.end(),
1269-
engineType.begin(),
1270-
[](unsigned char c) { return std::tolower(c); });
1271-
return engineType == "bp5writer";
1272-
};
1273-
12741259
if (engine.CurrentStep() == 0)
12751260
{
12761261
int max_steps_from_env =
@@ -1288,13 +1273,13 @@ AdvanceStatus ADIOS2File::advance(AdvanceMode mode)
12881273

12891274
// Check some conditions on which to now cancel operation due to
12901275
// unwieldy metadata sizes in BP5 with group encoding
1291-
if (this->m_impl->m_handler->m_encoding ==
1276+
if (m_is_bp5 &&
1277+
this->m_impl->m_handler->m_encoding ==
12921278
IterationEncoding::groupBased &&
12931279
this->m_max_steps_bp5.has_value() &&
12941280
engine.CurrentStep() >= *this->m_max_steps_bp5 &&
12951281
(this->m_mode == adios2::Mode::Write ||
1296-
this->m_mode == adios2::Mode::Append) &&
1297-
check_bp5())
1282+
this->m_mode == adios2::Mode::Append))
12981283
{
12991284
throw error::OperationUnsupportedInBackend(
13001285
"ADIOS2",

0 commit comments

Comments
 (0)