OOFEM 3.0
Loading...
Searching...
No Matches
combuff.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 combuff_h
36#define combuff_h
37
38#include "oofemenv.h"
39#include "datastream.h"
40#include "parallel.h"
41
42namespace oofem {
43
44#include <stdint.h>
45#include <limits.h>
46
47#if SIZE_MAX == UCHAR_MAX
48 #define my_MPI_SIZE_T MPI_UNSIGNED_CHAR
49#elif SIZE_MAX == USHRT_MAX
50 #define my_MPI_SIZE_T MPI_UNSIGNED_SHORT
51#elif SIZE_MAX == UINT_MAX
52 #define my_MPI_SIZE_T MPI_UNSIGNED
53#elif SIZE_MAX == ULONG_MAX
54 #define my_MPI_SIZE_T MPI_UNSIGNED_LONG
55#elif SIZE_MAX == ULLONG_MAX
56 #define my_MPI_SIZE_T MPI_UNSIGNED_LONG_LONG
57#else
58 #error "what is happening here?"
59#endif
60
61
62
63 #define __CommunicationBuffer_ALLOC_CHUNK 1024
68typedef char ComBuff_BYTE_TYPE;
69
71{
72protected:
74 std::size_t size, curr_pos;
84 MPI_Request request;
85
86public:
88 MPIBuffer(std::size_t size, bool dynamic = 0);
90 MPIBuffer(bool dynamic = 0);
92 virtual ~MPIBuffer();
93
102 int resize(std::size_t newSize);
106 virtual void init();
107
109 std::size_t giveSize() { return size; }
111 std::size_t giveAvailableSpace() { return ( size - curr_pos ); }
115 MPI_Request giveRequest() { return this->request; }
116
126 int packArray(MPI_Comm communicator, const void *src, std::size_t n, MPI_Datatype type);
135 int unpackArray(MPI_Comm communicator, void *dest, std::size_t n, MPI_Datatype type);
136
137
140
147 int givePackSize(MPI_Comm communicator, MPI_Datatype type, std::size_t size);
149
152
159 virtual int iSend(MPI_Comm communicator, int dest, int tag);
169 virtual int iRecv(MPI_Comm communicator, int source, int tag, std::size_t count = 0);
177 int testCompletion();
187 int testCompletion(int &source, int &tag);
196 virtual int waitCompletion();
205 int bcast(MPI_Comm communicator, int root);
206
207 void dump();
208
209private:
211 std::size_t givePosition() { return curr_pos; }
212};
213
214
228{
229protected:
230 MPI_Comm communicator;
231public:
232 CommunicationBuffer(MPI_Comm comm, std::size_t size, bool dynamic = 0) : communicator(comm) { }
234 CommunicationBuffer(MPI_Comm comm, bool dynamic = 0) : communicator(comm) { }
237
246 virtual int resize(std::size_t newSize) = 0;
250 virtual void init() = 0;
251
253 virtual void initForPacking() = 0;
255 virtual void initForUnpacking() = 0;
256
257 using DataStream::read;
258 int read(bool &data) override;
259
260 using DataStream::write;
261 int write(bool data) override;
262
263 int givePackSizeOfInt(std::size_t count) override;
264 int givePackSizeOfDouble(std::size_t count) override;
265 int givePackSizeOfChar(std::size_t count) override;
266 int givePackSizeOfBool(std::size_t count) override;
267 int givePackSizeOfLong(std::size_t count) override;
268 int givePackSizeOfSizet(std::size_t count) override;
269
270
273
279 virtual int iSend(int dest, int tag) = 0;
288 virtual int iRecv(int source, int tag, std::size_t count = 0) = 0;
296 virtual int testCompletion() = 0;
305 virtual int waitCompletion() = 0;
313 virtual int bcast(int root) = 0;
315};
316
317
319{
320public:
321 StaticCommunicationBuffer(MPI_Comm comm, int size, bool dynamic = 0) : CommunicationBuffer(comm, size, dynamic),
322 MPIBuffer(size, dynamic) { }
323
324 StaticCommunicationBuffer(MPI_Comm comm, bool dynamic = 0) : CommunicationBuffer(comm, dynamic), MPIBuffer(dynamic) { }
327
328 int resize(std::size_t newSize) override { return MPIBuffer :: resize(newSize); }
329
330 void init() override { return MPIBuffer :: init(); }
331 void initForPacking() override { this->init(); }
332 void initForUnpacking() override { this->init(); }
333
335 int write(const int *src, std::size_t n) override
336 { return MPIBuffer :: packArray(this->communicator, src, n, MPI_INT); }
337 int write(const long *src, std::size_t n) override
338 { return MPIBuffer :: packArray(this->communicator, src, n, MPI_LONG); }
339 int write(const unsigned long *src, std::size_t n) override
340 { return MPIBuffer :: packArray(this->communicator, src, n, MPI_UNSIGNED_LONG); }
341 int write(const double *src, std::size_t n) override
342 { return MPIBuffer :: packArray(this->communicator, src, n, MPI_DOUBLE); }
343 int write(const char *src, std::size_t n) override
344 { return MPIBuffer :: packArray(this->communicator, src, n, MPI_CHAR); }
345
347 int read(int *dest, std::size_t n) override
348 { return MPIBuffer :: unpackArray(this->communicator, dest, n, MPI_INT); }
349 int read(long *dest, std::size_t n) override
350 { return MPIBuffer :: unpackArray(this->communicator, dest, n, MPI_LONG); }
351 int read(unsigned long *dest, std::size_t n) override
352 { return MPIBuffer :: unpackArray(this->communicator, dest, n, MPI_UNSIGNED_LONG); }
353 int read(double *dest, std::size_t n) override
354 { return MPIBuffer :: unpackArray(this->communicator, dest, n, MPI_DOUBLE); }
355 int read(char *dest, std::size_t n) override
356 { return MPIBuffer :: unpackArray(this->communicator, dest, n, MPI_CHAR); }
357
358 #ifdef _MSC_VER
359 int read(std::size_t* data, std::size_t count) override { return MPIBuffer :: unpackArray(this->communicator, data, count, my_MPI_SIZE_T); }
360 int write(const std::size_t* data, std::size_t count) override { return MPIBuffer :: packArray(this->communicator, data, count, my_MPI_SIZE_T); }
361 #endif
362
363 int iSend(int dest, int tag) override { return MPIBuffer :: iSend(this->communicator, dest, tag); }
364
365 int iRecv(int source, int tag, std::size_t count = 0) override { return MPIBuffer :: iRecv(this->communicator, source, tag, count); }
366
367 int testCompletion() override { return MPIBuffer :: testCompletion(); }
368
369 int testCompletion(int &source, int &tag) { return MPIBuffer :: testCompletion(source, tag); }
370
371 int waitCompletion() override { return MPIBuffer :: waitCompletion(); }
372
373 int bcast(int root) override { return MPIBuffer :: bcast(this->communicator, root); }
374};
375} // end namespace oofem
376
377#endif // combuff_h
virtual int iRecv(int source, int tag, std::size_t count=0)=0
virtual int iSend(int dest, int tag)=0
int givePackSizeOfLong(std::size_t count) override
Definition combuff.C:307
virtual int resize(std::size_t newSize)=0
virtual void initForPacking()=0
Initialize for packing.
virtual int bcast(int root)=0
int givePackSizeOfSizet(std::size_t count) override
Definition combuff.C:314
int givePackSizeOfInt(std::size_t count) override
Definition combuff.C:279
int givePackSizeOfDouble(std::size_t count) override
Definition combuff.C:286
CommunicationBuffer(MPI_Comm comm, std::size_t size, bool dynamic=0)
Definition combuff.h:232
int givePackSizeOfChar(std::size_t count) override
Definition combuff.C:293
CommunicationBuffer(MPI_Comm comm, bool dynamic=0)
Constructor. Creates empty buffer, using given communicator for packing.
Definition combuff.h:234
virtual void initForUnpacking()=0
Initialize for Unpacking (data already received).
virtual int testCompletion()=0
virtual int waitCompletion()=0
int write(bool data) override
Writes a bool value.
Definition combuff.C:273
virtual ~CommunicationBuffer()
Destructor.
Definition combuff.h:236
int givePackSizeOfBool(std::size_t count) override
Definition combuff.C:300
int read(bool &data) override
Reads a bool value from data.
Definition combuff.C:265
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.
ComBuff_BYTE_TYPE * buff
Buffer. Dynamically allocated.
Definition combuff.h:78
virtual void init()
Definition combuff.C:114
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
std::size_t giveSize()
Definition combuff.h:109
bool isDynamic
Dynamic flag (if true, buffer can grow, but reallocation is needed).
Definition combuff.h:76
MPI_Request giveRequest()
Definition combuff.h:115
std::size_t givePosition()
Definition combuff.h:211
MPI_Request request
Definition combuff.h:84
std::size_t giveAvailableSpace()
Definition combuff.h:111
std::size_t curr_pos
Definition combuff.h:74
int resize(std::size_t newSize)
Definition combuff.C:78
int read(unsigned long *dest, std::size_t n) override
Reads count unsigned long values into array pointed by data.
Definition combuff.h:351
int write(const double *src, std::size_t n) override
Writes count double values from array pointed by data.
Definition combuff.h:341
int write(const char *src, std::size_t n) override
Writes count char values from array pointed by data.
Definition combuff.h:343
StaticCommunicationBuffer(MPI_Comm comm, int size, bool dynamic=0)
Definition combuff.h:321
void initForPacking() override
Initialize for packing.
Definition combuff.h:331
int read(int *dest, std::size_t n) override
Reads count integer values into array pointed by data.
Definition combuff.h:347
int write(const int *src, std::size_t n) override
Writes count integer values from array pointed by data.
Definition combuff.h:335
int read(char *dest, std::size_t n) override
Reads count char values into array pointed by data.
Definition combuff.h:355
int iSend(int dest, int tag) override
Definition combuff.h:363
int read(double *dest, std::size_t n) override
Reads count double values into array pointed by data.
Definition combuff.h:353
int iRecv(int source, int tag, std::size_t count=0) override
Definition combuff.h:365
StaticCommunicationBuffer(MPI_Comm comm, bool dynamic=0)
Constructor. Creates empty buffer, using given communicator for packing.
Definition combuff.h:324
int read(long *dest, std::size_t n) override
Reads count long values into array pointed by data.
Definition combuff.h:349
void initForUnpacking() override
Initialize for Unpacking (data already received).
Definition combuff.h:332
virtual ~StaticCommunicationBuffer()
Destructor.
Definition combuff.h:326
int resize(std::size_t newSize) override
Definition combuff.h:328
int testCompletion(int &source, int &tag)
Definition combuff.h:369
int write(const long *src, std::size_t n) override
Writes count long values from array pointed by data.
Definition combuff.h:337
int write(const unsigned long *src, std::size_t n) override
Writes count unsigned long values from array pointed by data.
Definition combuff.h:339
int bcast(int root) override
Definition combuff.h:373
#define my_MPI_SIZE_T
Definition combuff.h:48
char ComBuff_BYTE_TYPE
Definition combuff.h:68
#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