Skip to content

Commit 9ce0f2c

Browse files
committed
Open new instance of ADIOS per File
1 parent 0f456d3 commit 9ce0f2c

5 files changed

Lines changed: 110 additions & 102 deletions

File tree

include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ namespace adios_defs
8181
Open,
8282
ReopenFileThatWeCreated
8383
};
84+
85+
struct ParameterizedOperator
86+
{
87+
adios2::Operator op;
88+
adios2::Params params;
89+
};
8490
} // namespace adios_defs
8591

8692
/*

include/openPMD/IO/ADIOS/ADIOS2File.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class ADIOS2File
177177
* IO.
178178
*/
179179
std::string m_IOName;
180-
adios2::ADIOS &m_ADIOS;
180+
adios2::ADIOS m_ADIOS;
181181
adios2::IO m_IO;
182182
/**
183183
* The default queue for deferred actions.
@@ -421,6 +421,14 @@ class ADIOS2File
421421
return m_attributes;
422422
}
423423

424+
// read operators can (currently) not be specified per dataset, so parse
425+
// them once and then buffer them
426+
std::vector<adios_defs::ParameterizedOperator> readOperators;
427+
std::map<std::string, adios2::Operator> m_operators;
428+
429+
std::optional<adios2::Operator>
430+
getCompressionOperator(std::string const &compression);
431+
424432
private:
425433
ADIOS2IOHandlerImpl *m_impl;
426434
std::optional<adios2::Engine> m_engine; //! ADIOS engine

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ class ADIOS2IOHandlerImpl
221221
FlushTarget m_flushTarget = FlushTarget::Disk;
222222

223223
private:
224-
adios2::ADIOS m_ADIOS;
225224
#if openPMD_HAVE_MPI
226225
std::optional<MPI_Comm> m_communicator;
227226
#endif
@@ -296,16 +295,6 @@ class ADIOS2IOHandlerImpl
296295

297296
bool m_writeAttributesFromThisRank = true;
298297

299-
struct ParameterizedOperator
300-
{
301-
adios2::Operator op;
302-
adios2::Params params;
303-
};
304-
305-
// read operators can (currently) not be specified per dataset, so parse
306-
// them once and then buffer them
307-
std::vector<ParameterizedOperator> readOperators;
308-
309298
json::TracingJSON m_config;
310299
std::optional<nlohmann::json> m_buffered_dataset_config;
311300
static json::TracingJSON nullvalue;
@@ -340,11 +329,12 @@ class ADIOS2IOHandlerImpl
340329
* @return first parameter: the operators, second parameters: whether
341330
* operators have been configured
342331
*/
343-
std::optional<std::vector<ParameterizedOperator>>
344-
getOperators(json::TracingJSON config);
332+
std::optional<std::vector<adios_defs::ParameterizedOperator>>
333+
getOperators(detail::ADIOS2File &, json::TracingJSON config);
345334

346335
// use m_config
347-
std::optional<std::vector<ParameterizedOperator>> getOperators();
336+
std::optional<std::vector<adios_defs::ParameterizedOperator>>
337+
getOperators(detail::ADIOS2File &);
348338

349339
enum class Shape
350340
{
@@ -356,9 +346,10 @@ class ADIOS2IOHandlerImpl
356346
auto parseDatasetConfig(
357347
Parameter const &,
358348
Writable *,
349+
detail::ADIOS2File &filedata,
359350
std::string const &varName,
360-
std::vector<ParameterizedOperator> default_operators = {})
361-
-> std::tuple<std::vector<ParameterizedOperator>, Shape>;
351+
std::vector<adios_defs::ParameterizedOperator> default_operators = {})
352+
-> std::tuple<std::vector<adios_defs::ParameterizedOperator>, Shape>;
362353

363354
std::string fileSuffix(bool verbose = true) const;
364355

@@ -385,8 +376,6 @@ class ADIOS2IOHandlerImpl
385376
std::unordered_map<InvalidatableFile, std::unique_ptr<detail::ADIOS2File>>
386377
m_fileData;
387378

388-
std::map<std::string, adios2::Operator> m_operators;
389-
390379
// Overrides from AbstractIOHandlerImplCommon.
391380

392381
std::string
@@ -398,9 +387,6 @@ class ADIOS2IOHandlerImpl
398387

399388
// Helper methods.
400389

