ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
SpeculativeFor.h File Reference

The deterministic reservations of Blelloch, Fineman, Gibbons and Shun, beyond the book: speculativeFor( ex , step , s , e ) runs, on the threads of an executor [see Executor.h], a loop whose iterations \( s , s + 1 , \ldots , e - 1 \) a sequential program would run in this order, each depending on the ones before it, and gives the result of the sequential loop whatever the executor and the number of its threads (see Deterministic reservations, greedy algorithms). More...

#include "ADS/Contract.h"
#include "ADS/parallel/Executor.h"
#include <atomic>
#include <concepts>
#include <cstddef>
#include <limits>
#include <vector>
#include "ADS/parallel/impl/SpeculativeFor.tpp"

Go to the source code of this file.

Classes

class  ADS::Reservation
 a place reserved by the least of the iterations that want it More...
struct  ADS::SpeculativeCounts
 what speculativeFor() did: its rounds and the iterations tried, the failed ones counted again More...

Namespaces

namespace  ADS

Concepts

concept  ADS::SpeculativeStep
 the two steps of an iteration [see speculativeFor()]

Functions

template<Executor E, SpeculativeStep S>
void ADS::speculativeFor (E &ex, S &step, std::size_t s, std::size_t e, std::size_t g=50, SpeculativeCounts *c=nullptr)
 the iterations \( [ s , e ) \) of step by deterministic reservations, with the result of the sequential loop; the rounds of at most \( r_{\mathrm{max}} = \lfloor ( e - s ) / g \rfloor + 1 \) iterations; its work in *c, if given

Detailed description

The deterministic reservations of Blelloch, Fineman, Gibbons and Shun, beyond the book: speculativeFor( ex , step , s , e ) runs, on the threads of an executor [see Executor.h], a loop whose iterations \( s , s + 1 , \ldots , e - 1 \) a sequential program would run in this order, each depending on the ones before it, and gives the result of the sequential loop whatever the executor and the number of its threads (see Deterministic reservations, greedy algorithms).

An iteration \( i \) is split into the two steps of the object step: step.reserve( i ) reads the state that the earlier iterations left, and either finds that \( i \) has nothing to do (it returns false, and \( i \) is done) or writes \( i \) into a Reservation of each place of the state that it would change, and returns true; step.commit( i ) changes the state if \( i \) holds all its reservations and returns true, or returns false to be tried again in the next round, and the holder of a reservation frees it, so that all of them are free at the end of a round. By Lemma 4 of Deterministic reservations, greedy algorithms the least iteration of a round commits and the result is the sequential one. The phase-parallel framework of Shen, Wan, Gu and Sun generalizes the scheme to the loops whose dependences are not conflicts on places (e.g., the longest increasing subsequence); for the greedy algorithms on graphs the reservations remain the method of the benchmark suites (PBBS, GBBS).

The contracts [see Contract.h]: \( s \le e \), \( g \ge 1 \); the reserve() of distinct iterations write only reservations (and their own places), their commit() only the places whose reservations they hold, and the least iteration of a round commits (else the loop would stop; a round with no commit is a violated precondition).

See also
G. E. Blelloch, J. T. Fineman, P. B. Gibbons, J. Shun, Internally deterministic parallel algorithms can be fast, Proceedings of PPoPP, 181-192, 2012, doi:10.1145/2145816.2145840
G. E. Blelloch, J. T. Fineman, J. Shun, Greedy sequential maximal independent set and matching are parallel on average, Proceedings of SPAA, 308-317, 2012, doi:10.1145/2312005.2312058
M. Fischer, A. Noever, Tight analysis of parallel randomized greedy MIS, Proceedings of SODA, 2152-2160, 2018, doi:10.1137/1.9781611975031.140
Z. Shen, Z. Wan, Y. Gu, Y. Sun, Many sequential iterative algorithms can be parallel and (nearly) work-efficient, Proceedings of SPAA, 273-286, 2022, doi:10.1145/3490148.3538574
D. Anderson, G. E. Blelloch, L. Dhulipala, M. Dobson, Y. Sun, The problem-based benchmark suite (PBBS), V2, Proceedings of PPoPP, 445-447, 2022, doi:10.1145/3503221.3508422
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa