57#ifndef __ADS_TBBExecutor
58 #define __ADS_TBBExecutor
61#if defined( ADS_WITH_TBB )
70#include <tbb/blocked_range.h>
71#include <tbb/parallel_for.h>
72#include <tbb/parallel_invoke.h>
73#include <tbb/partitioner.h>
74#include <tbb/spin_mutex.h>
75#include <tbb/task_arena.h>
113 : std::max< std::size_t >( std::thread::hardware_concurrency() ,
115 f_own( std::in_place , int( f_p ) ) {
122 : f_p( 0 ) , f_user( &arena ) { }
134 const int c = f_user ? f_user->max_concurrency()
135 : tbb::this_task_arena::max_concurrency();
136 return( std::size_t( c > 0 ? c : 1 ) );
153 void bulk( std::size_t n , F && f ) {
155 for( std::size_t i = 0 ; i < n ; ++i )
161 tbb::blocked_range< std::size_t >( 0 , n , 1 ) ,
162 [ & ](
const tbb::blocked_range< std::size_t > & r ) {
163 for( std::size_t i = r.begin() ; i < r.end() ; ++i )
166 tbb::simple_partitioner() );
172 template<
class F ,
class G >
179 execute( [ & ] { tbb::parallel_invoke( f , g ); } );
204 void run( std::size_t p , F && f ) {
206 detail::RunCaller caller;
212 detail::FirstError error;
215 tbb::blocked_range< std::size_t >( 0 , p , 1 ) ,
216 [ & ](
const tbb::blocked_range< std::size_t > & r ) {
217 for( std::size_t i = r.begin() ; i < r.end() ; ++i )
218 tbb::this_task_arena::isolate( [ & ] {
227 tbb::simple_partitioner() );
236 void execute( B && body ) {
238 f_user->execute( body );
240 f_own->execute( body );
246 std::optional< tbb::task_arena > f_own;
247 tbb::task_arena * f_user =
nullptr;
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...
TBBExecutor(Current)
the executor on the arena of the thread that makes each call (the arena of a loop of oneTBB that call...
Definition TBBExecutor.h:127
void run(std::size_t p, F &&f)
the calls of long-lived workers, at the same time on threads of the arena
Definition TBBExecutor.h:204
void invoke(F &&f, G &&g)
the calls f() and g() in parallel, by the parallel_invoke of oneTBB in the arena
Definition TBBExecutor.h:173
void bulk(std::size_t n, F &&f)
the calls on the threads of the arena
Definition TBBExecutor.h:153
std::size_t concurrency(void) const
the number of threads of the arena: for its own, the concurrency of the arena of the program,...
Definition TBBExecutor.h:131
TBBExecutor(tbb::task_arena &arena)
the executor on the arena of the program, which it does not own and which must outlive it; its thread...
Definition TBBExecutor.h:121
TBBExecutor(std::size_t p=0)
the executor of an arena of its own, of threads (the hardware threads if )
Definition TBBExecutor.h:111
static constexpr Current current
the executor on the arena of the thread that makes each call [see TBBExecutor( Current )]
Definition TBBExecutor.h:106
tbb::spin_mutex lock_type
the lock of the data shared by the workers of run()
Definition TBBExecutor.h:183
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
the tag of the executor on the arena of the calling thread
Definition TBBExecutor.h:102