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-
8557namespace openPMD ::detail
8658{
8759template <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 &&
0 commit comments