Common SLURM environment variables

Slurm sets these variables inside jobs and job steps. Not all variables will always be set, depending on how the job was launched and the requested resources. An unset variable does not necessarily mean that no resources were allocated.

Common SLURM Environment Variables

Variable

Description

$SLURM_JOB_ID

The ID of the job allocation.

$SLURM_JOBID

Deprecated. Use $SLURM_JOB_ID instead.

$SLURM_SUBMIT_DIR

The directory from which the job was submitted or interactive session started.

$SLURM_SUBMIT_HOST

The hostname from which the job was submitted or interactive session started.

$SLURM_JOB_NODELIST

Nodes allocated to the job, possibly in a compressed form such as node[001-002]. Expand it with scontrol show hostnames "$SLURM_JOB_NODELIST".

$SLURM_NODELIST

Deprecated. Use $SLURM_JOB_NODELIST instead.

$SLURM_CPUS_PER_TASK

CPUs requested per task. Set when --cpus-per-task or --tres-per-task=cpu=... is specified.

$SLURM_CPUS_ON_NODE

CPUs allocated to the current job step on this node.

$SLURM_JOB_CPUS_PER_NODE

CPUs allocated to the job on each node, in SLURM_JOB_NODELIST order. For example, 4(x2),2 means four CPUs on each of the first two nodes and two CPUs on the third node.

$SLURM_CPUS_PER_GPU

CPUs requested per GPU. Set when --cpus-per-gpu is specified.

$SLURM_MEM_PER_CPU

Host RAM per CPU in MB, corresponding to --mem-per-cpu.

$SLURM_MEM_PER_GPU

Host RAM requested per GPU in MB, set when --mem-per-gpu is specified. (Not GPU VRAM.)

$SLURM_MEM_PER_NODE

Host RAM per node in MB, set for --mem. A --mem-per-cpu request sets SLURM_MEM_PER_CPU instead.

$SLURM_GPUS

GPUs requested with --gpus (-G). Set when that option is specified. Stanage’s documented --gres=gpu:... requests do not set this variable. Use SLURM_GPUS_ON_NODE for the GPU count on this node.

$SLURM_GPUS_ON_NODE

GPUs available to the current job step on this node.

$SLURM_JOB_GPUS

Global GPU IDs allocated to the job. These are device identifiers, not a GPU count or CUDA device indices relative to a job’s device cgroup.

$SLURM_STEP_GPUS

Global GPU IDs allocated to the current step, excluding batch and interactive steps.

$SLURM_NTASKS

Number of tasks in the job or current job step, corresponding to --ntasks.

$SLURM_NTASKS_PER_NODE

Tasks requested per node. Set when --ntasks-per-node is specified.

$SLURM_NTASKS_PER_SOCKET

Tasks requested per socket. Set when --ntasks-per-socket is specified.

$SLURM_NTASKS_PER_CORE

Tasks requested per core. Set when --ntasks-per-core is specified.

$SLURM_NTASKS_PER_GPU

Tasks requested per GPU. Set when --ntasks-per-gpu is specified.

$SLURM_NPROCS

Deprecated. Use $SLURM_NTASKS instead.

$SLURM_JOB_NUM_NODES

Total number of nodes allocated to the job.

$SLURM_NNODES

Deprecated. Use $SLURM_JOB_NUM_NODES instead.

$SLURM_TASKS_PER_NODE

Tasks on each node in SLURM_JOB_NODELIST order. Repeated counts may be compressed, for example 2(x3),1.

$SLURM_ARRAY_JOB_ID

Job array’s master job ID.

$SLURM_ARRAY_TASK_ID

Current array task’s index.

$SLURM_ARRAY_TASK_COUNT

Total number of tasks in the job array.

$SLURM_ARRAY_TASK_MAX

Highest task index in the job array.

$SLURM_ARRAY_TASK_MIN

Lowest task index in the job array.

Array variables apply to array jobs. SLURM_GPUS_ON_NODE, SLURM_JOB_GPUS and SLURM_STEP_GPUS also apply to --gres=gpu:... requests, subject to the step restrictions above. Within a GPU job, CUDA_VISIBLE_DEVICES identifies the CUDA devices visible to the process; its indices can differ from the global GPU IDs in SLURM_JOB_GPUS or SLURM_STEP_GPUS.

For a full list and the conditions under which variables are set, see the output environment-variable sections of the sbatch manual and the srun manual.