Repository navigation
FIX Use "sequential_blas_under_openmp" to limit BLAS under OpenMP - #35180
Merged
ogrisel merged 2 commits intoOct 27, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
With OpenBLAS's OpenMP threading layer, threadpoolctl 3.7 limits BLAS with omp_set_num_threads, which also limits the OpenMP code of the calling thread. ArgKmin reads its number of threads inside its BLAS limit, so it ran on a single thread. Co-Authored-By: Claude Opus 5.5 <[email protected]>
cakedev0
marked this pull request as ready for review
October 20, 2026 06:48
Member
Author
This was referenced Oct 20, 2026
DOC Recommend "sequential_blas_under_openmp" for BLAS calls in OpenMP loops
cakedev0/threadpoolctl#1
Closed
ogrisel
approved these changes
Oct 20, 2026
Member
|
Thanks for the fix! |
Member
|
Also cc @jeremiedbb. I remember we implemented this option together in |
itamarst
approved these changes
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Closes joblib/threadpoolctl#272
Found while working on kmeans++ optimization: since threadpoolctl 3.7, with OpenBLAS's OpenMP threading layer,
limits=1, user_api="blas"also sets the number of OpenMP threads of the calling thread to 1.What does this implement/fix? Explain your changes.
ArgKmin.compute(used bykneighbors,pairwise_distances_argmin, ...) creates its object inside its BLAS limit, and the constructor reads the number of OpenMP threads with_openmp_effective_n_threads(). With OpenBLAS's OpenMP threading layer (the default of conda-forge on macOS) and threadpoolctl 3.7, it gets 1, and the whole k-NN search runs on a single thread.This PR replaces
limits=1, user_api="blas"withlimits="sequential_blas_under_openmp"where needed. threadpoolctl added this option in 3.1 for this use case (joblib/threadpoolctl#114): it limits BLAS to 1 thread, except for OpenBLAS with the OpenMP threading layer where it does nothing: inside an OpenMP parallel region, OpenBLAS then usesblas_omp_threads_localthreads, which is 1 by default (common_thread.h).Only
ArgKminis affected: the other reductions create their object before the BLAS limit, andKMeanscomputes its number of threads infit. Still, I changed them too, so that all the internal limits are the same.The first commit (dc5a54a) only adds the test, which fails on main in the macOS arm64 conda-forge job (OpenBLAS 0.3.34 with OpenMP threading, threadpoolctl 3.7.0): CI log (
assert [1] == [2]). I also checked it locally on Linux with conda-forge's OpenBLAS with OpenMP threading: the test fails on main and passes with this PR.AI usage disclosure
I used AI assistance for:
Benchmarks
MacBook Pro M2, conda-forge OpenBLAS 0.3.34 with OpenMP threading (llvm-openmp), 8 threads, best of 3, two runs each, in ABBA order. "3.7 + this PR" is main with threadpoolctl 3.7.0 and
ArgKminpatched to use"sequential_blas_under_openmp".kneighbors, euclidean, 50k x 32, k=5kneighbors, manhattan, 5k queriespairwise_distances_argmin, 50k vs 1k