22#include <opm/common/utility/TimeService.hpp>
23#include <opm/simulators/utils/ParallelCommunication.hpp>
25#include <dune/common/parallel/mpitraits.hh>
37std::size_t mpi_buffer_size(
const std::size_t
bufsize,
const std::size_t position);
40template <
bool pod,
class T>
43 static std::size_t packSize(
const T&, Parallel::MPIComm);
44 static void pack(
const T&, std::vector<char>&, std::size_t&, Parallel::MPIComm);
45 static void unpack(T&,
const std::vector<char>&, std::size_t&, Parallel::MPIComm);
55 static std::size_t
packSize(
const T& data, Parallel::MPIComm comm)
57 return packSize(&data, 1, comm);
64 static std::size_t
packSize(
const T*, std::size_t
n, Parallel::MPIComm comm)
68 if (
n*
sizeof(T) > std::numeric_limits<int>::max())
69 throw std::invalid_argument(
"packSize will be larger than max integer - this is not supported.");
72 return static_cast<std::size_t
>(size);
80 static void pack(
const T& data,
82 std::size_t& position,
83 Parallel::MPIComm comm)
85 pack(&data, 1,
buffer, position, comm);
94 static void pack(
const T* data,
97 std::size_t& position,
98 Parallel::MPIComm comm)
101 MPI_Pack(data,
n, Dune::MPITraits<T>::getType(),
buffer.data()+position,
112 const std::vector<char>&
buffer,
113 std::size_t& position,
114 Parallel::MPIComm comm)
116 unpack(&data, 1,
buffer, position, comm);
127 const std::vector<char>&
buffer,
128 std::size_t& position,
129 Parallel::MPIComm comm)
133 Dune::MPITraits<T>::getType(), comm);
142 static std::size_t packSize(
const T&, Parallel::MPIComm)
144 static_assert(!std::is_same_v<T,T>,
"Packing not supported for type");
148 static void pack(
const T&, std::vector<char>&, std::size_t&,
151 static_assert(!std::is_same_v<T,T>,
"Packing not supported for type");
154 static void unpack(T&,
const std::vector<char>&, std::size_t&,
157 static_assert(!std::is_same_v<T,T>,
"Packing not supported for type");
162template <std::
size_t Size>
165 static std::size_t packSize(
const std::bitset<Size>&, Opm::Parallel::MPIComm);
166 static void pack(
const std::bitset<Size>&, std::vector<char>&, std::size_t&, Opm::Parallel::MPIComm);
167 static void unpack(std::bitset<Size>&,
const std::vector<char>&,
168 std::size_t&, Opm::Parallel::MPIComm);
171#define ADD_PACK_SPECIALIZATION(T) \
173 struct Packing<false,T> \
175 static std::size_t packSize(const T&, Parallel::MPIComm); \
176 static void pack(const T&, std::vector<char>&, std::size_t&, Parallel::MPIComm); \
177 static void unpack(T&, const std::vector<char>&, std::size_t&, Parallel::MPIComm); \
180ADD_PACK_SPECIALIZATION(std::string)
183#undef ADD_PACK_SPECIALIZATION
210 std::size_t
packSize(
const T* data, std::size_t
n)
const
212 static_assert(std::is_pod_v<T>,
"Array packing not supported for non-pod data");
223 std::vector<char>&
buffer,
224 std::size_t& position)
const
238 std::vector<char>&
buffer,
239 std::size_t& position)
const
241 static_assert(std::is_pod_v<T>,
"Array packing not supported for non-pod data");
252 const std::vector<char>&
buffer,
253 std::size_t& position)
const
267 const std::vector<char>&
buffer,
268 std::size_t& position)
const
270 static_assert(std::is_pod_v<T>,
"Array packing not supported for non-pod data");
275 Parallel::Communication m_comm;
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
Struct handling packing of serialization for MPI communication.
Definition MPIPacker.hpp:189
Packer(Parallel::Communication comm)
Constructor.
Definition MPIPacker.hpp:192
void unpack(T &data, const std::vector< char > &buffer, std::size_t &position) const
Unpack a variable.
Definition MPIPacker.hpp:251
void pack(const T *data, std::size_t n, std::vector< char > &buffer, std::size_t &position) const
Pack an array.
Definition MPIPacker.hpp:236
void unpack(T *data, std::size_t n, const std::vector< char > &buffer, std::size_t &position) const
Unpack an array.
Definition MPIPacker.hpp:265
std::size_t packSize(const T *data, std::size_t n) const
Calculates the pack size for an array.
Definition MPIPacker.hpp:210
std::size_t packSize(const T &data) const
Calculates the pack size for a variable.
Definition MPIPacker.hpp:200
void pack(const T &data, std::vector< char > &buffer, std::size_t &position) const
Pack a variable.
Definition MPIPacker.hpp:222
static void pack(const T *data, std::size_t n, std::vector< char > &buffer, std::size_t &position, Parallel::MPIComm comm)
Pack an array of POD.
Definition MPIPacker.hpp:94
static void pack(const T &data, std::vector< char > &buffer, std::size_t &position, Parallel::MPIComm comm)
Pack a POD.
Definition MPIPacker.hpp:80
static std::size_t packSize(const T *, std::size_t n, Parallel::MPIComm comm)
Calculates the pack size for an array of POD.
Definition MPIPacker.hpp:64
static void unpack(T *data, std::size_t n, const std::vector< char > &buffer, std::size_t &position, Parallel::MPIComm comm)
Unpack an array of POD.
Definition MPIPacker.hpp:125
static void unpack(T &data, const std::vector< char > &buffer, std::size_t &position, Parallel::MPIComm comm)
Unpack a POD.
Definition MPIPacker.hpp:111
static std::size_t packSize(const T &data, Parallel::MPIComm comm)
Calculates the pack size for a POD.
Definition MPIPacker.hpp:55
Abstract struct for packing which is (partially) specialized for specific types.
Definition MPIPacker.hpp:42