Environment Variables # Slurm Environment Variables Variables set by Slurm inside job scripts and job steps. ## Most Commonly Used | Variable | Description | Example | |----------|-------------|---------| | `SLURM_JOB_ID` | Job ID | `12345` | | `SLURM_JOB_NAME` | Job name (`--job-name`) | `blast_run` | | `SLURM_SUBMIT_DIR` | Directory where `sbatch` was run | `/home/jdoe/project` | | `SLURM_NODELIST` | Allocated node(s) | `node[042-043]` | | `SLURM_NTASKS` | Total tasks (`--ntasks`) | `32` | | `SLURM_CPUS_PER_TASK` | CPUs per task (`--cpus-per-task`) | `8` | | `SLURM_JOB_NUM_NODES` | Number of nodes | `2` | | `SLURM_MEM_PER_NODE` | Memory per node in MB | `65536` | | `SLURM_JOB_PARTITION` | Partition name | `batch` | | `SLURM_JOB_ACCOUNT` | Account name | `smith_lab` | ## Job Array Variables | Variable | Description | Example | |----------|-------------|---------| | `SLURM_ARRAY_JOB_ID` | Parent array job ID | `12340` | | `SLURM_ARRAY_TASK_ID` | This task's index | `42` | | `SLURM_ARRAY_TASK_COUNT` | Total tasks in array | `100` | | `SLURM_ARRAY_TASK_MIN` | Lowest index | `1` | | `SLURM_ARRAY_TASK_MAX` | Highest index | `100` | ## Node & Task Details | Variable | Description | Example | |----------|-------------|---------| | `SLURMD_NODENAME` | Name of this compute node | `node042` | | `SLURM_NODEID` | Node index (0-based) in allocation | `0` | | `SLURM_PROCID` | MPI rank (global task ID) | `7` | | `SLURM_LOCALID` | Local task ID on this node | `3` | | `SLURM_NTASKS_PER_NODE` | Tasks per node | `16` | | `SLURM_CPUS_ON_NODE` | CPUs on this node | `64` | | `SLURM_NNODES` | Number of nodes in allocation | `4` | ## GPU Variables | Variable | Description | Example | |----------|-------------|---------| | `SLURM_GPUS_ON_NODE` | GPUs allocated on this node | `2` | | `CUDA_VISIBLE_DEVICES` | GPU device indices (set by Slurm cgroups) | `0,1` | | `SLURM_JOB_GPUS` | GPU IDs allocated to job | `0,1` | ## Output Filename Patterns Used in `--output` and `--error`: | Pattern | Expands To | Example | |---------|-----------|---------| | `%j` | Job ID | `12345` | | `%x` | Job name | `blast_run` | | `%A` | Array job ID | `12340` | | `%a` | Array task ID | `42` | | `%N` | First node hostname | `node042` | | `%u` | Username | `jdoe` | | `%%` | Literal `%` | `%` | ===== ## References - [SchedMD: sbatch -- Output Environment Variables](https://slurm.schedmd.com/sbatch.html#lbAF) - [SchedMD: srun -- Environment Variables](https://slurm.schedmd.com/srun.html#lbAF)