Skip to content

Commit e56641e

Browse files
committed
Open new instance of ADIOS per File
1 parent df87fa7 commit e56641e

File tree

5 files changed

+112
-107
lines changed

5 files changed

+112
-107
lines changed

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
@@ -179,7 +179,7 @@ class ADIOS2File
179179
* IO.
180180
*/
181181
std::string m_IOName;
182-
adios2::ADIOS &m_ADIOS;
182+
adios2::ADIOS m_ADIOS;
183183
adios2::IO m_IO;
184184
/**
185185
* The default queue for deferred actions.
@@ -426,6 +426,14 @@ class ADIOS2File
426426
return m_variables;
427427
}
428428

429+
// read operators can (currently) not be specified per dataset, so parse
430+
// them once and then buffer them
431+
std::vector<adios_defs::ParameterizedOperator> readOperators;
432+
std::map<std::string, adios2::Operator> m_operators;
433+
434+
std::optional<adios2::Operator>
435+
getCompressionOperator(std::string const &compression);
436+
429437
private:
430438
ADIOS2IOHandlerImpl *m_impl;
431439
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
@@ -223,7 +223,6 @@ class ADIOS2IOHandlerImpl
223223
FlushTarget m_flushTarget = FlushTarget::Disk;
224224

225225
private:
226-
adios2::ADIOS m_ADIOS;
227226
#if openPMD_HAVE_MPI
228227
std::optional<MPI_Comm> m_communicator;
229228
#endif
@@ -298,16 +297,6 @@ class ADIOS2IOHandlerImpl
298297

299298
bool m_writeAttributesFromThisRank = true;
300299

301-
struct ParameterizedOperator
302-
{
303-
adios2::Operator op;
304-
adios2::Params params;
305-
};
306-
307-
// read operators can (currently) not be specified per dataset, so parse
308-
// them once and then buffer them
309-
std::vector<ParameterizedOperator> readOperators;
310-
311300
json::TracingJSON m_config;
312301
std::optional<nlohmann::json> m_buffered_dataset_config;
313302
static json::TracingJSON nullvalue;
@@ -342,11 +331,12 @@ class ADIOS2IOHandlerImpl
342331
* @return first parameter: the operators, second parameters: whether
343332
* operators have been configured
344333
*/
345-
std::optional<std::vector<ParameterizedOperator>>
346-
getOperators(json::TracingJSON config);
334+
std::optional<std::vector<adios_defs::ParameterizedOperator>>
335+
getOperators(detail::ADIOS2File &, json::TracingJSON config);
347336

348337
// use m_config
349-
std::optional<std::vector<ParameterizedOperator>> getOperators();
338+
std::optional<std::vector<adios_defs::ParameterizedOperator>>
339+
getOperators(detail::ADIOS2File &);
350340

351341
enum class Shape
352342
{
@@ -358,9 +348,10 @@ class ADIOS2IOHandlerImpl
358348
auto parseDatasetConfig(
359349
Parameter const &,
360350
Writable *,
351+
detail::ADIOS2File &filedata,
361352
std::string const &varName,
362-
std::vector<ParameterizedOperator> default_operators = {})
363-
-> std::tuple<std::vector<ParameterizedOperator>, Shape>;
353+
std::vector<adios_defs::ParameterizedOperator> default_operators = {})
354+
-> std::tuple<std::vector<adios_defs::ParameterizedOperator>, Shape>;
364355

365356
std::string fileSuffix(bool verbose = true) const;
366357

@@ -387,8 +378,6 @@ class ADIOS2IOHandlerImpl
387378
std::unordered_map<InvalidatableFile, std::unique_ptr<detail::ADIOS2File>>
388379
m_fileData;
389380

390-
std::map<std::string, adios2::Operator> m_operators;
391-
392381
// Overrides from AbstractIOHandlerImplCommon.
393382

394383
std::string
@@ -400,9 +389,6 @@ class ADIOS2IOHandlerImpl
400389

401390
// Helper methods.
402391

403-
std::optional<adios2::Operator>
404-
getCompressionOperator(std::string const &compression);
405-
406392
/*
407393
* The name of the ADIOS2 variable associated with this Writable.
408394
* To be used for Writables that represent a dataset.
@@ -704,8 +690,7 @@ namespace detail
704690
std::string const &varName,
705691
Parameter<Operation::OPEN_DATASET> &parameters,
706692
std::optional<size_t> stepSelection,
707-
std::vector<ADIOS2IOHandlerImpl::ParameterizedOperator> const
708-
&operators,
693+
std::vector<adios_defs::ParameterizedOperator> const &operators,
709694
detail::AdiosVariables const &);
710695

711696
static constexpr char const *errorMsg = "ADIOS2: openDataset()";
@@ -732,8 +717,7 @@ namespace detail
732717
static void call(
733718
adios2::IO &IO,
734719
std::string const &name,
735-
std::vector<ADIOS2IOHandlerImpl::ParameterizedOperator> const
736-
&compressions,
720+
std::vector<adios_defs::ParameterizedOperator> const &compressions,
737721
adios2::Dims const &shape = adios2::Dims(),
738722
adios2::Dims const &start = adios2::Dims(),
739723
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
@@ -232,25 +232,43 @@ ADIOS2File::ADIOS2File(
232232
InvalidatableFile file,
233233
adios_defs::OpenFileAs openFileAs)
234234
: m_file(impl.fullPath(std::move(file)))
235-
, m_ADIOS(impl.m_ADIOS)
235+
#if openPMD_HAVE_MPI
236+
, m_ADIOS([&]() {
237+
if (impl.m_communicator.has_value())
238+
{
239+
return adios2::ADIOS(*impl.m_communicator);
240+
}
241+
else
242+
{
243+
return adios2::ADIOS();
244+
}
245+
}())
246+
#else
247+
, m_ADIOS2()
248+
#endif
236249
, m_impl(&impl)
237250
{
238251
// Declaring these members in the constructor body to avoid
239252
// initialization order hazards. Need the IO_ prefix since in some
240253
// situation there seems to be trouble with number-only IO names
241254
m_mode = impl.adios2AccessMode(m_file, openFileAs);
242255
create_IO();
256+
243257
if (!m_IO)
244258
{
245259
throw std::runtime_error(
246260
"[ADIOS2] Internal error: Failed declaring ADIOS2 IO object "
247261
"for file " +
248262
m_file);
249263
}
250-
else
264+
265+
auto operators = impl.getOperators(*this);
266+
if (operators)
251267
{
252-
configure_IO();
268+
readOperators = std::move(operators.value());
253269
}
270+
271+
configure_IO();
254272
}
255273

256274
auto ADIOS2File::useGroupTable() const -> UseGroupTable
@@ -261,7 +279,7 @@ auto ADIOS2File::useGroupTable() const -> UseGroupTable
261279
void ADIOS2File::create_IO()
262280
{
263281
m_IOName = std::to_string(m_impl->nameCounter++);
264-
m_IO = m_impl->m_ADIOS.DeclareIO("IO_" + m_IOName);
282+
m_IO = m_ADIOS.DeclareIO("IO_" + m_IOName);
265283
}
266284

267285
ADIOS2File::~ADIOS2File()
@@ -425,6 +443,42 @@ std::optional<size_t> const &ADIOS2File::stepSelection() const
425443
return m_stepSelection;
426444
}
427445

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

0 commit comments

Comments
 (0)