the frontier of a best-first search of \( p \) workers, a StealablePriorityQueue each, with the steals from random victims and the detection of the termination; with the bounds Bd of the pairs, if not void, ordered by BdLess
More...
#include <ADS/concurrent/StealablePriorityQueue.h>
|
| | StealingFrontier (std::size_t p, std::uint64_t seed=1, Less less=Less(), BdLess bl=BdLess()) |
| | the frontier of \( p \) empty queues, the victims drawn from the seed seed
|
| | StealingFrontier (const StealingFrontier &)=delete |
| | no copy, since the workers share it by its address
|
| StealingFrontier & | operator= (const StealingFrontier &)=delete |
| | no copy, since the workers share it by its address
|
| | ~StealingFrontier () |
| | the frees of the queues and of their offers
|
| std::size_t | workers (void) const |
| | the number of the workers, \( p \)
|
| Queue & | queue (std::size_t i) |
| | the queue of the worker \( i \)
|
| void | push (std::size_t i, K k, T x) |
| | pushes \( ( k , x ) \) into the queue of the worker \( i \)
|
| void | push (std::size_t i, K k, Bound b, T x) |
| | pushes \( ( k , b , x ) \), with the bound \( b \), into the queue of the worker \( i \)
|
| std::optional< Bound > | minBound (std::size_t i) const |
| | the least bound of the pairs that the worker \( i \) holds, its offer not yet claimed included, nothing if it holds none [see StealablePriorityQueue::minBound()]
|
| template<class F> |
| std::size_t | drain (std::size_t i, F &&f) |
| | the calls f( e ) on all the pairs that the worker \( i \) holds, its heaps and its offer not yet claimed, removed (e.g., the queue pruned whole when its minBound() cannot improve the incumbent); their number; the next pop( i ) then steals or ends
|
| void | serve (std::size_t i) |
| | lets the worker \( i \) answer a thief in a long computation
|
| std::optional< Entry > | pop (std::size_t i) |
| | the least pair of the queue of the worker \( i \), or of what it steals when its queue is empty; nothing when no worker holds a pair, or after stop(); the call ends the work of \( i \) on the pair that its previous call returned
|
| void | stop (void) |
| | ends the computation: from now on pop() returns nothing to every worker; any thread may call it
|
| bool | stopped (void) const |
| | whether stop() was called
|
| bool | terminated (void) const |
| | whether no worker holds a pair, i.e., \( C = 0 \)
|
| std::size_t | steals (void) const |
| | the steals that succeeded, summed over the workers, exact when no worker runs
|
| template<class E, class F> |
| void | run (E &ex, F &&f) |
| | the calls \( f( i ) \) of the \( p \) workers by ex.run( p , f ); the first exception of a call stops the others, through stop(), and is thrown again once all have returned
|
| template<class F> |
| std::size_t | leftovers (F &&f) |
| | the calls f( e ) on the pairs left in the queues, each taken back from its offer first, in increasing order of the keys in each queue; their number
|
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
class ADS::StealingFrontier< K, T, Less, Bd, BdLess >
the frontier of a best-first search of \( p \) workers, a StealablePriorityQueue each, with the steals from random victims and the detection of the termination; with the bounds Bd of the pairs, if not void, ordered by BdLess
◆ Bound
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
the type of the bounds, detail::SpqNoBound if none
◆ Entry
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
◆ Queue
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
◆ StealingFrontier() [1/2]
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
| ADS::StealingFrontier< K, T, Less, Bd, BdLess >::StealingFrontier |
( |
std::size_t | p, |
|
|
std::uint64_t | seed = 1, |
|
|
Less | less = Less(), |
|
|
BdLess | bl = BdLess() ) |
|
explicit |
the frontier of \( p \) empty queues, the victims drawn from the seed seed
- Precondition
- \( p \ge 1 \)
◆ StealingFrontier() [2/2]
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
| ADS::StealingFrontier< K, T, Less, Bd, BdLess >::StealingFrontier |
( |
const StealingFrontier< K, T, Less, Bd, BdLess > & | | ) |
|
|
delete |
no copy, since the workers share it by its address
◆ ~StealingFrontier()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
the frees of the queues and of their offers
◆ drain()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
template<class F>
the calls f( e ) on all the pairs that the worker \( i \) holds, its heaps and its offer not yet claimed, removed (e.g., the queue pruned whole when its minBound() cannot improve the incumbent); their number; the next pop( i ) then steals or ends
- Precondition
- \( i < p \)
◆ leftovers()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
template<class F>
the calls f( e ) on the pairs left in the queues, each taken back from its offer first, in increasing order of the keys in each queue; their number
- Precondition
- no worker calls the frontier
◆ minBound()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
the least bound of the pairs that the worker \( i \) holds, its offer not yet claimed included, nothing if it holds none [see StealablePriorityQueue::minBound()]
- Precondition
- \( i < p \)
◆ operator=()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
no copy, since the workers share it by its address
◆ pop()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
the least pair of the queue of the worker \( i \), or of what it steals when its queue is empty; nothing when no worker holds a pair, or after stop(); the call ends the work of \( i \) on the pair that its previous call returned
In pseudocode (beyond the book), \( C \) the counter of the workers at work and of the thieves trying, \( p \) at the start:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{pop}( i ) \cr
2 & \quad e \gets \mathrm{pop}( Q_i );\ \textbf{if}\ e \ne
\textbf{nil}\ \textbf{then return}\ e \cr
3 & \quad C \gets C - 1\quad \triangleright\ i \text{ holds nothing}
\cr
4 & \quad \textbf{loop} \cr
5 & \qquad \textbf{if}\ \text{stopped}\ \textbf{or}\ C = 0
\ \textbf{then return nil} \cr
6 & \qquad v \gets \text{a worker} \ne i \text{ at random} \cr
7 & \qquad \textbf{if}\ v \text{ offers, or holds two pairs at least}
\ \textbf{then} \cr
8 & \qquad\quad C \gets C + 1 \cr
9 & \qquad\quad \textbf{if}\ \mathrm{steal}( Q_i , Q_v ) > 0
\ \textbf{then return}\ \mathrm{pop}( Q_i ) \cr
10 & \qquad\quad C \gets C - 1 \cr
11 & \qquad \text{back off}
\end{array}}
\]
- Precondition
- \( i < p \)
◆ push() [1/2]
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
pushes \( ( k , b , x ) \), with the bound \( b \), into the queue of the worker \( i \)
- Precondition
- \( i < p \)
◆ push() [2/2]
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
pushes \( ( k , x ) \) into the queue of the worker \( i \)
- Precondition
- \( i < p \)
◆ queue()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
the queue of the worker \( i \)
- Precondition
- \( i < p \)
◆ run()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
template<class E, class F>
the calls \( f( i ) \) of the \( p \) workers by ex.run( p , f ); the first exception of a call stops the others, through stop(), and is thrown again once all have returned
- Precondition
- the executor runs \( p \) workers at the same time
◆ serve()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
lets the worker \( i \) answer a thief in a long computation
- Precondition
- \( i < p \)
◆ steals()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
the steals that succeeded, summed over the workers, exact when no worker runs
◆ stop()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
ends the computation: from now on pop() returns nothing to every worker; any thread may call it
◆ stopped()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
◆ terminated()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
whether no worker holds a pair, i.e., \( C = 0 \)
◆ workers()
template<class K, class T, class Less = std::less< K >, class Bd = void, class BdLess = std::less<>>
the number of the workers, \( p \)
The documentation for this class was generated from the following file: