Difference between revisions of "Job Arrays"

From Carl R. Woese Institute for Genomic Biology - University of Illinois Urbana-Champaign
Jump to navigation Jump to search
(job.pl (Example Perl script ))
Line 1: Line 1:
 
== Job Array Introduction ==
 
== Job Array Introduction ==
  
Making a new copy of the script and then submitting each one for every input data file is time consuming. An alternative is to make a job array using the -t option in your '''QSUB''' '''submission''' '''script'''. The -t option allows many copies of the same script to be queued all at once. You can use the '''$PBS_ARRAYID''' environmental variable to differentiate between the different jobs in the array. The amount of resources you specify in the '''QSUB''' '''submission''' '''script''' is the amount of resources the '''job script''' gets each time it is called.
+
Making a new copy of the script and then submitting each one for every input data file is time consuming. An alternative is to make a job array using the -t option in your '''SBATCH submission script'''. The -t option allows many copies of the same script to be queued all at once. You can use the '''$SLURM_ARRAY_TASK_ID''' environmental variable to differentiate between the different jobs in the array. The amount of resources you specify in the '''SBATCH submission script''' is the amount of resources the '''job script''' gets each time it is called.
  
 
In this tutorial, we will be using '''three''' files:
 
In this tutorial, we will be using '''three''' files:
Line 9: Line 9:
 
</pre>
 
</pre>
 
