xref: /oneTBB/python/README.md (revision 89b2e0e3)
151c0b2f7Stbbdev# Python* API for Intel® oneAPI Threading Building Blocks (oneTBB) .
251c0b2f7Stbbdev
351c0b2f7Stbbdev## Overview
451c0b2f7StbbdevIt is a preview Python* module which unlocks opportunities for additional performance in
551c0b2f7Stbbdevmulti-threaded and multiprocess Python programs by enabling threading composability
651c0b2f7Stbbdevbetween two or more thread-enabled libraries like Numpy, Scipy, Sklearn, Dask, Joblib, and etc.
751c0b2f7Stbbdev
851c0b2f7StbbdevThe biggest improvement can be achieved when a task pool like the ThreadPool or Pool from the Python
951c0b2f7Stbbdevstandard library or libraries like Dask or Joblib (used either in multi-threading or multi-processing mode)
1051c0b2f7Stbbdevexecute tasks calling compute-intensive functions of Numpy/Scipy/Sklearn/PyDAAL which in turn are
1151c0b2f7Stbbdevparallelized using Intel® oneAPI Math Kernel Library or/and oneTBB.
1251c0b2f7Stbbdev
1351c0b2f7StbbdevThe module implements Pool class with the standard interface using oneTBB which can be used to replace Python's ThreadPool.
1451c0b2f7StbbdevThanks to the monkey-patching technique implemented in class Monkey, no source code change is needed in order to enable threading composability in Python programs.
1551c0b2f7Stbbdev
16*89b2e0e3SOlga MalyshevaFor more information and examples, please refer to [forum discussion](https://community.intel.com/t5/Intel-Distribution-for-Python/TBB-module-Unleash-parallel-performance-of-Python-programs/m-p/1074459).
1751c0b2f7Stbbdev
1851c0b2f7Stbbdev## Directories
1951c0b2f7Stbbdev - **rml** - The folder contains sources for building the plugin with cross-process dynamic thread scheduler implementation.
2051c0b2f7Stbbdev - **tbb** - The folder contains Python module sources.
2151c0b2f7Stbbdev
2251c0b2f7Stbbdev## Files
2351c0b2f7Stbbdev - **setup.py** - Standard Python setup script.
2451c0b2f7Stbbdev - **TBB.py** - Alternative entry point for Python module.
2551c0b2f7Stbbdev
2651c0b2f7Stbbdev## CMake predefined targets
2751c0b2f7Stbbdev - `irml` - compilation of plugin with cross-process dynamic thread scheduler implementation.
2851c0b2f7Stbbdev - `python_build` - building of oneTBB module for Python.
2951c0b2f7Stbbdev
3051c0b2f7Stbbdev## Command-line interface
3151c0b2f7Stbbdev
3251c0b2f7Stbbdev - `python3 -m tbb -h` - Print documentation on command-line interface.
3351c0b2f7Stbbdev - `pydoc tbb` - Read built-in documentation for Python interfaces.
3451c0b2f7Stbbdev - `python3 -m tbb your_script.py` - Run your_script.py in context of `with tbb.Monkey():` when oneTBB is enabled. By default only multi-threading will be covered.
3551c0b2f7Stbbdev - `python3 -m tbb --ipc your_script.py` - Run your_script.py in context of `with tbb.Monkey():` when oneTBB enabled in both multi-threading and multi-processing modes.
3651c0b2f7Stbbdev - `python3 setup.py build -b<output_directory_path> -f check` - Build oneTBB module for Python. (Prerequisites: built and sourced oneTBB and IRML libraries)
3751c0b2f7Stbbdev - `python3 setup.py build -b<output_directory_path> build_ext -I<path_to_tbb_includes> -L<path_to_prebuilt_libraries> install -f <additional_flags> ` - Build and install oneTBB module for Python. (Prerequisites: built oneTBB and IRML libraries)
3851c0b2f7Stbbdev - `python3 -m TBB test` - run test for oneTBB module for Python.
3951c0b2f7Stbbdev - `python3 -m tbb test` - run test for oneTBB module for Python.
4051c0b2f7Stbbdev
4151c0b2f7Stbbdev## System Requirements
4251c0b2f7Stbbdev - The Python module was not tested on older versions of Python thus we require at least Python and 3.5 or higher.
4351c0b2f7Stbbdev - SWIG must be of version 3.0.6 or higher.
44