MATLAB

Overview

MATLAB is an integrated technical computing environment from The MathWorks for Maths, Programming and Graphics.

Versions R2022a, R2021b, R2021a, R2020a, R2019a, R2018a and R2017a are installed on the CSF.

Restrictions on use

October 2023: We have removed the requirement to compile your MATLAB code!

Compilation is no longer needed now that the University has a larger pool of MATLAB licenses. Previously, compilation was used to check-out a license only at compile time, not runtime. Given that the CSF is often used for large job-arrays (10,000s of tasks) running MATLAB, it used to be possible to use up all of the campus licenses. Now that there are more licenses, we won’t run out. So you can run un-compiled MATLAB jobs and each one will safely get a license.

An advantage of NOT compiling your code is that you may now run code that uses the Signal Processing Toolkit. It is NOT possible to compile SPT code, but you can now run this un-compiled on the CSF.

You may still compile your MATLAB code if you wish to. It will not improve the performance of your code. One benefit would be if the University license servers were suddenly unavailable – a batch job using compiled MATLAB would be able to start without problems because it doesn’t need to check-out a license.

Other restrictions and advice remain:

  • Interactive use of the MATLAB GUI is strongly discouraged (remote use of the GUI is slow).
  • The only MATLAB components you should run on the login node are the mcc and mex compilers to compile your .m files. All MATLAB jobs, whether compiled or not, MUST be submitted to the batch system.
  • MATLAB parallel jobs cannot run across more than one CSF compute node. This is because the University does not have licenses for the Distributed Computing Server product. The maximum job size on CSF3 is therefore 32 cores. Please get in touch if you would like help assessing the requirements of your job.

Set up procedure

We now recommend loading modulefiles within your jobscript so that you have a full record of how the job was run. See the example jobscript below for how to do this. Alternatively, you may load modulefiles on the login node and let the job inherit these settings.

If you wish to compile your matlab code (it is no longer mandatory) you should also load the modulefile at the login node command-line.

Load one of the following modulefiles:

module load apps/binapps/matlab/R2022a
module load apps/binapps/matlab/R2021b
module load apps/binapps/matlab/R2021a
module load apps/binapps/matlab/R2020a
module load apps/binapps/matlab/R2019a
module load apps/binapps/matlab/R2018a
module load apps/binapps/matlab/R2017a

Running the application

Un-compiled MATLAB uses a slightly different command in your jobscript compared to compiled MATLAB. Please see

If you still wish to compile your MATLAB code (which is now optional), our instructions are still available:

NOTE: If you are running an application that uses random numbers, it is suggested that you read and understand the article Parallel Random Numbers in MATLAB

Official Toolboxes

To check which toolboxes are installed for a given version of MATLAB you can execute the following from a login node:

matlab -nojvm -batch ver

The following toolboxes are available in all versions of MATLAB on the CSF:

  • Bioinformatics Toolbox
  • Control System Toolbox
  • Deep learning Toolbox
  • Embedded Coder
  • Financial Toolbox
  • Fuzzy Logic Toolbox
  • Global Optimization Toolbox
  • Image Processing Toolbox
  • MATLAB
  • MATLAB Coder
  • MATLAB Compiler
  • Optimization Toolbox
  • Parallel Computing Toolbox
  • Partial Differential Equation Toolbox
  • Robust Control Toolbox
  • Signal Processing Toolbox
  • Simulink
  • Simulink 3D Animation
  • Simulink Coder
  • Simulink Control Design
  • Statistics and Machine Learning Toolbox
  • Symbolic Math Toolbox. Note: even though this toolbox is licensed, a lot of SMT code cannot be compiled so you may not be able to run your code on the CSF using this toolbox.
  • System Identification Toolbox
  • Wavelet Toolbox

R2020a has the Computer Vision Toolbox in addition to those listed above.

Please note that some of these toolboxes have extremely limited numbers of licenses. For example, there are only two licenses for the Bioinformatics toolbox site-wide.

If you can’t access one of the above toolboxes, or if you need to use a toolbox that isn’t included here, please read the advice given at the following URL. It gives advice on how to use alternatives to toolboxes along with contact details of IT Staff who can facilitate the purchase of extra toolboxes.

Additional Toolboxes

The following are available:

dicm2nii

dicm2nii github website

module load apps/binapps/matlab/third-party-toolboxes/dicm2nii/191001

easyspin

easyspin website

module load apps/binapps/matlab/third-party-toolboxes/easyspin/5.2.21
module load apps/binapps/matlab/third-party-toolboxes/easyspin/5.2.30

