20 #ifndef DUNE_COMMON_PARALLEL_MPIPACK_HH 21 #define DUNE_COMMON_PARALLEL_MPIPACK_HH 25 #include <type_traits> 37 std::vector<char> _buffer;
65 constexpr
bool has_static_size = decltype(
getMPIData(std::declval<T&>()))::static_size;
68 if (_position +
size > 0 &&
size_t(_position +
size) > _buffer.size())
69 _buffer.resize(_position +
size);
71 int size = mpidata.size();
72 MPI_Pack(&
size, 1, MPI_INT, _buffer.data(), _buffer.size(),
75 MPI_Pack(mpidata.ptr(), mpidata.size(),
76 mpidata.type(), _buffer.data(), _buffer.size(),
86 -> std::enable_if_t<decltype(getMPIData(data))::static_size, void>
89 MPI_Unpack(_buffer.data(), _buffer.size(), &_position,
90 mpidata.ptr(), mpidata.size(),
91 mpidata.type(), _comm);
100 -> std::enable_if_t<!decltype(getMPIData(data))::static_size, void>
104 MPI_Unpack(_buffer.data(), _buffer.size(), &_position,
107 mpidata.resize(
size);
108 MPI_Unpack(_buffer.data(), _buffer.size(), &_position,
109 mpidata.ptr(), mpidata.size(),
110 mpidata.type(), _comm);
146 _buffer.resize(
size);
152 _buffer.resize(_buffer.size() + s);
158 return _buffer.size();
178 return std::size_t(_position)==_buffer.size();
184 static int getPackSize(
int len,
const MPI_Comm& comm,
const MPI_Datatype& dt){
186 MPI_Pack_size(len, dt, comm, &
size);
191 return a._buffer == b._buffer && a._comm == b._comm;
200 struct MPIData<P,
std::enable_if_t<std::is_same<std::remove_const_t<P>, MPIPack>::value>> {
202 friend auto getMPIData<P>(P& t);
210 return (
void*)
data_._buffer.data();
231 #endif // DUNE_COMMON_PARALLEL_MPIPACK_HH friend bool operator==(const MPIPack &a, const MPIPack &b)
Definition: mpipack.hh:190
MPIData(P &t)
Definition: mpipack.hh:203
auto getMPIData(T &t)
Definition: mpidata.hh:44
Implements an utility class that provides MPI's collective communication methods. ...
MPI_Datatype type() const
Definition: mpipack.hh:217
int tell() const
Gets the position in the buffer where the next pack/unpack operation should take place.
Definition: mpipack.hh:171
void * ptr()
Definition: mpipack.hh:209
T & data_
Definition: mpidata.hh:54
MPIPack(Communication< MPI_Comm > comm, std::size_t size=0)
Definition: mpipack.hh:44
void pack(const T &data)
Packs the data into the object. Enlarges the internal buffer if necessary.
Definition: mpipack.hh:62
Interface class to translate objects to a MPI_Datatype, void* and size used for MPI calls...
Definition: mpidata.hh:41
friend bool operator!=(const MPIPack &a, const MPIPack &b)
Definition: mpipack.hh:193
static constexpr bool static_size
Definition: mpidata.hh:66
MPIPack & read(T &t)
Unpacks data from the object.
Definition: mpipack.hh:130
P & data_
Definition: mpipack.hh:225
Dune namespace
Definition: alignedallocator.hh:12
int size()
Definition: mpipack.hh:213
size_t size() const
Returns the size of the internal buffer.
Definition: mpipack.hh:157
auto unpack(T &data) -> std::enable_if_t< decltype(getMPIData(data))::static_size, void >
Unpacks data from the object.
Definition: mpipack.hh:85
void resize(int size)
Definition: mpipack.hh:221
void seek(int p)
Sets the position in the buffer where the next pack/unpack operation should take place.
Definition: mpipack.hh:164
int size() const
Definition: mpidata.hh:68
Specialization of Communication for MPI.
Definition: mpicommunication.hh:107
void enlarge(int s)
Enlarges the internal buffer.
Definition: mpipack.hh:151
friend MPIPack & operator>>(MPIPack &p, T &t)
Unpacks data from the object.
Definition: mpipack.hh:123
MPIPack & operator=(const MPIPack &other)=delete
auto unpack(T &data) -> std::enable_if_t<!decltype(getMPIData(data))::static_size, void >
Unpacks data from the object.
Definition: mpipack.hh:99
bool eof() const
Checks whether the end of the buffer is reached.
Definition: mpipack.hh:177
friend MPIPack & operator<<(MPIPack &p, const T &t)
Packs the data into the object. Enlarges the internal buffer if necessary.
Definition: mpipack.hh:116
static int getPackSize(int len, const MPI_Comm &comm, const MPI_Datatype &dt)
Returns the size of the data needed to store the data in an MPIPack. See MPI_Pack_size.
Definition: mpipack.hh:184
MPIPack & write(const T &t)
Packs the data into the object. Enlarges the internal buffer if necessary.
Definition: mpipack.hh:137
void resize(size_t size)
Resizes the internal buffer.
Definition: mpipack.hh:145
Definition: mpipack.hh:36