ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ParallelGreedy.h

The greedy algorithms on graphs in parallel, beyond the book, by the deterministic reservations of speculativeFor() on the threads of an executor. More...

Files

file  ADS/parallel/ParallelGreedy.h
 The greedy algorithms on graphs in parallel, beyond the book, by the deterministic reservations of speculativeFor() [see SpeculativeFor.h] on the threads of an executor [see Executor.h]: each gives exactly the result of the sequential greedy algorithm on the same order of the edges or of the nodes, on every executor and whatever the number of its threads (see Deterministic reservations, greedy algorithms).

Functions

std::vector< int > ADS::randomOrder (int n, unsigned long long seed)
 a random permutation of \( [ 0 , n ) \) from the seed, the same on every machine (the shuffle of Fisher and Yates on a SplitMix64 generator)
template<Executor E, class W>
std::vector< int > ADS::parallelKruskal (E &ex, int n, const std::vector< WeightedEdge< W > > &A)
 the places in \( A \) of the edges of the minimum spanning forest that Kruskal gives on the order \( ( w , \mathit{place} ) \), in that order
template<Executor E, class W>
std::vector< int > ADS::filterKruskal (E &ex, int n, const std::vector< WeightedEdge< W > > &A)
 the forest of parallelKruskal() above, by filter-Kruskal
template<Executor E>
std::vector< int > ADS::spanningForest (E &ex, int n, const std::vector< std::pair< int, int > > &A)
 the places in \( A \) of the edges of the spanning forest of the greedy algorithm in the order of \( A \), increasing
template<Executor E, class W, ArcLayout AL>
std::vector< int > ADS::maximalIndependentSet (E &ex, const StaticGraph< W, AL > &g, const std::vector< int > &pi)
 the nodes of the greedy maximal independent set of \( g \) in the order \( \pi \) (the node \( \pi[ 0 ] \) first), increasing
template<Executor E>
std::vector< int > ADS::maximalMatching (E &ex, int n, const std::vector< std::pair< int, int > > &A, const std::vector< int > &pi)
 the places in \( A \) of the edges of the greedy maximal matching in the order \( \pi \) of the edges (the edge \( A[ \pi[ 0 ] ] \) first), increasing

Detailed description

The greedy algorithms on graphs in parallel, beyond the book, by the deterministic reservations of speculativeFor() on the threads of an executor.

The definitions, the invariants and the costs of the area are in Theory of parallelism.

Function documentation

◆ filterKruskal()

template<Executor E, class W>
std::vector< int > ADS::filterKruskal ( E & ex,
int n,
const std::vector< WeightedEdge< W > > & A )
nodiscard

the forest of parallelKruskal() above, by filter-Kruskal

In pseudocode (Osipov, Sanders and Singler, beyond the book), with \( I \) the edges still to scan, all of them at first:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{filterKruskal}( I ) \cr 2 & \quad \textbf{if}\ |I| \le \max( 4096 , 2 n )\ \textbf{then} \ \mathrm{parallelKruskal}( I );\ \textbf{return} \cr 3 & \quad p \gets \text{the median of 1023 edges of } I \text{, evenly spaced, by } ( w( e ) , e ) \cr 4 & \quad I_< \gets \{ e \in I : e < p \};\ I_\ge \gets I \setminus I_< \quad \triangleright\ \text{two parallel filters} \cr 5 & \quad \mathrm{filterKruskal}( I_< ) \cr 6 & \quad I_\ge \gets \{ [ u , v ] \in I_\ge : \mathrm{find}( u ) \ne \mathrm{find}( v ) \} \quad \triangleright\ \text{a parallel filter} \cr 7 & \quad \mathrm{filterKruskal}( I_\ge ) \end{array}} \]

Precondition
\( n \ge 0 \), the ends of the edges in \( [ 0 , n ) \)
Postcondition
the forest of the sequential greedy algorithm (audit)

◆ maximalIndependentSet()

template<Executor E, class W, ArcLayout AL>
std::vector< int > ADS::maximalIndependentSet ( E & ex,
const StaticGraph< W, AL > & g,
const std::vector< int > & pi )
nodiscard

the nodes of the greedy maximal independent set of \( g \) in the order \( \pi \) (the node \( \pi[ 0 ] \) first), increasing

In pseudocode (Blelloch, Fineman and Shun, beyond the book), the two steps of the node \( v = \pi[ i ] \); a node never waits for a later one, so that no reservation is needed:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{reserve}( i ) \cr 2 & \quad s \gets \mathrm{IN} \cr 3 & \quad \textbf{foreach}\ u \in g.\mathrm{adj}( v )\ \textbf{with} \ \pi^{-1}( u ) < i\ \textbf{do} \cr 4 & \qquad \textbf{if}\ \mathit{state}[ u ] = \mathrm{IN}\ \textbf{then} \ s \gets \mathrm{OUT};\ \textbf{break} \cr 5 & \qquad \textbf{if}\ \mathit{state}[ u ] = \mathrm{UNDECIDED} \ \textbf{then}\ s \gets \mathrm{UNDECIDED} \cr 6 & \quad \mathit{next}[ v ] \gets s;\ \textbf{return}\ \textbf{true} \cr 7 & \textbf{function}\ \mathrm{commit}( i ) \cr 8 & \quad \mathit{state}[ v ] \gets \mathit{next}[ v ];\ \textbf{return} \ \mathit{state}[ v ] \ne \mathrm{UNDECIDED} \end{array}} \]

