OOFEM 3.0
Loading...
Searching...
No Matches
dyncombuff.h
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#ifndef dyncombuff_h
36#define dyncombuff_h
37
38#include "parallel.h"
39#include "combuff.h"
40#include <list>
41
42namespace oofem {
43class IntArray;
44class FloatArray;
45class FloatMatrix;
46
47 #define __CommunicationPacket_DEFAULT_SIZE 40960
48
59
61{
62protected:
63 int number;
65
66public:
67
68 #ifdef __USE_MPI
70 CommunicationPacket(MPI_Comm comm, std::size_t size, int num);
72 CommunicationPacket(MPI_Comm comm, int num);
73 #endif
75 virtual ~CommunicationPacket();
76
80 virtual void init(MPI_Comm comm);
81
84 #ifdef __USE_MPI
92 int iSend(MPI_Comm communicator, int dest, int tag) override;
102 int iRecv(MPI_Comm communicator, int source, int tag, std::size_t count = 0) override;
110 virtual int testCompletion();
119 int waitCompletion() override;
120 #endif
122
123 void setNumber(int _num) { this->number = _num; }
124 void setEOFFlag() { this->EOF_Flag = true; }
125 int getNumber() { return number; }
126 bool hasEOFFlag() { return EOF_Flag; }
127
129 int packHeader(MPI_Comm);
130 int unpackHeader(MPI_Comm);
131};
132
134{
135private:
136 std :: list< CommunicationPacket * >available_packets;
137 std :: list< CommunicationPacket * >leased_packets;
138
140public:
145 this->clear();
146 }
147
148 CommunicationPacket *popPacket(MPI_Comm);
149 void pushPacket(CommunicationPacket *);
150
151 void printInfo();
152
153private:
154 void clear();
155};
156
157
159{
160protected:
161 std :: list< CommunicationPacket * >packet_list;
163 std :: list< CommunicationPacket * > :: iterator recvIt;
169
176public:
178 DynamicCommunicationBuffer(MPI_Comm comm, std::size_t size, bool dynamic = 0);
180 DynamicCommunicationBuffer(MPI_Comm comm, bool dynamic = 0);
183
184 int resize(std::size_t newSize) override { return 1; }
185 void init() override;
186
188 void initForPacking() override;
190 void initForUnpacking() override;
191
192 int write(const int *src, std::size_t n) override
193 { return __write(src, n, MPI_INT); }
194 int write(const long *src, std::size_t n) override
195 { return __write(src, n, MPI_LONG); }
196 int write(const unsigned long *src, std::size_t n) override
197 { return __write(src, n, MPI_UNSIGNED_LONG); }
198 int write(const double *src, std::size_t n) override
199 { return __write(src, n, MPI_DOUBLE); }
200 int write(const char *src, std::size_t n) override
201 { return __write(src, n, MPI_CHAR); }
202
203 int read(int *dest, std::size_t n) override
204 { return __read(dest, n, MPI_INT); }
205 int read(long *dest, std::size_t n) override
206 { return __read(dest, n, MPI_LONG); }
207 int read(unsigned long *dest, std::size_t n) override
208 { return __read(dest, n, MPI_UNSIGNED_LONG); }
209 int read(double *dest, std::size_t n) override
210 { return __read(dest, n, MPI_DOUBLE); }
211 int read(char *dest, std::size_t n) override
212 { return __read(dest, n, MPI_CHAR); }
213
214
215 int iSend(int dest, int tag) override;
216 int iRecv(int source, int tag, std::size_t count = 0) override;
217 int bcast(int root) override;
218
226 int testCompletion() override;
235 int waitCompletion() override;
236
237
238 static void printInfo() { packetPool.printInfo(); }
239
240protected:
241 CommunicationPacket *allocateNewPacket(int);
242 void freePacket(CommunicationPacket *);
243
244 int receiveCompleted();
245 int sendCompleted();
246
247 void popNewRecvPacket();
248 void pushNewRecvPacket(CommunicationPacket *);
249
250 void clear();
251 int giveFitSize(MPI_Datatype type, int availableSpace, int arrySize);
252
258 template< class T > int __write(T *src, int n, MPI_Datatype type) {
259 int _result = 1;
260 int start_indx = 0, end_indx, _size;
261 int remaining_size = n;
262
263 do {
264 _size = this->giveFitSize(type, active_packet->giveAvailableSpace(), remaining_size);
265 end_indx = start_indx + _size;
266
267 if ( _size ) {
268 _result &= active_packet->packArray(communicator, src + start_indx, _size, type);
269 }
270
271 if ( end_indx >= n ) {
272 break;
273 }
274
275 // active packet full, allocate a new one
277 packet_list.push_back(active_packet);
278 start_indx = end_indx;
279 remaining_size -= _size;
280 } while ( 1 );
281
282 return _result;
283 }
284
290 template< class T > int __read(T *dest, int n, MPI_Datatype type) {
291 int _result = 1;
292 int start_indx = 0, end_indx, _size;
293 int remaining_size = n;
294
295 do {
296 _size = this->giveFitSize(type, active_packet->giveAvailableSpace(), remaining_size);
297 end_indx = start_indx + _size;
298
299 if ( _size ) {
300 _result &= active_packet->unpackArray(communicator, dest + start_indx, _size, type);
301 }
302
303 if ( end_indx >= n ) {
304 break;
305 }
306
307 // active packet exhausted, pop a new one
308 this->popNewRecvPacket();
309 start_indx = end_indx;
310 remaining_size -= _size;
311 } while ( 1 );
312
313 return _result;
314 }
315};
316} // end namespace oofem
317
318#endif // dyncombuff_h
CommunicationBuffer(MPI_Comm comm, std::size_t size, bool dynamic=0)
Definition combuff.h:232
std ::list< CommunicationPacket * > available_packets
Definition dyncombuff.h:136
std ::list< CommunicationPacket * > leased_packets
Definition dyncombuff.h:137
virtual void init(MPI_Comm comm)
Definition dyncombuff.C:66
int waitCompletion() override
Definition dyncombuff.C:110
CommunicationPacket(MPI_Comm comm, std::size_t size, int num)
Constructor. Creates buffer of given size, using given communicator for packing.
Definition dyncombuff.C:43
int iSend(MPI_Comm communicator, int dest, int tag) override
Definition dyncombuff.C:75
int iRecv(MPI_Comm communicator, int source, int tag, std::size_t count=0) override
Definition dyncombuff.C:84
virtual int testCompletion()
Definition dyncombuff.C:101
int write(const long *src, std::size_t n) override
Writes count long values from array pointed by data.
Definition dyncombuff.h:194
DynamicCommunicationBuffer(MPI_Comm comm, std::size_t size, bool dynamic=0)
Constructor. Creates buffer of given size, using given communicator for packing.
Definition dyncombuff.C:151
int __read(T *dest, int n, MPI_Datatype type)
Definition dyncombuff.h:290
int read(int *dest, std::size_t n) override
Reads count integer values into array pointed by data.
Definition dyncombuff.h:203
std::list< CommunicationPacket * >::iterator recvIt
Iterator to iterate over received packets.
Definition dyncombuff.h:163
int resize(std::size_t newSize) override
Definition dyncombuff.h:184
int write(const double *src, std::size_t n) override
Writes count double values from array pointed by data.
Definition dyncombuff.h:198
int write(const unsigned long *src, std::size_t n) override
Writes count unsigned long values from array pointed by data.
Definition dyncombuff.h:196
int read(unsigned long *dest, std::size_t n) override
Reads count unsigned long values into array pointed by data.
Definition dyncombuff.h:207
int active_tag
Active rank and tag (send by initSend,initReceive, and initExchange).
Definition dyncombuff.h:167
CommunicationPacket * active_packet
Active packet.
Definition dyncombuff.h:165
int write(const char *src, std::size_t n) override
Writes count char values from array pointed by data.
Definition dyncombuff.h:200
int write(const int *src, std::size_t n) override
Writes count integer values from array pointed by data.
Definition dyncombuff.h:192
int read(long *dest, std::size_t n) override
Reads count long values into array pointed by data.
Definition dyncombuff.h:205
int giveFitSize(MPI_Datatype type, int availableSpace, int arrySize)
Definition dyncombuff.C:381
static CommunicationPacketPool packetPool
Static packet pool.
Definition dyncombuff.h:173
int __write(T *src, int n, MPI_Datatype type)
Definition dyncombuff.h:258
bool completed
Communication completion flag.
Definition dyncombuff.h:175
int read(char *dest, std::size_t n) override
Reads count char values into array pointed by data.
Definition dyncombuff.h:211
std ::list< CommunicationPacket * > packet_list
Definition dyncombuff.h:161
int read(double *dest, std::size_t n) override
Reads count double values into array pointed by data.
Definition dyncombuff.h:209
CommunicationPacket * allocateNewPacket(int)
Definition dyncombuff.C:399
std::size_t size
Size and current position in buffer in bytes (sizeof(char)).
Definition combuff.h:74
MPIBuffer(std::size_t size, bool dynamic=0)
Constructor. Creates buffer of given size, using given communicator for packing.
Definition combuff.C:46
#define OOFEM_EXPORT
Definition oofemcfg.h:7

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011