I'm fairly new to HPC computing using the SLURM Workload Manager and hence have yet to find a reliable working routine. As of now, I have a jobscript with a bunch of #SBATCH flags that I modify whenever I do another calculation. This includes the total run time and the number of nodes / tasks / CPUs.
Since I'm still gaining experience, I would like to save the chosen options for reference in the standard .out - file produced by SLURM. I have found on the sbatch manual page a few options in the filename pattern section to at least remember the jobname, but what I really want is a complete list of all the set #SBATCH flags.
My current workaround goes like this
#!/bin/bash
#SBATCH --ntasks=2
#SBATCH --cpus-per-task=4
#SBATCH --time=0:20:00
#SBATCH --mem=4G
#SBATCH -p normal
#SBATCH -q cont
#SBATCH -J crosscorr
#SBATCH --output=jobscript_slurmout/R-%j.%x.out
echo "#SBATCH --ntasks=2
#SBATCH --cpus-per-task=4
#SBATCH --time=0:20:00
#SBATCH --mem=4G
#SBATCH -p normal
#SBATCH -q cont
#SBATCH -J crosscorr
#SBATCH --output=jobscript_slurmout/R-%j.%x.out
"
and is obviously not satisfying and also prone to typos. Since the SLURM manager relies on code that bash does not see (as it's commented out), I see no easy fix using the bash language for this. Neither did I find any hints using the sbatch options.
Maybe there even is another way to save those options. I know that I might grep these desired options using a automatized seff inquiry, but I wish there would be an easier way, because the Job ID is only assigned after job submission.
I don't know what
slurmis but you appear to be using a construct#SBATCHto set some options for it within what is otherwise abashscript so maybe you could populate a bash array with the options and then both print them and#SBATCHthem, e.g. (the spaces at the start of the here-document lines being read byreadarraymust be tabs, not blanks):You can use that to either replace your current script to set
#SBATCHif that works or to generate another script to replace your current script:or it looks like your file of
#SBATCHdirectives is used by a tool namedoptsso maybe you could do:to use command substitution to provide a "file" of
#SBATCHdirectives tosbatch, or ifsbatchrequires a regular file:to create the file of
#SBATCHcommands, callsbatchwith that file as an argument, then remove that file.all the the
| tee ...s above are just so you can see the#SBATCHdirectives being generated as I think that's mainly what you wanted.