Intel® oneAPI Threading Building Blocks (oneTBB)
The `tbb` library provides Intel® oneAPI Threading Building Blocks (oneTBB), a C++ template library for parallel programming. The Python package primarily distributes the oneTBB C++ runtime libraries and headers, enabling other Python packages (e.g., NumPy, SciPy) to leverage TBB for parallelization. It is currently at version 2022.3.1 and sees regular updates, typically a few times per year, to introduce new features and address issues.
Warnings
- gotcha The `tbb` Python package primarily provides Intel oneTBB C++ runtime libraries and headers. It does not offer direct Python APIs for parallelizing Python code. Users typically interact with libraries like NumPy, SciPy, or scikit-learn, which may be *built against* TBB for their internal parallelization.
- breaking Environment variable names for C++ include paths changed in oneTBB 2022.2.0. `CPATH` was replaced by `C_INCLUDE_PATH` and `CPLUS_INCLUDE_PATH` to prevent unintended compiler warnings.
- gotcha While the `tbb` Python package provides the necessary shared objects and headers, direct C++ development or Python extensions that link against TBB still require a C++ compiler and appropriate build system setup.
- breaking The primary C++ namespace for TBB migrated from `tbb` to `oneapi::tbb` with the introduction of oneAPI. While aliases often exist for backward compatibility, new C++ code should use the `oneapi::tbb` namespace.
- deprecated The `tbb::task_scheduler_init` class has been largely deprecated in modern TBB versions in favor of `tbb::task_arena` for finer-grained control over task execution and thread management.
Install
-
pip install tbb
Imports
- version_info
from tbb import version_info
- include_dir
from tbb import include_dir
- lib_dir
from tbb import lib_dir
Quickstart
import tbb
import os
# The 'tbb' Python package primarily provides access to the underlying
# C++ library paths and version, not direct Python parallel computing APIs.
# Other Python libraries (e.g., NumPy, SciPy) might be built to use TBB
# and will detect it automatically if installed.
print(f"TBB package version: {tbb.version_info}")
# Paths useful for C++ projects or Python extensions that link against TBB
print(f"TBB C++ include directory: {tbb.include_dir()}")
print(f"TBB C++ library directory: {tbb.lib_dir()}")
# Example of checking if TBB-enabled features are available in another library
# (Conceptual, 'some_tbb_enabled_lib' is a placeholder)
# try:
# import some_tbb_enabled_lib
# if hasattr(some_tbb_enabled_lib, 'is_tbb_enabled') and some_tbb_enabled_lib.is_tbb_enabled():
# print("A TBB-enabled Python library is detected and can use TBB.")
# except ImportError:
# print("No specific TBB-enabled Python library found for direct usage example.")