60#ifndef __ADS_SpeculativeFor
61 #define __ADS_SpeculativeFor
93 static constexpr std::size_t
NONE = std::numeric_limits< std::size_t >::max();
98 std::size_t c = f_r.load( std::memory_order_relaxed );
100 ! f_r.compare_exchange_weak( c , i , std::memory_order_relaxed ) )
105 [[nodiscard]]
bool check( std::size_t i )
const noexcept {
106 return( f_r.load( std::memory_order_relaxed ) == i );
110 [[nodiscard]]
bool reserved(
void )
const noexcept {
111 return( f_r.load( std::memory_order_relaxed ) !=
NONE );
115 void reset(
void )
noexcept { f_r.store(
NONE , std::memory_order_relaxed ); }
126 std::atomic< std::size_t > f_r{
NONE };
141 { s.reserve( i ) } -> std::convertible_to< bool >;
142 { s.commit( i ) } -> std::convertible_to< bool >;
178template< Executor E , SpeculativeStep S >
190#include "ADS/parallel/impl/SpeculativeFor.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The layer of execution of the parallel algorithms of ADS, beyond the book: an executor runs the calls...
a place reserved by the least of the iterations that want it
Definition SpeculativeFor.h:90
bool check(std::size_t i) const noexcept
whether holds the place
Definition SpeculativeFor.h:105
static constexpr std::size_t NONE
no iteration
Definition SpeculativeFor.h:93
bool reserved(void) const noexcept
whether some iteration holds the place
Definition SpeculativeFor.h:110
void reset(void) noexcept
frees the place
Definition SpeculativeFor.h:115
void reserve(std::size_t i) noexcept
keeps if it is less than the iteration there (a priority write, by compare-and-swap)
Definition SpeculativeFor.h:97
bool checkReset(std::size_t i) noexcept
frees the place if holds it; whether it did
Definition SpeculativeFor.h:118
the two steps of an iteration [see speculativeFor()]
Definition SpeculativeFor.h:139
void speculativeFor(E &ex, S &step, std::size_t s, std::size_t e, std::size_t g=50, SpeculativeCounts *c=nullptr)
the iterations of step by deterministic reservations, with the result of the sequential loop; the ro...
what speculativeFor() did: its rounds and the iterations tried, the failed ones counted again
Definition SpeculativeFor.h:132
long long rounds
the rounds
Definition SpeculativeFor.h:133
long long tried
the iterations tried
Definition SpeculativeFor.h:134