Skip to content

Commit

Permalink
Set OPENBLAS_NUM_THREADS=1 on local Distributed workers (JuliaLang/…
Browse files Browse the repository at this point in the history
…julia#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 f77b8a6)
  • Loading branch information
staticfloat authored and KristofferC committed Dec 14, 2022
1 parent 7f35b2e commit 72cb2fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ default_addprocs_params() = Dict{Symbol,Any}(
:dir => pwd(),
:exename => joinpath(Sys.BINDIR, julia_exename()),
:exeflags => ``,
:env => [],
:enable_threaded_blas => false,
:lazy => true)

Expand Down
10 changes: 9 additions & 1 deletion src/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,18 @@ function launch(manager::LocalManager, params::Dict, launched::Array, c::Conditi
exename = params[:exename]
exeflags = params[:exeflags]
bind_to = manager.restrict ? `127.0.0.1` : `$(LPROC.bind_addr)`
env = Dict{String,String}(params[:env])

# If we haven't explicitly asked for threaded BLAS, prevent OpenBLAS from starting
# up with multiple threads, thereby sucking up a bunch of wasted memory on Windows.
if !params[:enable_threaded_blas] &&
get(env, "OPENBLAS_NUM_THREADS", nothing) === nothing
env["OPENBLAS_NUM_THREADS"] = "1"
end

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

wconfig = WorkerConfig()
Expand Down

0 comments on commit 72cb2fd

Please sign in to comment.