Skip to content

Commit 7a4c4b0

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) (cherry picked from commit 8830c26)
1 parent fec82b7 commit 7a4c4b0

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
@@ -529,6 +529,7 @@ default_addprocs_params() = Dict{Symbol,Any}(
529529
:dir => pwd(),
530530
:exename => joinpath(Sys.BINDIR::String, julia_exename()),
531531
:exeflags => ``,
532+
:env => [],
532533
:enable_threaded_blas => false,
533534
:lazy => true)
534535

stdlib/Distributed/src/managers.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,18 @@ function launch(manager::LocalManager, params::Dict, launched::Array, c::Conditi
450450
exename = params[:exename]
451451
exeflags = params[:exeflags]
452452
bind_to = manager.restrict ? `127.0.0.1` : `$(LPROC.bind_addr)`
453+
env = Dict{String,String}(params[:env])
454+
455+
# If we haven't explicitly asked for threaded BLAS, prevent OpenBLAS from starting
456+
# up with multiple threads, thereby sucking up a bunch of wasted memory on Windows.
457+
if !params[:enable_threaded_blas] &&
458+
get(env, "OPENBLAS_NUM_THREADS", nothing) === nothing
459+
env["OPENBLAS_NUM_THREADS"] = "1"
460+
end
453461

454462
for i in 1:manager.np
455463
cmd = `$(julia_cmd(exename)) $exeflags --bind-to $bind_to --worker`
456-
io = open(detach(setenv(cmd, dir=dir)), "r+")
464+
io = open(detach(setenv(addenv(cmd, env), dir=dir)), "r+")
457465
write_cookie(io)
458466

459467
wconfig = WorkerConfig()

0 commit comments

Comments
 (0)