Skip to content

Commit 4e07013

Browse files
authored
Update slurmmanager.jl
1 parent c7d03e7 commit 4e07013

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

src/slurmmanager.jl

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,40 @@ mutable struct SlurmManager <: ClusterManager
1212
srun_proc
1313

1414
function SlurmManager(; launch_timeout=60.0, srun_post_exit_sleep=0.01)
15+
ntasks_int = get_slurm_ntasks_int()
16+
jobid_int = get_slurm_jobid_int()
1517

16-
jobid =
17-
if "SLURM_JOB_ID" in keys(ENV)
18-
ENV["SLURM_JOB_ID"]
19-
elseif "SLURM_JOBID" in keys(ENV)
20-
ENV["SLURM_JOBID"]
21-
else
22-
error("""
23-
SlurmManager must be constructed inside a slurm allocation environemnt.
24-
SLURM_JOB_ID or SLURM_JOBID must be defined.
25-
""")
26-
end
27-
28-
ntasks =
29-
if "SLURM_NTASKS" in keys(ENV)
30-
ENV["SLURM_NTASKS"]
31-
else
32-
error("""
33-
SlurmManager must be constructed inside a slurm environment with a specified number of tasks.
34-
SLURM_NTASKS must be defined.
35-
""")
36-
end
18+
new(jobid_int, ntasks_int, launch_timeout, srun_post_exit_sleep, nothing)
19+
end
20+
end
3721

38-
jobid = parse(Int, jobid)
39-
ntasks = parse(Int, ntasks)
22+
function get_slurm_ntasks_int()
23+
if "SLURM_JOB_ID" in keys(ENV)
24+
ntasks_str = ENV["SLURM_JOB_ID"]
25+
elseif "SLURM_JOBID" in keys(ENV)
26+
ntasks_str = ENV["SLURM_JOBID"]
27+
else
28+
msg = "SlurmManager must be constructed inside a Slurm allocation environment." *
29+
"SLURM_JOB_ID or SLURM_JOBID must be defined."
30+
error(msg)
31+
end
32+
ntasks_int = parse(Int, ntasks_str)::Int
33+
return ntasks_int
34+
end
4035

41-
new(jobid, ntasks, launch_timeout, srun_post_exit_sleep, nothing)
36+
function get_slurm_jobid_int()
37+
if "SLURM_JOB_ID" in keys(ENV)
38+
jobid_str = ENV["SLURM_JOB_ID"]
39+
elseif "SLURM_JOBID" in keys(ENV)
40+
jobid_str = ENV["SLURM_JOBID"]
41+
else
42+
msg = "SlurmManager must be constructed inside a Slurm allocation environment." *
43+
"SLURM_JOB_ID or SLURM_JOBID must be defined."
44+
error(msg)
4245
end
46+
47+
jobid_int = parse(Int, jobid_str)::Int
48+
return jobid_int
4349
end
4450

4551
@static if Base.VERSION >= v"1.9.0"

0 commit comments

Comments
 (0)