MATLAB

Notitle

MATLAB is a multi-paradigm numerical computing environment and programming language. A proprietary programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages.

MATLAB is available as a module on Apocrita. QMUL has a site licence for both MATLAB and MATLAB Distributed Computing Server up to a maximum of 32 cores.

Usage

To run the latest installed version of MATLAB, simply load the matlab module:

module load matlab

Once the module is loaded, MATLAB can be run either as an interactive job or as a batch job, via the scheduler.

MATLAB Resource Usage

Much of the core MATLAB functionality is multi-threaded and can make use of multiple processor cores.

This includes simple element-wise functions (=+=, .* etc.) which operate on individual elements in a matrix - and more complex algorithms such as FFT.

Running without the JVM

When running without the MATLAB GUI, the MATLAB Java API and without parfor, the JVM can be disabled via the -nojvm option, this will make MATLAB start faster, and use less memory.

Licensing

MATLAB is licensed for 32 cores on Apocrita, when running the application you can request licences via -l matlab <number of cores>.

Example Jobs

Interactive MATLAB

Interactive MATLAB sessions can be run in text-only mode or using the full MATLAB GUI. By default the matlab command will try to start the MATLAB GUI using X-Windows, if X is not available, then a text-only session will be started.

GUI

To run the MATLAB desktop GUI:

  • log in to the cluster with X-Windows forwarding enabled
  • start an X-Windows session on a node on the cluster using qsh.
  • from this xterm session:
    • load the appropriate MATLAB module: module load matlab
    • start the MATLAB GUI using the matlab command

To start an X-Windows terminal on a node with 4 cores and 4G of RAM:

qsh -pe smp 4 -l h_vmem=1G -l matlab=4

module load matlab
matlab

Note

Although the GUI appears on the local machine, the session is running on the cluster and can only access files on the cluster.

Text Only

To run a text-only MATLAB session:

  • start a session on a node on the cluster using qlogin
  • load the appropriate MATLAB module e.g. module load matlab
  • start MATLAB using matlab -nodisplay

To start a text-only session on a node with 8 cores and 16GB of RAM.

qlogin -pe smp 8 -l h_vmem=2G -l matlab=8

module load matlab
matlab -nodisplay

Specific JVM

If you require MATLAB to use a specific version of the Java, you can set the environment variable MATLAB_JAVA to path of the desired Java version.

Non-Interactive MATLAB

Non-interactive jobs are submitted via the Grid Engine queuing system using the qsub command, and should use the MATLAB -nodisplay option as they do not use the MATLAB desktop.

Array jobs

The SGE_TASK_ID can be accessed via str2num(getenv('SGE_TASK_ID'));

#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 4
#$ -l h_rt=1:0:0
#$ -l h_vmem=2G
#$ -l matlab=4

module load matlab
matlab -nodisplay -nojvm < ./example.m

Parallel Toolbox

Parallel jobs making use of the MATLAB parallel toolbox can be run in the smp parallel environment. Running with the parallel toolbox allows the launch of a local scheduler and utilisation of MATLAB parfor functionality on a single host.

Parallel Example Job Script
#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 16
#$ -l h_rt=4:0:0
#$ -l h_vmem=2G
#$ -l matlab=16

module load matlab

matlab -nodisplay < ./matlabparallel.m
Parallel Example MATLAB script
i=str2num(getenv('NSLOTS'));
pool = parpool('local', i);

parfor j = 1:i
    fprintf('Im iteration %d\\n', j);
end

delete(pool);

References