From 7a4c4b0a076eecdf28b0158ab7d77663a772d2cb Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Mon, 5 Dec 2022 14:40:25 -0500 Subject: [PATCH] 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 a8b399416208d91061324814ff8ae080a918e48b) (cherry picked from commit 8830c265eb1813bbf98b5fd7bb39a44b88892b7f) --- stdlib/Distributed/src/cluster.jl | 1 + stdlib/Distributed/src/managers.jl | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/stdlib/Distributed/src/cluster.jl b/stdlib/Distributed/src/cluster.jl index 80e5d6283cdbc..55a30ef6a5cc5 100644 --- a/stdlib/Distributed/src/cluster.jl +++ b/stdlib/Distributed/src/cluster.jl @@ -529,6 +529,7 @@ default_addprocs_params() = Dict{Symbol,Any}( :dir => pwd(), :exename => joinpath(Sys.BINDIR::String, julia_exename()), :exeflags => ``, + :env => [], :enable_threaded_blas => false, :lazy => true) diff --git a/stdlib/Distributed/src/managers.jl b/stdlib/Distributed/src/managers.jl index 3519259190fbc..2d171fb326344 100644 --- a/stdlib/Distributed/src/managers.jl +++ b/stdlib/Distributed/src/managers.jl @@ -450,10 +450,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()