Sample PBS Script to Submit a Single Processor Job to Torque

Create a script file that includes the details of the job that you want to run.

It can include the name of the program, the memory, wall time and processor requirements of the job, which queue it should run in and how to notify you of the results of the job.

Here is a sample PBS script.

#!/bin/bash -l
# declare a name for this job to be my_serial_job
# it is recommended that this name be kept to 16 characters or less
#PBS -N my_serial_job

# request the queue (enter the possible names, if omitted, default is the default)
# this job is going to use the default
#PBS -q default

# request 1 node
#PBS -l nodes=1:ppn=1

# request 0 hours and 15 minutes of wall time
# (Default is 1 hour without this directive)
#PBS -l walltime=00:15:00

# mail is sent to you when the job starts and when it terminates or aborts 
#PBS -m bea

# specify your email address 
#PBS -M John.Smith@dartmouth.edu

# By default, PBS scripts execute in your home directory, not the
# directory from which they were submitted. The following line
# places the job in the directory from which the job was submitted. 
cd $PBS_O_WORKDIR

# run the program using the relative path 
./program_name arg1 arg2 ...

exit 0

All of the lines that begin with a #PBS are directives to Torque. The meaning of the directives in the sample script are exampled in a comment line that precedes the directive.

The full list of available directives is explained in the man page for the qsub command which is available on discovery.

The #!/bin/bash -l is necessary so that the module commands will work in your script file.

Now submit the job and check its status:

$ qsub runjob.pbs
3912961.knorr.bw01.dartmouth.edu
$ myjobs

active jobs------------------------
JOBID              USERNAME      STATE PROCS   REMAINING            STARTTIME

3912961                pete    Running     1     0:14:57  Mon Mar 29 14:51:46

1 active job              1 of 944 processors in use by local jobs (0.11%)
                         68 of 114 nodes active      (59.65%)

eligible jobs----------------------
JOBID              USERNAME      STATE PROCS     WCLIMIT            QUEUETIME

0 eligible jobs

blocked jobs-----------------------
JOBID              USERNAME      STATE PROCS     WCLIMIT            QUEUETIME

0 blocked jobs

Total job:  1

Typically, a batch job generates at least two files: an output file (equivalent to STDOUT) and an error file (equivalent to STDERR). The naming convention is batch-script-name.x.JOBID, where x is either o for output or e for error.

JOBID is the unique ID of the job – in this case it is 3912961.

In this example, there is no error and hence the file my_serial_job.e18967 contains 0 record.

The output file, my_serial_job.o3912961, consists of three sections:

  • A header section, Prologue, which gives information such as JOBID, user name and node list.
  • A body section which include user output to STDOUT.
  • A footer section, Epilogue, which is similar to the header.
  • A useful difference is the report of wallclock time towards the end.
------------------------- Prologue ----------------------------
         Started: Mon Mar 29 16:21:58 EDT 2010
          Job ID: 3912961.knorr.bw01.dartmouth.edu
         User ID: pete
        Group ID: CGL
        Job Name: my_serial_job
 Resources Req'd: neednodes=t01,nodes=1:ppn=1,walltime=00:15:00
      Queue Name: default
    Account Name: RC
------------------------- Prologue ----------------------------

job output will show up here in the body...

------------------------- Epilogue ----------------------------
        Finished: Mon Mar 29 16:22:58 EDT 2010
          Job ID: 3912961.knorr.bw01.dartmouth.edu
         User ID: pete
        Group ID: CGL
        Job Name: my_serial_job
      Session ID: 23347
 Resources Req'd: neednodes=t01,nodes=1:ppn=1,walltime=00:15:00
  Resources Used: cput=00:00:00,mem=2956kb,vmem=188636kb,walltime=00:01:00
      Queue Name: default
    Account Name: RC
------------------------- Epilogue ----------------------------

File Management In a Batch Queue System

Sometimes you may be running the same program in multiple jobs and you will need to be sure to keep your input and output files separate for each job.

One way to manage your data files is to have a separate directory for each job.

  • Copy the required input files to the directory and then edit the batch script file to include a line where you change to the directory that contains the input files.
    • cd /home/username/input1
  • Place this line before the line where you issue the command to be run.
  • The sample script shown above includes the line cd $PBS_O_WORKDIR.
  • This command changes the current working directory to the directory you were in when you issued the qsub command.