Skip to content

Output environment variables in SLURM#

The SLURM controller will set the following variables in the environment of the batch script.

Documentation for ouput environment variables in slurm

Most used are:

Variable
SLURM_ARRAY_JOB_ID Job array's master job ID number.
SLURM_JOB_ID The ID of the job allocation.
SLURM_JOBID New version for the ID of the job allocation
SLURM_JOB_DEPENDENCY Set to value of the --dependency option
SLURM_JOB_NAME Name of the job.
SLURM_JOB_NODELIST List of nodes allocated to the job
SLURM_JOB_NUM_NODES Total number of nodes in the job's resource allocation
SLURM_JOB_PARTITION Name of the partition in which the job is running
SLURM_NODELIST List of nodes allocated to the job
SLURM_SUBMIT_DIR The directory from which sbatch was invoked

Script to show slurm variables#

With the following script you can show the variables numbered in the previous section:

#!/bin/bash
#SBATCH -J GNUParallel -o %x-%J.out
#SBATCH --time=00:10:00
#SBATCH --mem-per-cpu=2G
#SBATCH -n 16
#SBATCH -c 4
#SBATCH --ntasks-per-node=8
#SBATCH --constrains=<node arquitecture>  # sandy, ilk (icelake)... arquitecture

date
echo "SUBMITTED ON: $SLURM_SUBMIT_HOST IP: $SLURM_LAUNCH_NODE_IPADDR DIR: $SLURM_SUBMIT_DIR NODES ALLOCATED: $SLURM_JOB_NODELIST"
echo "RUNNING ON: $(hostname) $SLURMD_NODENAME"
echo "JOB_ID: $SLURM_JOB_ID ARRAY_JOB_ID: $SLURM_ARRAY_JOB_ID"
echo "STEP: $SLURM_STEP_ID NODEID: $SLURM_NODEID LOCALID: $SLURM_LOCALID PROCID: $SLURM_PROCID"
echo "ARRAY_TASK_COUNT: $SLURM_ARRAY_TASK_COUNT ARRAY_TASK_ID: $SLURM_ARRAY_TASK_ID ARRAY_TASK_MAX: $SLURM_ARRAY_TASK_MAX ARRAY_TASK_MIN: $SLURM_ARRAY_TASK_MIN ARRAY_STEPSIZE: $SLURM_ARRAY_TASK_STEP"
echo "Args: $*"
sleep 10