Skip to content

Commit 87dca7b

Browse files
committed
We need to go deeper
1 parent ca9fceb commit 87dca7b

4 files changed

Lines changed: 131 additions & 119 deletions

File tree

include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include <complex>
3636
#include <stdexcept>
37+
#include <typeinfo>
3738
#include <utility>
3839
#include <vector>
3940
#endif
@@ -228,6 +229,69 @@ namespace detail
228229
}
229230
} // namespace detail
230231

232+
bool shouldLogADIOS2ApiCalls();
233+
234+
template <typename T>
235+
auto formatType() -> char const *
236+
{
237+
return typeid(T).name();
238+
}
239+
240+
template <typename T>
241+
inline std::string formatValue(T const &value)
242+
{
243+
if constexpr (std::is_same_v<T, bool>)
244+
{
245+
return value ? "true" : "false";
246+
}
247+
else if constexpr (
248+
std::is_same_v<T, char const *> || std::is_same_v<T, char *> ||
249+
std::is_same_v<T, std::string>)
250+
{
251+
std::stringstream res;
252+
res << "\"" << value << "\"";
253+
return res.str();
254+
}
255+
else if constexpr (std::is_arithmetic_v<T>)
256+
{
257+
std::stringstream res;
258+
res << "(" << formatType<T>() << ")" << value;
259+
return res.str();
260+
}
261+
else
262+
{
263+
return "/*value*/";
264+
}
265+
}
266+
267+
template <typename T>
268+
inline std::string formatValue(T const *it, size_t size)
269+
{
270+
std::stringstream out;
271+
out << "std::vector<" << formatType<T>() << ">{";
272+
if (size == 0)
273+
{
274+
out << "}";
275+
return out.str();
276+
}
277+
out << *it;
278+
for (size_t i = 1; i < size; ++i)
279+
{
280+
out << ", " << it[i];
281+
}
282+
out << "}";
283+
return out.str();
284+
}
285+
286+
template <typename... Args>
287+
void ADIOS2_LOG_API_CALL(Args &&...args)
288+
{
289+
if (::openPMD::shouldLogADIOS2ApiCalls())
290+
{
291+
((std::cerr << "[ADIOS2 API] ") << ... << args) << std::endl;
292+
}
293+
}
294+
231295
/**
232296
* Generalizes switching over an openPMD datatype.
233297
*

src/IO/ADIOS/ADIOS2Auxiliary.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "openPMD/DatatypeHelpers.hpp"
2626
#include "openPMD/Datatype_internal.hpp"
2727
#include "openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp"
28+
#include "openPMD/auxiliary/Environment.hpp"
2829

2930
#include <iostream>
3031

@@ -281,4 +282,16 @@ Datatype attributeInfo(
281282
}
282283
}
283284
} // namespace openPMD::detail
285+
namespace openPMD
286+
{
287+
bool shouldLogADIOS2ApiCalls()
288+
{
289+
static int cached_result = -1;
290+
if (cached_result == -1)
291+
{
292+
cached_result = auxiliary::getEnvNum("OPENPMD_ADIOS2_LOG_API_CALLS", 0);
293+
}
294+
return cached_result != 0;
295+
}
296+
} // namespace openPMD
284297
#endif

src/IO/ADIOS/ADIOS2File.cpp

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,6 @@
5454

5555
#if openPMD_HAVE_ADIOS2
5656

57-
/*
58-
* Logging helper for ADIOS2 API calls to enable quick construction of
59-
* reproducers for bug reports. Output is formatted as C++ code.
60-
* Controlled by environment variable OPENPMD_ADIOS2_LOG_API_CALLS
61-
*/
62-
namespace
63-
{
64-
inline bool shouldLogADIOS2ApiCalls()
65-
{
66-
static int cached_result = -1;
67-
if (cached_result == -1)
68-
{
69-
cached_result =
70-
openPMD::auxiliary::getEnvNum("OPENPMD_ADIOS2_LOG_API_CALLS", 0);
71-
}
72-
return cached_result != 0;
73-
}
74-
} // namespace
75-
76-
#define ADIOS2_LOG_API_CALL(...) \
77-
do \
78-
{ \
79-
if (::shouldLogADIOS2ApiCalls()) \
80-
{ \
81-
std::cerr << "[ADIOS2 API] " << __VA_ARGS__ << std::endl; \
82-
} \
83-
} while (false)
84-
8557
namespace openPMD::detail
8658
{
8759
template <typename T>
@@ -141,6 +113,12 @@ void WriteDataset::call(ADIOS2File &ba, detail::BufferedPut &bp)
141113
ba.variables());
142114

