MATLAB¶
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 MATLAB.
Experienced MATLAB users may be accustomed to using MATLAB on the desktop interactively. Text mode should work well on Apocrita. While GUI mode is possible, we do not recommend it. Performance and ease of use are heavily dependent on a robust local X-Windows implementation (and we may not be able to support this on your desktop). The suggested workflow is to carry out prototyping work on your desktop and then run your jobs on Apocrita in batch mode to take advantage of its processing power.
Alternatively you can prototype interactively in text mode on Apocrita.
Please see here if you want to install MATLAB on your desktop. If you do want to try MATLAB interactively on Apocrita see below.
Usage¶
To run the default 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.
Example jobs¶
Simple batch job¶
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 1
#$ -l h_rt=1:0:0
#$ -l h_vmem=2G
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 toolbox job script¶
#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 8
#$ -l h_rt=1:0:0
#$ -l h_vmem=2G
module load matlab
matlab -nodisplay < ./matlabparallel.m
Example MATLAB script using parallel toolbox¶
i=str2num(getenv('NSLOTS'));
pool = parpool('local', i);
parfor j = 1:i
fprintf('Im iteration %d\\n', j);
end
delete(pool);
GPU job¶
This is an example of a MATLAB job requesting 1 GPU and the matching number of slots.
#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 8
#$ -l h_rt=240:0:0
#$ -l h_vmem=11G
#$ -l gpu=1
module load matlab
matlab -nodisplay < ./example.m
Memory request
Note that the memory is slightly less than half a node so it fits alongside the OS and a second job, see the Using GPUs page for more information.
Using MATLAB interactively on Apocrita¶
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
- load the appropriate MATLAB module:
To start an X-Windows terminal on a node with 4 cores and 4G of RAM:
qsh -V -pe smp 4 -l h_vmem=1G
module load matlab
matlab
File access restriction
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
module load matlab
matlab -nodisplay
Specific JVM
If you require MATLAB to use a specific version of Java, you can set
the environment variable MATLAB_JAVA
to path of the desired Java version.
Using additional libraries¶
Occasionally a MATLAB function may require external libraries or programs which are not available by default on Apocrita. It may be necessary for you to build them in your user space before running the MATLAB script, but currently on Apocrita we provide a module for:
- GStreamer, a suite of software for working with various kinds of media. Various MATLAB functions use this package to supplement the supported media formats.
To make a package available to MATLAB the module should be loaded before starting MATLAB. For example, to use the GStreamer functionality:
module load matlab
module load gstreamer
matlab ...
If you are not using a module then it may be necessary for you to set environment variables to allow MATLAB to find the package. Again, these should be set before starting the MATLAB interpreter.