Skip to content

Commit 8830c26

Browse files
staticfloatKristofferC
authored and
KristofferC
committed
Set OPENBLAS_NUM_THREADS=1 on local Distributed workers (#47803)
This should prevent LinearAlgebra from trying to increase our OpenBLAS thread count in its `__init__()` method when we're not trying to enable threaded BLAS. (cherry picked from commit a8b3994)
1 parent 4e152d4 commit 8830c26

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

stdlib/Distributed/src/cluster.jl

+1
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ default_addprocs_params() = Dict{Symbol,Any}(
536536
:dir => pwd(),
537537
:exename => joinpath(Sys.BINDIR, julia_exename()),
538538
:exeflags => ``,
539+
:env => [],
539540
:enable_threaded_blas => false,
540541
:lazy => true)
541542

stdlib/Distributed/src/managers.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,18 @@ function launch(manager::LocalManager, params::Dict, launched::Array, c::Conditi
462462
exename = params[:exename]
463463
exeflags = params[:exeflags]
464464
bind_to = manager.restrict ? `127.0.0.1` : `$(LPROC.bind_addr)`
465+
env = Dict{String,String}(params[:env])
466+
467+
# If we haven't explicitly asked for threaded BLAS, prevent OpenBLAS from starting
468+
# up with multiple threads, thereby sucking up a bunch of wasted memory on Windows.
469+
if !params[:enable_threaded_blas] &&
470+
get(env, "OPENBLAS_NUM_THREADS", nothing) === nothing
471+
env["OPENBLAS_NUM_THREADS"] = "1"
472+
end
465473

466474
for i in 1:manager.np
467475
cmd = `$(julia_cmd(exename)) $exeflags --bind-to $bind_to --worker`
468-
io = open(detach(setenv(cmd, dir=dir)), "r+")
476+
io = open(detach(setenv(addenv(cmd, env), dir=dir)), "r+")
469477
write_cookie(io)
470478

471479
wconfig = WorkerConfig()

0 commit comments

Comments
 (0)