Skip to content
Snippets Groups Projects
Commit c7264650 authored by Martin Schroschk's avatar Martin Schroschk
Browse files

WIP Add page on Slurm environment variables

parent aafafaf9
Branches slurm-env-vars
No related tags found
1 merge request!954Draft: WIP Add page on Slurm environment variables
Slurm Environment Variables
* Following is restricted to `sbatch` command
* Differentiation between input and output variables
The Slurm controller will set variables in the environment of the batch script
## Input Environment Variables
Upon startup, `sbatch` will read and handle the options set in the so-called *input environment
variables*. With few exceptions, all input variables will be set the same way as the corresponding
commandline options and `#SBATCH` directives. The following table provides some input environment
variables and the equivalent option to `sbatch`.
For a comprehensive documentation, please visit Slurm's
[page on input variables for sbatch](https://slurm.schedmd.com/sbatch.html#SECTION_INPUT-ENVIRONMENT-VARIABLES)
. Here, you will find the entire list of input variables for the latest Slurm version. ZIH systems
might operate on a older Slurm version.
| Environment Variable | Equivalent Option |
|:------------------------------|:-------------------|
| `SBATCH_ACCOUNT` | `-A, --account` |
| `SBATCH_CONSTRAINT` | `-C, --constraint` |
| `SBATCH_ERROR` | `-e, --error` |
| `SBATCH_OUPUT` | `-o, --output` |
| `SBATCH_JOB_NAME` | `-J, --job-name` |
| `SBATCH_HINT` or `SLURM_HINT` | `--hint` |
| `SBATCH_MEM_BIN` | `--mem-bind` |
!!! note "Priority: Commandline option > env. variable > option in jobfile"
Environment variables will override any options set in a batch script, and command line options
will override any environment variables.
## Output Environment Variables
The Slurm controller will set a number of *output environment variables* in the environment of the
batch script. This allows to obtain values of Slurm parameters within the environment of the job
script, e.g., `SLURM_JOB_ID`, `SLURM_NTASKS`, `SLURM_CPUS_PER_TASK`, `SLURM_MEM_PER_NODE`,
`SLURM_JOB_NODELIST`, `SLURM_JOB_NUM_NODES` and many more, which is quite useful for automation and
generalisation of job scripts.
!!! example ""
The following skeleton of a job script for an OpenMP-parallel application depicts the
generalization w.r.t. setting the number of threads basing on the environment variable
`SLURM_CPUS_PER_TASKS`. By this, you can only have to adjust the number of cpus per tasks within
the SBATCH directive and the OpenMP environment variable will set to the right value
automatically.
```console
#!/bin/bash
#SBATCH --cpus-per-task=4
[...]
if [ ! -z "${SLURM_CPUS_PER_TASK}" ] ; then
export OMP_NUM_THREADS=${SLURM_CPUS_PER_TASK}
else
export OMP_NUM_THREADS=1
fi
```
## Exporting Environment Variables to Slurm Jobs
WIP:
Using the `--export` option, you can export variables to the Slurm job at submit time.
<!--https://slurm.schedmd.com/sbatch.html#OPT_export_4-->
......@@ -114,6 +114,7 @@ nav:
- Batch System Slurm: jobs_and_resources/slurm.md
- Job Examples: jobs_and_resources/slurm_examples.md
- Slurm Resource Limits: jobs_and_resources/slurm_limits.md
- Slurm Environment Variables: jobs_and_resources/slurm_env_vars.md
- Slurm Job File Generator: jobs_and_resources/slurm_generator.md
- Checkpoint/Restart: jobs_and_resources/checkpoint_restart.md
- Binding and Distribution of Tasks: jobs_and_resources/binding_and_distribution_of_tasks.md
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment