2024-2: Submitting PBS Jobs part 2

https://mediahub.qut.edu.au/media/t/0_d0bsv333

Launching a Batch Job - Constructing a Job Script

It is possible to submit a batch job completely from the command line, saving the job parameters and commands in a text file is very handy for documenting you use of the HPC. In a job script #PBS is used to provide instructions to PBS, they are not run as commands. A small script is:

#!/bin/bash -l #PBS -l select=1:ncpus=1:mem=2gb #PBS -l walltime=00:10:00 echo $(hostname)

This job will request one node (select=1), one cpu (ncpus=1), 2gb of memory (mem=2gb) and run for a maximum of 10 minutes (walltime=00:10:00)

Notice how the options after #PBS are the same as the qsub command line?

This script is very basic, it will run the command hostname, which outputs the name of the computer this job is running on, then echo that to the screen.

While the name of the file is not important, I like to save my PBS job scripts as {name}.pbs to easily identify them in the file list. Use training01.pbs here.

Let’s use nano to create the file, nano is provided by a module:

module load nano

Create the file:

nano training01.pbs

Launching a Batch Job - Submitting a Job Script

Since all the options are contained in the job script, the qsub line is short:

qsub training01.pbs

And you will see a job number printed on the screen. Use qjobs to check on the status of the job.

 

Checking on the Job Status

To quickly check on you jobs that are queued and running, use the qjobs command

qjobs

You will get a summary of each queued job and the running ones. The finished ones are not displayed.

An alternative way to list your jobs:

qstat -u $user

Get more details about a particular job:

qstat -f {jobid}

 

Checking the Output

Since we told the job to print the name of the node the job was running on, how do we see it? PBS will save the output of the commands run in the job into two files by default. The format is {job name}.o{job id} and {job name}.e{job id}

Let's examine these files:

# find the files by listing the contents of the folder sorted by reverse date ls -ltr # the 'e' file is empty cat training01.pbs.o{tab} cl4n018 PBS Job 5228698.pbs CPU time : 00:00:00 Wall time : 00:00:02 Mem usage : 0b

We can see in this case, the job ran on the cl4n018 node, use no measurable cpu and memory, and lasted for 2 seconds. The two files represent the standard output and the error output of the commands. The name of the files and merging them is possible with more options.

 

More options in job scripts

We have just scratched the surface of what you can specify when you submit and run jobs. A few useful ones are:

  • Be notified when the job starts, use the -m option eg be sent an email if the job is aborted, when it begins, and when it ends: #PBS -m abe

  • Give the job a name: To find your job in a long list give it a meaning name with the -N option: #PBS -N MyJob01

  • Merge the error file into the standard output file: #PBS -j oe

  • Overriding the email address: If you want to send the job notification email to another address, use the -M option, eg #PBS -M bob@bob.com

Example 2

From the Introduction to the Unix Shell for HPC users course lets run the do-stats.sh script as a job.

First, change to the folder:

cd ~/workshop/2024-2/shell-lesson-data/north-pacific-gyre

Then, create the submission script (copy and paste!)

#!/bin/bash -l #PBS -N GooStatsRun01 #PBS -l select=1:ncpus=1:mem=2gb #PBS -l walltime=00:30:00 #PBS -m abe cd $PBS_O_WORKDIR # Calculate stats for data files. for datafile in NENE*A.txt NENE*B.txt do echo $datafile bash goostats.sh $datafile stats-$datafile done

Call this do-goostats.pbs

Now submit to the scheduler:

qsub do-goostats.pbs

And check the status:

qjobs

When run, check the output:

ls -ltr cat GooStatsRun01.o{job_id} ... CPU time : 00:00:00 Wall time : 00:00:33 Mem usage : 4648kb cat GooStatsRun01.e{job_id} {Empty File}

Tricks and Tips

When the job starts, PBS will logon to the node as you and your working directory will be your home folder. If your data is in a sub folder or in a shared folder, you can use this to automatically change to that folder:

