Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/reference/ndarray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It is a direct alias for ``array.vlmeta`` and uses the same persistent storage.
.. autoclass:: NDArray
:members:
:inherited-members:
:exclude-members: get_slice, set_slice, get_slice_numpy, get_oindex_numpy, set_oindex_numpy
:exclude-members: get_slice, set_slice, get_slice_numpy, get_basic_numpy, get_basic_start_stop, get_oindex_numpy, set_oindex_numpy
:member-order: groupwise

:Special Methods:
Expand Down
16 changes: 13 additions & 3 deletions src/blosc2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ def _raise(exc):
cpu_info = get_cpu_info()
nthreads = ncores = cpu_info.get("count", 1)
"""Number of threads to be used in compression/decompression.

It starts from the ``BLOSC_NTHREADS`` environment variable if that is set.
"""
# Protection against too many threads
nthreads = min(nthreads, 64)
Expand All @@ -515,14 +517,22 @@ def _raise(exc):
# Experiments say that, when using a large number of threads, it is better to not use them all
if nthreads > 16:
nthreads -= nthreads // 8
# Only call set_num_threads if within NUMEXPR_MAX_THREADS limit to avoid warning
# C-Blosc2 uses BLOSC_NTHREADS, when set to a valid number, for every compression and
# decompression, whatever the nthreads in their parameters; start from it (as C-Blosc2 reads
# it), so that nthreads and the CParams/DParams defaults say how many threads are used
from .blosc2_ext import context_nthreads

nthreads = context_nthreads(nthreads)
# Only call set_num_threads if within NUMEXPR_MAX_THREADS limit to avoid warning, and not
# over the thread count that the user gave numexpr with NUMEXPR_NUM_THREADS
numexpr_max_env = os.environ.get("NUMEXPR_MAX_THREADS")
numexpr_max: int | None = None
if numexpr_max_env is not None:
with contextlib.suppress(ValueError):
numexpr_max = int(numexpr_max_env)
if numexpr_max is None or nthreads <= numexpr_max:
numexpr.set_num_threads(nthreads)
if not os.environ.get("NUMEXPR_NUM_THREADS") and (numexpr_max is None or nthreads <= numexpr_max):
# BLOSC_NTHREADS can go beyond numexpr's own maximum, which it refuses with an error
numexpr.set_num_threads(min(nthreads, numexpr.MAX_THREADS))

# This import must be before ndarray and schunk
from .storage import ( # noqa: I001
Expand Down
Loading
Loading