Main menu

Search

Using Matlab

Matlab is installed on all the campus clusters. Here is a short tutorial to use Matlab, specifically for the Knot cluster. You can follow similar steps if you are using other clsuters.

Once you connect to a cluster (e.g. Knot) with Xwindows enabled, you can simply type /sw/bin/matlab to launch the Matlab graphical user interface. Xwindows is enabled by the -X option during ssh. For Windows, you will need a X-server installed, for example Xming. For MACs, you need XQuartz installed on your system. You can also use the NX Server.

Please do not run large calculations with this method! Use the method below to submit your script to the queuing system.

Basic Runs: Submission to the queue

For jobs that require a large number of resources and a long runtime, submission to the queue is required. Suppose you have a script names test.m in your working directory. Here is an example job submission script to run this script using Matlab:

This job asks for 12 cores in a single compute node with a walltime of 10 minutes. $PBS_O_WORKDIR ensures that you are in the directory where the job is submitted (and where test.m is located). Let's say that the name of this script is job.submission. The final step is to imply submit to the queue by

qsub job.submision

Using Matlab in parallel

The easiest way to use parallel processing in Matlab is parallelizing for loops. In this way, you can use all the cores in a given compute node in parallel. Note: Parallelization across different nodes require another toolbox of Matlab which is not existent on the Knot cluster.

Note: In the latest version of Matlab (2016), matlabpool is not included anymore. parfor will work automatically.

Compiled Matlab Scripts:

Another option is to compile your Matlab script. In this way, an executable is created which can be run directly. Consider the test.m example above. To create a compiled executable, create a new function that calls test.m, for example

function main
test;
close all;

Let's say that this function is saved in the script mainFun.m. To compile use the mcc compiler from Matlab:

/sw/MatLab/R2014b/bin/mcc -mv -R -nodisplay mainFun.m

This will create an executable mainFun and a shell srcipt run_mainFun.sh. To run it, you can use a job submission script, for example