Matlab on the Millipede cluster
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
# Run 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
Note that, modules 'maui' and 'torque' need to be loaded before you can use commands such as qsub, qstat and showq.
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.
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 "run_prog.sh". 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:
$ ./run_prog.sh /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 run_prog.sh). 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:
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.
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); end disp(N*N); exit(); end
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 18.104.22.1689 (R2010a) 64-bit (glnxa64)
February 5, 2010
To get started, type one of these: helpwin, helpdesk, or demo. For product information, visit ww.mathworks.com. >> 16
After compilation with mcc it can be run like:
$ ./Square 4 16
|Laatst gewijzigd:||02 oktober 2015 22:23|