MATLAB

MATLAB is a programming platform designed specifically for engineers and scientists. The heart of MATLAB is the MATLAB language, a matrix-based language allowing the most natural expression of computational mathematics.

Usage

The default version of MATLAB can be loaded with the following command:

module load apps/matlab

Alternatively, you can load a specific version using:

module load apps/matlab/2019a

For the list of available versions, please use:

module avail apps/matlab

Sample jobs

Below are some examples of different type of jobs that you might run on the cluster. Please adjust the submission parameters to suit your needs, in particular the partition. See here for more information.

Tip

You can reduce the memory footprint and improve the startup time of matlab by specifying -nojvm startup flag. Please note, that this option restricts functionality and some features that rely on Java won't work

Serial batch job

#!/bin/bash
#SBATCH --job-name=matlab # job name
#SBATCH --partition=test  # partition
#SBATCH --nodes=1         # number of nodes
#SBATCH --ntasks=1        # number of tasks
#SBATCH --mem=5G          # memory per job
#SBATCH --time=0-1:00     # runtime (D-HH:MM)

module load apps/matlab/2019a
matlab -nojvm -singleCompThread <./serial.m

Paralel SMP batch job

#!/bin/bash
#SBATCH --job-name=matlab # job name
#SBATCH --partition=test  # partition
#SBATCH --nodes=1         # number of nodes
#SBATCH --ntasks=5        # number of tasks
#SBATCH --mem 5G          # memory per job
#SBATCH --time=0-1:00     # runtime (D-HH:MM)

module load apps/matlab/2019a
matlab -nodisplay <./parallel.m

If you use parallel pools, you should be able to extract the number of requested cores from the environment and use that to create sufficiently sized one:

parpool_size = str2num(getenv('SLURM_NPROCS'));
pool = parpool('local', parpool_size);

Warning

Make sure that you only request a single node, as this type of the job cannot span multiple nodes.

GPU batch job

#!/bin/bash
#SBATCH --job-name=matlab    # job name
#SBATCH --partition=test_gpu # partition
#SBATCH --nodes=1            # number of nodes
#SBATCH --ntasks=1           # number of tasks
#SBATCH --mem=5G             # memory per job
#SBATCH --gres=gpu:1         # nuber of gpu's
#SBATCH --time=0-1:00        # runtime (D-HH:MM)

module load apps/matlab/2019a
matlab -nodisplay <./gpu.m

Functions will run on the GPU if you suppy the gpuArray argument:

A = gpuArray(rand(2^16,1));
B = fft(A);

For more information and the list of GPU enabled functions please see MATLAB documentation.

Licensing

MATLAB is a licensed software, however King's College London has a campus-wide license which covers the use on the cluster.

In addition, campus-wide license provides unlimited use of MATLAB and Simulink products to all faculty, staff, and researchers, on and off campus, on any device. Please see here for more information.