143115
engine.Put(var, ptr);
116+
ADIOS2_LOG_API_CALL(
117+
"// offs./ext.: ",
118+
auxiliary::vec_as_string(bp.param.offset),
119+
" / ",
120+
auxiliary::vec_as_string(bp.param.extent));
121+
ADIOS2_LOG_API_CALL("// var = ", bp.name);
144122
ADIOS2_LOG_API_CALL("engine.Put(var, ptr);");
145123
}
146124
else if constexpr (std::is_same_v<
@@ -213,6 +191,12 @@ struct RunUniquePtrPut
213191
std::nullopt,
214192
ba.variables());
215193
engine.Put(var, ptr);
194+
ADIOS2_LOG_API_CALL(
195+
"// offs./ext.: ",
196+
auxiliary::vec_as_string(bufferedPut.offset),
197+
" / ",
198+
auxiliary::vec_as_string(bufferedPut.extent));
199+
ADIOS2_LOG_API_CALL("\n// var = ", bufferedPut.name);
216200
ADIOS2_LOG_API_CALL("engine.Put(var, ptr);");
217201
}
218202

@@ -536,12 +520,20 @@ void ADIOS2File::configure_IO()
536520
? ADIOS2IOHandlerImpl::ModifiableAttributes::Yes
537521
: ADIOS2IOHandlerImpl::ModifiableAttributes::No;
538522
}
523+
bool_representation val = m_impl->m_modifiableAttributes ==
524+
ADIOS2IOHandlerImpl::ModifiableAttributes::No
525+
? 0
526+
: 1;
539527
m_IO.DefineAttribute<bool_representation>(
540-
adios_defaults::str_useModifiableAttributes,
541-
m_impl->m_modifiableAttributes ==
542-
ADIOS2IOHandlerImpl::ModifiableAttributes::No
543-
? 0
544-
: 1);
528+
adios_defaults::str_useModifiableAttributes, val);
529+
ADIOS2_LOG_API_CALL(
530+
"IO.DefineAttribute<",
531+
formatType<bool_representation>,
532+
">(",
533+
formatValue(adios_defaults::str_useModifiableAttributes),
534+
", ",
535+
std::to_string(unsigned(val)),
536+
");");
545537
}
546538

547539
// set engine type
@@ -865,14 +857,13 @@ adios2::Engine &ADIOS2File::getEngine()
865857
* Otherwise we don't see the group table attributes.
866858
* This branch is also taken by Streaming engines.
867859
*/
860+
ADIOS2_LOG_API_CALL("engine.BeginStep();");
868861
if (m_engine->BeginStep() != adios2::StepStatus::OK)
869862
{
870-
ADIOS2_LOG_API_CALL("engine.BeginStep();");
871863
throw std::runtime_error(
872864
"[ADIOS2] Unexpected step status when "
873865
"opening file/stream.");
874866
}
875-
ADIOS2_LOG_API_CALL("engine.BeginStep();");
876867
openedANewStep = true;
877868
}
878869

