Creating a PBS script

A PBS script is a text file that contains the information that PBS needs to set up the job, followed by the commands to be executed. In this example, we will be writing a PBS script to launch an R script called 'myscript.R' that we have verified will run without requiring used interaction. The PBS job submission script will request the necessary resources, set up the environment, and then launch the R script.

In the PBS script, the lines beginning with “#PBS” are PBS directives that specify the resource requirements and various other attributes of the job. Note that the directives must come first in the script as any directives after the first executable statement are ignored. Since the R program we will be running doesn't require any interaction, we want to submit the job to the batch queue. In this example, the job we will be running has the following requirements:

  • the job will need 1 node, 10 processors and 64 GB of RAM
  • the job will not require more than 48 hours to complete
  • the name of the job will be 'myscript', with the output written to myscript.out and errors written to myscript.err
  • we want email notifications to be sent to [email protected] when the job starts and stops or aborts. (Substitute with your actual email address)

The PBS directives for the above requirements are outlined below, along with a brief explanation of what each one does.

PBS Directive

What it does

#PBS -q batch

Specifies that the job be submitted to the batch queue

#PBS -l nodes=1:ppn=10

Requests 1 node and 10 processors per node

#PBS -l mem=64gb

Requests 64 GB of RAM

#PBS -l walltime=48:00:00

Sets max walltime for the job to 48 hours

#PBS -N myscript

Sets the name of the job as displayed by qstat

#PBS -o myscript.out

Sends standard output to myscript.out

#PBS -e myscript.err

Sends standard error to myscript.err

#PBS -j oe Merge output and error files. Both streams will be merged, intermixed, as standard output.

#PBS -m abe

Sends email on job abort, begin, and end

#PBS -M [email protected]

Specifies email address to which mail should be sent.

#PBS -S /bin/$shell

Sets the shell to be used in executing your script. If left out, it defaults to your normal login shell. Typical values for the $shell argument are /bin/bash, /bin/tcsh, /bin/csh or /bin/sh.
#PBS -V Export all environment variables in the qsub command environment to the batch job environment.

Once we have specified the PBS directives in our job submission script, we will want to add the commands to set up the environment and launch our script. We start out by changing to the PBS working directory (i.e., the directory from which we will be submitting our job, which is also the directory where our script is located). After that, we load any modules our script will need and call the script.

cd $PBS_O_WORKDIR/
module load R/3.5.1
Rscript --vanilla myscript.R

Putting it all Together

Now that we have the basics, we just need to put them together into a job submission script. In this example, we would save the following content in a file called myscript.pbs. For your actual job submission script, you will want to use your favorite text editor to make any necessary changes to the script (e.g., substitute all of the 'myscript' occurences with the actual name of your script, put in your actual email address, etc.) and save it as your_script_name.pbs. (Note: you can call it anything you want but it makes it easier to keep track of things if the name of your job submission script matches the name of the R script that it launches.)

#PBS -S /bin/bash
#PBS -q batch
#PBS -l nodes=1:ppn=10
#PBS -l mem=64gb
#PBS -l walltime=48:00:00
#PBS -N myscript
#PBS -o myscript.out
#PBS -e myscript.err
#PBS -m abe
#PBS -M [email protected]

 

cd $PBS_O_WORKDIR/
module load R/3.5.1
Rscript --vanilla myscript.R

Submitting the Job

Now that we have written our PBS job submission script, we are ready to submit the job to the cluster. To do that, we use the 'qsub' command and give it the name of the .pbs script. Since the script contains the PBS directives for everything our job needs, we don't need to specify any other commandline options.

[email protected]:~$ qsub myscript.pbs
 

Checking the Status of Your Job

Once you have submitted your job, you will want to check the status using the qstat command.

[email protected]:~$ qstat -a

More information on the qstat command can be found on our page for Monitoring Jobs on compute.cla.

 

Example PBS script for R

#PBS -S /bin/bash
#PBS -q batch
#PBS -l nodes=1:ppn=10
#PBS -l mem=64gb
#PBS -l walltime=48:00:00
#PBS -N myscript
#PBS -o myscript.out
#PBS -e myscript.err
#PBS -m abe
#PBS -M [email protected]

cd $PBS_O_WORKDIR/
module load R/3.5.1
Rscript --vanilla myscript.R

Example PBS script for Python

#PBS -S /bin/bash
#PBS -q batch
#PBS -l nodes=1:ppn=10
#PBS -l mem=64gb
#PBS -l walltime=48:00:00
#PBS -N myscript
#PBS -o myscript.out
#PBS -e myscript.err
#PBS -m abe
#PBS -M [email protected]

cd $PBS_O_WORKDIR/
module load python/conda/3.6
python myscript.py
 

Get Help

Linux Knowledge Articles

Articles including how to get access, using applications, and solving common issues.