ug4
ug::CommunicationScheme< TDerived, TValue > Class Template Reference

CRTP Base class for communications on layout/interfaces. More...

#include <communication_scheme.h>

+ Inheritance diagram for ug::CommunicationScheme< TDerived, TValue >:

Public Member Functions

virtual bool collect (ug::BinaryBuffer &buff, const Interface &interface)
 send data on the interface based on TDerived::send More...
 
TDerived & derived ()
 get the derived class More...
 
virtual bool extract (ug::BinaryBuffer &buff, const Interface &interface)
 receive data on the interface and hand it over to TDerived::receive More...
 
virtual int get_required_buffer_size (const Interface &interface)
 get the size of the required buffer for an interface More...
 
- Public Member Functions inherited from pcl::ICommunicationPolicy< IndexLayout >
virtual bool begin_layout_collection (const Layout *pLayout)
 signals the beginning of a layout collection. More...
 
virtual bool begin_layout_extraction (const Layout *pLayout)
 signals the beginning of a layout extraction. More...
 
virtual void begin_level_extraction (int level)
 signals that a new layout-level will now be processed. More...
 
virtual bool end_layout_collection (const Layout *pLayout)
 signals the end of a layout collection More...
 
virtual bool end_layout_extraction (const Layout *pLayout)
 signals the end of a layout extraction More...
 
virtual ~ICommunicationPolicy ()
 

Additional Inherited Members

- Public Types inherited from pcl::ICommunicationPolicy< IndexLayout >
typedef Layout::Interface Interface
 
typedef IndexLayout Layout
 

Detailed Description

template<typename TDerived, typename TValue>
class ug::CommunicationScheme< TDerived, TValue >

CRTP Base class for communications on layout/interfaces.

CommunicationScheme is a base class for a recurring programming task: You want to send data over a layout/interface. Now you just need to specify what to to at each index on the receiver side, and on each index on the sender side Example with own CommunicationScheme

class AddCommunicationScheme : public CommunicationScheme<AddCommunicationScheme, double>
{
public:
AddCommunicationScheme(const std::vector<double> &v) : vec(v) {}
double send(int pid, size_t index) const { return vec[index]; }
void receive(int pid, size_t index, double val) { vec[index] += val; }
inline int get_element_size() const { return sizeof(double); }
private:
const std::vector<double> &vec;
};

to use it, you just need to write

AddCommunicationScheme scheme(vec);
CommunicateOnInterfaces(parallelCommunicator, masterLayout, slaveLayout, scheme);
void CommunicateOnInterfaces(pcl::InterfaceCommunicator< IndexLayout > &communicator, const IndexLayout &sendingLayout, const IndexLayout &receivingLayout, TCommunicationScheme &scheme)
sends data over a CommunicationScheme from a sendingLayout to a receivingLayout
Definition: communication_scheme.h:292

and all slave nodes have been added the master nodes. (here slaveLayout is the receiving, and masterLayout is the sending Scheme)

Example with StdArrayCommunicationScheme:

std::vector<int> vec;
// ... do sth with the vector on both processors
// transfer data from master to slave
StdArrayCommunicationScheme<std::vector<int> > arrScheme(vec)
CommunicateOnIntefaces(parallelCommunicator, masterLayout, slaveLayout, arrScheme);
// ... done.

Now all master nodes have overwritten the data on the slave nodes. note that instead of int you can use any type for there is Serialize/Deserialize, so also: string, map, int, char, double and so on. There is also a specialization for bool which uses only 1 bit for each bool.

Note
The derived class has to have the functions:
  • StdArrayCommunicationScheme
  • const TValue &send(int pid, size_t index) const
  • void receive(int pid, size_t index, value_type &v)
  • inline int get_element_size() const
Template Parameters
TDerivedDerived class
TValue

Member Function Documentation

◆ collect()

template<typename TDerived , typename TValue >
virtual bool ug::CommunicationScheme< TDerived, TValue >::collect ( ug::BinaryBuffer buff,
const Interface interface 
)
inlinevirtual

send data on the interface based on TDerived::send

collect

Parameters
buffBinaryBuffer to write data to
interfaceinterface to pid over which to send This function does the following
  • loop through the interface. serialize each item we get from TDerived::send(pid, index) to a buffer
  • send the buffer to process pid over InterfaceCommunicator com.

Implements pcl::ICommunicationPolicy< IndexLayout >.

References pcl::OrderedInterface< TType, TContainer, TAlloc >::begin(), ug::CommunicationScheme< TDerived, TValue >::derived(), pcl::OrderedInterface< TType, TContainer, TAlloc >::end(), pcl::OrderedInterface< TType, TContainer, TAlloc >::get_element(), pcl::OrderedInterface< TType, TContainer, TAlloc >::get_target_proc(), and ug::Serialize().

◆ derived()

◆ extract()

template<typename TDerived , typename TValue >
virtual bool ug::CommunicationScheme< TDerived, TValue >::extract ( ug::BinaryBuffer buff,
const Interface interface 
)
inlinevirtual

receive data on the interface and hand it over to TDerived::receive

extract

Parameters
buffBinaryBuffer with the data we received from processor pid.
interfaceinterface to processor pid This function does the following *
  • loop through the interface. deserialize each item from s, and hand it to TDerived::receive(pid, index, item)

Implements pcl::ICommunicationPolicy< IndexLayout >.

References pcl::OrderedInterface< TType, TContainer, TAlloc >::begin(), ug::CommunicationScheme< TDerived, TValue >::derived(), ug::Deserialize(), pcl::OrderedInterface< TType, TContainer, TAlloc >::end(), pcl::OrderedInterface< TType, TContainer, TAlloc >::get_element(), and pcl::OrderedInterface< TType, TContainer, TAlloc >::get_target_proc().

◆ get_required_buffer_size()

template<typename TDerived , typename TValue >
virtual int ug::CommunicationScheme< TDerived, TValue >::get_required_buffer_size ( const Interface interface)
inlinevirtual

get the size of the required buffer for an interface

get_required_buffer_size

Parameters
interfaceThe interface so we can calculate the size If TDerived can specify an exact size for each item it serializes, we can calculate the size of the buffer otherwise, it returns -1, and we return -1 -> Buffer size is sent.

Reimplemented from pcl::ICommunicationPolicy< IndexLayout >.

References ug::CommunicationScheme< TDerived, TValue >::derived(), s, and pcl::OrderedInterface< TType, TContainer, TAlloc >::size().


The documentation for this class was generated from the following file: