ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::MeshChannels< Msg > Class Template Reference

the \( p^2 \) bounded queues of the pairs of workers [see SPSCQueue.h] More...

#include <ADS/parallel/Channels.h>

Public types

using Message = Msg
 the type of the messages

Public member functions

 MeshChannels (std::size_t p, std::size_t c=1024)
 the \( p^2 \) queues of \( p \) workers, of capacity \( c \) each
std::size_t size (void) const
 the number \( p \) of the workers
std::size_t tryPush (std::size_t from, std::size_t to, std::span< const Msg > m)
 the first messages of \( m \) that fit in the queue from from to to, pushed by one store of its tail, and their number
template<class F>
std::size_t drain (std::size_t me, F &&f)
 the calls f( x ) on the messages of the \( p \) queues to me, from a sender that turns at each call, and their number
ChannelPort< MeshChannels > port (std::size_t i)
 the channels seen by the worker \( i \)

Static public attributes

static constexpr bool bounded = true
 whether a push may push fewer messages than given

Detailed description

template<class Msg>
class ADS::MeshChannels< Msg >

the \( p^2 \) bounded queues of the pairs of workers [see SPSCQueue.h]

Member typedef documentation

◆ Message

template<class Msg>
using ADS::MeshChannels< Msg >::Message = Msg

the type of the messages

Constructor and destructor documentation

◆ MeshChannels()

template<class Msg>
ADS::MeshChannels< Msg >::MeshChannels ( std::size_t p,
std::size_t c = 1024 )
inlineexplicit

the \( p^2 \) queues of \( p \) workers, of capacity \( c \) each

Precondition
\( p \ge 1 \), \( c \ge 2 \) a power of 2

Member function documentation

◆ drain()

template<class Msg>
template<class F>
std::size_t ADS::MeshChannels< Msg >::drain ( std::size_t me,
F && f )
inline

the calls f( x ) on the messages of the \( p \) queues to me, from a sender that turns at each call, and their number

In pseudocode (beyond the book), \( s \) the first sender of me:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{drain}( \mathit{me} , f ) \cr 2 & \quad n \gets 0 \cr 3 & \quad \textbf{for}\ j \gets 0\ \textbf{to}\ p - 1\ \textbf{do} \ n \gets n + \mathrm{consume}( Q_{( s + j ) \bmod p , \mathit{me}} , f ) \cr 4 & \quad s \gets ( s + 1 ) \bmod p;\ \textbf{return}\ n \end{array}} \]

Precondition
me is a worker

◆ port()

template<class Msg>
ChannelPort< MeshChannels > ADS::MeshChannels< Msg >::port ( std::size_t i)
inlinenodiscard

the channels seen by the worker \( i \)

◆ size()

template<class Msg>
std::size_t ADS::MeshChannels< Msg >::size ( void ) const
inlinenodiscard

the number \( p \) of the workers

◆ tryPush()

template<class Msg>
std::size_t ADS::MeshChannels< Msg >::tryPush ( std::size_t from,
std::size_t to,
std::span< const Msg > m )
inline

the first messages of \( m \) that fit in the queue from from to to, pushed by one store of its tail, and their number

In pseudocode (beyond the book), \( Q_{\mathit{from} , \mathit{to}} \) the queue of the pair:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{tryPush}( \mathit{from} , \mathit{to} , m ) \cr 2 & \quad \textbf{return}\ \mathrm{pushMany}( Q_{\mathit{from} , \mathit{to}} , m ) \end{array}} \]

Precondition
from and to are workers

Member data documentation

◆ bounded

template<class Msg>
bool ADS::MeshChannels< Msg >::bounded = true
staticconstexpr

whether a push may push fewer messages than given


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