CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-threadpoolctl

Python helpers to limit the number of threads used in threadpool-backed native libraries for scientific computing

Overview
Eval results
Files

introspection.mddocs/

Thread Pool Introspection

Discover and inspect thread pool libraries currently loaded in the Python process. This capability provides detailed information about each detected library including implementation details, version information, and current thread settings.

Capabilities

Basic Introspection

Get information about all thread pool libraries currently loaded in the process.

def threadpool_info():
    """
    Return thread pool information for all detected libraries.
    
    Scans loaded shared libraries and returns info for supported thread pool
    libraries (BLAS implementations and OpenMP runtimes).
    
    Returns:
        list[dict]: List of library information dictionaries, each containing:
            - user_api (str): Standardized API ('blas' or 'openmp')
            - internal_api (str): Implementation name ('openblas', 'mkl', 'blis', 'flexiblas', 'openmp')  
            - prefix (str): Shared library filename prefix
            - filepath (str): Full path to the loaded shared library
            - version (str | None): Library version if detectable
            - num_threads (int): Current maximum thread count
            - Additional implementation-specific attributes
    """

Usage Examples

from threadpoolctl import threadpool_info
import numpy  # This loads BLAS libraries

# Get information about all thread pool libraries
info = threadpool_info()

for lib in info:
    print(f"Library: {lib['internal_api']} ({lib['user_api']})")
    print(f"  Version: {lib['version']}")
    print(f"  Threads: {lib['num_threads']}")
    print(f"  Path: {lib['filepath']}")
    
    # BLAS libraries may have additional attributes
    if lib['user_api'] == 'blas':
        if 'threading_layer' in lib:
            print(f"  Threading: {lib['threading_layer']}")
        if 'architecture' in lib:
            print(f"  Architecture: {lib['architecture']}")
    print()

Library-Specific Information

Different library implementations provide additional attributes beyond the standard set:

OpenBLAS Libraries

  • threading_layer: Threading backend ("openmp", "pthreads", "disabled")
  • architecture: Target architecture detected by OpenBLAS

BLIS Libraries

  • threading_layer: Threading backend ("openmp", "pthreads", "disabled")
  • architecture: Target architecture detected by BLIS

MKL Libraries

  • threading_layer: Threading layer ("intel", "sequential", "pgi", "gnu", "tbb", "not specified")

FlexiBLAS Libraries

  • available_backends: List of configured backend names
  • loaded_backends: List of currently loaded backend names
  • current_backend: Name of the currently active backend

Common Usage Patterns

from threadpoolctl import threadpool_info

# Check if specific libraries are loaded
info = threadpool_info()
has_openblas = any(lib['internal_api'] == 'openblas' for lib in info)
has_openmp = any(lib['user_api'] == 'openmp' for lib in info)

# Find libraries with many threads
high_thread_libs = [lib for lib in info if lib['num_threads'] > 4]

# Group by API type
blas_libs = [lib for lib in info if lib['user_api'] == 'blas']  
openmp_libs = [lib for lib in info if lib['user_api'] == 'openmp']

print(f"Found {len(blas_libs)} BLAS libraries")
print(f"Found {len(openmp_libs)} OpenMP libraries")

Install with Tessl CLI

npx tessl i tessl/pypi-threadpoolctl

docs

advanced-control.md

custom-libraries.md

index.md

introspection.md

limiting.md

tile.json