22#include <opm/common/utility/TimeService.hpp>
23#include <opm/simulators/utils/ParallelCommunication.hpp>
25#include <dune/common/parallel/mpitraits.hh>
36template <
bool pod,
class T>
39 static std::size_t packSize(
const T&, Parallel::MPIComm);
40 static void pack(
const T&, std::vector<char>&,
int&, Parallel::MPIComm);
41 static void unpack(T&, std::vector<char>&,
int&, Parallel::MPIComm);
51 static std::size_t
packSize(
const T& data, Parallel::MPIComm comm)
53 return packSize(&data, 1, comm);
60 static std::size_t
packSize(
const T*, std::size_t n, Parallel::MPIComm comm)
63 MPI_Pack_size(n, Dune::MPITraits<T>::getType(), comm, &size);
72 static void pack(
const T& data,
73 std::vector<char>& buffer,
75 Parallel::MPIComm comm)
77 pack(&data, 1, buffer, position, comm);
86 static void pack(
const T* data,
88 std::vector<char>& buffer,
90 Parallel::MPIComm comm)
92 MPI_Pack(data, n, Dune::MPITraits<T>::getType(), buffer.data(),
93 buffer.size(), &position, comm);
102 std::vector<char>& buffer,
104 Parallel::MPIComm comm)
106 unpack(&data, 1, buffer, position, comm);
117 std::vector<char>& buffer,
119 Parallel::MPIComm comm)
121 MPI_Unpack(buffer.data(), buffer.size(), &position, data, n,
122 Dune::MPITraits<T>::getType(), comm);
130 static std::size_t packSize(
const T&, Parallel::MPIComm)
132 static_assert(!std::is_same_v<T,T>,
"Packing not supported for type");
136 static void pack(
const T&, std::vector<char>&,
int&,
139 static_assert(!std::is_same_v<T,T>,
"Packing not supported for type");
142 static void unpack(T&, std::vector<char>&,
int&,
145 static_assert(!std::is_same_v<T,T>,
"Packing not supported for type");
150template <std::
size_t Size>
153 static std::size_t packSize(
const std::bitset<Size>&, Opm::Parallel::MPIComm);
154 static void pack(
const std::bitset<Size>&, std::vector<char>&,
int&, Opm::Parallel::MPIComm);
155 static void unpack(std::bitset<Size>&, std::vector<char>&,
int&, Opm::Parallel::MPIComm);
158#define ADD_PACK_SPECIALIZATION(T) \
160 struct Packing<false,T> \
162 static std::size_t packSize(const T&, Parallel::MPIComm); \
163 static void pack(const T&, std::vector<char>&, int&, Parallel::MPIComm); \
164 static void unpack(T&, std::vector<char>&, int&, Parallel::MPIComm); \
167ADD_PACK_SPECIALIZATION(std::string)
168ADD_PACK_SPECIALIZATION(time_point)
170#undef ADD_PACK_SPECIALIZATION
196 std::size_t
packSize(
const T* data, std::size_t n)
const
198 static_assert(std::is_pod_v<T>,
"Array packing not supported for non-pod data");
209 std::vector<char>& buffer,
224 std::vector<char>& buffer,
227 static_assert(std::is_pod_v<T>,
"Array packing not supported for non-pod data");
238 std::vector<char>& buffer,
253 std::vector<char>& buffer,
256 static_assert(std::is_pod_v<T>,
"Array packing not supported for non-pod data");
261 Parallel::Communication m_comm;
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
Struct handling packing of serialization for MPI communication.
Definition: MPIPacker.hpp:175
void unpack(T *data, std::size_t n, std::vector< char > &buffer, int &position) const
Unpack an array.
Definition: MPIPacker.hpp:251
void pack(const T *data, std::size_t n, std::vector< char > &buffer, int &position) const
Pack an array.
Definition: MPIPacker.hpp:222
Packer(Parallel::Communication comm)
Constructor.
Definition: MPIPacker.hpp:178
std::size_t packSize(const T *data, std::size_t n) const
Calculates the pack size for an array.
Definition: MPIPacker.hpp:196
void pack(const T &data, std::vector< char > &buffer, int &position) const
Pack a variable.
Definition: MPIPacker.hpp:208
std::size_t packSize(const T &data) const
Calculates the pack size for a variable.
Definition: MPIPacker.hpp:186
void unpack(T &data, std::vector< char > &buffer, int &position) const
Unpack a variable.
Definition: MPIPacker.hpp:237
static void unpack(T &data, std::vector< char > &buffer, int &position, Parallel::MPIComm comm)
Unpack a POD.
Definition: MPIPacker.hpp:101
static void pack(const T *data, std::size_t n, std::vector< char > &buffer, int &position, Parallel::MPIComm comm)
Pack an array of POD.
Definition: MPIPacker.hpp:86
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:60
static void unpack(T *data, std::size_t n, std::vector< char > &buffer, int &position, Parallel::MPIComm comm)
Unpack an array of POD.
Definition: MPIPacker.hpp:115
static void pack(const T &data, std::vector< char > &buffer, int &position, Parallel::MPIComm comm)
Pack a POD.
Definition: MPIPacker.hpp:72
static std::size_t packSize(const T &data, Parallel::MPIComm comm)
Calculates the pack size for a POD.
Definition: MPIPacker.hpp:51
Abstract struct for packing which is (partially) specialized for specific types.
Definition: MPIPacker.hpp:38