From 390503ebe26074646d880b43ef0f4cf17db37df0 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Sun, 22 May 2022 09:33:43 -0400 Subject: [PATCH] set default blas num threads to Sys.CPU_THREADS / 2 (#45412) Set default blas num threads to Sys.CPU_THREADS / 2 in absence of OPENBLAS_NUM_THREADS Co-authored-by: SamuraiAku <61489439+SamuraiAku@users.noreply.github.com> --- stdlib/LinearAlgebra/src/LinearAlgebra.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/LinearAlgebra/src/LinearAlgebra.jl b/stdlib/LinearAlgebra/src/LinearAlgebra.jl index 28dd32e1cec5b..38f7b8588d1fa 100644 --- a/stdlib/LinearAlgebra/src/LinearAlgebra.jl +++ b/stdlib/LinearAlgebra/src/LinearAlgebra.jl @@ -580,6 +580,10 @@ function __init__() end # register a hook to disable BLAS threading Base.at_disable_library_threading(() -> BLAS.set_num_threads(1)) + + if !haskey(ENV, "OPENBLAS_NUM_THREADS") + BLAS.set_num_threads(max(1, Sys.CPU_THREADS รท 2)) + end end end # module LinearAlgebra