|
ADS
Algorithms and Data Structures
|
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). More...
#include "ADS/Contract.h"#include "ADS/graph/MinimumSpanningTree.h"#include "ADS/graph/StaticGraph.h"#include "ADS/parallel/Executor.h"#include "ADS/parallel/ParallelSort.h"#include "ADS/parallel/SpeculativeFor.h"#include <cstddef>#include <utility>#include <vector>#include "ADS/parallel/impl/ParallelGreedy.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
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 | |
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).
They are the algorithm of Kruskal (parallelKruskal(), section 14.3 of the book) and its filter-Kruskal variant (filterKruskal()), the spanning forest in the order of the edges (spanningForest(), by the union-find of section 10.2), and the greedy maximal independent set and maximal matching in a given order (maximalIndependentSet(), maximalMatching()); on a random order (randomOrder()) the iterations that wait for each other form short chains, and the rounds are few.
The union-find of the forests links the roots with no rank, and its find() halves the paths (a write of a node to its grandparent, which a concurrent find() reads either way, since no link happens while the finds run). On one thread, or on fewer than 4096 items, the sequential greedy algorithm runs instead.
The contracts [see Contract.h]: \( n \ge 0 \), the ends of the edges in \( [ 0 , n ) \) (a loop \( [ u , u ] \) joins nothing and matches nothing; parallel edges are allowed); the graph is unoriented; an order is a permutation. At the level of the audits each result is checked against the sequential greedy algorithm.