From fff19a2cf3d8dc72fc596b693500dec0e04f4fbe Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sun, 3 Jan 2021 10:30:51 +0100 Subject: [PATCH] Serialize std::chrono::system_clock::time_point through std::time_t --- opm/simulators/utils/ParallelRestart.cpp | 24 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 ++ 2 files changed, 26 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index b2065c9d1..347645eb0 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -22,6 +22,7 @@ #endif #include "ParallelRestart.hpp" +#include #include #define HANDLE_AS_POD(T) \ @@ -282,6 +283,13 @@ std::size_t packSize(const RestartValue& data, Dune::MPIHelper::MPICommunicator + packSize(data.extra, comm); } +std::size_t packSize(const std::chrono::system_clock::time_point&, Dune::MPIHelper::MPICommunicator comm) +{ + std::time_t tp; + return packSize(tp, comm); +} + + ////// pack routines template @@ -568,6 +576,13 @@ void pack(const RestartValue& data, std::vector& buffer, int& position, pack(data.extra, buffer, position, comm); } +void pack(const std::chrono::system_clock::time_point& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(std::chrono::system_clock::to_time_t(data), buffer, position, comm); +} + + /// unpack routines template @@ -872,6 +887,15 @@ void unpack(RestartValue& data, std::vector& buffer, int& position, unpack(data.extra, buffer, position, comm); } +void unpack(std::chrono::system_clock::time_point& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::time_t tp; + unpack(tp, buffer, position, comm); + data = std::chrono::system_clock::from_time_t(tp); +} + + #define INSTANTIATE_PACK_VECTOR(...) \ template std::size_t packSize(const std::vector<__VA_ARGS__>& data, \ Dune::MPIHelper::MPICommunicator comm); \ diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index f8b018b31..aad0ce9be 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -30,6 +30,7 @@ #include +#include #include #include #include @@ -317,6 +318,7 @@ ADD_PACK_PROTOTYPES(data::WellRates) ADD_PACK_PROTOTYPES(RestartKey) ADD_PACK_PROTOTYPES(RestartValue) ADD_PACK_PROTOTYPES(std::string) +ADD_PACK_PROTOTYPES(std::chrono::system_clock::time_point) } // end namespace Mpi