From 72cb2fd70793b02dcbe38a0c5082bd47c59e5a48 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 (JuliaLang/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 f77b8a6993284e205cddf5a041d6337d3b2d23d3) --- src/cluster.jl | 1 + src/managers.jl | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cluster.jl b/src/cluster.jl index b7268a7..37f1660 100644 --- a/src/cluster.jl +++ b/src/cluster.jl @@ -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) diff --git a/src/managers.jl b/src/managers.jl index e3ecb97..f5f2d87 100644 --- a/src/managers.jl +++ b/src/managers.jl @@ -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()