27#ifndef EWOMS_MPI_BUFFER_HH
28#define EWOMS_MPI_BUFFER_HH
44template <
class DataType>
59 data_ =
new DataType[
size];
77 data_ =
new DataType[newSize];
85 void send([[maybe_unused]]
unsigned peerRank)
89 static_cast<int>(mpiDataSize_),
91 static_cast<int>(peerRank),
104 MPI_Wait(&mpiRequest_, &mpiStatus_);
111 void receive([[maybe_unused]]
unsigned peerRank)
115 static_cast<int>(mpiDataSize_),
117 static_cast<int>(peerRank),
131 {
return mpiRequest_; }
138 {
return mpiRequest_; }
146 {
return mpiStatus_; }
153 {
return mpiStatus_; }
160 {
return dataSize_; }
167 assert(i < dataSize_);
176 assert(i < dataSize_);
181 void setMpiDataType_()
185 if (std::is_same<DataType, char>::value)
186 mpiDataType_ = MPI_CHAR;
187 else if (std::is_same<DataType, unsigned char>::value)
188 mpiDataType_ = MPI_UNSIGNED_CHAR;
189 else if (std::is_same<DataType, short>::value)
190 mpiDataType_ = MPI_SHORT;
191 else if (std::is_same<DataType, unsigned short>::value)
192 mpiDataType_ = MPI_UNSIGNED_SHORT;
193 else if (std::is_same<DataType, int>::value)
194 mpiDataType_ = MPI_INT;
195 else if (std::is_same<DataType, unsigned>::value)
196 mpiDataType_ = MPI_UNSIGNED;
197 else if (std::is_same<DataType, long>::value)
198 mpiDataType_ = MPI_LONG;
199 else if (std::is_same<DataType, unsigned long>::value)
200 mpiDataType_ = MPI_UNSIGNED_LONG;
201 else if (std::is_same<DataType, long long>::value)
202 mpiDataType_ = MPI_LONG_LONG;
203 else if (std::is_same<DataType, unsigned long long>::value)
204 mpiDataType_ = MPI_UNSIGNED_LONG_LONG;
205 else if (std::is_same<DataType, float>::value)
206 mpiDataType_ = MPI_FLOAT;
207 else if (std::is_same<DataType, double>::value)
208 mpiDataType_ = MPI_DOUBLE;
209 else if (std::is_same<DataType, long double>::value)
210 mpiDataType_ = MPI_LONG_DOUBLE;
212 mpiDataType_ = MPI_BYTE;
217 void updateMpiDataSize_()
220 mpiDataSize_ = dataSize_;
221 if (mpiDataType_ == MPI_BYTE)
222 mpiDataSize_ *=
sizeof(DataType);
230 MPI_Datatype mpiDataType_;
231 MPI_Request mpiRequest_;
232 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:137
size_t size() const
Returns the number of data objects in the buffer.
Definition: mpibuffer.hh:159
MpiBuffer(size_t size)
Definition: mpibuffer.hh:57
MPI_Status & status()
Returns the current MPI_Status object.
Definition: mpibuffer.hh:145
void resize(size_t newSize)
Set the size of the buffer.
Definition: mpibuffer.hh:74
const DataType & operator[](size_t i) const
Provide access to the buffer data.
Definition: mpibuffer.hh:174
MpiBuffer()
Definition: mpibuffer.hh:48
MpiBuffer(const MpiBuffer &)=default
MPI_Request & request()
Returns the current MPI_Request object.
Definition: mpibuffer.hh:130
~MpiBuffer()
Definition: mpibuffer.hh:68
const MPI_Status & status() const
Returns the current MPI_Status object.
Definition: mpibuffer.hh:152
DataType & operator[](size_t i)
Provide access to the buffer data.
Definition: mpibuffer.hh:165
void wait()
Wait until the buffer was send to the peer completely.
Definition: mpibuffer.hh:101
void send(unsigned peerRank)
Send the buffer asyncronously to a peer process.
Definition: mpibuffer.hh:85
void receive(unsigned peerRank)
Receive the buffer syncronously from a peer rank.
Definition: mpibuffer.hh:111
Definition: blackoilboundaryratevector.hh:37