cd $PBS_O_WORKDIR

$PBS_O_WORKDIR is a special environment variable created by PBS. This will be the folder where you ran the qsub command.

Example 3

We can run commands to check and trim fastq sequences.

Start by changing directory:

cd $HOME/workshop/2024-2

Then, download the data and scripts (Copy and Paste!):

wget https://github.com/eresearchqut/hpc_training_3/archive/refs/tags/1.0.tar.gz

Then, unpack the downloaded file with the tar command

tar xvzf 1.0.tar.gz

Change into the newly create folder (Don’t forget TAB completion):

cd hpc_training_3-1.0

Examine the data and scripts

ls cat stage1.pbs

stage1.pbs

#!/bin/bash -l #PBS -N Stage1-FastQC #PBS -m abe #PBS -l select=1:ncpus=1:mem=4gb #PBS -l walltime=1:00:00 # Change to folder where we launched the job cd $PBS_O_WORKDIR # Make a directory for the fastqc results mkdir fastqc # Load the fastqc module module load fastqc/0.11.7-java-1.8.0_92 # Run fastqc fastqc --threads 2 --outdir fastqc data/sample1_R1.fastq.gz data/sample1_R2.fastq.gz

This job script will load the fastqc app from the module system and run with the samples. This job script will produce the fastqc directory that holds the results of the run.

stage2.pbs

#!/bin/bash -l #PBS -N Stage2-seqtk #PBS -m abe #PBS -l select=1:ncpus=2:mem=8gb #PBS -l walltime=1:00:00 # Change to folder where we launched the job cd $PBS_O_WORKDIR # Make a directory for the seqtk results mkdir trimmed # Use Singularity to supply trim the files singularity exec https://depot.galaxyproject.org/singularity/seqtk:1.4--he4a0461_1 bash -c \ 'seqtk trimfq data/sample1_R1.fastq.gz | \ gzip --no-name > trimmed/sample1_R1.fastq.trimmed.gz' singularity exec https://depot.galaxyproject.org/singularity/seqtk:1.4--he4a0461_1 bash -c \ 'seqtk trimfq data/sample1_R2.fastq.gz | \ gzip --no-name > trimmed/sample1_R2.fastq.trimmed.gz'

This job script will run the seqtk app over the sample fastq files using default settings. Since seqtk is not available on the HPC, we can use singularity to supply the app. This script will saved the trimmed fastq files in the trimmed folder.

stage3.pbs

#!/bin/bash -l #PBS -N Stage3-multiqc #PBS -m abe #PBS -l select=1:ncpus=2:mem=8gb #PBS -l walltime=1:00:00 # Change to folder where we launched the job cd $PBS_O_WORKDIR # Make a directory for the seqtk results mkdir multiqc # Use Singularity to supply trim the files singularity exec https://depot.galaxyproject.org/singularity/multiqc:1.21--pyhdfd78af_0 \ multiqc --force --outdir multiqc data fastqc trimmed

This job script will run multiqc to create a summary of the data and operations of the previous stages. Like stage2, multiqc is not available on the HPC so we can run it via singularity. The results will be saved in the multiqc folder.

 

These files must be run one after each other, they cannot run at the same time.

Launch stage1.pbs

qsub stage1.pbs qjobs cat Stage1.o{tab} cat Stage1.e{tab}

When finished, launch stage2.pbs

qsub stage2.pbs qjobs cat Stage2.o{tab} cat Stage2.e{tab}

Finally, when stage2 is finished, launch stage3.pbs

qsub stage3.pbs qjobs cat Stage3.o{tab} cat Stage3.e{tab}

 

These jobs will send you an email when the job starts and finishes. It can be handy to receive the email rather than watching qjobs etc.

 

Once stage3 is finished, open up the hpc_training_3-1.0 folder in Windows Explorer/Finder and examine the files, especially in the multiqc folder.

 

image-20240911-065224.png