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
58 #error "what is happening here?"
63 #define __CommunicationBuffer_ALLOC_CHUNK 1024
102 int resize(std::size_t newSize);
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);
147 int givePackSize(MPI_Comm communicator, MPI_Datatype type, std::size_t size);
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);
246 virtual int resize(std::size_t newSize) = 0;
258 int read(
bool &data)
override;
261 int write(
bool data)
override;
279 virtual int iSend(
int dest,
int tag) = 0;
288 virtual int iRecv(
int source,
int tag, std::size_t count = 0) = 0;
328 int resize(std::size_t newSize)
override {
return MPIBuffer :: resize(newSize); }
330 void init()
override {
return MPIBuffer :: init(); }
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); }
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); }
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); }
363 int iSend(
int dest,
int tag)
override {
return MPIBuffer :: iSend(this->
communicator, dest, tag); }
365 int iRecv(
int source,
int tag, std::size_t count = 0)
override {
return MPIBuffer :: iRecv(this->
communicator, source, tag, count); }
369 int testCompletion(
int &source,
int &tag) {
return MPIBuffer :: testCompletion(source, tag); }
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
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
int givePackSizeOfInt(std::size_t count) override
int givePackSizeOfDouble(std::size_t count) override
CommunicationBuffer(MPI_Comm comm, std::size_t size, bool dynamic=0)
int givePackSizeOfChar(std::size_t count) override
CommunicationBuffer(MPI_Comm comm, bool dynamic=0)
Constructor. Creates empty buffer, using given communicator for packing.
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.
virtual ~CommunicationBuffer()
Destructor.
int givePackSizeOfBool(std::size_t count) override
int read(bool &data) override
Reads a bool value from data.
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.
std::size_t size
Size and current position in buffer in bytes (sizeof(char)).
MPIBuffer(std::size_t size, bool dynamic=0)
Constructor. Creates buffer of given size, using given communicator for packing.
bool isDynamic
Dynamic flag (if true, buffer can grow, but reallocation is needed).
MPI_Request giveRequest()
std::size_t givePosition()
std::size_t giveAvailableSpace()
int resize(std::size_t newSize)
int waitCompletion() override
int read(unsigned long *dest, std::size_t n) override
Reads count unsigned long values into array pointed by data.
int write(const double *src, std::size_t n) override
Writes count double values from array pointed by data.
int write(const char *src, std::size_t n) override
Writes count char values from array pointed by data.
StaticCommunicationBuffer(MPI_Comm comm, int size, bool dynamic=0)
void initForPacking() override
Initialize for packing.
int read(int *dest, std::size_t n) override
Reads count integer values into array pointed by data.
int write(const int *src, std::size_t n) override
Writes count integer values from array pointed by data.
int read(char *dest, std::size_t n) override
Reads count char values into array pointed by data.
int iSend(int dest, int tag) override
int read(double *dest, std::size_t n) override
Reads count double values into array pointed by data.
int iRecv(int source, int tag, std::size_t count=0) override
StaticCommunicationBuffer(MPI_Comm comm, bool dynamic=0)
Constructor. Creates empty buffer, using given communicator for packing.
int read(long *dest, std::size_t n) override
Reads count long values into array pointed by data.
void initForUnpacking() override
Initialize for Unpacking (data already received).
virtual ~StaticCommunicationBuffer()
Destructor.
int resize(std::size_t newSize) override
int testCompletion(int &source, int &tag)
int write(const long *src, std::size_t n) override
Writes count long values from array pointed by data.
int write(const unsigned long *src, std::size_t n) override
Writes count unsigned long values from array pointed by data.
int bcast(int root) override
int testCompletion() override