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.
Please see here if you want to install MATLAB on your desktop.
Usage¶
GUI support via OnDemand
To use the MATLAB GUI, launch the software via the OnDemand MATLAB interactive app.
To run the default installed version of MATLAB, simply load the matlab
module:
$ module load matlab
$ matlab -nodisplay -help
Usage: matlab [-h|-help] | [-n | -e]
[v=variant]
[-c licensefile] [-display Xdisplay | -nodisplay]
[--noFigureWindows]
[-nosplash] [-debug]
[-softwareopengl | -nosoftwareopengl]
[-desktop | -nodesktop | -nojvm]
[-batch MATLAB_command | -r MATLAB_command]
[-sd folder | -useStartupFolderPref]
[-logfile log]
[-singleCompThread]
[-jdb [port]]
[-Ddebugger [options]]
[-nouserjavapath]
...
For further usage documentation, see the output of matlab -nodisplay -help
.
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 display and JVM
When running MATLAB in command-line mode, we recommend launching the
matlab
application with the -nodisplay
and -nojvm
options. This will
make MATLAB start faster, and use less memory.
Example jobs¶
Array jobs
The SGE_TASK_ID
can be accessed via str2num(getenv('SGE_TASK_ID'));
Serial job (single-core)¶
Here is an example job running on 1 core and 4GB of memory:
#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 1
#$ -l h_rt=1:0:0
#$ -l h_vmem=4G
module load matlab
matlab -nodisplay -nojvm < ./example.m
Serial job (multi-core)¶
Jobs making use of the MATLAB parallel toolbox can be run in the smp
parallel
environment. Running with the parallel toolbox allows the utilisation of the
MATLAB parfor
functionality on a single host.
Here is an example job running on 4 cores and 8GB of memory:
#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 4
#$ -l h_rt=1:0:0
#$ -l h_vmem=2G
module load matlab
matlab -nodisplay < ./matlabparallel.m
Below shows an example MATLAB script using the 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¶
Here is an example job running on 1 GPU:
#!/bin/bash
#$ -cwd
#$ -j y
#$ -pe smp 12
#$ -l h_rt=240:0:0
#$ -l h_vmem=7.5G
#$ -l gpu=1
module load matlab
matlab -nodisplay < ./gpu_example.m
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, it may be necessary for you to set environment variables to allow MATLAB to find the additional package. Again, these should be set before starting the MATLAB interpreter.