WARPXM v1.10.0
Loading...
Searching...
No Matches
wxmsgtmpl.h
Go to the documentation of this file.
1#ifndef wxmsgtmpl_h
2#define wxmsgtmpl_h
3
4#include <mpi.h>
5
6// std includes
7#include <vector>
8
19{
20};
22
26template<typename T> class WxMsgTmpl
27{
28public:
32 virtual ~WxMsgTmpl()
33 {
34 delete[] _sendBuff;
35 delete[] _recvBuff;
36 }
37
45 virtual void send(unsigned num, const T* array, unsigned recvRank, int tag) const = 0;
46
52 virtual void finishSend(WxMsgStatus ms) const = 0;
53
63 virtual WxMsgStatus
64 startSend(unsigned num, const T* arr, unsigned recvRank, int tag) const = 0;
65
73 virtual void
74 recv(unsigned num, std::vector<T>& array, unsigned sendRank, int tag) const = 0;
75
83 virtual void recv(unsigned num, T* array, unsigned sendRank, int tag) const = 0;
84
92 virtual WxMsgStatus
93 startRecv(unsigned num, unsigned sendRank, int tag = -1) const = 0;
94
104 virtual WxMsgStatus
105 startRecv(unsigned num, T* arr, unsigned sendRank, int tag = -1) const = 0;
106
115 virtual void allReduce(unsigned num, T* sendBuff, T* recvBuff, MPI_Op op) const = 0;
116
117 virtual void broadcast(unsigned num, T* buffer, int root) const = 0;
118
119protected:
124 {
125 }
126
135 void resizeArray(T*& array, unsigned& numElem, unsigned reqNumElem) const
136 {
137 if (numElem < reqNumElem)
138 {
139 // delete old array and allocate new memory
140 delete[] array;
141 array = new T[reqNumElem];
142 }
143 // set number of elements
144 numElem = reqNumElem;
145 return;
146 }
147
153 void resizeSendBuff(unsigned reqSize)
154 {
155 if (_sendSize < reqSize)
156 {
157 // delete old array and allocate new memory
158 delete[] _sendBuff;
159 _sendSize = reqSize;
160 _sendBuff = new T[_sendSize];
161 }
162 return;
163 }
164
170 void resizeRecvBuff(unsigned reqSize)
171 {
172 if (_recvSize < reqSize)
173 {
174 delete[] _recvBuff;
175 _recvSize = reqSize;
176 _recvBuff = new T[_recvSize];
177 }
178 return;
179 }
180
181 unsigned _sendSize;
182 T* _sendBuff; // buffer for sending
183
184 unsigned _recvSize;
185 T* _recvBuff; // buffer for receiving
186};
187
189#endif // wxmsgtmpl_h
Provides interface for messaging between processes.
Definition: wxmsgtmpl.h:27
virtual void recv(unsigned num, std::vector< T > &array, unsigned sendRank, int tag) const =0
Receive an array from another rank.
void resizeArray(T *&array, unsigned &numElem, unsigned reqNumElem) const
Resizes a array.
Definition: wxmsgtmpl.h:135
virtual void recv(unsigned num, T *array, unsigned sendRank, int tag) const =0
Receive an array from another rank.
WxMsgTmpl()
Protected so only children can make instances.
Definition: wxmsgtmpl.h:123
virtual void finishSend(WxMsgStatus ms) const =0
Finish the send started by startSend.
virtual WxMsgStatus startRecv(unsigned num, unsigned sendRank, int tag=-1) const =0
Receive an array from another rank.
virtual void broadcast(unsigned num, T *buffer, int root) const =0
virtual WxMsgStatus startSend(unsigned num, const T *arr, unsigned recvRank, int tag) const =0
Send an array to another rank.
unsigned _sendSize
Definition: wxmsgtmpl.h:181
virtual ~WxMsgTmpl()
Destructor.
Definition: wxmsgtmpl.h:32
virtual void allReduce(unsigned num, T *sendBuff, T *recvBuff, MPI_Op op) const =0
Reduce data to all ranks.
void resizeSendBuff(unsigned reqSize)
Checks the buffer and resizes it if necessary.
Definition: wxmsgtmpl.h:153
virtual WxMsgStatus startRecv(unsigned num, T *arr, unsigned sendRank, int tag=-1) const =0
Receive an array from another rank.
T * _recvBuff
Definition: wxmsgtmpl.h:185
T * _sendBuff
Definition: wxmsgtmpl.h:182
void resizeRecvBuff(unsigned reqSize)
Checks the buffer and resizes it if necessary.
Definition: wxmsgtmpl.h:170
virtual void send(unsigned num, const T *array, unsigned recvRank, int tag) const =0
Send an array to another rank.
unsigned _recvSize
Definition: wxmsgtmpl.h:184
WxMsgStatus_v * WxMsgStatus
Definition: wxmsgtmpl.h:21
Provides a means for derived messengers to return implimentation specific message status flags and da...
Definition: wxmsgtmpl.h:19