22#include <opm/common/utility/TimeService.hpp>
23#include <opm/simulators/utils/ParallelCommunication.hpp>
25#include <dune/common/parallel/mpitraits.hh>
38constexpr bool is_pod_v = std::is_standard_layout_v<T> && std::is_trivial_v<T>;
40std::size_t mpi_buffer_size(
const std::size_t
bufsize,
const std::size_t position);
43template <
bool pod,
class T>
46 static std::size_t packSize(
const T&, Parallel::MPIComm);
47 static void pack(
const T&, std::vector<char>&, std::size_t&, Parallel::MPIComm);
48 static void unpack(T&,
const std::vector<char>&, std::size_t&, Parallel::MPIComm);
58 static std::size_t
packSize(
const T& data, Parallel::MPIComm comm)
60 return packSize(&data, 1, comm);
67 static std::size_t
packSize(
const T*, std::size_t
n, Parallel::MPIComm comm)
71 if (
n*
sizeof(T) > std::numeric_limits<int>::max())
72 throw std::invalid_argument(
"packSize will be larger than max integer - this is not supported.");
75 return static_cast<std::size_t
>(size);
83 static void pack(
const T& data,
85 std::size_t& position,
86 Parallel::MPIComm comm)
88 pack(&data, 1,
buffer, position, comm);
97 static void pack(
const T* data,
100 std::size_t& position,
101 Parallel::MPIComm comm)
104 MPI_Pack(data,
n, Dune::MPITraits<T>::getType(),
buffer.data()+position,
115 const std::vector<char>&
buffer,
116 std::size_t& position,
117 Parallel::MPIComm comm)
119 unpack(&data, 1,
buffer, position, comm);
130 const std::vector<char>&
buffer,
131 std::size_t& position,
132 Parallel::MPIComm comm)
136 Dune::MPITraits<T>::getType(), comm);
145 static std::size_t packSize(
const T&, Parallel::MPIComm)
147 static_assert(!std::is_same_v<T,T>,
"Packing not supported for type");
151 static void pack(
const T&, std::vector<char>&, std::size_t&,
154 static_assert(!std::is_same_v<T,T>,
"Packing not supported for type");
157 static void unpack(T&,
const std::vector<char>&, std::size_t&,
160 static_assert(!std::is_same_v<T,T>,
"Packing not supported for type");
165template <std::
size_t Size>
168 static std::size_t packSize(
const std::bitset<Size>&, Opm::Parallel::MPIComm);
169 static void pack(
const std::bitset<Size>&, std::vector<char>&, std::size_t&, Opm::Parallel::MPIComm);
170 static void unpack(std::bitset<Size>&,
const std::vector<char>&,
171 std::size_t&, Opm::Parallel::MPIComm);
174#define ADD_PACK_SPECIALIZATION(T) \
176 struct Packing<false,T> \
178 static std::size_t packSize(const T&, Parallel::MPIComm); \
179 static void pack(const T&, std::vector<char>&, std::size_t&, Parallel::MPIComm); \
180 static void unpack(T&, const std::vector<char>&, std::size_t&, Parallel::MPIComm); \
183ADD_PACK_SPECIALIZATION(std::string)
186#undef ADD_PACK_SPECIALIZATION
195 explicit Packer(Parallel::Communication comm)
213 std::size_t
packSize(
const T* data, std::size_t
n)
const
215 static_assert(detail::is_pod_v<T>,
"Array packing not supported for non-pod data");
226 std::vector<char>&
buffer,
227 std::size_t& position)
const
241 std::vector<char>&
buffer,
242 std::size_t& position)
const
244 static_assert(detail::is_pod_v<T>,
"Array packing not supported for non-pod data");
255 const std::vector<char>&
buffer,
256 std::size_t& position)
const
270 const std::vector<char>&
buffer,
271 std::size_t& position)
const
273 static_assert(detail::is_pod_v<T>,
"Array packing not supported for non-pod data");
278 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:192
Packer(Parallel::Communication comm)
Constructor.
Definition MPIPacker.hpp:195
void unpack(T &data, const std::vector< char > &buffer, std::size_t &position) const
Unpack a variable.
Definition MPIPacker.hpp:254
void pack(const T *data, std::size_t n, std::vector< char > &buffer, std::size_t &position) const
Pack an array.
Definition MPIPacker.hpp:239
void unpack(T *data, std::size_t n, const std::vector< char > &buffer, std::size_t &position) const
Unpack an array.
Definition MPIPacker.hpp:268
std::size_t packSize(const T *data, std::size_t n) const
Calculates the pack size for an array.
Definition MPIPacker.hpp:213
std::size_t packSize(const T &data) const
Calculates the pack size for a variable.
Definition MPIPacker.hpp:203
void pack(const T &data, std::vector< char > &buffer, std::size_t &position) const
Pack a variable.
Definition MPIPacker.hpp:225
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:97
static void pack(const T &data, std::vector< char > &buffer, std::size_t &position, Parallel::MPIComm comm)
Pack a POD.
Definition MPIPacker.hpp:83
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:67
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:128
static void unpack(T &data, const std::vector< char > &buffer, std::size_t &position, Parallel::MPIComm comm)
Unpack a POD.
Definition MPIPacker.hpp:114
static std::size_t packSize(const T &data, Parallel::MPIComm comm)
Calculates the pack size for a POD.
Definition MPIPacker.hpp:58
Abstract struct for packing which is (partially) specialized for specific types.
Definition MPIPacker.hpp:45