50#ifndef __ADS_StdParExecutor
51 #define __ADS_StdParExecutor
56#if defined( __cpp_lib_parallel_algorithm ) || defined( ADS_WITH_STDPAR )
86 using iterator_category = std::random_access_iterator_tag;
87 using value_type = std::size_t;
88 using difference_type = std::ptrdiff_t;
89 using pointer =
const std::size_t *;
90 using reference = std::size_t;
94 std::size_t operator*()
const {
return( i ); }
95 std::size_t operator[]( difference_type k )
const {
96 return( i + std::size_t( k ) );
98 IndexIterator & operator++() {
102 IndexIterator operator++(
int ) {
103 IndexIterator t = *
this;
107 IndexIterator & operator--() {
111 IndexIterator operator--(
int ) {
112 IndexIterator t = *
this;
116 IndexIterator & operator+=( difference_type k ) {
117 i += std::size_t( k );
120 IndexIterator & operator-=( difference_type k ) {
121 i -= std::size_t( k );
124 friend IndexIterator operator+( IndexIterator a , difference_type k ) {
127 friend IndexIterator operator+( difference_type k , IndexIterator a ) {
130 friend IndexIterator operator-( IndexIterator a , difference_type k ) {
133 friend difference_type operator-( IndexIterator a , IndexIterator b ) {
134 return( difference_type( a.i ) - difference_type( b.i ) );
136 friend bool operator==( IndexIterator , IndexIterator ) =
default;
137 friend auto operator<=>( IndexIterator , IndexIterator ) =
default;
148template<
class Policy = std::execution::parallel_policy >
150 std::is_execution_policy_v< Policy > &&
151 ! std::is_same_v< Policy , std::execution::parallel_unsequenced_policy > )
161 : std::max< std::size_t >( std::thread::hardware_concurrency() ,
165 [[nodiscard]] std::size_t
concurrency(
void )
const {
return( f_p ); }
183 void bulk( std::size_t n , F && f ) {
184 if( ( n <= 1 ) || ( f_p == 1 ) ) {
185 for( std::size_t i = 0 ; i < n ; ++i )
189 detail::FirstError error;
193 std::for_each( policy , detail::IndexIterator{ 0 } ,
194 detail::IndexIterator{ n } , [ & ]( std::size_t i ) {
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...
void bulk(std::size_t n, F &&f)
the calls by the std::for_each of the policy
Definition StdParExecutor.h:183
StdParExecutor(std::size_t p=0)
the executor of the policy, which tells the algorithms of ADS that it has threads (the hardware thre...
Definition StdParExecutor.h:159
std::size_t concurrency(void) const
the number of threads given to the constructor
Definition StdParExecutor.h:165