From ec95a19f4c290ad7076b66556b43cf2075c37d3d Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 29 Nov 2019 11:19:34 +0100 Subject: [PATCH] add mpi serialization for SimpleTable --- opm/simulators/utils/ParallelRestart.cpp | 28 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 ++ tests/test_ParallelRestart.cpp | 20 +++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index a0834b785..caa993e18 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -285,6 +286,13 @@ std::size_t packSize(const TableColumn& data, Dune::MPIHelper::MPICommunicator c packSize(data.defaultCount(), comm); } +std::size_t packSize(const SimpleTable& data, Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.schema(), comm) + + packSize(data.columns(), comm) + + packSize(data.jfunc(), comm); +} + ////// pack routines template @@ -555,6 +563,14 @@ void pack(const TableColumn& data, std::vector& buffer, int& position, pack(data.defaultCount(), buffer, position, comm); } +void pack(const SimpleTable& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.schema(), buffer, position, comm); + pack(data.columns(), buffer, position, comm); + pack(data.jfunc(), buffer, position, comm); +} + /// unpack routines template @@ -869,6 +885,18 @@ void unpack(TableColumn& data, std::vector& buffer, int& position, data = TableColumn(schema, name, values, defaults, defaultCount); } +void unpack(SimpleTable& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + TableSchema schema; + OrderedMap columns; + bool jf; + unpack(schema, buffer, position, comm); + unpack(columns, buffer, position, comm); + unpack(jf, buffer, position, comm); + data = SimpleTable(schema, columns, jf); +} + } // end namespace Mpi RestartValue loadParallelRestart(const EclipseIO* eclIO, SummaryState& summaryState, const std::vector& solutionKeys, diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index ab209ec04..967a41e56 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -43,6 +43,7 @@ class NNC; struct NNCdata; class Rock2dTable; class Rock2dtrTable; +class SimpleTable; class TableColumn; class TableSchema; class ThresholdPressure; @@ -226,6 +227,7 @@ ADD_PACK_PROTOTYPES(RestartValue) ADD_PACK_PROTOTYPES(Rock2dTable) ADD_PACK_PROTOTYPES(Rock2dtrTable) ADD_PACK_PROTOTYPES(std::string) +ADD_PACK_PROTOTYPES(SimpleTable) ADD_PACK_PROTOTYPES(TableColumn) ADD_PACK_PROTOTYPES(TableSchema) ADD_PACK_PROTOTYPES(ThresholdPressure) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index fb354752e..a08c0c65d 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -139,6 +140,14 @@ Opm::TableColumn getTableColumn() } +Opm::SimpleTable getSimpleTable() +{ + Opm::OrderedMap data; + data.insert({"test3", getTableColumn()}); + return Opm::SimpleTable(getTableSchema(), data, true); +} + + } @@ -356,6 +365,17 @@ BOOST_AUTO_TEST_CASE(TableColumn) } +BOOST_AUTO_TEST_CASE(SimpleTable) +{ +#if HAVE_MPI + Opm::SimpleTable val1 = getSimpleTable(); + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + bool init_unit_test_func() { return true;