Bureaucrats, cc_docs_admin, cc_staff
2,879
edits
(Remove Draft, mark for translation) |
(Marked this version for translation) |
||
Line 2: | Line 2: | ||
<translate> | <translate> | ||
<!--T:1--> | |||
''Parent page: [[Running jobs]]'' | ''Parent page: [[Running jobs]]'' | ||
<!--T:2--> | |||
If your work consists of a large number of tasks which differ only in some parameter, you can conveniently submit many tasks at once using a ''job array,'' also known as a ''task array'' or an ''array job''. The individual tasks in the array are distinguished by an environment variable, <code>$SLURM_ARRAY_TASK_ID</code>, which Slurm sets to a different value for each task. You set the range of values with the <code>--array</code> parameter. | If your work consists of a large number of tasks which differ only in some parameter, you can conveniently submit many tasks at once using a ''job array,'' also known as a ''task array'' or an ''array job''. The individual tasks in the array are distinguished by an environment variable, <code>$SLURM_ARRAY_TASK_ID</code>, which Slurm sets to a different value for each task. You set the range of values with the <code>--array</code> parameter. | ||
See [https://slurm.schedmd.com/job_array.html Job Array Support] at SchedMD.com for detailed documentation. | See [https://slurm.schedmd.com/job_array.html Job Array Support] at SchedMD.com for detailed documentation. | ||
== Examples of the --array parameter == | == Examples of the --array parameter == <!--T:3--> | ||
sbatch --array=0-7 # $SLURM_ARRAY_TASK_ID takes values from 0 to 7 inclusive | <!--T:4--> | ||
sbatch --array=0-7 # $SLURM_ARRAY_TASK_ID takes values from 0 to 7 inclusive | |||
sbatch --array=1,3,5,7 # $SLURM_ARRAY_TASK_ID takes the listed values | sbatch --array=1,3,5,7 # $SLURM_ARRAY_TASK_ID takes the listed values | ||
sbatch --array=1-7:2 # Step-size of 2, same as the previous example | sbatch --array=1-7:2 # Step-size of 2, same as the previous example | ||
sbatch --array=1-100%10 # Allows no more than 10 of the jobs to run simultaneously | sbatch --array=1-100%10 # Allows no more than 10 of the jobs to run simultaneously | ||
== A simple example == | == A simple example == <!--T:5--> | ||
<!--T:6--> | |||
{{File | {{File | ||
|name=simple_array.sh | |name=simple_array.sh | ||
Line 27: | Line 31: | ||
}} | }} | ||
<!--T:7--> | |||
This job will be scheduled as ten independent tasks. Each task has a separate time limit of 3 hours, and each may start at a different time on a different host. | This job will be scheduled as ten independent tasks. Each task has a separate time limit of 3 hours, and each may start at a different time on a different host. | ||
<!--T:8--> | |||
The script references $SLURM_ARRAY_TASK_ID to select an input file, for example ("program_x"), or to set a command-line argument for the application ("program_y"). | The script references $SLURM_ARRAY_TASK_ID to select an input file, for example ("program_x"), or to set a command-line argument for the application ("program_y"). | ||
<!--T:9--> | |||
Using a job array instead of a large number of separate serial jobs has advantages for you and other users. A waiting job array only produces one line of output in squeue, making it easier for you to read its output. The scheduler does not have to analyze job requirements for each array task separately, so it can run more efficiently too. | Using a job array instead of a large number of separate serial jobs has advantages for you and other users. A waiting job array only produces one line of output in squeue, making it easier for you to read its output. The scheduler does not have to analyze job requirements for each array task separately, so it can run more efficiently too. | ||
<!--T:10--> | |||
Note that, other than the initial job-submission step with <code>sbatch</code>, the load on the scheduler is the same for an array job as for the equivalent number of non-array jobs. The cost of dispatching each array task is the same as dispatching a non-array job. You should not use a job array to submit tasks with very short run times, e.g. much less than an hour. Tasks with run times of only a few minutes should be grouped into longer jobs using [[Glost]], [[GNU Parallel]], or a shell loop. | Note that, other than the initial job-submission step with <code>sbatch</code>, the load on the scheduler is the same for an array job as for the equivalent number of non-array jobs. The cost of dispatching each array task is the same as dispatching a non-array job. You should not use a job array to submit tasks with very short run times, e.g. much less than an hour. Tasks with run times of only a few minutes should be grouped into longer jobs using [[Glost]], [[GNU Parallel]], or a shell loop. | ||
== Example: Multiple directories == | == Example: Multiple directories == <!--T:11--> | ||
<!--T:12--> | |||
Suppose you have multiple directories, each with the same structure, and you want to run the same script in each directory. If the directories can be named with sequential numbers then the example above can be easily adapted. If the names are not so systematic, then create a file with the names of the directories, like so: | Suppose you have multiple directories, each with the same structure, and you want to run the same script in each directory. If the directories can be named with sequential numbers then the example above can be easily adapted. If the names are not so systematic, then create a file with the names of the directories, like so: | ||
$ cat case_list | <!--T:13--> | ||
$ cat case_list | |||
pacific2016 | pacific2016 | ||
pacific2017 | pacific2017 | ||
Line 45: | Line 55: | ||
atlantic2017 | atlantic2017 | ||
<!--T:14--> | |||
There are several ways to select a given line from a file; this example uses <code>sed</code> to do so: | There are several ways to select a given line from a file; this example uses <code>sed</code> to do so: | ||
<!--T:15--> | |||
{{File | {{File | ||
|name=directories_array.sh | |name=directories_array.sh | ||
Line 55: | Line 67: | ||
#SBATCH --array=1-4 | #SBATCH --array=1-4 | ||
<!--T:16--> | |||
echo "Starting task $SLURM_ARRAY_TASK_ID" | echo "Starting task $SLURM_ARRAY_TASK_ID" | ||
DIR=$(sed -n "${SLURM_ARRAY_TASK_ID}p" case_list) | DIR=$(sed -n "${SLURM_ARRAY_TASK_ID}p" case_list) | ||
cd $DIR | cd $DIR | ||
<!--T:17--> | |||
# Place the code to execute here | # Place the code to execute here | ||
pwd | pwd | ||
Line 64: | Line 78: | ||
}} | }} | ||
<!--T:18--> | |||
Cautions: | Cautions: | ||
* Take care that the number of tasks you request matches the number of entries in the file. | * Take care that the number of tasks you request matches the number of entries in the file. |