Intel oneAPI Threading Building Blocks (oneTBB)
raw JSON → 2023.0.0 verified Fri May 01 auth: no python
Intel oneAPI Threading Building Blocks (oneTBB) is a C++ library for parallel programming. The tbb-devel package provides Python bindings (via pybind11) to access TBB's parallel algorithms, concurrent containers, task scheduling, and flow graphs. Version 2023.0.0 is the latest stable release. Releases occur roughly yearly.
pip install tbb-devel Common errors
error ImportError: No module named tbb ↓
cause tbb-devel is not installed or the Python environment does not have it.
fix
Run: pip install tbb-devel
error NameError: name 'parallel_for' is not defined ↓
cause The user tried to use parallel_for without importing it correctly.
fix
Import with: from tbb import parallel_for
Warnings
breaking The tbb-devel package provides Python bindings for oneTBB, but the C++ library has breaking changes between major versions (e.g., TBB 2020 to 2021). The Python API may not be fully compatible across versions. ↓
fix Ensure your code is tested with the specific tbb-devel version you deploy. Check the oneTBB release notes for C++ API changes.
deprecated The tbb::task_scheduler_init class is deprecated. Use tbb::global_control to set the number of threads. ↓
fix Replace task_scheduler_init with global_control. In Python: from tbb import global_control; ctrl = global_control(global_control.max_allowed_parallelism, nthreads)
gotcha The Python tbb module is a thin wrapper around C++ TBB. It may not expose all C++ features, and some functions (e.g., flow graph) have limited or no Python bindings. ↓
fix Check the tbb module's exported symbols via dir(tbb) or refer to the C++ oneTBB documentation for available features.
Imports
- parallel_for wrong
from tbb import tbb_parallel_forcorrectfrom tbb import parallel_for - task_group wrong
from tbb import task_group_contextcorrectfrom tbb import task_group
Quickstart
import os
from tbb import parallel_for
def square(x):
return x * x
# Parallel for loop
results = parallel_for(range(10), square)
print(list(results))