3

I'm trying to run a matlab script (ga_opt_main.m) in a cluster. I have to write a job submission file, which is essentially just a shell script. But I have never written a shell script and this is what I wrote

  #!/bin/bash
  #PBS -q *queuename*
  #PBS -l nodes=1:ppn=20
  #PBS -l walltime=02:00:00
  #PBS -N ga_opt_main

  module load matlab/R2011b
  module list

  unset DISPLAY
  matlab -nodisplay -nodesktop -r *directory path/ga_opt_main.m*

MATLAB opens in the background but my job is not run. Instead I get an error file saying

  bash: -c: line 0: syntax error in conditional expression
  bash: -c: line 0: syntax error near `fraction'

Any ideas on why this occurs and how it can be avoided? Thanks!

4
  • 1
    I've never used PBS before, but it looks like the words in between the asterisks are placeholder text that you are supposed to replace with something else. For example #PBS -q *queuename* looks a little fishy.... Commented Aug 4, 2012 at 0:29
  • @CypressFrankenfeld: anything passed in between -r "..." must be correct commands as you would type them in MATLAB command window in the IDE. To run a script, you either browse to the same directory as the file or you add its folder to the path, then call it by name (or use the RUN function as I've showed). Commented Aug 4, 2012 at 0:36
  • @Amro, you are completely correct. I'll delete that post and just refer to your answer. Commented Aug 4, 2012 at 0:46
  • You may need to replace *directory path/ga_opt_main.m* with a Matlab command, as Amro stated. Commented Aug 4, 2012 at 0:47

2 Answers 2

2

I've never used PBS before, but to run a MATLAB script from the shell, try the following:

matlab -nodesktop -nodisplay -r "addpath('/directory/path'); ga_opt_main; quit;"

where ga_opt_main.m is the name of the script file, and '/directory/path' is the directory where it resides. Note that you must have any other dependencies to this script on the MATLAB path as well.

There is also a convenient RUN function that does something similar:

matlab ... -r "run('/directory/path/ga_opt_main.m'); quit;"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. Yes, there was an error in the directory path command. Fixed it..Thanks again!
1
 ###############################
 #!/bin/sh
 #PBS -l nodes=1
 #PBS -l walltime=2:0:0
 #PBS -j oe
 #PBS -o localhost:/dev/null
 #PBS -d /your/working/directory


     cd $PBS_O_WORKDIR
     matlab -nodisplay -nodesktop -nojvm -nosplash -r "your_matlab_function"

I like to add addpath(genpath('~/your/script's/home')); to the actual matlab script/function. Also, do not add the ".m" to your matlab filename.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.