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

The parallel shortest paths from a node \( s \) of a GRAPH whose costs are not negative, beyond the book, on the threads of an executor. More...

Files

file  ADS/parallel/ParallelShortestPaths.h
 The parallel shortest paths from a node \( s \) of a GRAPH whose costs are not negative, beyond the book, on the threads of an executor [see Executor.h]: the stepping algorithms, which relax in parallel all the active nodes whose distance is below a threshold, with the distances of the algorithm of Dijkstra [see ShortestPaths.h], value for value.

Functions

template<Executor E, Graph G>
std::vector< typename G::Weight > ADS::deltaStepping (E &ex, const G &g, int s, typename G::Weight delta)
 the distances from \( s \) by the \( \Delta \)-stepping of Meyer and Sanders, infinity() for the nodes not reached and for the unused names, in a vector of g.bound() places
template<Executor E, Graph G>
std::vector< typename G::Weight > ADS::rhoStepping (E &ex, const G &g, int s, std::size_t rho=std::size_t(1)<< 20)
 the distances from \( s \) by the \( \rho \)-stepping of Dong, Gu, Sun and Zhang, infinity() for the nodes not reached and for the unused names, in a vector of g.bound() places

Detailed description

The parallel shortest paths from a node \( s \) of a GRAPH whose costs are not negative, beyond the book, on the threads of an executor.

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

Function documentation

◆ deltaStepping()

template<Executor E, Graph G>
std::vector< typename G::Weight > ADS::deltaStepping ( E & ex,
const G & g,
int s,
typename G::Weight delta )
nodiscard

the distances from \( s \) by the \( \Delta \)-stepping of Meyer and Sanders, infinity() for the nodes not reached and for the unused names, in a vector of g.bound() places

In pseudocode (Meyer and Sanders, on the buckets of each thread of the GAP benchmark suite, beyond the book), \( B_k[ b ] \) the bucket \( b \) of the thread \( k \) and \( \beta( x ) = \lfloor x / \Delta \rfloor \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{deltaStepping}( \mathit{ex} , G , s , \Delta ) \cr 2 & \quad \textbf{foreach}\ v \in V\ \textbf{do}\ d[ v ] \gets \infty \cr 3 & \quad d[ s ] \gets 0;\ F \gets ( s );\ c \gets 0 \cr 4 & \quad \text{on each thread } k \text{ of } \mathit{ex} \text{, from} \text{ the barrier where it joins,}\ \textbf{loop} \cr 5 & \qquad \textbf{foreach}\ v \in F\ \textbf{with}\ \beta( d[ v ] ) \ge c\ \textbf{do in parallel}\ \mathrm{relax}( k , v )\quad \triangleright\ \text{64 at a time} \cr 6 & \qquad \textbf{while}\ 0 < | B_k[ c ] | < 1000\ \textbf{do} \ \textbf{foreach}\ v\ \text{taken from } B_k[ c ]\ \textbf{do} \ \mathrm{relax}( k , v ) \cr 7 & \qquad \text{barrier: } c \gets \min_k \min\{ b \ge c : B_k[ b ] \ne \emptyset \};\ \textbf{if}\ \text{there is none}\ \textbf{then} \ \textbf{return}\ d \cr 8 & \qquad F \gets \text{the } B_k[ c ] \text{ of all the threads, each} \text{ at a place of its own};\ B_k[ c ] \gets \emptyset \cr 9 & \qquad \text{barrier} \cr 10 & \textbf{procedure}\ \mathrm{relax}( k , v ) \cr 11 & \quad \textbf{if}\ \text{the distances are kept}\ \textbf{then} \cr 12 & \qquad \textbf{if}\ \mathit{last}[ v ] = d[ v ]\ \textbf{then} \ \textbf{return};\ \mathit{last}[ v ] \gets d[ v ] \cr 13 & \quad \textbf{foreach}\ ( v , u ) \in E\ \textbf{do} \cr 14 & \qquad \textbf{if}\ \mathrm{writeMin}( d[ u ] , d[ v ] + w( v , u ) )\ \textbf{then}\ \text{append } u \text{ to } B_k[ \beta( d[ v ] + w( v , u ) ) ] \end{array}} \]

