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#if DUNE_VERSION_NEWER(DUNE_GRID, 2, 7)
153 using BaseType = Dune::Communication<MPICommunicator>;
155 using BaseType = CollectiveCommunication< MPICommunicator>;
160 static const int messagetag = 234;
162 typedef std::map< int, int > linkage_t;
163 typedef std::vector< int > vector_t;
165 linkage_t sendLinkage_ ;
166 linkage_t recvLinkage_ ;
169 vector_t recvSource_ ;
171 mutable vector_t _recvBufferSizes;
172 mutable bool _recvBufferSizesComputed;
175 using BaseType :: rank;
176 using BaseType :: size;
189 virtual void localComputation () {}
205 inline int sendLinks ()
const {
return sendLinkage_.size(); }
208 inline int recvLinks ()
const {
return recvLinkage_.size(); }
216 assert (sendLinkage_.end () != sendLinkage_.find (rank)) ;
217 return (* sendLinkage_.find (rank)).second ;
223 assert (recvLinkage_.end () != recvLinkage_.find (rank)) ;
224 return (* recvLinkage_.find (rank)).second ;
228 const std::vector< int > &
sendDest ()
const {
return sendDest_; }
230 const std::vector< int > &
recvSource ()
const {
return recvSource_; }
236 virtual std::vector< MessageBufferType >
exchange (
const std::vector< MessageBufferType > &)
const;
239 virtual void exchange ( DataHandleInterface& )
const;
247 inline void computeDestinations(
const linkage_t& linkage, vector_t& dest );
250 static int getMessageTag(
const unsigned int increment )
252 static int tag = messagetag + 2 ;
254 const int retTag = tag;
260 tag = messagetag + 2 ;
266 static int getMessageTag()
268 return getMessageTag( 1 );
275#include "p2pcommunicator_impl.hh"
Definition: p2pcommunicator.hh:181
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:208
int recvLink(const int rank) const
return recv link number for a given recv rank number
Definition: p2pcommunicator.hh:221
const std::vector< int > & sendDest() const
return vector containing all process numbers we will send to
Definition: p2pcommunicator.hh:228
const std::vector< int > & recvSource() const
return vector containing all process numbers we will receive from
Definition: p2pcommunicator.hh:230
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:214
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:205
const vector_t & recvBufferSizes() const
return vector containing possible recv buffer sizes
Definition: p2pcommunicator.hh:211
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:194
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:198
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
std::pair< char *, int > buffer() const
return pointer to buffer and size for use with MPI functions
Definition: p2pcommunicator.hh:134
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
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10