25 #ifndef EWOMS_MPI_BUFFER_HH
26 #define EWOMS_MPI_BUFFER_HH
33 #include <type_traits>
41 template <
class DataType>
56 data_ =
new DataType[
size];
72 data_ =
new DataType[newSize];
80 void send(
int peerRank,
bool setNoAccess =
true)
83 MPI_Isend(data_, mpiDataSize_, mpiDataType_, peerRank, 0,
84 MPI_COMM_WORLD, &mpiRequest_);
94 MPI_Wait(&mpiRequest_, &mpiStatus_);
104 MPI_Recv(data_, mpiDataSize_, mpiDataType_, peerRank, 0,
105 MPI_COMM_WORLD, &mpiStatus_);
106 assert(!mpiStatus_.MPI_ERROR);
117 {
return mpiRequest_; }
124 {
return mpiRequest_; }
132 {
return mpiStatus_; }
139 {
return mpiStatus_; }
146 {
return dataSize_; }
153 assert(0 <= i && i < dataSize_);
162 assert(0 <= i && i < dataSize_);
167 void setMpiDataType_()
171 if (std::is_same<DataType, char>::value)
172 mpiDataType_ = MPI_CHAR;
173 else if (std::is_same<DataType, unsigned char>::value)
174 mpiDataType_ = MPI_UNSIGNED_CHAR;
175 else if (std::is_same<DataType, short>::value)
176 mpiDataType_ = MPI_SHORT;
177 else if (std::is_same<DataType, unsigned short>::value)
178 mpiDataType_ = MPI_UNSIGNED_SHORT;
179 else if (std::is_same<DataType, int>::value)
180 mpiDataType_ = MPI_INT;
181 else if (std::is_same<DataType, unsigned>::value)
182 mpiDataType_ = MPI_UNSIGNED;
183 else if (std::is_same<DataType, long>::value)
184 mpiDataType_ = MPI_LONG;
185 else if (std::is_same<DataType, unsigned long>::value)
186 mpiDataType_ = MPI_UNSIGNED_LONG;
187 else if (std::is_same<DataType, long long>::value)
188 mpiDataType_ = MPI_LONG_LONG;
189 else if (std::is_same<DataType, unsigned long long>::value)
190 mpiDataType_ = MPI_UNSIGNED_LONG_LONG;
191 else if (std::is_same<DataType, float>::value)
192 mpiDataType_ = MPI_FLOAT;
193 else if (std::is_same<DataType, double>::value)
194 mpiDataType_ = MPI_DOUBLE;
195 else if (std::is_same<DataType, long double>::value)
196 mpiDataType_ = MPI_LONG_DOUBLE;
198 mpiDataType_ = MPI_BYTE;
203 void updateMpiDataSize_()
206 mpiDataSize_ = dataSize_;
207 if (mpiDataType_ == MPI_BYTE)
208 mpiDataSize_ *=
sizeof(DataType);
216 MPI_Datatype mpiDataType_;
217 MPI_Request mpiRequest_;
218 MPI_Status mpiStatus_;
const MPI_Status & status() const
Returns the current MPI_Status object.
Definition: mpibuffer.hh:138
void send(int peerRank, bool setNoAccess=true)
Send the buffer asyncronously to a peer process.
Definition: mpibuffer.hh:80
const DataType & operator[](size_t i) const
Provide access to the buffer data.
Definition: mpibuffer.hh:160
MPI_Request & request()
Returns the current MPI_Request object.
Definition: mpibuffer.hh:116
void receive(int peerRank)
Receive the buffer syncronously from a peer rank.
Definition: mpibuffer.hh:101
Definition: baseauxiliarymodule.hh:35
MPI_Status & status()
Returns the current MPI_Status object.
Definition: mpibuffer.hh:131
size_t size() const
Returns the number of data objects in the buffer.
Definition: mpibuffer.hh:145
~MpiBuffer()
Definition: mpibuffer.hh:63
MpiBuffer(int size)
Definition: mpibuffer.hh:54
void wait()
Wait until the buffer was send to the peer completely.
Definition: mpibuffer.hh:91
const MPI_Request & request() const
Returns the current MPI_Request object.
Definition: mpibuffer.hh:123
Simplifies handling of buffers to be used in conjunction with MPI.
Definition: mpibuffer.hh:42
MpiBuffer()
Definition: mpibuffer.hh:45
DataType & operator[](size_t i)
Provide access to the buffer data.
Definition: mpibuffer.hh:151
void resize(size_t newSize)
Set the size of the buffer.
Definition: mpibuffer.hh:69