@@ -962,18 +953,17 @@ adios2::Engine &ADIOS2File::getEngine()
962953
"very buggy, so please use "
963954
"READ_ONLY/READ_RANDOM_ACCESS instead.");
964955
}
956+
ADIOS2_LOG_API_CALL("engine.BeginStep();");
965957
if (!openedANewStep &&
966958
m_engine.value().BeginStep() !=
967959
adios2::StepStatus::OK)
968960
{
969-
ADIOS2_LOG_API_CALL("engine.BeginStep();");
970961
throw std::runtime_error(
971962
"[ADIOS2] Unexpected step status when "
972963
"opening file/stream.");
973964
}
974965
if (!openedANewStep)
975966
{
976-
ADIOS2_LOG_API_CALL("engine.BeginStep();");
977967
}
978968
streamStatus = StreamStatus::DuringStep;
979969
}
@@ -1066,6 +1056,12 @@ void ADIOS2File::flush_impl(
10661056
if (m_impl->m_writeAttributesFromThisRank)
10671057
{
10681058
m_IO.DefineAttribute<uint64_t>(adios_defaults::str_adios2Schema, 0);
1059+
ADIOS2_LOG_API_CALL(
1060+
"IO.DefineAttribute(",
1061+
formatValue(adios_defaults::str_adios2Schema),
1062+
", ",
1063+
formatValue(static_cast<uint64_t>(0)),
1064+
");");
10691065
}
10701066
initializedDefaults = true;
10711067
}
@@ -1265,6 +1261,7 @@ AdvanceStatus ADIOS2File::advance(AdvanceMode mode)
12651261
*/
12661262
if (streamStatus == StreamStatus::OutsideOfStep)
12671263
{
1264+
ADIOS2_LOG_API_CALL("engine.BeginStep();");
12681265
if (getEngine().BeginStep() != adios2::StepStatus::OK)
12691266
{
12701267
throw std::runtime_error(
@@ -1279,11 +1276,20 @@ AdvanceStatus ADIOS2File::advance(AdvanceMode mode)
12791276
{
12801277
m_IO.DefineAttribute<bool_representation>(
12811278
adios_defaults::str_usesstepsAttribute, 1);
1279+
ADIOS2_LOG_API_CALL(
1280+
"IO.DefineAttribute(",
1281+
formatValue(adios_defaults::str_usesstepsAttribute),
1282+
", ",
1283+
formatValue(static_cast<bool_representation>(1)),
1284+
");");
12821285
}
12831286

12841287
flush(
12851288
ADIOS2FlushParams{FlushLevel::UserFlush},
1286-
[](ADIOS2File &, adios2::Engine &eng) { eng.EndStep(); },
1289+
[](ADIOS2File &, adios2::Engine &eng) {
1290+
eng.EndStep();
1291+
ADIOS2_LOG_API_CALL("engine.EndStep();");
1292+
},
12871293
/* writeLatePuts = */ true,
12881294
/* flushUnconditionally = */ true);
12891295
uncommittedAttributes.clear();
@@ -1359,6 +1365,7 @@ Be aware of the performance implications described above.)");
13591365

13601366
if (streamStatus != StreamStatus::DuringStep)
13611367
{
1368+
ADIOS2_LOG_API_CALL("engine.BeginStep();");
13621369
adiosStatus = engine.BeginStep();
13631370
}
13641371
else
@@ -1459,6 +1466,15 @@ void ADIOS2File::markActive(Writable *writable)
14591466
/* variableName = */ "",
14601467
/* separator = */ "/",
14611468
/* allowModification = */ true);
1469+
ADIOS2_LOG_API_CALL(
1470+
"IO.DefineAttribute(",
1471+
formatValue(fullPath),
1472+
", ",
1473+
formatValue(currentStepBuffered),
1474+
", ",
1475+
R"("", "/", )",
1476+
formatValue(true),
1477+
");");
14621478
m_pathsMarkedAsActive.emplace(writable);
14631479
writable = writable->parent;
14641480
} while (writable &&

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
#include <stdexcept>
5656
#include <string>
5757
#include <type_traits>
58-
#include <typeinfo>
5958
#include <variant>
6059

6160
namespace openPMD
@@ -82,86 +81,6 @@ namespace openPMD
8281

8382
#if openPMD_HAVE_ADIOS2
8483

85-
/*
86-
* Logging helper for ADIOS2 API calls to enable quick construction of
87-
* reproducers for bug reports. Output is formatted as C++ code.
88-
* Controlled by environment variable OPENPMD_ADIOS2_LOG_API_CALLS
89-
*/
90-
namespace
91-
{
92-
inline bool shouldLogADIOS2ApiCalls()
93-
{
94-
static int cached_result = -1;
95-
if (cached_result == -1)
96-
{
97-
cached_result =
98-
auxiliary::getEnvNum("OPENPMD_ADIOS2_LOG_API_CALLS", 0);
99-
}
100-
return cached_result != 0;
101-
}
102-
103-
template <typename T>
104-
auto formatType() -> char const *
105-
{
106-
return typeid(T).name();
107-
}
108-
109-
template <typename T>
110-
inline std::string formatValue(T const &value)
111-
{
112-
if constexpr (std::is_same_v<T, bool>)
113-
{
114-
return value ? "true" : "false";
115-
}
116-
else if constexpr (
117-
std::is_same_v<T, char const *> || std::is_same_v<T, char *> ||
118-
std::is_same_v<T, std::string>)
119-
{
120-
std::stringstream res;
121-
res << "\"" << value << "\"";
122-
return res.str();
123-
}
124-
else if constexpr (std::is_arithmetic_v<T>)
125-
{
126-
std::stringstream res;
127-
res << "(" << formatType<T>() << ")" << value;
128-
return res.str();
129-
}
130-
else
131-
{
132-
return "/*value*/";
133-
}
134-
}
135-
136-
template <typename T>
137-
inline std::string formatValue(T const *it, size_t size)
138-
{
139-
std::stringstream out;
140-
out << "std::vector<" << formatType<T>() << ">{";
141-
if (size == 0)
142-
{
143-
out << "}";
144-
return out.str();
145-
}
146-
out << *it;
147-
for (size_t i = 1; i < size; ++i)
148-
{
149-
out << ", " << it[i];
150-
}
151-
out << "}";
152-
return out.str();
153-
}
154-
} // namespace
155-
156-
template <typename... Args>
157-
void ADIOS2_LOG_API_CALL(Args &&...args)
158-
{
159-
if (::openPMD::shouldLogADIOS2ApiCalls())
160-
{
161-
((std::cerr << "[ADIOS2 API] ") << ... << args) << std::endl;
162-
}
163-
}
164-
16584
std::optional<size_t> joinedDimension(adios2::Dims const &dims)
16685
{
16786
for (size_t i = 0; i < dims.size(); ++i)

0 commit comments

Comments
 (0)