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

the inboxes as vectors under a lock, the portable baseline More...

#include <ADS/parallel/Channels.h>

Public types

using Message = Msg
 the type of the messages

Public member functions

 LockedChannels (std::size_t p)
 the inboxes of \( p \) workers
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 messages of \( m \) appended to the inbox of to under its lock, all of them
template<class F>
std::size_t drain (std::size_t me, F &&f)
 the calls f( x ) on the messages of the inbox of me, in the order of their pushes, and their number
ChannelPort< LockedChannels > port (std::size_t i)
 the channels seen by the worker \( i \)

Static public attributes

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

Detailed description

template<class Msg, class Lock = std::mutex>
class ADS::LockedChannels< Msg, Lock >

the inboxes as vectors under a lock, the portable baseline

Member typedef documentation

◆ Message

template<class Msg, class Lock = std::mutex>
using ADS::LockedChannels< Msg, Lock >::Message = Msg

the type of the messages

Constructor and destructor documentation

◆ LockedChannels()

template<class Msg, class Lock = std::mutex>
ADS::LockedChannels< Msg, Lock >::LockedChannels ( std::size_t p)
inlineexplicit

the inboxes of \( p \) workers

Precondition
\( p \ge 1 \)

Member function documentation

◆ drain()

template<class Msg, class Lock = std::mutex>
template<class F>
std::size_t ADS::LockedChannels< Msg, Lock >::drain ( std::size_t me,
F && f )
inline

the calls f( x ) on the messages of the inbox of me, in the order of their pushes, and their number

In pseudocode (beyond the book), \( W \) an empty vector of me:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{drain}( \mathit{me} , f ) \cr 2 & \quad \textbf{if}\ \text{the published size is } 0\ \textbf{then} \ \textbf{return}\ 0\quad \triangleright\ \text{no lock taken} \cr 3 & \quad \text{under the lock of } \mathit{me} \text{: swap } V_{\mathit{me}} \text{ and } W \text{, and publish } 0 \cr 4 & \quad \textbf{foreach}\ x \in W\ \textbf{do}\ f( x ) \cr 5 & \quad \textbf{return}\ |W| \text{, after emptying } W \end{array}} \]

Precondition
me is a worker

◆ port()

template<class Msg, class Lock = std::mutex>
ChannelPort< LockedChannels > ADS::LockedChannels< Msg, Lock >::port ( std::size_t i)
inlinenodiscard

the channels seen by the worker \( i \)

◆ size()

template<class Msg, class Lock = std::mutex>
std::size_t ADS::LockedChannels< Msg, Lock >::size ( void ) const
inlinenodiscard

the number \( p \) of the workers

◆ tryPush()

template<class Msg, class Lock = std::mutex>
std::size_t ADS::LockedChannels< Msg, Lock >::tryPush ( std::size_t from,
std::size_t to,
std::span< const Msg > m )
inline

the messages of \( m \) appended to the inbox of to under its lock, all of them

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{tryPush}( \mathit{from} , \mathit{to} , m ) \cr 2 & \quad \text{under the lock of } \mathit{to} \text{: append } m \text{ to its vector } V_{\mathit{to}} \text{, and publish } |V_{\mathit{to}}| \cr 3 & \quad \textbf{return}\ |m| \end{array}} \]

Precondition
from and to are workers

Member data documentation

◆ bounded

template<class Msg, class Lock = std::mutex>
bool ADS::LockedChannels< Msg, Lock >::bounded = false
staticconstexpr

whether a push may push fewer messages than given


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