Job arrays: Difference between revisions

No edit summary
Line 26: Line 26:


Using a job array instead of a large number of separate serial jobs has advantages for other users and the system as a whole. 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 other users and the system as a whole. 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.
== Running the same script in multiple directories ==
This example assumes that you have multiple directories, each with the same structure, and you want to run the same script in each of these directories. You could use the following bash script :
{{File
|title=script.sh
|language=bash
|contents=
#!/bin/bash
#SBATCH --ntasks=1
#SBATCH --time=2:00:00
echo "Starting run at: `date`"
DIRS=($(find . -maxdepth 1 -type d \( ! -name . \)))
DIR=${DIRS[$SLURM_ARRAY_TASK_ID]}
cd $DIR
pwd
# Place the code to execute here
}}
and submit it using the following command :
{{Commands
|N{{=}}$(find . -maxdepth 1 -type d \( ! -name . \) {{!}} wc -l)
|sbatch --array{{=}}1-$N script.sh
}}
Bureaucrats, cc_docs_admin, cc_staff, rsnt_translations
2,837

edits