The barrier of the lines 4, 7 and 9 in pseudocode, \( c \) the threads counted, \( a \) those arrived, \( q \) those that joined since the last release and \( \gamma \) the generation; a thread calls join() when the executor starts its call, and arrive( s ) at each barrier, the last to arrive running \( s \) (e.g., the choice of \( c \) of the line 7):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{join}() \cr 2 & \quad \text{under the lock:}\ \textbf{if}\ \text{over} \ \textbf{then return false} \cr 3 & \quad \text{under the lock:}\ \textbf{if}\ \text{not started} \ \textbf{then}\ \text{start};\ c \gets 1;\ \textbf{return true} \cr 4 & \quad \text{under the lock:}\ q \gets q + 1;\ g \gets \gamma \cr 5 & \quad \text{wait while}\ \gamma = g\quad \triangleright \ \text{acquire};\ \textbf{return}\ \text{not over} \cr 6 & \textbf{procedure}\ \mathrm{arrive}( s ) \cr 7 & \quad g \gets \gamma\quad \triangleright\ \text{acquire} \cr 8 & \quad \textbf{if}\ \mathrm{fetchAndAdd}( a , 1 ) + 1 = c \ \textbf{then}\quad \triangleright\ \text{the last to arrive} \cr 9 & \qquad \text{under the lock:}\ c \gets c + q;\ q \gets 0; \ s();\ a \gets 0;\ \gamma \gets g + 1\quad \triangleright \ \text{release} \cr 10 & \quad \textbf{else}\ \text{wait while}\ \gamma = g\quad \triangleright\ \text{acquire} \end{array}} \]

Precondition
\( s \) is a node, the costs are not negative, \( \Delta > 0 \)

◆ rhoStepping()

template<Executor E, Graph G>
std::vector< typename G::Weight > ADS::rhoStepping ( E & ex,
const G & g,
int s,
std::size_t rho = std::size_t(1)<< 20 )
nodiscard

the distances from \( s \) by the \( \rho \)-stepping of Dong, Gu, Sun and Zhang, infinity() for the nodes not reached and for the unused names, in a vector of g.bound() places

In pseudocode (Dong, Gu, Sun and Zhang, beyond the book), \( A \) the active nodes:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{rhoStepping}( \mathit{ex} , G , s , \rho ) \cr 2 & \quad \textbf{foreach}\ v \in V\ \textbf{do}\ d[ v ] \gets \infty \cr 3 & \quad d[ s ] \gets 0;\ A \gets \{ s \} \cr 4 & \quad \textbf{while}\ A \ne \emptyset\ \textbf{do} \cr 5 & \qquad \textbf{if}\ |A| \le \rho\ \textbf{then}\ \theta \gets \infty \cr 6 & \qquad \textbf{else}\ \theta \gets \text{the } \lceil 1024 \rho / |A| \rceil \text{-th least of the distances of } 1024 \text{ nodes of } A \cr 7 & \qquad F \gets \{ v \in A : d[ v ] \le \theta \};\ A \gets A \setminus F \cr 8 & \qquad \textbf{foreach}\ v \in F , ( v , u ) \in E\ \textbf{do in} \ \textbf{parallel} \cr 9 & \qquad\quad \textbf{if}\ \mathrm{writeMin}( d[ u ] , d[ v ] + w( v , u ) )\ \textbf{and}\ u \notin A\ \textbf{then}\ A \gets A \cup \{ u \} \cr 10 & \quad \textbf{return}\ d \end{array}} \]

Precondition
\( s \) is a node, the costs are not negative, \( \rho \ge 1 \)