Skip to ContentSkip to Navigation
Society/business Center for Information Technology Research and Innovation Support Virtual Reality and Visualisation

Matlab on the Millipede cluster

Matlab jobs

To run a single-processor Matlab batch job, a PBS script is required. The PBS script can be submitted to the PBS batch queue for execution. Since the job requires 'Matlab', the 'matlab' module needs to be loaded using command 'module load matlab'.


Here is an example of a PBS script 'matlab.pbs':

#PBS -N matlab
#PBS -l walltime=10:00:00
#PBS -l nodes=1:ppn=1
#PBS -j oe
# cd to your work directory where the M-file is located
# Load MATLAB module
module load matlab
matlab -nodisplay -r myTestJob

This script includes a request for one processor and 10 hours of wall time. It also includes the command to load the MATLAB module and specifies the '-nodisplay' option. With the '-nodisplay' option, attempts to open plot and similar windows will be simply ignored. The script specifies that the actual MATLAB program (or "M-file") to be run is contained in the file "myTestJob.m".

Note that the command to execute an M-file doesn't use the '.m' extension of the file. If the '.m' extension is used, you will get the following error message:

??? Undefined variable "myTestJob" or class "myTestJob.m"

In this case, the path to the M-file needs to be added to the MATLAB search path. To avoid this error, change to the working directory where the M-file is located before running matlab (as shown in the PBS script above).

The PBS script is submitted to the batch queue using the command

qsub matlab.pbs

Note that, modules 'maui' and 'torque' need to be loaded before you can use commands such as qsub, qstat and showq.

Matlab licenses

The number of licenses available for running matlab on the cluster is limited. For this reason you are only allowed to use 5 matlab licenses  at the same time. When running many jobs you will quickly run into this limit. The easiest way to get around this is by making use of the matlab compiler.

Matlab compiler

The matlab compiler can change your matlab code into a stand-alone executable. This executable does not need a matlab license to run. The way to compile your code is by using the command mcc. If your matlab program is called prog.m you can compile it using

$ mcc -m prog.m

Note that this will generate several files, including some C code and supporting files. After the compilation you will have both an executable "prog" and a helper script "". The script expects as input the path of the matlab compiler runtime. This is the same path as where matlab is installed on the cluster (currently /cm/shared/apps/matlab). You can therefor run your compiled matlab program using:

$ ./ /cm/shared/apps/matlab

Another way to run the program is by directly calling prog. In that case you will need to set some environment variables (the same as those set by This can also easily be done by loading the module "matlab".

$ module load matlab

The program can in that case simpy be run by giving the command:

$ ./prog

Note that for running this in a job you still have to insert this in a jobscript. In the jobscript example given earlier the line that calls matlab has to be changed into the line given above.

Program arguments

If your matlab program is a function expecting arguments some care has to be taken with numeric arguments. When run from the command-line or using a compiled program numeric arguments are read in as strings. You will therefore need to convert these arguments to numbers first. For simple cases this can be done using the matlab functions ischar and str2num. Below is an example function.

function Square(N)
   if ischar(N)
      N = str2num(N);

When running this using matlab on the command line the argument has to specified together with the function name like:

$ matlab -nodisplay -r "Square 4"

                            < M A T L A B (R) >
                  Copyright 1984-2010 The MathWorks, Inc.
                Version (R2010a) 64-bit (glnxa64)
                              February 5, 2010
  To get started, type one of these: helpwin, helpdesk, or demo.   For product information, visit >> 16

After compilation with mcc it can be run like:

$ ./Square 4
Last modified:02 October 2015 10.23 p.m.