From a0650012c3e4a481271263f568b45ab4f6a2a81f Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Mon, 25 Nov 2019 13:04:40 +0100 Subject: [PATCH] ParallelRestart: use references and allow non-default template parameters. packSize now uses a reference to map/unordered_map to prevent copying. In addition we always specify all template parameters for the containers to allow for sending data if non-default ones are used. --- opm/simulators/utils/ParallelRestart.cpp | 36 ++++++++++++------------ opm/simulators/utils/ParallelRestart.hpp | 36 ++++++++++++------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 792f83b58..53cd79269 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -90,8 +90,8 @@ std::size_t packSize(const std::pair& data, Dune::MPIHelper::MPICommunica return packSize(data.first, comm) + packSize(data.second, comm); } -template -std::size_t packSize(const std::vector& data, Dune::MPIHelper::MPICommunicator comm) +template +std::size_t packSize(const std::vector& data, Dune::MPIHelper::MPICommunicator comm) { if (std::is_pod::value) // size written automatically @@ -125,8 +125,8 @@ std::size_t packSize(const std::string& str, Dune::MPIHelper::MPICommunicator co return packSize(str.c_str(), comm); } -template -std::size_t packSize(const std::map data, Dune::MPIHelper::MPICommunicator comm) +template +std::size_t packSize(const std::map& data, Dune::MPIHelper::MPICommunicator comm) { std::size_t totalSize = packSize(data.size(), comm); for (const auto& entry: data) @@ -136,8 +136,8 @@ std::size_t packSize(const std::map data, Dune::MPIHelper::MPICommunicato return totalSize; } -template -std::size_t packSize(const std::unordered_map data, Dune::MPIHelper::MPICommunicator comm) +template +std::size_t packSize(const std::unordered_map& data, Dune::MPIHelper::MPICommunicator comm) { std::size_t totalSize = packSize(data.size(), comm); for (const auto& entry: data) @@ -277,8 +277,8 @@ void pack(const std::pair& data, std::vector& buffer, int& position pack(data.second, buffer, position, comm); } -template -void pack(const std::vector& data, std::vector& buffer, int& position, +template +void pack(const std::vector& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { if (std::is_pod::value) @@ -317,8 +317,8 @@ void pack(const std::string& str, std::vector& buffer, int& position, pack(str.c_str(), buffer, position, comm); } -template -void pack(const std::map& data, std::vector& buffer, int& position, +template +void pack(const std::map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { pack(data.size(), buffer, position, comm); @@ -329,8 +329,8 @@ void pack(const std::map& data, std::vector& buffer, int& position, } } -template -void pack(const std::unordered_map& data, std::vector& buffer, int& position, +template +void pack(const std::unordered_map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { pack(data.size(), buffer, position, comm); @@ -486,8 +486,8 @@ void unpack(std::pair& data, std::vector& buffer, int& position, unpack(data.second, buffer, position, comm); } -template -void unpack(std::vector& data, std::vector& buffer, int& position, +template +void unpack(std::vector& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { std::size_t length=0; @@ -529,8 +529,8 @@ void unpack(std::string& str, std::vector& buffer, int& position, str.append(cStr.data()); } -template -void unpack(std::map& data, std::vector& buffer, int& position, +template +void unpack(std::map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { std::size_t size=0; @@ -544,8 +544,8 @@ void unpack(std::map& data, std::vector& buffer, int& position, } } -template -void unpack(std::unordered_map& data, std::vector& buffer, int& position, +template +void unpack(std::unordered_map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { std::size_t size=0; diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index cf80420b6..1dee1f0a3 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -61,18 +61,18 @@ std::size_t packSize(const T& data, Dune::MPIHelper::MPICommunicator comm); template std::size_t packSize(const std::pair& data, Dune::MPIHelper::MPICommunicator comm); -template -std::size_t packSize(const std::vector& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const std::vector& data, Dune::MPIHelper::MPICommunicator comm); std::size_t packSize(const char* str, Dune::MPIHelper::MPICommunicator comm); std::size_t packSize(const std::string& str, Dune::MPIHelper::MPICommunicator comm); -template -std::size_t packSize(const std::map data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const std::map& data, Dune::MPIHelper::MPICommunicator comm); -template -std::size_t packSize(const std::unordered_map data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const std::unordered_map& data, Dune::MPIHelper::MPICommunicator comm); std::size_t packSize(const data::Rates& data, Dune::MPIHelper::MPICommunicator comm); @@ -123,8 +123,8 @@ template void pack(const std::pair& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); -template -void pack(const std::vector& data, std::vector& buffer, int& position, +template +void pack(const std::vector& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -134,13 +134,13 @@ void pack(const char* str, std::vector& buffer, int& position, void pack(const std::string& str, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); -template -void pack(const std::map& data, std::vector& buffer, int& position, +template +void pack(const std::map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); -template -void pack(const std::unordered_map& data, std::vector& buffer, int& position, +template +void pack(const std::unordered_map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -202,8 +202,8 @@ template void unpack(std::pair& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); -template -void unpack(std::vector& data, std::vector& buffer, int& position, +template +void unpack(std::vector& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -213,12 +213,12 @@ void unpack(char* str, std::size_t length, std::vector& buffer, int& posit void unpack(std::string& str, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); -template -void unpack(std::map& data, std::vector& buffer, int& position, +template +void unpack(std::map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); -template -void unpack(std::unordered_map& data, std::vector& buffer, int& position, +template +void unpack(std::unordered_map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); void unpack(data::Rates& data, std::vector& buffer, int& position,