Skip to content

Commit

Permalink
[LinearAlgebra] Initialise number of BLAS threads with `uv_available_…
Browse files Browse the repository at this point in the history
…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.).
  • Loading branch information
giordano committed Aug 23, 2024
1 parent 58c7186 commit 12da794
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,9 @@ function __init__()
# https://github.com/xianyi/OpenBLAS/blob/c43ec53bdd00d9423fc609d7b7ecb35e7bf41b85/README.md#setting-the-number-of-threads-using-environment-variables
if !haskey(ENV, "OPENBLAS_NUM_THREADS") && !haskey(ENV, "GOTO_NUM_THREADS") && !haskey(ENV, "OMP_NUM_THREADS")
@static if Sys.isapple() && Base.BinaryPlatforms.arch(Base.BinaryPlatforms.HostPlatform()) == "aarch64"
BLAS.set_num_threads(max(1, Sys.CPU_THREADS))
BLAS.set_num_threads(max(1, @ccall(uv_available_parallelism()::Cint)))
else
BLAS.set_num_threads(max(1, Sys.CPU_THREADS ÷ 2))
BLAS.set_num_threads(max(1, @ccall(uv_available_parallelism()::Cint) ÷ 2))
end
end
end
Expand Down

0 comments on commit 12da794

Please sign in to comment.