From 346077412c481eb7cb0a8eca89625214b27894ee Mon Sep 17 00:00:00 2001 From: Kiran Date: Wed, 24 May 2023 11:01:20 -0400 Subject: [PATCH] Ensure Distributed workers inherit threads spec properly (#49942) (cherry picked from commit aea56a9d9547cff43c3bcfb3dac0fff91bd53793) --- stdlib/Distributed/src/cluster.jl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/stdlib/Distributed/src/cluster.jl b/stdlib/Distributed/src/cluster.jl index d2cbe55e63270..554a3d9185080 100644 --- a/stdlib/Distributed/src/cluster.jl +++ b/stdlib/Distributed/src/cluster.jl @@ -1317,6 +1317,20 @@ end write_cookie(io::IO) = print(io.in, string(cluster_cookie(), "\n")) +function get_threads_spec(opts) + if opts.nthreads > 0 + @assert opts.nthreadpools >= 1 + @assert opts.nthreads_per_pool != C_NULL + thr = "$(unsafe_load(opts.nthreads_per_pool))" + if opts.nthreadpools == 2 + thr = "$(thr),$(unsafe_load(opts.nthreads_per_pool, 2))" + end + `--threads=$(thr)` + else + `` + end +end + # Starts workers specified by (-n|--procs) and --machine-file command line options function process_opts(opts) # startup worker. @@ -1331,7 +1345,9 @@ function process_opts(opts) end # Propagate --threads to workers - exeflags = opts.nthreads > 0 ? `--threads=$(opts.nthreads)` : `` + threads = get_threads_spec(opts) + + exeflags = `$threads` # add processors if opts.nprocs > 0