`threadpool_limits(1, user_api="blas")` also limits OpenMP to 1 thread with OpenBLAS's OpenMP threading layer (3.7.0)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- performance
Línea de trabajo
Start from the OpenBLAS controller's set_num_threads in threadpoolctl, where it now calls omp_set_num_threads for the OpenMP threading layer, and from the reproduction script that prints the OpenMP thread count under threadpool_limits(limits=1, user_api="blas"). Done means the BLAS limit no longer changes the OpenMP count for the current thread, with the 3.6.0 behaviour restored. The maintainer has not settled the fix, so check the comment thread for a decided approach before writing code.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
Since 3.7.0, with OpenBLAS's OpenMP threading layer, limiting BLAS also limits the OpenMP runtime of the current thread: inside threadpool_limits(limits=1, user_api="blas"), omp_get_max_threads() returns 1, so any OpenMP parallel region started from this thread without an explicit num_threads runs on a single thread. With 3.6.0 and the same OpenBLAS (0.3.34), it stays at 8.
It comes from set_num_threads of the OpenBLAS controller, which now calls omp_set_num_threads when the threading layer is OpenMP, to get a limit per thread rather than per process. But OpenBLAS and the caller share the same OpenMP runtime, so the BLAS limit becomes an OpenMP limit too.
In scikit-learn, the usual pattern for nested parallelism is to limit BLAS to 1 thread around Cython code that calls BLAS inside OpenMP prange loops. Any code that reads the number of OpenMP threads inside that limit now gets 1.
For instance, a KMeans fitted under threadpool_limits(1, user_api="blas") now runs its OpenMP code on 1 thread (see below).
I'm not sure what the best fix is, maybe just some documentation?
Steps/Code to Reproduce
import numpy as np # loads OpenBLAS
from threadpoolctl import threadpool_info, threadpool_limits
def openmp_num_threads():
return [i["num_threads"] for i in threadpool_info() if i["user_api"] == "openmp"]
print("openmp num_threads:", openmp_num_threads())
with threadpool_limits(limits=1, user_api="blas"):
print("openmp num_threads under blas limit 1:", openmp_num_threads())
With scikit-learn:
import numpy as np
from threadpoolctl import threadpool_limits
from sklearn.cluster import KMeans
X = np.random.RandomState(0).randn(1000, 5)
with threadpool_limits(limits=1, user_api="blas"):
print(KMeans(3, n_init=1).fit(X)._n_threads)
Expected Results
With OMP_NUM_THREADS=8:
openmp num_threads: [8]
openmp num_threads under blas limit 1: [8]
and 8 for KMeans._n_threads. That's what 3.6.0 gives.
Actual Results
openmp num_threads: [8]
openmp num_threads under blas limit 1: [1]
and 1 for KMeans._n_threads.
Versions
MacBook Pro M2 (macOS 26.6.2), conda-forge packages:
python 3.13.16
numpy 2.5.4
libopenblas 0.3.34 openmp_h5e6e99c_1 (threading_layer: openmp, VORTEX)
llvm-openmp 23.1.3
threadpoolctl 3.7.0
- Lenguaje dominante
- Python
- Estrellas
- 434
- Forks
- 38
- Merge medio
- 2 d 9 h
- PR fusionados (30 d)
- 7
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de joblib/threadpoolctl
-
Make it possible to set active/spin wait behavior of LLVM/Intel OpenMP via `kmp_set_blocktime`Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
joblib/threadpoolctl#271 ·
Los mantenedores suelen responder en 1 día
-
Make it possible to inspect active/spin wait behavior of LLVM/Intel OpenMP via `kmp_get_blocktime`Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
joblib/threadpoolctl#270 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 1-2 días Aptitud para principiantes 32/100
joblib/threadpoolctl#264 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
joblib/threadpoolctl#261 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Opt-in API that has a cached `ThreadpoolController`Posiblemente ocupada @itamarst la tomó hace 27 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
joblib/threadpoolctl#254 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de joblib/threadpoolctl
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
[Device Support Request] HOBEIAN ZG-204ZL (Tuya PIR motion sensor with illuminance)Posiblemente ocupada @lenucksi la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
zigpy/zha-device-handlers#5493 ·
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
drevendev/BeautifulRepo#42 ·
Los mantenedores suelen responder en 1 día
-
enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
writerslogic/holographic-memory#93 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
antoine-tena/kiln#47 ·
Los mantenedores suelen responder en 1 día