I started recently to learn using Linux. I want to write a script in bash shell to run a serial job on a cluster. I have been searching for hints and instructions on how to write such a script. I managed to write the following:

#PBS -l nodes=1:ppn=8
#PBS -l walltime=1:00:00
#PBS -e test.err
#PBS -o test.log
cd /home/myuser/
echo "Running on host `hostname`"
echo "Time is `date`"
echo "Directory is `pwd`"
/home/myuser/comsol4.3b/bin/comsol batch -inputfile DF.mph -outputfile output.mph -batchlog out.log

The last line calls the program (it is called COMSOL) to run. One of the things that are missing in my code is the command “qsub”; I don’t know how to incorporate it with the rest of commands in my code. Can anyone please instruct me how to modify the line that calls the program I am using by “qsub” command please?

Sorry if my question is so simple, I spent a lot of time trying to make it work but I couldn’t unfortunately.

EDIT: To summarize, if I typed the last line of the code ONLY it will be run on the main node only, I don't want that. What I want is to modify the last line of the code such that it uses the resources I allocated to it using PBS lines, how should I do that?

For the record, the command qhost shows there are 250 nodes with varying cores per node from 4 cores/node to 16 cores/node

  • You want to submit this job multiple times, changing something about it as part of each submission? If you're using PBS or GrdEngine they typically provide you a facility called arrays that can be used to do this. You can also call qsub like so: qsub jobX.bash 1234. The 1234` argument could be parameterized and fed via a for loop. We'd need to see more of the actual array of values to help further. – slm Nov 11 '13 at 16:24
  • No it isn't an array. I don't want to change anything. I want the job to use the resources I allocated to it by PBS lines. If I only typed the last line of the code it will run on the main node only. I don't want that, what I want is running it on many nodes as I can specify using "qsub" or PBS scheduler. My question is simply, what command should I write to make the code run on allocated resources rather than the main node only?? Do you think I should write that in my question for clarification? @slm – Gotaquestion Nov 11 '13 at 17:31
  • Yes include that in the Q please. Can you explain what other nodes there are? You typically use the command qhost to find the other nodes. You can either submit to them directly or select a common attribute that they all have (2GB RAM) or something similar. Generally though the qsub command should automatically submit your job to any node. I would seek out your administrator of your cluster if this isn't working like that. – slm Nov 11 '13 at 17:36
  • Thank you @slm I modefied the question. The problem is that 'qsub' command is not included in my code as you see. I believe that is the starting point to fix it. – Gotaquestion Nov 12 '13 at 10:09
  • 1
    If the script you wrote is in the file foo.sh, then you want to give the command qsub foo.sh to submit it to the batch system. It will then be routed onto one of the execute nodes with the resources you requested. – doneal24 Nov 12 '13 at 13:50

You don't specifically say which clustering software you're using, but based on the fact you're asking about qsub, I know that both GridEngine (and derivatives) along with PBS use that particular command, so let's start with those.

I'm most familiar with GridEngine (and derivatives) so to submit a command using that package you'd do something like this.


Here's a sample script, we'll call it sample.bash.

echo "Working directory is $PWD"

To submit this script, you do the following:

$ qsub sample.bash

To target specific nodes within the cluster you'll need to include attributes that are unique to a set of these nodes, so that the GridEngine scheduling software can pick one of these nodes, and run your job on one of them.

| improve this answer | |
  • Thank you very much, that is useful. Until now when I wanted to run the script I used to type 'bash sample.sh' is that different from running the script using qsub?? And one more thing please, what attributes should I look for to use particular nodes? I am sorry for those naive questions @slm – Gotaquestion Nov 12 '13 at 17:47
  • @Gotaquestion - that is different. Running bash sample.sh runs the script on the current box. Running via qsub will submit the script to the head node, which will then farm it out to one of the worker nodes. Attributes will be things like RAM, OS levels, etc. – slm Nov 12 '13 at 17:49
  • @Gotaquestion - what cluster software are you using? – slm Nov 12 '13 at 17:49
  • The cluster software is Son of Grid Engine which is a continouation of old Sun grid engine @slm – Gotaquestion Nov 13 '13 at 10:16
  • It is SGE 8.1.6 in particular – Gotaquestion Nov 13 '13 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.