Using environment variables

Slurm exports a number of environment variables related to the Cluster, the general configuration and the actual parameters of the Job. These variables are accessible in scripts and have very similar names to the corresponding Slurm or SBATCH options and are therefore easily identifiable.

The full list of environment variables is available at : https://slurm.schedmd.com/sbatch.html#lbAG


Some useful variables :

SLURM_JOB_PARTITION Partition used (--partition)
SLURM_JOB_NAME Job name (Warning, unlike the output / error options, the variables% j /% N ... are not replaced !)
SLURM_NTASKS Number of Tasks (--ntasks)
SLURM_CPUS_PER_TASK Number of CPUs per Task (--cpus-per-task)
SLURM_JOB_NUM_NODES Number of nodes requested / deducted (--nodes)
SLURM_JOB_NODELIST List of nodes used (--nodelist)

 


 

To retrieve a 'VAR' environment variable in...

  • Shell/Bash/[T]CSH:  $VAR
  • Python: os.environ.get('VAR') [OU] os.getenv('VAR')
  • Java: System.getenv("VAR")
  • Lua: os.getenv(VAR)