
Security News
Official Go SDK for MCP in Development, Stable Release Expected in August
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
numthreads
is a really tiny and simple Python package designed to set the number of threads for various computing libraries including OpenBLAS, Intel's Math Kernel Library (MKL), OpenMP, NumExpr, Accelerate, and Numba.
The number of threads can be set via the command line or in Python code.
The performance of many numerical algorithms varies significantly based on the number of threads employed.
While increasing the number of threads can often accelerate these algorithms, it's not always the case.
In some instances, using more threads may actually impede computational efficiency.
Therefore, it's important to be able to easily set the number of threads used by these libraries.
To install numthreads
, run the following command:
pip install numthreads
Get started with numthreads
in a few seconds.
You can also use numthreads
as a Python module:
from numthreads import set_num_threads
set_num_threads(4)
This will set the number of threads using the following environment variables:
OPENBLAS_NUM_THREADS
)MKL_NUM_THREADS
)OMP_NUM_THREADS
)NUMEXPR_NUM_THREADS
)VECLIB_MAXIMUM_THREADS
)NUMBA_NUM_THREADS
)or use it as a context manager:
from numthreads import num_threads
with num_threads(4):
# Your code here will run with the specified number of threads
pass
[!WARNING] Since environment variables are global and typically need to be set before importing any libraries, it's recommended to set the number of threads at the beginning of your Python script.
To set OMP (OpenMP) threads at any time (OpenMP docs), you can use omp_set_num_threads
or the omp_num_threads
context manager:
from numthreads import omp_set_num_threads
omp_set_num_threads(4)
or
from numthreads import omp_num_threads
with omp_num_threads(4):
# Your code here will run with the specified number of threads
pass
After installing numthreads
, you can easily set the number of threads used by supported libraries via the command line. For example, to print the command to set the number of threads to 4, run:
numthreads 4
Which will print the following:
export OPENBLAS_NUM_THREADS='4' ; export MKL_NUM_THREADS='4' ; export OMP_NUM_THREADS='4' ; export NUMEXPR_NUM_THREADS='4' ; export VECLIB_MAXIMUM_THREADS='4' ; export NUMBA_NUM_THREADS='4'
To apply the settings in your shell:
eval $(numthreads <number_of_threads>)
In PowerShell, use:
Invoke-Expression $(numthreads <number_of_threads>)
To get the number of threads currently set, run:
eval $(numthreads 12) # first set something
numthreads get
Which will print the following:
OPENBLAS_NUM_THREADS: 12
MKL_NUM_THREADS: 12
OMP_NUM_THREADS: 12
NUMEXPR_NUM_THREADS: 12
VECLIB_MAXIMUM_THREADS: 12
NUMBA_NUM_THREADS: 12
Check the numthreads -h
message for more information:
usage: numthreads [-h] n
Set the number of threads for OpenBLAS, MKL, OMP, NumExpr, and Accelerate.
Usage: Run `numthreads <number>` to print the export commands. On Unix-like
systems (Linux, macOS, WSL), use `eval $(numthreads <number>)` in your shell
to apply these settings. On Windows, in PowerShell, use `Invoke-Expression
$(numthreads <number>)`.
positional arguments:
n Number of threads to set or use 'get' to display current
settings.
options:
-h, --help show this help message and exit
numthreads
can be used as a pytest plugin to automatically set the number of threads for your tests.
To use it, make sure numthreads
is installed. Then, run pytest with the --numthreads
option followed by the desired number of threads:
pytest --numthreads 1
This will set the number of threads for OpenBLAS, MKL, OMP, NumExpr, and Accelerate before running your tests.
For more information, or to report issues, please visit numthreads GitHub repository.
FAQs
Set the number of threads for OpenBLAS, MKL, OMP, NumExpr, and Accelerate.
We found that numthreads demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.