<div dir="ltr">Hi Chris,<div><br></div><div>I think my question isn't quite clear, but I'm also pretty confident the answer is no at this point. The idea is that the script is sort of like a template for running a job, and an end user can submit a custom job with their own desired resource requests which will end up filling in the template. I'm not in control of the Slurm cluster that will ultimately run the job, nor the details of the job itself. For example, <font face="monospace">template-job.sh</font> might look like this:<br><br><font face="monospace">#!/bin/bash</font></div><div><font face="monospace">srun -c 1 --mem=1k echo "Preamble"</font></div><div><font face="monospace">srun -c <CPUs> --mem=<Memory>m /bin/sh -c <user's shell script></font></div><div><font face="monospace">srun -c 1 --mem=1k echo "Postamble"</font></div><div><br></div><div>My goal is that even if the user requests 10 CPUs when the cluster only has 4 available, the Preamble and Postamble steps will always run. But as I said, it seems like that's not possible since the maximum number of CPUs needs to be set on the <font face="monospace">sbatch</font><font face="arial, sans-serif"> allocation and the whole job would be rejected on the basis that too many CPUs were requested. Is that correct?</font></div></div><div dir="auto"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 5, 2020, 11:13 PM Chris Samuel <<a href="mailto:chris@csamuel.org" target="_blank">chris@csamuel.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tuesday, 5 May 2020 11:00:27 PM PDT Maria Semple wrote:<br>
<br>
> Is there no way to achieve what I want then? I'd like the first and last job<br>
> steps to always be able to run, even if the second step needs too many<br>
> resources (based on the cluster).<br>
<br>
That should just work.<br>
<br>
#!/bin/bash<br>
#SBATCH -c 2<br>
#SBATCH -n 1<br>
<br>
srun -c 1 echo hello<br>
srun -c 4 echo big wide<br>
srun -c 1 echo world<br>
<br>
gives:<br>
<br>
hello<br>
srun: Job step's --cpus-per-task value exceeds that of job (4 > 2). Job step <br>
may never run.<br>
srun: error: Unable to create step for job 604659: More processors requested <br>
than permitted<br>
world<br>
<br>
> As a side note, do you know why it's not even possible to restrict the<br>
> number of resources a single step uses (i.e. set less CPUs than are<br>
> available to the full job)?<br>
<br>
My suspicion is that you've not set up Slurm to use cgroups to restrict the <br>
resources a job can use to just those requested.<br>
<br>
<a href="https://slurm.schedmd.com/cgroups.html" rel="noreferrer noreferrer" target="_blank">https://slurm.schedmd.com/cgroups.html</a><br>
<br>
All the best,<br>
Chris<br>
-- <br>
  Chris Samuel  :  <a href="http://www.csamuel.org/" rel="noreferrer noreferrer" target="_blank">http://www.csamuel.org/</a>  :  Berkeley, CA, USA<br>
<br>
<br>
<br>
<br>
</blockquote></div>