Skip to content

Commit cfd9d63

Browse files
committed
Factor the "construct srun command" functionality out into a separate construct_srun_cmd() function
1 parent c7d03e7 commit cfd9d63

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/slurmmanager.jl

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,31 +171,42 @@ function warn_if_unexpected_params(params::Dict)
171171
return nothing
172172
end
173173

174+
@static if Base.VERSION >= v"1.6.0"
175+
# Pass the key-value pairs from `params[:env]` to the `srun` command:
176+
function construct_srun_cmd(; params::Dict)
177+
exehome = params[:dir]
178+
exename = params[:exename]
179+
exeflags = params[:exeflags]
180+
181+
_srun_cmd_without_env = `srun -D $exehome $exename $exeflags --worker`
182+
183+
env2 = _new_environment_additions(Dict{String,String}(params[:env]))
184+
srun_cmd_with_env = addenv(_srun_cmd_without_env, env2)
185+
186+
return srun_cmd_with_env
187+
end
188+
else
189+
# See discussion above for why we don't support this functionality on Julia 1.5 and earlier.
190+
function construct_srun_cmd(; params::Dict)
191+
exehome = params[:dir]
192+
exename = params[:exename]
193+
exeflags = params[:exeflags]
194+
195+
_srun_cmd_without_env = `srun -D $exehome $exename $exeflags --worker`
196+
197+
return _srun_cmd_without_env
198+
end
199+
end
200+
174201
function Distributed.launch(manager::SlurmManager, params::Dict, instances_arr::Array, c::Condition)
175202
try
176203
warn_if_unexpected_params(params)
177204

178-
exehome = params[:dir]
179-
exename = params[:exename]
180-
exeflags = params[:exeflags]
181-
182-
_srun_cmd_without_env = `srun -D $exehome $exename $exeflags --worker`
183-
184-
@static if Base.VERSION >= v"1.6.0"
185-
# Pass the key-value pairs from `params[:env]` to the `srun` command:
186-
env2 = _new_environment_additions(Dict{String,String}(params[:env]))
187-
srun_cmd_with_env = addenv(_srun_cmd_without_env, env2)
188-
else
189-
# See discussion above for why we don't support this functionality on Julia 1.5 and earlier.
190-
if haskey(params, :env)
191-
@warn "SlurmClusterManager.jl does not support params[:env] on Julia 1.5 and earlier" Base.VERSION
192-
end
193-
srun_cmd_with_env = _srun_cmd_without_env
194-
end
205+
srun_cmd = construct_srun_cmd(; params=params)
195206

196207
# Pass cookie as stdin to srun; srun forwards stdin to process
197208
# This way the cookie won't be visible in ps, top, etc on the compute node
198-
manager.srun_proc = open(srun_cmd_with_env, write=true, read=true)
209+
manager.srun_proc = open(srun_cmd, write=true, read=true)
199210
write(manager.srun_proc, cluster_cookie())
200211
write(manager.srun_proc, "\n")
201212

0 commit comments

Comments
 (0)