33 #ifndef COMMUNICATION_SCHEME_H_
34 #define COMMUNICATION_SCHEME_H_
103 template<
typename TDerived,
typename TValue>
109 return static_cast<TDerived&
>(*this);
160 int s =
derived().get_element_size();
164 return s * interface.
size();
176 template<
typename TDerived>
180 TDerived&
derived() {
return static_cast<TDerived&
>(*this); }
218 bool b = a & (1 << j);
220 derived().receive(pid, index, b);
228 return sizeof(char) * (interface.
size()/8 + (interface.
size()%8==0?0:1) );
250 template<
typename TArray>
252 typename TArray::value_type >
291 template<
typename TCommunicationScheme>
302 scheme.collect(buff, interface);
306 scheme.get_required_buffer_size(interface) != -1);
309 int receivingLayoutSize=0;
311 receivingLayoutSize++;
317 scheme.get_required_buffer_size(receivingLayout.
interface(it)));
322 scheme.extract(bufs[i], receivingLayout.
interface(it));
325 template<
typename TCommunicationScheme>
330 template<
typename TCommunicationScheme>
346 template<
typename TSendingScheme,
typename TPIDs>
352 for(
size_t i=0; i<pids.size(); i++)
358 sender.collect(buff, interface);
361 communicator.
send_raw(pid, buff.buffer(), buff.write_pos(),
362 sender.get_required_buffer_size(interface) != -1);
377 template<
typename TPIDs,
typename TReceiveScheme>
382 for(
size_t i=0; i<pids.size(); i++)
383 communicator.
receive_raw(pids[i], bufs[i], receiver.get_required_buffer_size(layout.
interface(pids[i])));
387 for(
size_t i=0; i<pids.size(); i++)
388 receiver.extract(bufs[i], layout.
interface(pids[i]));
398 template<
typename TDerived,
typename TValue>
403 TDerived& derived() {
404 return static_cast<TDerived&
>(*this);
419 int pid = interface.get_target_proc();
424 if(derived().need_send(pid, index))
427 if(a)
Serialize(buff, derived().send(pid, index);
442 int pid = interface.get_target_proc();
451 derived().receive(pid, interface.get_element(iter), val);
463 get_required_buffer_size(
const Interface& interface)
465 int s = derived().get_element_size();
469 return s * interface.size();
specializations are responsible to pack and unpack interface data during communication.
Definition: pcl_communication_structs.h:790
Performs communication between interfaces on different processes.
Definition: pcl_interface_communicator.h:68
void send_raw(int targetProc, const void *pBuff, int bufferSize, bool bSizeKnownAtTarget=false)
sends raw data to a target-proc.
Definition: pcl_interface_communicator_impl.hpp:61
void receive_raw(int srcProc, ug::BinaryBuffer &bufOut, int bufSize=-1)
registers a binary-stream to receive data from a source-proc.
Definition: pcl_interface_communicator_impl.hpp:166
bool communicate(int tag=749345)
sends and receives the collected data.
Definition: pcl_interface_communicator_impl.hpp:409
You may add elements to this interface and iterate over them.
Definition: pcl_communication_structs.h:207
ElemContainer::const_iterator const_iterator
Definition: pcl_communication_structs.h:237
iterator end()
Definition: pcl_communication_structs.h:293
iterator begin()
Definition: pcl_communication_structs.h:292
Element & get_element(iterator iter)
Definition: pcl_communication_structs.h:298
int get_target_proc() const
Definition: pcl_communication_structs.h:309
size_t size() const
returns the number of elements that are stored in the interface.
Definition: pcl_communication_structs.h:306
iterator end(size_t level=0)
returns the iterator to the last interface of the layout.
Definition: pcl_communication_structs.h:492
iterator begin(size_t level=0)
returns the iterator to the first interface of the layout.
Definition: pcl_communication_structs.h:486
int proc_id(iterator iter) const
returns the target process of the interface given in iterator
Definition: pcl_communication_structs.h:509
Interface & interface(iterator iter)
returns the interface to the given iterator.
Definition: pcl_communication_structs.h:505
InterfaceMap::const_iterator const_iterator
Definition: pcl_communication_structs.h:477
A Buffer for binary data.
Definition: binary_buffer.h:56
char * buffer()
returns the raw buffer pointer or NULL if the buffer is empty (capacity() == 0)
Definition: binary_buffer_impl.h:94
size_t write_pos() const
returns the current write-pos (in bytes)
Definition: binary_buffer_impl.h:53
virtual bool collect(ug::BinaryBuffer &buff, const Interface &interface)
should write data which is associated with the interface elements to the buffer.
Definition: communication_scheme.h:183
TDerived & derived()
Definition: communication_scheme.h:180
virtual bool extract(ug::BinaryBuffer &buff, const Interface &interface)
extract data from the buffer and assigns it to the interface-elements.
Definition: communication_scheme.h:205
virtual int get_required_buffer_size(const Interface &interface)
returns the size of the buffer in bytes, that will be required for interface-communication.
Definition: communication_scheme.h:226
CRTP Base class for communications on layout/interfaces.
Definition: communication_scheme.h:105
TDerived & derived()
get the derived class
Definition: communication_scheme.h:108
virtual int get_required_buffer_size(const Interface &interface)
get the size of the required buffer for an interface
Definition: communication_scheme.h:158
virtual bool extract(ug::BinaryBuffer &buff, const Interface &interface)
receive data on the interface and hand it over to TDerived::receive
Definition: communication_scheme.h:139
virtual bool collect(ug::BinaryBuffer &buff, const Interface &interface)
send data on the interface based on TDerived::send
Definition: communication_scheme.h:121
Holds Interfaces and communicators for horizontal communication.
Definition: algebra_layouts.h:48
const pcl::ProcessCommunicator & proc_comm() const
returns process communicator
Definition: algebra_layouts.h:68
const IndexLayout & slave() const
Definition: algebra_layouts.h:63
const IndexLayout & master() const
Definition: algebra_layouts.h:61
Communication Scheme for synchronization of arrays or similar datastructures.
Definition: communication_scheme.h:253
StdArrayCommunicationScheme(TArray &t)
Definition: communication_scheme.h:256
TArray::value_type value_type
Definition: communication_scheme.h:254
int get_element_size() const
Definition: communication_scheme.h:271
const value_type & send(int pid, size_t index) const
Definition: communication_scheme.h:261
TArray & m_arr
Definition: communication_scheme.h:278
void receive(int pid, size_t index, value_type &v)
Definition: communication_scheme.h:266
Definition: stl_debug.h:45
void SendOnInterfaces(pcl::InterfaceCommunicator< IndexLayout > &communicator, TPIDs &pids, IndexLayout &layout, TSendingScheme &sender)
sends data over a interface based on a CommunicationScheme to a subgroup of processes
Definition: communication_scheme.h:347
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
void ReceiveOnInterfaces(pcl::InterfaceCommunicator< IndexLayout > &communicator, TPIDs &pids, IndexLayout &layout, TReceiveScheme &receiver)
receives data over a interface based on a CommunicationScheme on a subgroup of processes
Definition: communication_scheme.h:378
void CommunicateFromMasterToSlave(HorizontalAlgebraLayouts &layouts, TCommunicationScheme &scheme)
Definition: communication_scheme.h:331
void CommunicateFromSlaveToMaster(HorizontalAlgebraLayouts &layouts, TCommunicationScheme &scheme)
Definition: communication_scheme.h:326
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition: restart_bridge.cpp:112
void Serialize(TOStream &buf, const ParallelVector< T > &v)
Serialize for ParallelVector<T>
Definition: restart_bridge.cpp:103
T value_type
Definition: sparsematrix_interface.h:2
Definition: communication_policies.h:58