Skip to content

Commit 12da794

Browse files
committed
[LinearAlgebra] Initialise number of BLAS threads with uv_available_parallelism
This is a safer estimate than `Sys.CPU_THREADS` to avoid oversubscribing the machine when running distributed applications, or when the Julia process is constrained by external controls (`taskset`, `cgroups`, etc.).
1 parent 58c7186 commit 12da794

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

stdlib/LinearAlgebra/src/LinearAlgebra.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,9 @@ function __init__()
843843
# https://github.com/xianyi/OpenBLAS/blob/c43ec53bdd00d9423fc609d7b7ecb35e7bf41b85/README.md#setting-the-number-of-threads-using-environment-variables
844844
if !haskey(ENV, "OPENBLAS_NUM_THREADS") && !haskey(ENV, "GOTO_NUM_THREADS") && !haskey(ENV, "OMP_NUM_THREADS")
845845
@static if Sys.isapple() && Base.BinaryPlatforms.arch(Base.BinaryPlatforms.HostPlatform()) == "aarch64"
846-
BLAS.set_num_threads(max(1, Sys.CPU_THREADS))
846+
BLAS.set_num_threads(max(1, @ccall(uv_available_parallelism()::Cint)))
847847
else
848-
BLAS.set_num_threads(max(1, Sys.CPU_THREADS ÷ 2))
848+
BLAS.set_num_threads(max(1, @ccall(uv_available_parallelism()::Cint) ÷ 2))
849849
end
850850
end
851851
end

0 commit comments

Comments
 (0)