`threadpool_limits(1, user_api="blas")` also limits OpenMP to 1 thread with OpenBLAS's OpenMP threading layer (3.7.0)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- python
- 领域
- performance
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Python
- 星标
- 434
- 派生
- 38
- 平均合并
- 2 天 9 小时
- 30 天内合并 PR
- 7
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
joblib/threadpoolctl 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 25/100
joblib/threadpoolctl#271 ·
维护者通常 1 天内回复
-
Make it possible to inspect active/spin wait behavior of LLVM/Intel OpenMP via `kmp_get_blocktime`未关闭
难度 3/5 1-2 天 新手友好度 42/100
joblib/threadpoolctl#270 ·
维护者通常 1 天内回复
-
难度 4/5 1-2 天 新手友好度 32/100
joblib/threadpoolctl#264 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 22/100
joblib/threadpoolctl#261 · 3 条评论 ·
维护者通常 1 天内回复
-
Opt-in API that has a cached `ThreadpoolController`可能已有人在做 @itamarst 于 27 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
joblib/threadpoolctl#254 · 3 条评论 ·
维护者通常 1 天内回复
查看 joblib/threadpoolctl 的全部 Issue
相似的 Issue
-
Use mhctools predictor_required=False for saved-result rescoring可能已有人在做 @iskandr 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
-
难度 1/5 1 小时以内 新手友好度 85/100
521xueweihan/HelloGitHub#4051 · 1 条评论 ·
-
bug documentation
难度 2/5 1-3 小时 新手友好度 78/100
awslabs/visual-asset-management-system#514 ·
维护者通常 1 天内回复
-
backend bug spec:REQ-053
难度 2/5 1-3 小时 新手友好度 66/100
nolte/kamerplanter#2547 ·
维护者通常 1 天内回复