Skip to content

SLURM Environment Variables

The Slurm controller will set variables in the environment of the batch script. Below is a list of SLURM variables and the corresponding Torque/MOAB environment variables for the comparison.

SLURM Variables Torque/MOAB Description
SLURM_ARRAY_TASK_COUNT Total number of tasks in a job array
SLURM_ARRAY_TASK_ID PBS_ARRAYID Job array ID (index) number
SLURM_ARRAY_TASK_MAX Job array's maximum ID (index) number
SLURM_ARRAY_TASK_MIN Job array's minimum ID (index) number
SLURM_ARRAY_TASK_STEP Job array's index step size
SLURM_ARRAY_JOB_ID PBS_JOBID Job array's master job ID number
SLURM_CLUSTER_NAME Name of the cluster on which the job is executing
SLURM_CPUS_ON_NODE Number of CPUS on the allocated node
SLURM_CPUS_PER_TASK PBS_VNODENUM Number of cpus requested per task. Only set if the --cpus-per-task option is specified.
SLURM_JOB_ACCOUNT Account name associated of the job allocation
SLURM_JOBID, SLURM_JOB_ID PBS_JOBID The ID of the job allocation
SLURM_JOB_CPUS_PER_NODE PBS_NUM_PPN Count of processors available to the job on this node.
SLURM_JOB_DEPENDENCY Set to value of the --dependency option
SLURM_NODELIST, SLURM_JOB_NODELIST PBS_NODEFILE List of nodes allocated to the job
SLURM_NNODES, SLURM_JOB_NUM_NODES Total number of different nodes in the job's resource allocation
SLURM_MEM_PER_NODE Same as --mem
SLURM_MEM_PER_CPU Same as --mem-per-cpu
SLURM_NTASKS_PER_NODE Number of tasks requested per node. Only set if the --ntasks-per-node option is specified.
SLURM_NTASKS_PER_SOCKET Number of tasks requested per socket. Only set if the --ntasks-per-socket option is specified.
SLURM_SUBMIT_DIR PBS_O_WORKDIR The directory from which sbatch was invoked
SLURM_SUBMIT_HOST PBS_O_HOST The hostname of the computer from which sbatch was invoked
SLURM_TASK_PID The process ID of the task being started
SLURMD_NODENAME Name of the node running the job script
SLURM_JOB_GPUS GPU IDs allocated to the job (if any).

Using Variables in SLURM Jobs

You may also set your own variables for use in your SLURM jobs. One way is to set them inside the script itself, but that requires modifying the script. It is possible to pass variables into a SLURM job when you submit the job using the --export flag. For example to pass the value of the variables REPS and X into the job script named you can use:

sbatch --export=REPS=500,X='test'

These are then available in your jobs as $REPS and $X

Using variables to set SLURM job name and output files

SLURM does not support using variables in the #SBATCH lines within a job script (for example, #SBATCH -N=$REPS will NOT work). A very limited number of variables are available in the #SBATCH just as %j for JOB ID. However, values passed from the command line have precedence over values defined in the job script and you can set certain SLURM variables in the command line. For example, you could set the job name and output/error files can be passed on the sbatch command line:

sbatch --job-name=$RUNTYPE.$ --output=$RUNTYPE.$RUNUMBER.txt --export=A=$A,b=$b jobscript.sbatch

However note in this example, the output file doesn't have the job ID, which is not available from the command line, only inside the sbatch shell script.