diff --git a/include/openPMD/Series.hpp b/include/openPMD/Series.hpp index e90595d1b7..8f49afd491 100644 --- a/include/openPMD/Series.hpp +++ b/include/openPMD/Series.hpp @@ -700,12 +700,13 @@ OPENPMD_private Access at, std::string const &options, MPI_Communicator &&...); - template + template std::tuple, TracingJSON> initIOHandler( std::string const &filepath, std::string const &options, Access at, - bool resolve_generic_extension); + bool resolve_generic_extension, + MPI_Communicator &&...); void initSeries( std::unique_ptr, std::unique_ptr); void initDefaults(IterationEncoding, bool initAll = false); diff --git a/src/Series.cpp b/src/Series.cpp index f02c0709aa..a4897c3c97 100644 --- a/src/Series.cpp +++ b/src/Series.cpp @@ -600,36 +600,39 @@ void Series::init( std::make_unique(parsed_directory, at)); auto &series = get(); series.iterations.linkHierarchy(writable()); - series.m_deferred_initialization = [called_this_already = false, - filepath, - options, - at, - comm...](Series &s) mutable { - if (called_this_already) - { - throw std::runtime_error("Must be called one time only"); - } - else - { - called_this_already = true; - } - - auto [parsed_input, tracing_json] = - s.initIOHandler(filepath, options, at, true); + series.m_deferred_initialization = + [called_this_already = false, filepath, options, at, comm...]( + Series &s) mutable { + if (called_this_already) + { + throw std::runtime_error("Must be called one time only"); + } + else + { + called_this_already = true; + } - auto io_handler = createIOHandler( - parsed_input->path, - at, - parsed_input->format, - parsed_input->filenameExtension.value_or(std::string()), - comm..., - tracing_json, - filepath); - auto res = io_handler.get(); - s.initSeries(std::move(io_handler), std::move(parsed_input)); - json::warnGlobalUnusedOptions(tracing_json); - return res; - }; + auto [parsed_input, tracing_json] = + s.initIOHandler( + filepath, + options, + at, + true, + std::forward(comm)...); + + auto io_handler = createIOHandler( + parsed_input->path, + at, + parsed_input->format, + parsed_input->filenameExtension.value_or(std::string()), + comm..., + tracing_json, + filepath); + auto res = io_handler.get(); + s.initSeries(std::move(io_handler), std::move(parsed_input)); + json::warnGlobalUnusedOptions(tracing_json); + return res; + }; }; switch (at) @@ -637,15 +640,24 @@ void Series::init( case Access::CREATE: case Access::READ_WRITE: case Access::READ_ONLY: { - auto [parsed_input, tracing_json] = - initIOHandler(filepath, options, at, true); + auto [parsed_input, tracing_json] = initIOHandler( + filepath, + options, + at, + true, + std::forward(comm)...); init_directly(std::move(parsed_input), std::move(tracing_json)); } break; case Access::READ_LINEAR: case Access::APPEND: { auto [first_parsed_input, first_tracing_json] = - initIOHandler(filepath, options, at, false); + initIOHandler( + filepath, + options, + at, + false, + std::forward(comm)...); if (first_parsed_input->filenameExtension.has_value()) { init_directly( @@ -666,16 +678,19 @@ void Series::init( } } -template +template auto Series::initIOHandler( std::string const &filepath, std::string const &options, Access at, - bool resolve_generic_extension) + bool resolve_generic_extension, + MPI_Communicator &&...comm) -> std::tuple, TracingJSON> { - json::TracingJSON optionsJson = - json::parseOptions(options, /* considerFiles = */ true); + json::TracingJSON optionsJson = json::parseOptions( + options, + std::forward(comm)..., + /* considerFiles = */ true); auto input = parseInput(filepath); if (resolve_generic_extension && input->format == Format::GENERIC && at != Access::CREATE)