Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| habrok:advanced_job_management:job_arrays [2020/12/22 10:07] – external edit 127.0.0.1 | habrok:advanced_job_management:job_arrays [2026/03/27 14:09] (current) – pedro | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Job arrays ====== | ====== Job arrays ====== | ||
| - | Job arrays allow you to easily submit a whole bunch of very similar jobs with a single job script. All jobs need to have the same resource requirements. The job array allows you to define some range of numbers; the length of this range determines how many jobs will be submitted. Furthermore, | + | Job arrays allow you to easily submit a whole bunch of very similar jobs with a single job script. All jobs need to have the same resource requirements. The job array allows you to define some range of numbers; the length of this range determines how many jobs will be submitted. Furthermore, |
| In order to create a job array, start by creating the job script that you would need to run just one instance of the job. For instance, consider the following job script for running R: | In order to create a job array, start by creating the job script that you would need to run just one instance of the job. For instance, consider the following job script for running R: | ||
| - | < | + | < |
| #!/bin/bash | #!/bin/bash | ||
| #SBATCH --job-name=R_job | #SBATCH --job-name=R_job | ||
| Line 17: | Line 17: | ||
| Now suppose you want this to be run 100 times. You can simply add the array definition by adding the following line somewhere at the top of the script: | Now suppose you want this to be run 100 times. You can simply add the array definition by adding the following line somewhere at the top of the script: | ||
| - | < | + | < |
| #SBATCH --array=1-100 | #SBATCH --array=1-100 | ||
| </ | </ | ||
| \\ | \\ | ||
| - | Then you can use "sbatch <name of job script>" | + | Then you can use '' |
| ===== Using ${SLURM_ARRAY_TASK_ID} ===== | ===== Using ${SLURM_ARRAY_TASK_ID} ===== | ||
| Line 27: | Line 27: | ||
| So let us take it a step further: suppose we have 100 different R scripts that have to be run, which are named myscript1.r, | So let us take it a step further: suppose we have 100 different R scripts that have to be run, which are named myscript1.r, | ||
| - | < | + | < |
| #!/bin/bash | #!/bin/bash | ||
| #SBATCH --job-name=R_job | #SBATCH --job-name=R_job | ||
| Line 39: | Line 39: | ||
| </ | </ | ||
| \\ | \\ | ||
| - | Here the variable ${SLURM_ARRAY_TASK_ID} will be replaced for each job by a value in the given range. | + | Here the variable |
| ===== More complex ranges ===== | ===== More complex ranges ===== | ||
| Line 53: | Line 53: | ||
| ===== Even more complex cases ===== | ===== Even more complex cases ===== | ||
| - | Suppose that you want to use this to pass input parameters to your program. If the input parameter takes a complex range of values, or if you need more than one parameter, the approach described above would probably not work. In this case you could put all your input parameter combinations in a file, where each combination is on a separate line. You can then use the $SLURM_ARRAY_TASK_ID variable to get the n-th line from the file, and pass that your program. For instance: | + | Suppose that you want to use this to pass input parameters to your program. If the input parameter takes a complex range of values, or if you need more than one parameter, the approach described above would probably not work. In this case you could put all your input parameter combinations in a file, where each combination is on a separate line. You can then use the '' |
| < | < | ||
| Line 64: | Line 64: | ||
| </ | </ | ||
| - | Alternatively, | + | Alternatively, |
| < | < | ||
| Line 76: | Line 76: | ||
| ===== Output and job information for job arrays ===== | ===== Output and job information for job arrays ===== | ||
| - | A job array will get just one main job id, just like a regular job. However, the index values of the range will be used as suffix for the job id: < | + | A job array will get just one main job id, just like a regular job. However, the index values of the range will be used as suffix for the job id: < |
| - | The same kind of job ids will also be used in the output of SLURM tools like squeue and sacct. The squeue command will usually try to combine the jobs in the array into a single line, e.g.: | + | The same kind of job ids will also be used in the output of SLURM tools like '' |
| < | < | ||
| Line 85: | Line 85: | ||
| </ | </ | ||
| \\ | \\ | ||
| - | If you want to get each job of the array to appear on a separate line, you can pass the -r or —array option to squeue. | + | If you want to get each job of the array to appear on a separate line, you can pass the '' |
| ===== Cancelling job arrays ===== | ===== Cancelling job arrays ===== | ||