Graybat  1.1
Graph Approach for Highly Generic Communication Schemes Based on Adaptive Topologies
graybat::communicationPolicy::ZMQ Class Reference

Implementation of the Cage communicationPolicy interface based on ZMQ. More...

#include <ZMQ.hpp>

Inheritance diagram for graybat::communicationPolicy::ZMQ:
graybat::communicationPolicy::Base< ZMQ >

Public Types

using Tag = typename graybat::communicationPolicy::Tag< ZMQ >
 
using ContextID = typename graybat::communicationPolicy::ContextID< ZMQ >
 
using MsgType = typename graybat::communicationPolicy::MsgType< ZMQ >
 
using MsgID = typename graybat::communicationPolicy::MsgID< ZMQ >
 
using VAddr = typename graybat::communicationPolicy::VAddr< ZMQ >
 
using Context = typename graybat::communicationPolicy::Context< ZMQ >
 
using Event = typename graybat::communicationPolicy::Event< ZMQ >
 
using Config = typename graybat::communicationPolicy::Config< ZMQ >
 
using Uri = std::string
 
- Public Types inherited from graybat::communicationPolicy::Base< ZMQ >
using CommunicationPolicy = ZMQ
 
using VAddr = typename graybat::communicationPolicy::VAddr< CommunicationPolicy >
 
using Tag = typename graybat::communicationPolicy::Tag< CommunicationPolicy >
 
using Context = typename graybat::communicationPolicy::Context< CommunicationPolicy >
 
using Event = typename graybat::communicationPolicy::Event< CommunicationPolicy >
 

Public Member Functions

 ZMQ (Config const config)
 
 ZMQ (ZMQ &&other)=delete
 
 ZMQ (ZMQ &other)=delete
 
Point to Point Communication Interface
template<typename T_Send >
void send (const VAddr destVAddr, const Tag tag, const Context context, const T_Send &sendData)
 Blocking transmission of a message sendData to peer with virtual address destVAddr. More...
 
template<typename T_Send >
Event asyncSend (const VAddr destVAddr, const Tag tag, const Context context, T_Send &sendData)
 Non blocking transmission of a message sendData to peer with virtual address destVAddr. More...
 
template<typename T_Send >
void asyncSendImpl (const MsgType msgType, const MsgID msgID, const Context context, const VAddr destVAddr, const Tag tag, T_Send &sendData)
 
template<typename T_Recv >
void recv (const VAddr srcVAddr, const Tag tag, const Context context, T_Recv &recvData)
 Blocking receive of a message recvData from peer with virtual address srcVAddr. More...
 
template<typename T_Recv >
Event recv (const Context context, T_Recv &recvData)
 
template<typename T_Recv >
void recvImpl (const MsgType msgType, const Context context, const VAddr srcVAddr, const Tag tag, T_Recv &recvData)
 
template<typename T_Recv >
Event recvImpl (const Context context, T_Recv &recvData)
 
void wait (const MsgType msgID, const Context context, const VAddr vAddr, const Tag tag)
 
bool ready (const MsgType msgID, const Context context, const VAddr vAddr, const Tag tag)
 
Context Interface
Context splitContext (const bool isMember, const Context oldContext)
 
Context getGlobalContext ()
 Returns the context that contains all peers.
 
- Public Member Functions inherited from graybat::communicationPolicy::Base< ZMQ >
void send (const VAddr destVAddr, const Tag tag, const Context context, const T_Send &sendData)=delete
 
Event asyncSend (const VAddr destVAddr, const Tag tag, const Context context, const T_Send &sendData)=delete
 
void recv (const VAddr srcVAddr, const Tag tag, const Context context, T_Recv &recvData)=delete
 
Event recv (const Context context, T_Recv &recvData)=delete
 
Event asyncRecv (const VAddr srcVAddr, const Tag tag, const Context context, T_Recv &recvData)=delete
 
void gather (const VAddr rootVAddr, const Context context, const T_Send &sendData, T_Recv &recvData)
 Collects sendData from all peers of the context and transmits it as a list to the peer with rootVAddr. Data of all peers has to be from the same size. More...
 
void gatherVar (const VAddr rootVAddr, const Context context, const T_Send &sendData, T_Recv &recvData, std::vector< unsigned > &recvCount)
 Collects sendData from all members of the context with varying size and transmits it as a list to peer with rootVAddr. More...
 
void allGather (Context context, const T_Send &sendData, T_Recv &recvData)
 Collects sendData from all members of the context and transmits it as a list to every peer in the context More...
 
void allGatherVar (const Context context, const T_Send &sendData, T_Recv &recvData, std::vector< unsigned > &recvCount)
 Collects sendData from all peers of the context. Size of sendData can vary in size. The data is received by every peer in the context. More...
 
void scatter (const VAddr rootVAddr, const Context context, const T_Send &sendData, T_Recv &recvData)
 Distributes sendData from peer rootVAddr to all peers in context. Every peer will receive different data. More...
 
void allScatter (const Context context, const T_Send &sendData, T_Recv &recvData)
 Distributes sendData of all peer in the context to all peers in the context. Every peer will receive data from every other peer (also the own data) More...
 
