Ticket 12245

Summary: Can't shrink a running job that used --nodes=minnodes-maxnodes
Product: Slurm Reporter: Felix Abecassis <fabecassis>
Component: SchedulingAssignee: Scott Hilton <shilton>
Status: RESOLVED FIXED QA Contact: Danny Auble <dauble>
Severity: 4 - Minor Issue    
Priority: --- CC: jbernauer, jblomqvist, lyeager
Version: 20.11.8   
Hardware: Linux   
OS: Linux   
Site: NVIDIA (PSLA) Slinky Site: ---
Alineos Sites: --- Atos/Eviden Sites: ---
Confidential Site: --- Coreweave sites: ---
Cray Sites: --- DS9 clusters: ---
Google sites: --- HPCnow Sites: ---
HPE Sites: --- IBM Sites: ---
NOAA SIte: --- NoveTech Sites: ---
Nvidia HWinf-CS Sites: --- OCF Sites: ---
Recursion Pharma Sites: --- SFW Sites: ---
SNIC sites: --- Tzag Elita Sites: ---
Linux Distro: --- Machine Name:
CLE Version: Version Fixed: 21.08.2 22.05.0pre1
Target Release: --- DevPrio: ---
Emory-Cloud Sites: ---

Description Felix Abecassis 2021-08-09 20:53:40 MDT
We have a job that can use a varying number of nodes, but let's assume it has an additional constraint: the number of nodes must be a multiple of 4. 

It would be ideal to be able to do something like this: sbatch --nodes=4,8,12,16. But AFAIK no such feature exists.

Instead, we can use --nodes=4-16; and inside the sbatch script we start by shrinking the allocation by rounding down to the nearest multiple of 4. Shrinking a job is described in the Slurm FAQ: https://slurm.schedmd.com/faq.html#job_size

Unfortunately, using a range for --nodes is incompatible with the approach mentioned above. On a 8 nodes cluster where 2 nodes are currently in-use, use the following run.sub and commands:
$ cat run_bug.sub 
#!/bin/bash -eu

echo initial allocation: ${SLURM_NNODES} ${SLURM_NODELIST}

scontrol update jobid=${SLURM_JOBID} NumNodes=4 >/dev/null
source ./slurm_job_${SLURM_JOBID}_resize.sh
rm -f ./slurm_job_${SLURM_JOBID}_resize.{csh,sh}

echo new allocation: ${SLURM_NNODES} ${SLURM_NODELIST}

$ sbatch -N4-8 run_bug.sub 
Submitted batch job 396

$ cat slurm-396.out 
initial allocation: 6 node-[1-6]
Job is no longer pending execution for job 396

But an equivalent sbatch with the same number of initial nodes but no nodes range will work fine:
$ sbatch -N6 run_bug.sub 
Submitted batch job 398
$ cat slurm-398.out 
initial allocation: 6 node-[1-6]
new allocation: 4 node-[1-4]


Looking at the slurmctld log, with -N4-8, the following line appears in the slurmctld log:
slurmctld: _update_job: adjusting min_cpus (prev: 1) to be at least : 4

The job update is subsequently rejected here: https://github.com/SchedMD/slurm/blob/slurm-20-11-8-1/src/slurmctld/job_mgr.c#L12791


It seems like the two cases should be equivalent.

This is not very high priority though, since we found a workaround: shrink the job with NodeList instead of NumNodes:
scontrol update jobid=${SLURM_JOBID} NodeList=$(scontrol show hostname "${SLURM_NODELIST}" | head -n 4 | tr '\n' ',')
This works fine, by printing the node list and truncating it to the first 4 nodes. This is really hacky though.
Comment 1 Felix Abecassis 2021-08-09 21:03:51 MDT
Note that if there is another solution to this problem that doesn't require shrinking the job at runtime, then it would be even better.
Comment 2 Jason Booth 2021-08-10 14:26:46 MDT
This does seem like a but to me. One other option available to you might be the use of constraint with a count.

$ salloc  --constraint="[css*4|css*2]"
salloc: Granted job allocation 5137

$ echo $SLURM_JOB_NODELIST
n[1-4]

This requires you to specify "Feature=css" on each node in your slurm.conf.

https://slurm.schedmd.com/sbatch.html#OPT_cluster-constraint


I will have our engineering team look into the possible bug here.
Comment 4 Felix Abecassis 2021-08-18 19:05:11 MDT
Jason, unfortunately we can't use that as we also use the new node_features/helper plugin (that we contributed), but a known limitation is that it can't support all the operators of the constraints DSL, see https://bugs.schedmd.com/show_bug.cgi?id=12286
Comment 19 Scott Hilton 2021-09-21 15:54:36 MDT
Felix, 

We found and fixed the bug and it should be in 21.08.2. See commit 369502dfe8.

-Scott