Precondition
\( g \) is unoriented, \( \pi \) is a permutation of its nodes
Postcondition
the set of the sequential greedy algorithm (audit)

◆ maximalMatching()

template<Executor E>
std::vector< int > ADS::maximalMatching ( E & ex,
int n,
const std::vector< std::pair< int, int > > & A,
const std::vector< int > & pi )
nodiscard

the places in \( A \) of the edges of the greedy maximal matching in the order \( \pi \) of the edges (the edge \( A[ \pi[ 0 ] ] \) first), increasing

In pseudocode (Blelloch, Fineman and Shun, beyond the book), the two steps of the edge \( [ u , v ] = A[ \pi[ i ] ] \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{reserve}( i ) \cr 2 & \quad \textbf{if}\ u = v \textbf{ or } u \text{ is matched} \textbf{ or } v \text{ is matched}\ \textbf{then}\ \textbf{return} \ \textbf{false} \cr 3 & \quad \mathrm{reserve}( R[ u ] , i );\ \mathrm{reserve}( R[ v ] , i ); \ \textbf{return}\ \textbf{true} \cr 4 & \textbf{function}\ \mathrm{commit}( i ) \cr 5 & \quad \textbf{if}\ R[ v ] \text{ holds } i\ \textbf{then} \ \text{free } R[ v ] \cr 6 & \qquad \textbf{if}\ R[ u ] \text{ holds } i\ \textbf{then} \ \text{free } R[ u ];\ \text{match } u \text{ and } v; \ \textbf{return}\ \textbf{true} \cr 7 & \quad \textbf{else}\ \text{free } R[ u ] \text{ if it holds } i \cr 8 & \quad \textbf{return}\ \textbf{false} \quad \triangleright \ \text{tried again} \end{array}} \]

Precondition
\( n \ge 0 \), the ends of the edges in \( [ 0 , n ) \), \( \pi \) is a permutation of \( [ 0 , |A| ) \)
Postcondition
the matching of the sequential greedy algorithm (audit)

◆ parallelKruskal()

template<Executor E, class W>
std::vector< int > ADS::parallelKruskal ( E & ex,
int n,
const std::vector< WeightedEdge< W > > & A )
nodiscard

the places in \( A \) of the edges of the minimum spanning forest that Kruskal gives on the order \( ( w , \mathit{place} ) \), in that order

In pseudocode (section 14.3, on the deterministic reservations of Blelloch, Fineman, Gibbons and Shun), the two steps of the edge \( e_i = [ u , v ] \) of place \( i \) in the order, \( R \) the reservations of the roots:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{reserve}( i ) \cr 2 & \quad r_u \gets \mathrm{find}( u );\ r_v \gets \mathrm{find}( v ) \cr 3 & \quad \textbf{if}\ r_u = r_v\ \textbf{then}\ \textbf{return} \ \textbf{false} \quad \triangleright\ \text{left out} \cr 4 & \quad \mathrm{reserve}( R[ r_u ] , i );\ \mathrm{reserve}( R[ r_v ] , i );\ \textbf{return}\ \textbf{true} \cr 5 & \textbf{function}\ \mathrm{commit}( i ) \cr 6 & \quad \textbf{if}\ R[ r_u ] \text{ holds } i\ \textbf{then} \ \text{free } R[ r_u ] \text{, and } R[ r_v ] \text{ if it holds } i;\ p[ r_u ] \gets r_v \cr & \qquad \text{take } e_i;\ \textbf{return}\ \textbf{true} \cr 7 & \quad \textbf{if}\ R[ r_v ] \text{ holds } i\ \textbf{then} \ \text{free it};\ p[ r_v ] \gets r_u;\ \text{take } e_i; \ \textbf{return}\ \textbf{true} \cr 8 & \quad \textbf{return}\ \textbf{false} \quad \triangleright \ \text{tried again} \end{array}} \]

Precondition
\( n \ge 0 \), the ends of the edges in \( [ 0 , n ) \)
Postcondition
the forest of the sequential greedy algorithm (audit)

◆ randomOrder()

std::vector< int > ADS::randomOrder ( int n,
unsigned long long seed )
inlinenodiscard

a random permutation of \( [ 0 , n ) \) from the seed, the same on every machine (the shuffle of Fisher and Yates on a SplitMix64 generator)

Precondition
\( n \ge 0 \)

◆ spanningForest()

template<Executor E>
std::vector< int > ADS::spanningForest ( E & ex,
int n,
const std::vector< std::pair< int, int > > & A )
nodiscard

the places in \( A \) of the edges of the spanning forest of the greedy algorithm in the order of \( A \), increasing

In pseudocode (section 10.2), the steps of parallelKruskal() above on the edges in the order of \( A \), with no sort:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{spanningForest}( n , A ) \cr 2 & \quad \textbf{return}\ \text{the edges that } \mathrm{reserve} \text{ and } \mathrm{commit} \text{ of } \mathrm{parallelKruskal} \text{ take on } A \text{ in its order} \end{array}} \]

Precondition
\( n \ge 0 \), the ends of the edges in \( [ 0 , n ) \)
Postcondition
the forest of the sequential greedy algorithm (audit)