27 #ifndef EWOMS_MPI_BUFFER_HH 28 #define EWOMS_MPI_BUFFER_HH 36 #include <type_traits> 44 template <
class DataType>
59 data_ =
new DataType[
size];
77 data_ =
new DataType[newSize];
85 void send(
unsigned peerRank)
89 static_cast<int>(mpiDataSize_),
91 static_cast<int>(peerRank),
104 MPI_Wait(&mpiRequest_, &mpiStatus_);
115 static_cast<int>(mpiDataSize_),
117 static_cast<int>(peerRank),
121 assert(!mpiStatus_.MPI_ERROR);
131 MPI_Request& request()
132 {
return mpiRequest_; }
138 const MPI_Request& request()
const 139 {
return mpiRequest_; }
147 {
return mpiStatus_; }
153 const MPI_Status& status()
const 154 {
return mpiStatus_; }
161 {
return dataSize_; }
168 assert(0 <= i && i < dataSize_);
177 assert(0 <= i && i < dataSize_);
182 void setMpiDataType_()
186 if (std::is_same<DataType, char>::value)
187 mpiDataType_ = MPI_CHAR;
188 else if (std::is_same<DataType, unsigned char>::value)
189 mpiDataType_ = MPI_UNSIGNED_CHAR;
190 else if (std::is_same<DataType, short>::value)
191 mpiDataType_ = MPI_SHORT;
192 else if (std::is_same<DataType, unsigned short>::value)
193 mpiDataType_ = MPI_UNSIGNED_SHORT;
194 else if (std::is_same<DataType, int>::value)
195 mpiDataType_ = MPI_INT;
196 else if (std::is_same<DataType, unsigned>::value)
197 mpiDataType_ = MPI_UNSIGNED;
198 else if (std::is_same<DataType, long>::value)
199 mpiDataType_ = MPI_LONG;
200 else if (std::is_same<DataType, unsigned long>::value)
201 mpiDataType_ = MPI_UNSIGNED_LONG;
202 else if (std::is_same<DataType, long long>::value)
203 mpiDataType_ = MPI_LONG_LONG;
204 else if (std::is_same<DataType, unsigned long long>::value)
205 mpiDataType_ = MPI_UNSIGNED_LONG_LONG;
206 else if (std::is_same<DataType, float>::value)
207 mpiDataType_ = MPI_FLOAT;
208 else if (std::is_same<DataType, double>::value)
209 mpiDataType_ = MPI_DOUBLE;
210 else if (std::is_same<DataType, long double>::value)
211 mpiDataType_ = MPI_LONG_DOUBLE;
213 mpiDataType_ = MPI_BYTE;
218 void updateMpiDataSize_()
221 mpiDataSize_ = dataSize_;
222 if (mpiDataType_ == MPI_BYTE)
223 mpiDataSize_ *=
sizeof(DataType);
231 MPI_Datatype mpiDataType_;
232 MPI_Request mpiRequest_;
233 MPI_Status mpiStatus_;
Simplifies handling of buffers to be used in conjunction with MPI.
Definition: mpibuffer.hh:45
const DataType & operator[](size_t i) const
Provide access to the buffer data.
Definition: mpibuffer.hh:175
Definition: baseauxiliarymodule.hh:37
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
void resize(size_t newSize)
Set the size of the buffer.
Definition: mpibuffer.hh:74
size_t size() const
Returns the number of data objects in the buffer.
Definition: mpibuffer.hh:160
void wait()
Wait until the buffer was send to the peer completely.
Definition: mpibuffer.hh:101
DataType & operator[](size_t i)
Provide access to the buffer data.
Definition: mpibuffer.hh:166