401-
std::optional<adios2::Operator>
402-
getCompressionOperator(std::string const &compression);
403-
404390
/*
405391
* The name of the ADIOS2 variable associated with this Writable.
406392
* To be used for Writables that represent a dataset.
@@ -630,8 +616,7 @@ namespace detail
630616
std::string const &varName,
631617
Parameter<Operation::OPEN_DATASET> &parameters,
632618
std::optional<size_t> stepSelection,
633-
std::vector<ADIOS2IOHandlerImpl::ParameterizedOperator> const
634-
&operators);
619+
std::vector<adios_defs::ParameterizedOperator> const &operators);
635620

636621
static constexpr char const *errorMsg = "ADIOS2: openDataset()";
637622
};
@@ -657,8 +642,7 @@ namespace detail
657642
static void call(
658643
adios2::IO &IO,
659644
std::string const &name,
660-
std::vector<ADIOS2IOHandlerImpl::ParameterizedOperator> const
661-
&compressions,
645+
std::vector<adios_defs::ParameterizedOperator> const &compressions,
662646
adios2::Dims const &shape = adios2::Dims(),
663647
adios2::Dims const &start = adios2::Dims(),
664648
adios2::Dims const &count = adios2::Dims(),

src/IO/ADIOS/ADIOS2File.cpp

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,43 @@ ADIOS2File::ADIOS2File(
217217
InvalidatableFile file,
218218
adios_defs::OpenFileAs openFileAs)
219219
: m_file(impl.fullPath(std::move(file)))
220-
, m_ADIOS(impl.m_ADIOS)
220+
#if openPMD_HAVE_MPI
221+
, m_ADIOS([&]() {
222+
if (impl.m_communicator.has_value())
223+
{
224+
return adios2::ADIOS(*impl.m_communicator);
225+
}
226+
else
227+
{
228+
return adios2::ADIOS();
229+
}
230+
}())
231+
#else
232+
, m_ADIOS2()
233+
#endif
221234
, m_impl(&impl)
222235
{
223236
// Declaring these members in the constructor body to avoid
224237
// initialization order hazards. Need the IO_ prefix since in some
225238
// situation there seems to be trouble with number-only IO names
226239
m_mode = impl.adios2AccessMode(m_file, openFileAs);
227240
create_IO();
241+
228242
if (!m_IO)
229243
{
230244
throw std::runtime_error(
231245
"[ADIOS2] Internal error: Failed declaring ADIOS2 IO object "
232246
"for file " +
233247
m_file);
234248
}
235-
else
249+
250+
auto operators = impl.getOperators(*this);
251+
if (operators)
236252
{
237-
configure_IO();
253+
readOperators = std::move(operators.value());
238254
}
255+
256+
configure_IO();
239257
}
240258

241259
auto ADIOS2File::useGroupTable() const -> UseGroupTable
@@ -246,7 +264,7 @@ auto ADIOS2File::useGroupTable() const -> UseGroupTable
246264
void ADIOS2File::create_IO()
247265
{
248266
m_IOName = std::to_string(m_impl->nameCounter++);
249-
m_IO = m_impl->m_ADIOS.DeclareIO("IO_" + m_IOName);
267+
m_IO = m_ADIOS.DeclareIO("IO_" + m_IOName);
250268
}
251269

252270
ADIOS2File::~ADIOS2File()
@@ -426,6 +444,42 @@ std::optional<size_t> ADIOS2File::stepSelection() const
426444
}
427445
}
428446

447+
std::optional<adios2::Operator>
448+
ADIOS2File::getCompressionOperator(std::string const &compression)
449+
{
450+
adios2::Operator res;
451+
auto it = m_operators.find(compression);
452+
if (it == m_operators.end())
453+
{
454+
try
455+
{
456+
res = m_ADIOS.DefineOperator(compression, compression);
457+
}
458+
catch (std::invalid_argument const &e)
459+
{
460+
std::cerr << "Warning: ADIOS2 backend does not support compression "
461+
"method "
462+
<< compression << ". Continuing without compression."
463+
<< "\nOriginal error: " << e.what() << std::endl;
464+
return std::optional<adios2::Operator>();
465+
}
466+
catch (std::string const &s)
467+
{
468+
std::cerr << "Warning: ADIOS2 backend does not support compression "
469+
"method "
470+
<< compression << ". Continuing without compression."
471+
<< "\nOriginal error: " << s << std::endl;
472+
return std::optional<adios2::Operator>();
473+
}
474+
m_operators.emplace(compression, res);
475+
}
476+
else
477+
{
478+
res = it->second;
479+
}
480+
return std::make_optional(adios2::Operator(res));
481+
}
482+
429483
void ADIOS2File::configure_IO_Read()
430484
{
431485
bool upfrontParsing = supportsUpfrontParsing(

0 commit comments

Comments
 (0)