The open source version that is available via Github has also been made available. Easyspin is usually written as .p MATLAB files this causes issues with dependencies in the compilation stage as the nested Easyspin .p code functions failto compile properly. This version comprises solely of .m functions and therefore compiles as expected. To load please do the following.

module load apps/binapps/matlab/third-party-toolboxes/easyspin/5c7b2cc  (# 5c7b2cc - refers to the github commit)

Please note when it comes to compiling your MATLAB code you will need to include the Easyspin toolbox and any required datafiles, e.g.

mcc -R -singleCompThread -m CW_EPR_W_band_CSF_updated.m -I $EASYSPINDIR -I $EASYSPIN_PRIVATE -a $EASYSPIN_PRIVATE/isotopedata.txt

Once compiled, submit a job as described on the following page Compiling and submitting Matlab Jobs

SDETools

SDETools

module load apps/binapps/matlab/third-party-toolboxes/sdetools/1.2

SPM

SPM Website<
Two versions available:

module load apps/binapps/matlab/third-party-toolboxes/spm/12.5
module load apps/binapps/matlab/third-party-toolboxes/spm/12.4

Compilation (basic usage)

Loading the SPM module file sets an environment variable SPM_STANDALONE=~/scratch/SPM-standalone, which you should use when  compiling the SPM toolbox:

# load an interactive job to compile
qrsh -l short -pe smp.pe 2

# load the SPM module you require
module load apps/binapps/matlab/third-party-toolboxes/spm/12.5

# Copy the toolbox to ${HOME}/scratch/SPM${SPM_VER} 
source $SPM_COPY

# Create a directory in your scratch area in which you'll compile the toolbox.
# This is easy to do if we use the environment variable SPM_STANDALONE:
mkdir -p $SPM_STANDALONE

# Now compile the spm12 toolbox in to your directory:
matlab -batch "addpath ${USER_SPM_DIR}; spm_jobman initcfg; spm_make_standalone('$SPM_STANDALONE');"

Compilation (including your own toolbox code)

If you need to use code from your own toolbox in addition to the SPM toolbox, you will need to use a different process to compile the SPM toolbox:

# load an interactive job to compile
qrsh -l short -pe smp.pe 2

# load the SPM module you require
module load apps/binapps/matlab/third-party-toolboxes/spm/12.5
set -e
set -u
# Copy the toolbox to ${HOME}/scratch/SPM${SPM_VER} 
source $SPM_COPY

# Create the directory ~/scratch/SPM-standalone
mkdir -p $SPM_STANDALONE

# Compile the package. Allow ~20 minutes to complete.
matlab -batch "addpath ${USER_SPM_DIR}; spm_jobman initcfg; spm_make_standalone('$SPM_STANDALONE');"
echo "Done."

Submitting a job

After compilation, exit the interactive job to return to the login node and navigate to your SPM_STANDALONE directory so that your jobscript can find the files you compiled above:

cd $SPM_STANDALONE

Then use this line in your job script (instead of the usual matlab commands):

./run_spm12.sh $MATLAB_HOME script yourscript.m             # Replace yourscript.m with the name of your script

The compiled spm12 code will run the matlab code you have written in yourscript.m but this is still essentially a compiled matlab job so will be kind to the license servers.

MTEX

MTEX website

module load apps/binapps/matlab/third-party-toolboxes/mtex/5.3

Compile your script with one of the below:

compile-mtext your-matlab-script.m
compile-mtex-parallel your-matlab-script.m

Spinach

Spinach website

module load apps/binapps/matlab/third-party-toolboxes/spinach/2.4.5157

Compile with :

compile-parallel-spinach.sh your-matlab-script.m

Spinach may require a scratch directory to write to. We recommend adding this to your script:

sys.scratch=strcat('/scratch/',getenv("USER"),'/spinach-tmp') 

MDSINE

MDSINE website
This toolbox hasn’t been maintained for years, and the latest version of MATLAB it works with is R2015b.

module load apps/binapps/matlab/R2015b
module load apps/binapps/matlab/third-party-toolboxes/mdsine/1.3

The second module will prompt you to issue a command which copies the whole toolbox to your scratch area (~/scratch/mdsine1.3/). You should move the script you want to run into this folder.

From this directory (~/scratch/mdsine1.3/) you can then run the following command to compile your code:

compile-mdsine.sh your-script.m

Further information

  • It is often possible to speed-up MATLAB code significantly using techniques such as vectorisation, mex files, parallelisation and more. If you would like advice on how to optimise your MATLAB application then contact the Research IT applications team

Last modified on October 25, 2023 at 3:19 pm by George Leaver