You can inspect all environment variables available in a job by submitting the following jobscript

#!/bin/bash
#SBATCH --nodes=1 --time=1:00
echo "-----"
echo "Non-SLURM environment"
echo "-----"
env | grep -v SLURM
echo "-----"
echo "SLURM environment"
echo "-----"
env | grep SLURM

and inspecting the output.

SLURM sets automatically several environment variables. A non-exhaustive list of the most useful variables is shown here.

Variable nameDescription
USERYour username.
HOSTNAMEName of the computer currently running the script.
HOMEYour home directory.
PWDCurrent directory the script is running in. Changes when you do cd in a script.
SLURM_SUBMIT_DIRDirectory where the sbatch command was executed.
SLURM_JOBIDID number assigned to the job upon submission. The same number is seen in showq.
SLURM_JOB_NAMEName of the job script.
SLURM_NODELISTA collapsed list of nodes assigned to this job (see comments below)
SLURM_ARRAY_TASK_IDArray ID numbers for jobs submitted with the -t flag. For #SBATCH -a 1-8, this will be an integer between 1 and 8.
SLURM_NTASKSNumber of tasks for the job.
SLURM_NTASKS_PER_NODENumber of tasks per node.

The list of nodes assigned to a job is stored in the variable $SLURM_NODELIST in a compact form (e.g: "tcn[1-10]" means nodes tcn1, tcn2, ..., tcn10 are assigned to the job). To obtain the full list of compute nodes available for the job you can use the following command:

scontrol show hostnames 

which will print all the nodes available as ordered list, e.g:

tcn1
tcn2
tcn3
tcn4
tcn5
tcn6
tcn7
tcn8
tcn9
tcn10

On Snellius we are not exporting  environment variables which are set by the user within the bash session.

This apply both to variables set by the user (interactively and in .bashrc or similar configuration files)  or set by module files. This means that every variable you would like to be set at runtime, needs to be explicitly exported in the job script. Similar to this, any module you would like to have loaded at runtime, needs to be explicitly loaded within the job script. 

  • No labels