SBATCH Directives
SBATCH directives are the commands SLURM uses to define your job - the resources it needs and how the job should behave as it is started. These directives work for both jobs started from the command line and from submission scripts. Directives are added to scripts using the following pattern:
#SBATCH --<directive>=<value> #in a batch script
or
salloc --<directive>=<value>
example:
#SBATCH --mem=12G #Request 12GB of Memory
or
salloc --mem=12G
Supported Directives
The SLURM documentation has a list of all supported directives. A selection of useful ones are recorded in the table below.
| Directive |
Description |
| --job-name |
Gives the job a name that will be shown along with the job number in squeue. By default, it is the name of the batch script used to submit the job. |
| --output |
Name of the file that SLURM should save terminal output during the job run into. If not specified, the default filename is slurm-<jobID>.out. |
| --partition |
The name of the partition to submit to. By default, the requeue partition is used. |
| --nodes |
The number of nodes requested for your job. It is highly recommended to set this, or SLURM may assign your CPU cores across multiple nodes which increases communication overhead. |
| --ntasks |
The number of tasks, which by default will be assigned 1 CPU core each. |
| --mem |
The amount of memory requested for your job. SLURM accepts units of K,M,G,T |
| --time |
The time limit for your job. The max time for public queues is 2 days and the format is DD-HH:MM:SS. |
| --mail-user |
The username to email with job updates. The default is the user that submitted the job. |
| --mail-type |
The events that will trigger an email to the named user. Some useful events are: BEGIN,END,FAIL,REQUEUE,ALL |
| --get-user-env |
This will cause SLURM to pass your current environment variables into the job environment. This is not recommended; your job should set its own environment with Lmod if needed. |
Filename Patterns Within Directives
SLURM directives that interact with filenames support variables within the directives. These variables are only available within the SLURM layer and are not available to code that executes once the job has started.
These variables are used to manipulate filenames in a programmatic way.
They are denoted by a "%" symbol and some useful ones are:
| Symbol |
Replaced With |
| %j |
The job # of the job |
| %A |
Job array's master job #. |
| %a |
Array job # |
| %u |
Username |
| %x |
Job name |
The full list of supported filename patterns from the SLURM documentation is available here.