SGE: Submitting Your First Job With Examples

Submitting a simple serial job to the queue (your own compiled application)

Assuming that you have correctly compiled your application to an executable called myprogram , a simple script to:

  • submit the job from your current working directory using your current module environment
  • using 1 hour of runtime
  • email you at the start and end of your job


# Example script:
# Set current working directory
#$ -cwd
# Use current environment variables and modules
#$ -V
#Request one hour of runtime
#$ -l h_rt=1:00:00
#Email at the beginning and end of the job
#$ -m be
#Run the executable 'myprogram' from the current working directory

Once the script has been saved to a file (e.g. ), it can be submitted to the queue with the qsub command:

$ qsub

Submitting a serial application job to the queue (using ‘R’ as an example)

To run R (for example) in batch-mode you must first generate a list of commands for R to process in a file, e.g.

A script must then be created that will request resources from the queuing system and launch the R executable, for example :

# Example script:
# Run in current working directory and use current environment
#$ -cwd -V
# Set a 6 hour run-time limit
#$ -l h_rt=6:00:00
#Request more memory, the default is 1Gb
#$ -l h_vmem=1536M
# Load R module
module add R
# run R using command file
# CMD BATCH flag should be given to suppress graphics (ie. run R in batch rather than interactive mode)

This can then be submitted to the queuing system using:

$ qsub

In this example, any results will then be made available in the file r.out .

Requesting an interactive session from the queue (using ‘R’ as an example)

A number of applications (R included) can run as interactive sessions as well as batch processes.
The queue system allows users to run a program on the back-end compute nodes but only if the required resources are available at the time the request is made.

The following will launch R interactively via the batch queue.

$ qrsh -cwd -V -l h_rt= R 

h_rt is the length of run-time the shell will exist for, so to run R for 6 hours:

$ qrsh -cwd -V -l h_rt=6:00:00 R 

Note that <option> must be set to one of

Option Description
–save DO save workspace at the end of the session
–no-save DON’T save workspace at the end of the session
–vanilla Combine –no-save , –no-restore , –no-site-file , –no-init-file and –no-environ

This will run R from within the terminal from which it was launched.

If qrsh can’t allocate resources to you within a couple of minutes it will report back with an error, particularly at busy times. Resubmitting your qrsh request normally works.

Checking the status of your job

Once you have submitted your job to the queue, you can check on its status using the qstat command. You will see a report displayed something like this:

job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID
   3049 1.00050 vn108_2    userid       r     12/17/2013 10:18:39   128

The state column will indicate the progress of your job:

qw waiting in the queue to start
t transferring to a node (about to start)
r running
h job held back by user request
E error

Removing a job from the queue

If you want to remove a job from the queue, you can use the qdel command (perhaps there’s a bug in your code or you don’t need to run it anymore).

First, run qstat to get the job-ID of your job (it’s the leftmost column in the example above). Then:


( qdel 3049 in this example)

Altering the status of a job in the queue

It is possible to do this, but only with jobs that are still queuing.

If your job is currently running so it is more straightforward just to delete it by using qdel and then resubmitting a revised job to the queue.

If the job is still queued, you can change some of the parameters:

Get the jobid by running the qstat command (it will be the left hand column in the table displayed).

job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID
3672742 0.56000 submission userid       r     12/19/2013 11:35:51     8

Find all the -l parameters from your submission script:

qstat -j  | grep h_rt

An example result might be:


Change the parameter you want, so here change the runtime from the initial 4 hrs to (say) 6 hours and then use the qalter command to alter the job entry in the queue:

qalter -l env=centos6,h_rt=21600,h_vmem=1536M