Thread Composability Manager
tcmlib is a Python library by Intel that implements the Thread Composability Manager. It coordinates CPU resource usage between Intel® oneAPI Threading Building Blocks (oneTBB) and Intel® OpenMP to prevent excessive oversubscription when both runtimes are used concurrently within a single process. This helps optimize performance for multi-threaded Python applications, particularly in AI/ML and scientific computing workloads. The library is currently at version 1.4.1 and is actively maintained by Intel.
Warnings
- gotcha The Thread Composability Manager's core functionality is largely activated by setting the `TCM_ENABLE=1` environment variable *before* your Python script executes, rather than through direct Python API calls within your code. Failing to set this environment variable will prevent the manager from coordinating resources.
- gotcha tcmlib operates by coordinating Intel® oneAPI Threading Building Blocks (oneTBB) and Intel® OpenMP. Its benefits are most pronounced when your Python application, or the libraries it depends on (e.g., NumPy, SciPy if linked against oneMKL), utilize these underlying Intel runtimes. Without these components, the `tcmlib` package may have little to no discernible effect on performance.
- gotcha The `tcmlib` package is distributed under an 'Other/Proprietary License (Intel Simplified Software License)'. Users should review the terms of this license to ensure compliance with their project requirements.
- gotcha As `tcmlib` is an Intel-specific optimization library, its performance benefits are primarily targeted at Intel CPU architectures. While it may not cause issues on other architectures, its intended performance gains might not be realized without compatible Intel hardware and software stacks. The wheels available on PyPI target `manylinux` and `win_amd64` for `x86_64` architecture, supporting Python 2 and 3.
Install
-
pip install tcmlib
Imports
- tcmlib (module)
import tcmlib
Quickstart
import os
import numpy as np
import time
# The Thread Composability Manager is often enabled via an environment variable.
# For demonstration, we'll set it here, but typically it's set before the Python process starts.
# Ensure Intel oneTBB and OpenMP runtimes are installed and configured for optimal effect.
# NOTE: For actual use, set this environment variable BEFORE running your Python script,
# e.g., in bash: export TCM_ENABLE=1 python your_script.py
# Or in a system-wide environment configuration.
os.environ['TCM_ENABLE'] = os.environ.get('TCM_ENABLE', '1') # Set to '1' to enable, '0' to disable if not already set.
print(f"TCM_ENABLE is set to: {os.environ.get('TCM_ENABLE')}")
def heavy_computation(size):
# Simulate a compute-intensive task that might use OpenMP/oneTBB internally
start_time = time.time()
matrix_a = np.random.rand(size, size)
matrix_b = np.random.rand(size, size)
result = np.dot(matrix_a, matrix_b)
end_time = time.time()
return end_time - start_time
if __name__ == '__main__':
print("Starting heavy computation...")
duration = heavy_computation(1000) # Adjust size based on your CPU/memory
print(f"Computation finished in {duration:.4f} seconds.")
print("To observe the effects of tcmlib, compare performance with and without TCM_ENABLE=1,")
print("especially when other Intel-optimized libraries (like NumPy with oneMKL) are also used.")
# Clean up environment variable for subsequent runs in the same shell/notebook session if needed
# del os.environ['TCM_ENABLE']