`threadpool_limits(1, user_api="blas")` also limits OpenMP to 1 thread with OpenBLAS's OpenMP threading layer (3.7.0)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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
- 平均マージ
- 3日 7時間
- マージ済み PR(30日)
- 6
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
joblib/threadpoolctl のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
joblib/threadpoolctl#279 ·
メンテナーはふだん 1 日以内に返信
-
limits= dict and list form don't allow full customizaton対応中かも @itamarst が今日担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
joblib/threadpoolctl#277 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 57/100
joblib/threadpoolctl#276 ·
メンテナーはふだん 1 日以内に返信
-
難易度 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 日以内に返信
joblib/threadpoolctl の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
fossasia/visdom-dev#77 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
aws-cloudformation/cfn-lint#4890 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
volcengine/OpenViking#6521 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
AstrBotDevs/AstrBot#10720 ·
メンテナーはふだん 1 日以内に返信