Intel® oneAPI Threading Building Blocks Developer Guide and API Reference
ID
772616
Date
10/31/2024
Public
A newer version of this document is available. Customers should click here to go to the newest version.
Package Contents
Parallelizing Simple Loops
Parallelizing Complex Loops
Parallelizing Data Flow and Dependence Graphs
Work Isolation
Exceptions and Cancellation
Containers
Mutual Exclusion
Timing
Memory Allocation
The Task Scheduler
Design Patterns
Migrating from Threading Building Blocks (TBB)
Constrained APIs
Invoke a Callable Object
Appendix A Costs of Time Slicing
Appendix B Mixing With Other Threading Packages
References
parallel_for_each Body semantics and requirements
parallel_sort ranges interface extension
TBB_malloc_replacement_log Function
Parallel Reduction for rvalues
Type-specified message keys for join_node
Scalable Memory Pools
Helper Functions for Expressing Graphs
concurrent_lru_cache
task_group extensions
The customizing mutex type for concurrent_hash_map
Waiting for Single Messages in Flow Graph
Appendix B Mixing With Other Threading Packages
oneAPI Threading Building Blocks (oneTBB) can be mixed with other threading packages. No special effort is required to use any part of oneTBB with other threading packages.
Here is an example that parallelizes an outer loop with OpenMP and an inner loop with oneTBB.
int M, N; struct InnerBody { ... }; void TBB_NestedInOpenMP() { #pragma omp parallel { #pragma omp for for( int i=0; i<M; ++ ) { parallel_for( blocked_range<int>(0,N,10), InnerBody(i) ); } } }
The details of InnerBody are omitted for brevity. The #pragma omp parallel causes the OpenMP to create a team of threads, and each thread executes the block statement associated with the pragma. The #pragma omp for indicates that the compiler should use the previously created thread team to execute the loop in parallel.
Here is the same example written using POSIX* Threads.
int M, N; struct InnerBody { ... }; void* OuterLoopIteration( void* args ) { int i = (int)args; parallel_for( blocked_range<int>(0,N,10), InnerBody(i) ); } void TBB_NestedInPThreads() { std::vector<pthread_t> id( M ); // Create thread for each outer loop iteration for( int i=0; i<M; ++i ) pthread_create( &id[i], NULL, OuterLoopIteration, NULL ); // Wait for outer loop threads to finish for( int i=0; i<M; ++i ) pthread_join( &id[i], NULL ); }