the inboxes as vectors under a lock, the portable baseline
More...
#include <ADS/parallel/Channels.h>
|
| using | Message = Msg |
| | the type of the messages
|
|
| | 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 constexpr bool | bounded = false |
| | whether a push may push fewer messages than given
|
template<class Msg, class Lock = std::mutex>
class ADS::LockedChannels< Msg, Lock >
the inboxes as vectors under a lock, the portable baseline
◆ Message
template<class Msg, class Lock = std::mutex>
◆ LockedChannels()
template<class Msg, class Lock = std::mutex>
the inboxes of \( p \) workers
- Precondition
- \( p \ge 1 \)
◆ drain()
template<class Msg, class Lock = std::mutex>
template<class F>
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>
the channels seen by the worker \( i \)
◆ size()
template<class Msg, class Lock = std::mutex>
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
◆ bounded
template<class Msg, class Lock = std::mutex>
whether a push may push fewer messages than given
The documentation for this class was generated from the following file: