OOFEM 3.0
Loading...
Searching...
No Matches
processcomm.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 processcomm_h
36#define processcomm_h
37
38#include <cstdint>
39#include "oofemenv.h"
40#include "combuff.h"
41#include "commbufftype.h"
42#include "communicatormode.h"
43#include "floatmatrix.h"
44#include "floatarray.h"
45#include "intarray.h"
46#include "error.h"
47#include "logger.h"
48
49#include <string>
50#include <memory>
51
52namespace oofem {
67{
68protected:
70 std::unique_ptr<CommunicationBuffer> send_buff;
72 std::unique_ptr<CommunicationBuffer> recv_buff;
73public:
76
77 int givePackSizeOfInt(std::size_t count) override { return send_buff->givePackSizeOfInt(count); }
78 int givePackSizeOfDouble(std::size_t count) override { return send_buff->givePackSizeOfDouble(count); }
79 int givePackSizeOfChar(std::size_t count) override { return send_buff->givePackSizeOfChar(count); }
80 int givePackSizeOfBool(std::size_t count) override { return send_buff->givePackSizeOfBool(count); }
81 int givePackSizeOfLong(std::size_t count) override { return send_buff->givePackSizeOfLong(count); }
82 int givePackSizeOfSizet(std::size_t count) override { return send_buff->givePackSizeOfSizet(count); }
83
84
86 int write(const int *data, std::size_t count) override { return send_buff->write(data, count); }
87 int write(const long *data, std::size_t count) override { return send_buff->write(data, count); }
88 int write(const unsigned long *data, std::size_t count) override { return send_buff->write(data, count); }
89 int write(const double *data, std::size_t count) override { return send_buff->write(data, count); }
90 int write(const char *data, std::size_t count) override { return send_buff->write(data, count); }
91 int write(bool data) override { return send_buff->write(data); }
92
93 using DataStream::read;
94 int read(int *data, std::size_t count) override { return this->recv_buff->read(data, count); }
95 int read(long *data, std::size_t count) override { return this->recv_buff->read(data, count); }
96 int read(unsigned long *data, std::size_t count) override { return this->recv_buff->read(data, count); }
97 int read(double *data, std::size_t count) override { return this->recv_buff->read(data, count); }
98 int read(char *data, std::size_t count) override { return this->recv_buff->read(data, count); }
99 int read(bool &data) override { return recv_buff->read(data); }
100
102 void initSendBuff() { send_buff->init(); }
104 void initRecvBuff() { recv_buff->init(); }
106 void init() {
107 initSendBuff();
108 initRecvBuff();
109 }
110
112 void initForPacking() { send_buff->initForPacking(); }
114 void initForUnpacking() { recv_buff->initForUnpacking(); }
115
123 int initExchange(int rank, int tag) {
124 int result = 1;
125 result &= initSend(rank, tag);
126 result &= initReceive(rank, tag);
127
128 return result;
129 }
130
137 int initSend(int rank, int tag) { return send_buff->iSend(rank, tag); }
145 int initReceive(int rank, int tag) { return recv_buff->iRecv(rank, tag); }
146
150 void clearBuffers() { }
151
152 void resizeSendBuffer(std::size_t size) { send_buff->resize(size); }
153 void resizeReceiveBuffer(std::size_t size) { recv_buff->resize(size); }
154
157 int sendCompleted() { return send_buff->testCompletion(); }
158 int receiveCompleted() { return recv_buff->testCompletion(); }
159 int testCompletion() { return ( send_buff->testCompletion() && recv_buff->testCompletion() ); }
160 int waitCompletion() { return ( send_buff->waitCompletion() && recv_buff->waitCompletion() ); }
162
171};
172
173
180{
181protected:
183 int rank; // remote problem id = rank
184
187
194
195public:
204
208 int giveRank() { return rank; }
209
212 if ( pcBuffer ) {
213 return pcBuffer;
214 }
215
216 OOFEM_ERROR("ProcessCommunicatorBuff undefined");
217 return NULL;
218 }
219
220
224 const IntArray &giveToSendMap() { return toSend; }
228 const IntArray &giveToRecvMap() { return toReceive; }
229
230
241 template< class T > void setToSendArry(T *emodel, const IntArray &src, int packUnpackType);
252 template< class T > void setToRecvArry(T *emodel, const IntArray &src, int packUnpackType);
260 template< class T > int packData( T *emodel, int ( T :: *packFunc )( ProcessCommunicator & ) )
261 {
262 if ( !toSend.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
263 giveProcessCommunicatorBuff()->initForPacking();
264 return ( emodel->*packFunc )(* this);
265 } else {
266 return 1;
267 }
268 }
269
277 template< class T, class P > int packData( T *emodel, P *src, int ( T :: *packFunc )( P *, ProcessCommunicator & ) )
278 {
279 if ( !toSend.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
280 giveProcessCommunicatorBuff()->initForPacking();
281 return ( emodel->*packFunc )(src, * this);
282 } else {
283 return 1;
284 }
285 }
286
293 template< class T > int unpackData( T *emodel, int ( T :: *unpackFunc )( ProcessCommunicator & ) )
294 {
295 if ( !toReceive.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
296 giveProcessCommunicatorBuff()->initForUnpacking();
297 return ( emodel->*unpackFunc )(* this);
298 } else {
299 return 1;
300 }
301 }
302
310 template< class T, class P > int unpackData( T *emodel, P *dest, int ( T :: *unpackFunc )( P *, ProcessCommunicator & ) )
311 {
312 if ( !toReceive.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
313 giveProcessCommunicatorBuff()->initForUnpacking();
314 return ( emodel->*unpackFunc )(dest, * this);
315 } else {
316 return 1;
317 }
318 }
319
325 int initExchange(int tag);
332 int initSend(int tag);
339 int initReceive(int tag);
341 int finishExchange();
342
343
346 int sendCompleted();
347 int receiveCompleted();
348 int testCompletion();
349 int waitCompletion();
350
352
353 void clearBuffers();
354
355private:
365 template< class T > int resizeSendBuff(T *emodel, int packUnpackType);
375 template< class T > int resizeRecvBuff(T *emodel, int packUnpackType);
376};
377
378template< class T > void
379ProcessCommunicator :: setToSendArry(T *emodel, const IntArray &src, int packUnpackType)
380{
381 toSend = src;
382 // toSend.sort (&NlDEIDynamicDomainComunicator::nodeSortFunct);
383 //sortCommMap (toSend);
384 resizeSendBuff(emodel, packUnpackType);
385}
386
387
388template< class T > void
389ProcessCommunicator :: setToRecvArry(T *emodel, const IntArray &src, int packUnpackType)
390{
391 toReceive = src;
392 //toReceive.sort (&NlDEIDynamicDomainComunicator::nodeSortFunct);
393 //sortCommMap (toReceive);
394 resizeRecvBuff(emodel, packUnpackType);
395}
396
397
398template< class T > int
399ProcessCommunicator :: resizeSendBuff(T *emodel, int packUnpackType)
400{
401 int size;
402 // determine space for send buffer
403 size = emodel->estimateMaxPackSize(toSend, giveProcessCommunicatorBuff()->giveSendBuff(), packUnpackType);
404 giveProcessCommunicatorBuff()->resizeSendBuffer(size);
405 //giveSendBuff()->resize (size);
406 return 1;
407}
408
409
410template< class T > int
411ProcessCommunicator :: resizeRecvBuff(T *emodel, int packUnpackType)
412{
413 int size;
414
415 // determine space for recv buffer
416 size = emodel->estimateMaxPackSize(toReceive, giveProcessCommunicatorBuff()->giveRecvBuff(), packUnpackType);
417 giveProcessCommunicatorBuff()->resizeReceiveBuffer(size);
418 //giveRecvBuff()->resize (size);
419
420 return 1;
421}
422} // end namespace oofem
423#endif // processcomm_h
virtual int read(int *data, std::size_t count)=0
Reads count integer values into array pointed by data.
virtual int write(const int *data, std::size_t count)=0
Writes count integer values from array pointed by data.
int givePackSizeOfBool(std::size_t count) override
Definition processcomm.h:80
int read(unsigned long *data, std::size_t count) override
Reads count unsigned long values into array pointed by data.
Definition processcomm.h:96
void resizeReceiveBuffer(std::size_t size)
int read(long *data, std::size_t count) override
Reads count long values into array pointed by data.
Definition processcomm.h:95
ProcessCommunicatorBuff(CommBuffType t)
Constructor, creates empty send and receive com buffs in MPI_COMM_WORLD.
Definition processcomm.C:45
CommunicationBuffer & giveRecvBuff()
int givePackSizeOfSizet(std::size_t count) override
Definition processcomm.h:82
int initExchange(int rank, int tag)
int write(const char *data, std::size_t count) override
Writes count char values from array pointed by data.
Definition processcomm.h:90
void init()
Initializes receiver buffers.
int givePackSizeOfDouble(std::size_t count) override
Definition processcomm.h:78
int read(int *data, std::size_t count) override
Reads count integer values into array pointed by data.
Definition processcomm.h:94
int givePackSizeOfLong(std::size_t count) override
Definition processcomm.h:81
int write(const unsigned long *data, std::size_t count) override
Writes count unsigned long values from array pointed by data.
Definition processcomm.h:88
void initSendBuff()
Initializes send buffer to empty state. All packed data are lost.
std::unique_ptr< CommunicationBuffer > recv_buff
Receive buffer.
Definition processcomm.h:72
int initReceive(int rank, int tag)
int initSend(int rank, int tag)
std::unique_ptr< CommunicationBuffer > send_buff
Send buffer.
Definition processcomm.h:70
int read(bool &data) override
Reads a bool value from data.
Definition processcomm.h:99
int read(double *data, std::size_t count) override
Reads count double values into array pointed by data.
Definition processcomm.h:97
CommunicationBuffer & giveSendBuff()
int write(bool data) override
Writes a bool value.
Definition processcomm.h:91
void initForUnpacking()
Initialize for Unpacking (data already received).
void resizeSendBuffer(std::size_t size)
void initForPacking()
Initialize for packing.
int givePackSizeOfInt(std::size_t count) override
Definition processcomm.h:77
int givePackSizeOfChar(std::size_t count) override
Definition processcomm.h:79
int write(const long *data, std::size_t count) override
Writes count long values from array pointed by data.
Definition processcomm.h:87
int read(char *data, std::size_t count) override
Reads count char values into array pointed by data.
Definition processcomm.h:98
void initRecvBuff()
Initializes send buffer to empty state. All packed data are lost.
int write(const int *data, std::size_t count) override
Writes count integer values from array pointed by data.
Definition processcomm.h:86
int write(const double *data, std::size_t count) override
Writes count double values from array pointed by data.
Definition processcomm.h:89
IntArray toReceive
Nodes to receive.
const IntArray & giveToRecvMap()
ProcessCommunicatorBuff * giveProcessCommunicatorBuff()
Returns communication buffer.
int unpackData(T *emodel, int(T ::*unpackFunc)(ProcessCommunicator &))
int packData(T *emodel, P *src, int(T ::*packFunc)(P *, ProcessCommunicator &))
int resizeRecvBuff(T *emodel, int packUnpackType)
IntArray toSend
Nodes to send.
ProcessCommunicatorBuff * pcBuffer
Communicator buffers representation.
CommunicatorMode mode
Mode.
ProcessCommunicator(ProcessCommunicatorBuff *b, int irank, CommunicatorMode m=CommMode_Static)
Definition processcomm.C:57
int unpackData(T *emodel, P *dest, int(T ::*unpackFunc)(P *, ProcessCommunicator &))
int rank
Associated partition (problem) number (rank).
const IntArray & giveToSendMap()
int packData(T *emodel, int(T ::*packFunc)(ProcessCommunicator &))
int resizeSendBuff(T *emodel, int packUnpackType)
#define OOFEM_ERROR(...)
Definition error.h:79
#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