From dd0e83903a52b25b9aee2c114fe706713025a257 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) --- stdlib/Distributed/src/managers.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stdlib/Distributed/src/managers.jl b/stdlib/Distributed/src/managers.jl index e3ecb97767ae39..9f8f9335a90689 100644 --- a/stdlib/Distributed/src/managers.jl +++ b/stdlib/Distributed/src/managers.jl @@ -462,6 +462,14 @@ 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`