27#ifndef EWOMS_MPI_BUFFER_HH
28#define EWOMS_MPI_BUFFER_HH
44template <
class DataType>
67 data_.resize(newSize);
74 void send([[maybe_unused]]
unsigned peerRank)
77 MPI_Isend(data_.data(),
78 static_cast<int>(mpiDataSize_),
80 static_cast<int>(peerRank),
93 MPI_Wait(&mpiRequest_, &mpiStatus_);
100 void receive([[maybe_unused]]
unsigned peerRank)
103 MPI_Recv(data_.data(),
104 static_cast<int>(mpiDataSize_),
106 static_cast<int>(peerRank),
120 {
return mpiRequest_; }
128 {
return mpiRequest_; }
136 {
return mpiStatus_; }
144 {
return mpiStatus_; }
151 {
return data_.size(); }
158 assert(i < data_.size());
167 assert(i < data_.size());
172 void setMpiDataType_()
176 if constexpr (std::is_same_v<DataType, char>) {
177 mpiDataType_ = MPI_CHAR;
179 else if constexpr (std::is_same_v<DataType, unsigned char>) {
180 mpiDataType_ = MPI_UNSIGNED_CHAR;
182 else if constexpr (std::is_same_v<DataType, short>) {
183 mpiDataType_ = MPI_SHORT;
185 else if constexpr (std::is_same_v<DataType, unsigned short>) {
186 mpiDataType_ = MPI_UNSIGNED_SHORT;
188 else if constexpr (std::is_same_v<DataType, int>) {
189 mpiDataType_ = MPI_INT;
191 else if constexpr (std::is_same_v<DataType, unsigned>) {
192 mpiDataType_ = MPI_UNSIGNED;
194 else if constexpr (std::is_same_v<DataType, long>) {
195 mpiDataType_ = MPI_LONG;
197 else if constexpr (std::is_same_v<DataType, unsigned long>) {
198 mpiDataType_ = MPI_UNSIGNED_LONG;
200 else if constexpr (std::is_same_v<DataType, long long>) {
201 mpiDataType_ = MPI_LONG_LONG;
203 else if constexpr (std::is_same_v<DataType, unsigned long long>) {
204 mpiDataType_ = MPI_UNSIGNED_LONG_LONG;
206 else if constexpr (std::is_same_v<DataType, float>) {
207 mpiDataType_ = MPI_FLOAT;
209 else if constexpr (std::is_same_v<DataType, double>) {
210 mpiDataType_ = MPI_DOUBLE;
212 else if constexpr (std::is_same_v<DataType, long double>) {
213 mpiDataType_ = MPI_LONG_DOUBLE;
216 mpiDataType_ = MPI_BYTE;
221 void updateMpiDataSize_()
224 mpiDataSize_ = data_.size();
225 if (mpiDataType_ == MPI_BYTE) {
226 mpiDataSize_ *=
sizeof(DataType);
231 std::vector<DataType> data_;
234 std::size_t mpiDataSize_;
235 MPI_Datatype mpiDataType_;
236 MPI_Request mpiRequest_;
237 MPI_Status mpiStatus_;
Simplifies handling of buffers to be used in conjunction with MPI.
Definition: mpibuffer.hh:46
const MPI_Request & request() const
Returns the current MPI_Request object.
Definition: mpibuffer.hh:127
MPI_Status & status()
Returns the current MPI_Status object.
Definition: mpibuffer.hh:135
MpiBuffer(std::size_t size)
Definition: mpibuffer.hh:54
DataType & operator[](std::size_t i)
Provide access to the buffer data.
Definition: mpibuffer.hh:156
MpiBuffer()
Definition: mpibuffer.hh:48
const DataType & operator[](std::size_t i) const
Provide access to the buffer data.
Definition: mpibuffer.hh:165
MPI_Request & request()
Returns the current MPI_Request object.
Definition: mpibuffer.hh:119
const MPI_Status & status() const
Returns the current MPI_Status object.
Definition: mpibuffer.hh:143
void wait()
Wait until the buffer was send to the peer completely.
Definition: mpibuffer.hh:90
void resize(std::size_t newSize)
Set the size of the buffer.
Definition: mpibuffer.hh:65
void send(unsigned peerRank)
Send the buffer asyncronously to a peer process.
Definition: mpibuffer.hh:74
std::size_t size() const
Returns the number of data objects in the buffer.
Definition: mpibuffer.hh:150
void receive(unsigned peerRank)
Receive the buffer syncronously from a peer rank.
Definition: mpibuffer.hh:100
Definition: blackoilboundaryratevector.hh:39