blosc2.set_nthreads

blosc2.set_nthreads(nthreads: int) int[source]

Set the number of threads to be used during Blosc operations.

Parameters:

nthreads (int) – The number of threads to be used during Blosc operations.

Returns:

out – The previous number of threads used.

Return type:

int

Raises:

ValueError – If nthreads is larger than the maximum number of threads Blosc can use. If nthreads is not a positive integer.

Notes

The number of threads can also be set via the BLOSC_NTHREADS environment variable (e.g., export BLOSC_NTHREADS=1). Additionally, you may want to set NUMEXPR_NUM_THREADS (e.g., export NUMEXPR_NUM_THREADS=1) as well since numexpr is used under the hood when performing some operations. Note that this function only sets the number of threads used by Blosc, not the number of threads used by numexpr.

The maximum number of threads for Blosc is \(2^{31} - 1\). In some cases, Blosc gets better results if you set the number of threads to a value slightly below your number of cores (via detect_number_of_cores()).

Examples

Set the number of threads to 2 and then to 1:

>>> oldn = blosc2.set_nthreads(2)
>>> blosc2.set_nthreads(1)
2

See also

nthreads