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!

Amro
  • 123,847
  • 25
  • 243
  • 454
  • 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.... – Cypress Frankenfeld Aug 04 '12 at 00: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). – Amro Aug 04 '12 at 00:36
  • @Amro, you are completely correct. I'll delete that post and just refer to your answer. – Cypress Frankenfeld Aug 04 '12 at 00:46
  • You may need to replace `*directory path/ga_opt_main.m*` with a Matlab command, as Amro stated. – Cypress Frankenfeld Aug 04 '12 at 00:47

2 Answers2

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;"
Amro
  • 123,847
  • 25
  • 243
  • 454
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.

AGS
  • 14,288
  • 5
  • 52
  • 67