19 #ifndef DUNE_COMMUNICATOR_HEADER_INCLUDED
20 #define DUNE_COMMUNICATOR_HEADER_INCLUDED
28 #include <dune/common/version.hh>
30 #include <dune/common/parallel/mpihelper.hh>
31 #if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 7)
32 #include <dune/common/parallel/communication.hh>
34 #include <dune/common/parallel/collectivecommunication.hh>
39 #if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 7)
40 #include <dune/common/parallel/mpicommunication.hh>
42 #include <dune/common/parallel/mpicollectivecommunication.hh>
51 typedef std::vector< char > BufferType;
53 mutable BufferType buffer_;
60 : buffer_(), factor_( factor )
70 size_t size()
const {
return buffer_.size(); }
75 buffer_.reserve(
size );
81 buffer_.resize(
size );
89 const size_t tsize =
sizeof( T );
90 size_t pos = buffer_.size();
91 const size_t sizeNeeded = pos + tsize ;
93 if( buffer_.capacity() < sizeNeeded )
95 reserve(
size_t(factor_ * sizeNeeded) ) ;
98 buffer_.resize( sizeNeeded );
100 std::copy_n(
reinterpret_cast<const char *
> (&value), tsize, buffer_.data()+pos );
103 void write(
const std::string& str)
105 int size = str.size();
107 for (
int k = 0; k <
size; ++k) {
117 const size_t tsize =
sizeof( T );
118 assert( pos_ + tsize <= buffer_.size() );
119 std::copy_n( buffer_.data()+pos_, tsize,
reinterpret_cast<char *
> (&value) );
123 void read( std::string& str)
const
128 for (
int k = 0; k <
size; ++k) {
136 return std::make_pair( buffer_.data(),
int(buffer_.size()) );
141 template <
class MsgBuffer >
152 typedef CollectiveCommunication< MPICommunicator > BaseType;
156 static const int messagetag = 234;
158 typedef std::map< int, int > linkage_t;
159 typedef std::vector< int > vector_t;
161 linkage_t sendLinkage_ ;
162 linkage_t recvLinkage_ ;
165 vector_t recvSource_ ;
167 mutable vector_t _recvBufferSizes;
168 mutable bool _recvBufferSizesComputed;
171 using BaseType :: rank;
172 using BaseType :: size;
185 virtual void localComputation () {}
201 inline int sendLinks ()
const {
return sendLinkage_.size(); }
204 inline int recvLinks ()
const {
return recvLinkage_.size(); }
212 assert (sendLinkage_.end () != sendLinkage_.find (rank)) ;
213 return (* sendLinkage_.find (rank)).second ;
219 assert (recvLinkage_.end () != recvLinkage_.find (rank)) ;
220 return (* recvLinkage_.find (rank)).second ;
224 const std::vector< int > &
sendDest ()
const {
return sendDest_; }
226 const std::vector< int > &
recvSource ()
const {
return recvSource_; }
232 virtual std::vector< MessageBufferType >
exchange (
const std::vector< MessageBufferType > &)
const;
235 virtual void exchange ( DataHandleInterface& )
const;
243 inline void computeDestinations(
const linkage_t& linkage, vector_t& dest );
246 static int getMessageTag(
const unsigned int increment )
248 static int tag = messagetag + 2 ;
250 const int retTag = tag;
256 tag = messagetag + 2 ;
262 static int getMessageTag()
264 return getMessageTag( 1 );
271 #include "p2pcommunicator_impl.hh"
Definition: p2pcommunicator.hh:177
Point-2-Point communicator for exchange messages between processes.
Definition: p2pcommunicator.hh:143
MsgBuffer MessageBufferType
type of message buffer used
Definition: p2pcommunicator.hh:149
int recvLinks() const
return number of processes we will receive data from
Definition: p2pcommunicator.hh:204
int recvLink(const int rank) const
return recv link number for a given recv rank number
Definition: p2pcommunicator.hh:217
MPIHelper::MPICommunicator MPICommunicator
type of MPI communicator, either MPI_Comm or NoComm as defined in MPIHelper
Definition: p2pcommunicator.hh:146
int sendLink(const int rank) const
return send link number for a given send rank number
Definition: p2pcommunicator.hh:210
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:201
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:190
const std::vector< int > & recvSource() const
return vector containing all process numbers we will receive from
Definition: p2pcommunicator.hh:226
const std::vector< int > & sendDest() const
return vector containing all process numbers we will send to
Definition: p2pcommunicator.hh:224
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
const vector_t & recvBufferSizes() const
return vector containing possible recv buffer sizes
Definition: p2pcommunicator.hh:207
Point2PointCommunicator(const BaseType &comm)
constructor taking collective communication
Definition: p2pcommunicator.hh:194
Definition: p2pcommunicator.hh:50
void resetReadPosition()
reset read position of buffer to beginning
Definition: p2pcommunicator.hh:68
size_t size() const
return size of buffer
Definition: p2pcommunicator.hh:70
void clear()
clear the buffer
Definition: p2pcommunicator.hh:66
void reserve(const size_t size)
reserve memory for 'size' entries
Definition: p2pcommunicator.hh:73
void resize(const size_t size)
resize buffer to 'size' entries
Definition: p2pcommunicator.hh:79
SimpleMessageBuffer(const double factor=1.1)
constructor taking memory reserve estimation factor (default is 1.1, i.e.
Definition: p2pcommunicator.hh:59
void read(T &value) const
read value from buffer, value must implement the operator= correctly (i.e.
Definition: p2pcommunicator.hh:114
void write(const T &value)
write value to buffer, value must implement the operator= correctly (i.e.
Definition: p2pcommunicator.hh:86
std::pair< char *, int > buffer() const
return pointer to buffer and size for use with MPI functions
Definition: p2pcommunicator.hh:134
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10