Lets say you want to run '''16 jobs'''. Instead of submitting 16 different jobs, you can submit one job, but use the ''''-t'''' parameter and the '''PBS_ARRAYID''' variable. You can read more about the&nbsp;&nbsp;''''-t''''&nbsp;&nbsp;parameter at&nbsp;[http://docs.adaptivecomputing.com/torque/4-1-4/Content/topics/commands/qsub.htm#T http://docs.adaptivecomputing.com/torque/4-1-4/Content/topics/commands/qsub.htm]
 
Lets say you want to run '''16 jobs'''. Instead of submitting 16 different jobs, you can submit one job, but use the ''''-t'''' parameter and the '''PBS_ARRAYID''' variable. You can read more about the&nbsp;&nbsp;''''-t''''&nbsp;&nbsp;parameter at&nbsp;[http://docs.adaptivecomputing.com/torque/4-1-4/Content/topics/commands/qsub.htm#T http://docs.adaptivecomputing.com/torque/4-1-4/Content/topics/commands/qsub.htm]
<pre>#PBS -t 0-15</pre>
+
<pre>#SBATCH --array 1-10</pre>
The -t parameter sets the range of the '''PBS_ARRAYID''' variable. So setting it to
+
The --array parameter sets the range of the '''$SLURM_ARRAY_TASK_ID''' variable. So setting it to
<pre>#PBS -t 0-4</pre>
+
<pre>#SBATCH --array 1-4</pre>
will cause the qsub script to call the script 5 times, each time updating the '''PBS_ARRAYID''', from 0 to 4 , which results in
+
will cause the qsub script to call the script 4 times, each time updating the '''$SLURM_ARRAY_TASK_ID''', from 1 to 4 , which results in
<pre>( perl job.pl $PBS_ARRAYID )
+
<pre>( perl job.pl $SLURM_ARRAY_TASK_ID )
 +
 
  
perl job.pl 0
 
 
perl job.pl 1
 
perl job.pl 1
 
perl job.pl 2
 
perl job.pl 2
Line 27: Line 27:
 
It redirects the stderror and stdout into one file, and emails the job owner on completion or abort.
 
It redirects the stderror and stdout into one file, and emails the job owner on completion or abort.
  
For each job , it passes the '-t' parameter to the job.pl script, which in this case is 0 to 15
+
For each job , it passes the '--array' parameter to the job.pl script, which in this case is 0 to 15
 
<pre>#!/bin/bash
 
<pre>#!/bin/bash
# ----------------QSUB Parameters----------------- #
+
# ----------------SBATCH Parameters----------------- #
#PBS -q default
+
#SBATCH -p normal
#PBS -l nodes=1:ppn=2,mem=1000mb
+
#SBATCH -n 1
#PBS -M youremail@illinois.edu
+
#SBATCH -N 1
#PBS -m abe
+
#SBATCH --mail-user  youremail@illinois.edu
#PBS -N array_of_perl_jobs
+
#SBATCH --mail-type BEGIN, END, FAIL
#PBS -t 1-16
+
#SBATCH -J array_of_jobs
#PBS -j oe
+
#SBATCH --array 1-10
 +
#SBATCH -D /home/a-m/USERNAME
 
# ----------------Load Modules-------------------- #
 
# ----------------Load Modules-------------------- #
module load perl/5.16.1
+
module load perl/5.24.1-IGB-gcc-4.9.4
 
# ----------------Your Commands------------------- #
 
# ----------------Your Commands------------------- #
cd $PBS_O_WORKDIR
+
 
perl job.pl $PBS_ARRAYID</pre>
+
perl job.pl $SLURM_ARRAY_TASK_ID</pre>
  
 
== job.pl (Example Perl script ) ==
 
== job.pl (Example Perl script ) ==
 
<pre>#!/usr/bin/env perl
 
<pre>#!/usr/bin/env perl
#This script echos the job array element that has been passed in
+
#This script outputs the job array element that has been passed in
  
 
use strict;
 
use strict;
Line 66: Line 67:
 
dataset650
 
dataset650
 
</pre>
 
</pre>
== Default vs Highthroughput Queue ==
 
 
'''The default queue only allows you to queue up to 150 jobs, but they do not use a walltime limit.'''
 
 
*This queue is most appropriate for a lot of jobs that may run a long time.
 
 
'''The highthroughput queue allows you to queue up to 550 jobs, but they have a walltime limit.'''
 
 
*This queue is most appropriate for a lot of jobs that you want to run in parallel and finish quickly.
 
  
 
== Effectively Using job_array_index ==
 
== Effectively Using job_array_index ==
Line 90: Line 82:
 
Here is some simple pseudo code for this situation
 
Here is some simple pseudo code for this situation
 
<pre>data sets per job = N
 
<pre>data sets per job = N
startLineNumber =  $PBS_ARRAYID * datasets per job
+
startLineNumber =  $SLURM_ARRAY_TASK_ID * datasets per job
 
endLineNumber = startLineNumber + data_sets_per_job
 
endLineNumber = startLineNumber + data_sets_per_job
  
Line 100: Line 92:
 
                 go to next line
 
                 go to next line
 
  </pre>
 
  </pre>
== Putting it all together (Example Qsub Submission with submissions script, configuration file, and experiment script ==
+
== Putting it all together (Example SBATCH Submission with submissions script, configuration file, and experiment script ==
  
 
In order to use the following script, you will need to properly set
 
In order to use the following script, you will need to properly set
  
*'-t' (the number of array elements you want)
+
*'--array' (the number of array elements you want)
  
 
*-itemsToProcess (the number of items in the job.conf list to pass into your script)
 
*-itemsToProcess (the number of items in the job.conf list to pass into your script)
Line 110: Line 102:
 
*-Your script , modules and custom settings
 
*-Your script , modules and custom settings
 
<pre>#!/bin/bash
 
<pre>#!/bin/bash
# ----------------QSUB Parameters----------------- #
+
# ----------------SBATCH Parameters----------------- #
#PBS -S /bin/bash
+
#SBATCH -p normal
#PBS -q default
+
#SBATCH -n 1
#PBS -l nodes=1:ppn=1,mem=1000mb
+
SSBATCH -N 1
#PBS -M netid@Illinois.edu
+
#SBATCH --mail-user  youremail@illinois.edu
#PBS -m abe
+
#SBATCH --mail-type BEGIN, END, FAIL
#PBS -N Blast_100_in_chunks_of_10
+
#SBATCH -J array_of_jobs
#PBS -d /home/n-z/yournetid/experimentA/
+
#SBATCH --array 1-10
# --EDIT HERE
+
#SBATCH -D /home/a-m/USERNAME
#PBS -t 1-10
+
 
 
# ----------------Load Modules-------------------- #
 
# ----------------Load Modules-------------------- #
module load blast/2.2.26
+
module load BLAST+/2.6.0-IGB-gcc-4.9.4
 
# ----------------Your Commands------------------- #
 
# ----------------Your Commands------------------- #
 
# --EDIT HERE
 
# --EDIT HERE
Line 128: Line 120:
  
 
#No need to edit this
 
#No need to edit this
taskID=$PBS_ARRAYID
+
taskID=$SLURM_ARRAY_TASK_ID
 
startLineNumber=$(($taskID * $itemsToProcess))
 
startLineNumber=$(($taskID * $itemsToProcess))
 
endLineNumber=$(( $startLineNumber + $itemsToProcess ))
 
endLineNumber=$(( $startLineNumber + $itemsToProcess ))

Revision as of 08:13, 14 March 2018

Job Array Introduction[edit]

Making a new copy of the script and then submitting each one for every input data file is time consuming. An alternative is to make a job array using the -t option in your SBATCH submission script. The -t option allows many copies of the same script to be queued all at once. You can use the $SLURM_ARRAY_TASK_ID environmental variable to differentiate between the different jobs in the array. The amount of resources you specify in the SBATCH submission script is the amount of resources the job script gets each time it is called.

In this tutorial, we will be using three files:

array.sh
job.pl
job.conf

Lets say you want to run 16 jobs. Instead of submitting 16 different jobs, you can submit one job, but use the '-t' parameter and the PBS_ARRAYID variable. You can read more about the  '-t'  parameter at http://docs.adaptivecomputing.com/torque/4-1-4/Content/topics/commands/qsub.htm

#SBATCH --array 1-10

The --array parameter sets the range of the $SLURM_ARRAY_TASK_ID variable. So setting it to

#SBATCH --array 1-4

will cause the qsub script to call the script 4 times, each time updating the $SLURM_ARRAY_TASK_ID, from 1 to 4 , which results in

( perl job.pl $SLURM_ARRAY_TASK_ID )


perl job.pl 1
perl job.pl 2
perl job.pl 3
perl job.pl 4

array.sh (Example submission script)[edit]

This submission script changes to the current working directory, submits 16 jobs, and reserves 2 processors and 1gb of ram for each job.

It redirects the stderror and stdout into one file, and emails the job owner on completion or abort.

For each job , it passes the '--array' parameter to the job.pl script, which in this case is 0 to 15

#!/bin/bash
# ----------------SBATCH Parameters----------------- #
#SBATCH -p normal
#SBATCH -n 1
#SBATCH -N 1
#SBATCH --mail-user  youremail@illinois.edu
#SBATCH --mail-type BEGIN, END, FAIL 
#SBATCH -J array_of_jobs
#SBATCH --array 1-10
#SBATCH -D /home/a-m/USERNAME
# ----------------Load Modules-------------------- #
module load perl/5.24.1-IGB-gcc-4.9.4
# ----------------Your Commands------------------- #

perl job.pl $SLURM_ARRAY_TASK_ID

job.pl (Example Perl script )[edit]

#!/usr/bin/env perl
#This script outputs the job array element that has been passed in

use strict;
my $pbs_array_id = shift @ARGV;
my $experimentID = $pbs_array_id;
my $experimentName = `head -n $pbs_array_id job.conf | tail -n1`;

print "This is job number $pbs_array_id \n";
print "About to perform experimentID: $experimentID experimentName:$experimentName\n";

job.conf (example configuration file)[edit]

dataset0
dataset1
dataset2
dataset3
dataset4
dataset5
..
dataset650

Effectively Using job_array_index[edit]

You have 650 datasets you want to analyze, but you can only submit 80 jobs at a time. Instead of submitting 80 jobs, and waiting for them to finish, submit a single 80 element array job that can handle all of the datasets.

A simple formula for dividing and sending your datasets to your script is as follows:

 data sets per job = ceiling ( Number of datasets / Number of Job Elements ) 
data sets per Job = ceiling ( 650 / 80 ) = ceiling(8.12500) = 9

So that means that your 80 jobs are each responsible for handling 9 datasets. So each time you call your job script, you need to pass it the position in the list of datasets , which is the $PBS_ARRAYID and the data sets per job ( N ) That way, your job will be able to determine which datasets from the list you need to process.


Here is some simple pseudo code for this situation

data sets per job = N
startLineNumber =  $SLURM_ARRAY_TASK_ID * datasets per job
endLineNumber = startLineNumber + data_sets_per_job

open list of data:
      go to  startLineNumber
                get dataset
                do work with dataset
                if lineNumber <  endLineNumber
                go to next line
 

Putting it all together (Example SBATCH Submission with submissions script, configuration file, and experiment script[edit]

In order to use the following script, you will need to properly set

  • '--array' (the number of array elements you want)
  • -itemsToProcess (the number of items in the job.conf list to pass into your script)
  • -Your script , modules and custom settings
#!/bin/bash
# ----------------SBATCH Parameters----------------- #
#SBATCH -p normal
#SBATCH -n 1
SSBATCH -N 1
#SBATCH --mail-user  youremail@illinois.edu
#SBATCH --mail-type BEGIN, END, FAIL 
#SBATCH -J array_of_jobs
#SBATCH --array 1-10
#SBATCH -D /home/a-m/USERNAME

# ----------------Load Modules-------------------- #
module load BLAST+/2.6.0-IGB-gcc-4.9.4
# ----------------Your Commands------------------- #
# --EDIT HERE
itemsToProcess=10
jobList="job.conf"

#No need to edit this
taskID=$SLURM_ARRAY_TASK_ID
startLineNumber=$(($taskID * $itemsToProcess))
endLineNumber=$(( $startLineNumber + $itemsToProcess ))
startLineNumber=$(( $startLineNumber + 1))
#Grab an experiment from the job.conf file
for line in `seq $startLineNumber $endLineNumber`
do
    experiment=$( head -n $line $jobList | tail -n 1 )
# --EDIT HERE
 echo blastall -i $experiment -o $experiment\.blast
done