19#ifndef DUNE_COMMUNICATOR_HEADER_INCLUDED
20#define DUNE_COMMUNICATOR_HEADER_INCLUDED
28#include <dune/common/parallel/mpihelper.hh>
29#include <dune/common/parallel/communication.hh>
33#include <dune/common/parallel/mpicommunication.hh>
40 typedef std::vector< char > BufferType;
42 mutable BufferType buffer_;
49 : buffer_(), factor_( factor )
59 size_t size()
const {
return buffer_.size(); }
64 buffer_.reserve(
size );
70 buffer_.resize(
size );
78 const size_t tsize =
sizeof( T );
79 size_t pos = buffer_.size();
80 const size_t sizeNeeded = pos + tsize ;
82 if( buffer_.capacity() < sizeNeeded )
84 reserve(
size_t(factor_ * sizeNeeded) ) ;
87 buffer_.resize( sizeNeeded );
89 std::copy_n(
reinterpret_cast<const char *
> (&value), tsize, buffer_.data()+pos );
92 void write(
const std::string& str)
94 int size = str.size();
96 for (
int k = 0; k <
size; ++k) {
106 const size_t tsize =
sizeof( T );
107 assert( pos_ + tsize <= buffer_.size() );
108 std::copy_n( buffer_.data()+pos_, tsize,
reinterpret_cast<char *
> (&value) );
112 void read( std::string& str)
const
117 for (
int k = 0; k <
size; ++k) {
125 return std::make_pair( buffer_.data(),
int(buffer_.size()) );
130 template <
class MsgBuffer >
141 using BaseType = Dune::Communication<MPICommunicator>;
145 static const int messagetag = 234;
147 typedef std::map< int, int > linkage_t;
148 typedef std::vector< int > vector_t;
150 linkage_t sendLinkage_ ;
151 linkage_t recvLinkage_ ;
154 vector_t recvSource_ ;
156 mutable vector_t _recvBufferSizes;
157 mutable bool _recvBufferSizesComputed;
160 using BaseType :: rank;
161 using BaseType :: size;
174 virtual void localComputation () {}
190 inline int sendLinks ()
const {
return sendLinkage_.size(); }
193 inline int recvLinks ()
const {
return recvLinkage_.size(); }
201 assert (sendLinkage_.end () != sendLinkage_.find (rank)) ;
202 return (* sendLinkage_.find (rank)).second ;
208 assert (recvLinkage_.end () != recvLinkage_.find (rank)) ;
209 return (* recvLinkage_.find (rank)).second ;
213 const std::vector< int > &
sendDest ()
const {
return sendDest_; }
215 const std::vector< int > &
recvSource ()
const {
return recvSource_; }
221 virtual std::vector< MessageBufferType >
exchange (
const std::vector< MessageBufferType > &)
const;
224 virtual void exchange ( DataHandleInterface& )
const;
232 inline void computeDestinations(
const linkage_t& linkage, vector_t& dest );
235 int getMessageTag(
const unsigned int increment)
const
237 const int retTag = this->tag_;
238 this->generateNextMessageTag(increment);
243 int getMessageTag()
const
245 return this->getMessageTag(1u);
249 mutable int tag_{messagetag + 2};
251 void generateNextMessageTag(
const unsigned int increment)
const
253 this->tag_ += increment;
257 if (this->tag_ >= (1 << 15) - 1)
259 this->tag_ = messagetag + 2;
267#include "p2pcommunicator_impl.hh"
Definition p2pcommunicator.hh:166
Point-2-Point communicator for exchange messages between processes.
Definition p2pcommunicator.hh:132
int recvLinks() const
return number of processes we will receive data from
Definition p2pcommunicator.hh:193
int recvLink(const int rank) const
return recv link number for a given recv rank number
Definition p2pcommunicator.hh:206
const std::vector< int > & sendDest() const
return vector containing all process numbers we will send to
Definition p2pcommunicator.hh:213
const std::vector< int > & recvSource() const
return vector containing all process numbers we will receive from
Definition p2pcommunicator.hh:215
int sendLink(const int rank) const
return send link number for a given send rank number
Definition p2pcommunicator.hh:199
virtual void exchangeCached(DataHandleInterface &) const
exchange data with peers, handle defines pack and unpack of data, if receive buffers are known from p...
Definition p2pcommunicator_impl.hh:619
int sendLinks() const
return number of processes we will send data to
Definition p2pcommunicator.hh:190
const vector_t & recvBufferSizes() const
return vector containing possible recv buffer sizes
Definition p2pcommunicator.hh:196
MsgBuffer MessageBufferType
type of message buffer used
Definition p2pcommunicator.hh:138
virtual std::vector< MessageBufferType > exchange(const std::vector< MessageBufferType > &) const
exchange message buffers with peers defined by inserted linkage
Definition p2pcommunicator_impl.hh:599
Point2PointCommunicator(const MPICommunicator &mpiComm=MPIHelper::getCommunicator())
constructor taking mpi communicator
Definition p2pcommunicator.hh:179
MPIHelper::MPICommunicator MPICommunicator
type of MPI communicator, either MPI_Comm or NoComm as defined in MPIHelper
Definition p2pcommunicator.hh:135
void insertRequest(const std::set< int > &sendLinks, const std::set< int > &recvLinks)
insert communication request with a set os ranks to send to and a set of ranks to receive from
Definition p2pcommunicator_impl.hh:59
void removeLinkage()
remove stored linkage
Definition p2pcommunicator_impl.hh:30
Point2PointCommunicator(const BaseType &comm)
constructor taking collective communication
Definition p2pcommunicator.hh:183
Definition p2pcommunicator.hh:39
void resetReadPosition()
reset read position of buffer to beginning
Definition p2pcommunicator.hh:57
size_t size() const
return size of buffer
Definition p2pcommunicator.hh:59
std::pair< char *, int > buffer() const
return pointer to buffer and size for use with MPI functions
Definition p2pcommunicator.hh:123
void clear()
clear the buffer
Definition p2pcommunicator.hh:55
void reserve(const size_t size)
reserve memory for 'size' entries
Definition p2pcommunicator.hh:62
void resize(const size_t size)
resize buffer to 'size' entries
Definition p2pcommunicator.hh:68
SimpleMessageBuffer(const double factor=1.1)
constructor taking memory reserve estimation factor (default is 1.1, i.e.
Definition p2pcommunicator.hh:48
void read(T &value) const
read value from buffer, value must implement the operator= correctly (i.e.
Definition p2pcommunicator.hh:103
void write(const T &value)
write value to buffer, value must implement the operator= correctly (i.e.
Definition p2pcommunicator.hh:75
Copyright 2019 Equinor AS.
Definition CartesianIndexMapper.hpp:10