void reduce (const VAddr rootVAddr, const Context context, const T_Op op, const T_Send &sendData, T_Recv &recvData)
 Performs a reduction with a binary operator op on all sendData elements from all peers whithin the context. The result will be received by the peer with rootVAddr. Binary operations like std::plus, std::minus can be used. But, they can also be defined as binary operator simular to std::plus etc. More...
 
void allReduce (const Context context, T_Op op, const T_Send &sendData, T_Recv &recvData)
 Performs a reduction with a binary operator op on all sendData elements from all peers whithin the context. The result will be received by all peers. More...
 
void broadcast (const VAddr rootVAddr, const Context context, T_SendRecv &data)
 Send sendData from peer rootVAddr to all peers in context. Every peer will receive the same data. More...
 
void synchronize (const Context context)
 Synchronizes all peers within context to the same point in the programm execution (barrier).
 

Public Attributes

::zmq::context_t zmqContext
 
::zmq::context_t zmqSignalingContext
 
::zmq::socket_t recvSocket
 
::zmq::socket_t signalingSocket
 
const int zmqHwm
 
Context initialContext
 
std::map< ContextID, std::map< VAddr, std::size_t > > sendSocketMappings
 
std::vector<::zmq::socket_t > sendSockets
 
std::map< ContextID, std::map< VAddr, Uri > > phoneBook
 
std::map< ContextID, std::map< Uri, VAddr > > inversePhoneBook
 
std::map< ContextID, Context > contexts
 
utils::MessageBox<::zmq::message_t, MsgType, ContextID, VAddr, TaginBox
 
unsigned maxMsgID
 
std::thread recvHandler
 
std::mutex sendMtx
 
std::mutex recvMtx
 
const Uri masterUri
 
const Uri peerUri
 

Static Public Attributes

static const MsgType VADDR_REQUEST = 0
 
static const MsgType VADDR_LOOKUP = 1
 
static const MsgType DESTRUCT = 2
 
static const MsgType RETRY = 3
 
static const MsgType ACK = 4
 
static const MsgType CONTEXT_INIT = 5
 
static const MsgType CONTEXT_REQUEST = 6
 
static const MsgType PEER = 7
 
static const MsgType CONFIRM = 8
 
static const MsgType SPLIT = 9
 

ZMQ Utility functions

ContextID getInitialContextID (::zmq::socket_t &socket, const size_t contextSize)
 
ContextID getContextID (::zmq::socket_t &socket)
 
VAddr getVAddr (::zmq::socket_t &socket, const ContextID contextID, const Uri uri)
 
Uri getUri (::zmq::socket_t &socket, const ContextID contextID, const VAddr vAddr)
 
MsgID getMsgID ()
 
template<typename T_Data >
void zmqMessageToData (::zmq::message_t &message, T_Data &data)
 
Uri bindToNextFreePort (::zmq::socket_t &socket, const std::string peerUri)
 
void handleRecv ()
 
static char * s_recv (::zmq::socket_t &socket)
 
static int s_send (::zmq::socket_t &socket, const char *string)
 

Detailed Description

Implementation of the Cage communicationPolicy interface based on ZMQ.

Member Function Documentation

template<typename T_Send >
Event graybat::communicationPolicy::ZMQ::asyncSend ( const VAddr  destVAddr,
const Tag  tag,
const Context  context,
T_Send &  sendData 
)
inline

Non blocking transmission of a message sendData to peer with virtual address destVAddr.

Parameters
[in]destVAddrVAddr of peer that will receive the message
[in]tagDescription of the message to better distinguish messages types
[in]contextContext in which both sender and receiver are included
[in]sendDataData reference of template type T will be. T need to provide the function data(), that returns the pointer to the data memory address. And the function size(), that return the amount of data elements to send. Notice, that std::vector and std::array implement this interface.
Returns
Event
template<typename T_Recv >
void graybat::communicationPolicy::ZMQ::recv ( const VAddr  srcVAddr,
const Tag  tag,
const Context  context,
T_Recv &  recvData 
)
inline

Blocking receive of a message recvData from peer with virtual address srcVAddr.

Parameters
[in]srcVAddrVAddr of peer that sended the message
[in]tagDescription of the message to better distinguish messages types
[in]contextContext in which both sender and receiver are included
[out]recvDataData reference of template type T will be received from sender peer. T need to provide the function data(), that returns the pointer to the data memory address. And the function size(), that return the amount of data elements to send. Notice, that std::vector and std::array implement this interface.
template<typename T_Send >
void graybat::communicationPolicy::ZMQ::send ( const VAddr  destVAddr,
const Tag  tag,
const Context  context,
const T_Send &  sendData 
)
inline

Blocking transmission of a message sendData to peer with virtual address destVAddr.

Parameters
[in]destVAddrVAddr of peer that will receive the message
[in]tagDescription of the message to better distinguish messages types
[in]contextContext in which both sender and receiver are included
[in]sendDataData reference of template type T will be send to receiver peer. T need to provide the function data(), that returns the pointer to the data memory address. And the function size(), that return the amount of data elements to send. Notice, that std::vector and std::array implement this interface.
Context graybat::communicationPolicy::ZMQ::splitContext ( const bool  isMember,
const Context  oldContext 
)
inline

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