Difference between revisions of "Using Variables in SLURM Jobs"

From UFRC
Jump to navigation Jump to search
m (Text replacement - "Category:SLURM" to "Category:Scheduler")
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:SLURM]]
+
[[Category:Scheduler]]
  
 
=Passing variables into a job at submission=
 
=Passing variables into a job at submission=
Line 5: Line 5:
 
For example to pass the value of the variables A and b into the job script named jobscript.sbatch you can use:
 
For example to pass the value of the variables A and b into the job script named jobscript.sbatch you can use:
 
  sbatch --export=A=5,b='test' jobscript.sbatch
 
  sbatch --export=A=5,b='test' jobscript.sbatch
 +
 +
or
 +
sbatch --export=ALL,A=4,b='test' jobscript.sbatch
 +
 +
The first example will replace the user's environment with a new environment containing only values for A and b and the SLURM_* environment variables.  The second will add the values for A and b to the existing environment.
  
 
=Using variables to set SLURM job name and output files=
 
=Using variables to set SLURM job name and output files=
  
SLURM does not support using variables in the #SBATCH lines within a job script. However, values passed from the command line have precedence over values defined in the job script. So job name and output/error files can be passed on the sbatch command line:
+
SLURM does not support using variables in the #SBATCH lines within a job script. However, values passed from the command line have precedence over values defined in the job script. So the job name and output/error files can be passed on the sbatch command line:
  sbatch --job-name=$A.$b.run --output=$A.$b.out --export=A=5,b='test' jobscript.sbatch
+
A=5
 +
b='test'
 +
  sbatch --job-name=$A.$b.run --output=$A.$b.out --export=A=$A,b=$b jobscript.sbatch

Latest revision as of 20:02, 2 August 2021


Passing variables into a job at submission

It is possible to pass variables into a SLURM job when you submit the job using the --export flag. For example to pass the value of the variables A and b into the job script named jobscript.sbatch you can use:

sbatch --export=A=5,b='test' jobscript.sbatch

or

sbatch --export=ALL,A=4,b='test' jobscript.sbatch

The first example will replace the user's environment with a new environment containing only values for A and b and the SLURM_* environment variables. The second will add the values for A and b to the existing environment.

Using variables to set SLURM job name and output files

SLURM does not support using variables in the #SBATCH lines within a job script. However, values passed from the command line have precedence over values defined in the job script. So the job name and output/error files can be passed on the sbatch command line:

A=5
b='test'
sbatch --job-name=$A.$b.run --output=$A.$b.out --export=A=$A,b=$b jobscript.sbatch