Skip to content

Commit 674f016

Browse files
committed
SSHManager: Add the custom_worker_flag option, but don't add it to the public API
1 parent e49016d commit 674f016

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

src/slurmmanager.jl

+45-6
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,35 @@ end
4444

4545
@static if Base.VERSION >= v"1.9.0"
4646
# In Julia 1.9 and later, the no-argument method `Distributed.default_addprocs_params()`
47-
# includes :env, so we don't need to do anything.
47+
# includes :env.
4848
# See also: https://github.com/JuliaLang/julia/blob/v1.9.0/stdlib/Distributed/src/cluster.jl#L526-L541
49+
#
50+
# So we don't need to add `:env`
51+
# But we do still need to add `:custom_worker_flag`
4952

50-
Distributed.default_addprocs_params(::SlurmManager) = Distributed.default_addprocs_params()
53+
function Distributed.default_addprocs_params(::SlurmManager)
54+
our_stuff = Dict{Symbol,Any}(
55+
:custom_worker_flag => `--worker`,
56+
)
57+
upstreams_stuff = Distributed.default_addprocs_params()
58+
total_stuff = merge(our_stuff, upstreams_stuff)
59+
return total_stuff
60+
end
5161
elseif v"1.6.0" <= Base.VERSION < v"1.9.0"
5262
# In Julia 1.6 through 1.8, the no-argument method `Distributed.default_addprocs_params()`
5363
# does not include :env. However, Julia does allow us to add a specialized method
5464
# `Distributed.default_addprocs_params(::SlurmManager)`, so we do so here.
5565
#
5666
# The ability to add the specialized `Distributed.default_addprocs_params(::SlurmManager)`
57-
# method was added to Julia in https://github.com/JuliaLang/julia/pull/38570
67+
# method was added to Julia in https://github.com/JuliaLang/julia/pull/38570,
68+
# which corresponds to https://github.com/JuliaLang/julia/commit/687378ebfd1188ee7af302ec089cf3d31689647c,
69+
# which is in Julia 1.6 and later.
5870
#
5971
# See also: https://github.com/JuliaLang/julia/blob/v1.8.0/stdlib/Distributed/src/cluster.jl#L526-L540
6072
function Distributed.default_addprocs_params(::SlurmManager)
6173
our_stuff = Dict{Symbol,Any}(
6274
:env => [],
75+
:custom_worker_flag => `--worker`,
6376
)
6477
upstreams_stuff = Distributed.default_addprocs_params()
6578
total_stuff = merge(our_stuff, upstreams_stuff)
@@ -69,6 +82,10 @@ elseif Base.VERSION < v"1.6.0"
6982
# In Julia 1.5 and earlier, Julia does not have the `addenv()` function.
7083
# I don't want to add a dependency on Compat.jl just for this one feature,
7184
# so we will just choose to not support `params[:env]` on Julia 1.5 and earlier.
85+
#
86+
# Also, in Julia 1.5 and earlier, Julia does not have the
87+
# ability to add the specialized `Distributed.default_addprocs_params(::SlurmManager)`
88+
# method.
7289
end
7390

7491
function _new_environment_additions(params_env::Dict{String, String})
@@ -142,6 +159,23 @@ function warn_if_unexpected_params(params::Dict)
142159
# and there is no problem.
143160
end
144161
end
162+
elseif k == :custom_worker_flag
163+
# We special-case `:custom_worker_flag`, because our support status depends on the Julia version
164+
if v == `--worker`
165+
# Either the user didn't provide the `:env` kwarg,
166+
# or the user provided `custom_worker_flag=`--worker``.
167+
#
168+
# Either way, in this case, we don't print a log message.
169+
# @debug "k == :custom_worker_flag and v == `--worker`" k v
170+
else
171+
# In this case, the user has provided the `:custom_worker_flag` kwarg, and it is something other than `--worker`.
172+
if Base.VERSION < v"1.6.0"
173+
@warn "The user provided the `custom_worker_flag` kwarg, but SlurmClusterManager.jl's support for the `custom_worker_flag` kwarg requires Julia 1.6 or later" Base.VERSION
174+
else
175+
# Here, the Julia version is >= 1.6, so we do support `:custom_worker_flag`,
176+
# and there is no problem.
177+
end
178+
end
145179
elseif k in params_that_we_support
146180
# We support this param, so no problem.
147181
else
@@ -179,9 +213,10 @@ function Distributed.launch(manager::SlurmManager, params::Dict, instances_arr::
179213
exename = params[:exename]
180214
exeflags = params[:exeflags]
181215

182-
_srun_cmd_without_env = `srun -D $exehome $exename $exeflags --worker`
183-
184216
@static if Base.VERSION >= v"1.6.0"
217+
custom_worker_flag = params[:custom_worker_flag]
218+
_srun_cmd_without_env = `srun -D $exehome $exename $exeflags $custom_worker_flag`
219+
185220
# Pass the key-value pairs from `params[:env]` to the `srun` command:
186221
env2 = _new_environment_additions(Dict{String,String}(params[:env]))
187222
srun_cmd_with_env = addenv(_srun_cmd_without_env, env2)
@@ -190,7 +225,11 @@ function Distributed.launch(manager::SlurmManager, params::Dict, instances_arr::
190225
if haskey(params, :env)
191226
@warn "SlurmClusterManager.jl does not support params[:env] on Julia 1.5 and earlier" Base.VERSION
192227
end
193-
srun_cmd_with_env = _srun_cmd_without_env
228+
if haskey(params, :custom_worker_flag)
229+
@warn "SlurmClusterManager.jl does not support params[:custom_worker_flag] on Julia 1.5 and earlier" Base.VERSION
230+
end
231+
232+
srun_cmd_with_env = `srun -D $exehome $exename $exeflags --worker`
194233
end
195234

196235
# Pass cookie as stdin to srun; srun forwards stdin to process

0 commit comments

Comments
 (0)