Skip to content

MATLAB

MATLAB

MATLAB is a numerical computing and programming environment with a broad range of functionality.

DIPC owns licenses for all the existing toolboxes for MATLAB.

Usage

The MATLAB Module

MATLAB has to be loaded using Lmod prior to running it.

$ module load MATLAB/R2020b

You can also list all available versions using Lmod's spider command:

$ module spider MATLAB

Non-interactive MATLAB Sessions

Even if on desktop computers MATLAB is usually run in interactive mode given the nature of supercomputing resources, the preferred mode of operation for MATLAB on our systems is non-interactive.

One way to run MATLAB non-interactively is through

  • Re-directing the standard input and output when invoking Matlab.
  • Invoking MATLAB from a batch script, submitted to the queue via qsub command.

Input and output re-direction is arguably the easiest way of running MATLAB non-interactivelly.

$ matlab < script.m > output.log

The main function/program (e.g. script.m) should have the exit command at the end in order to force Matlab to quit after finishing the execution of the code.

Submission scripts should contain the following lne to run the Matlab script:

#!/bin/bash
#SBATCH --partition=regular
#SBATCH --job-name=MATLAB_JOB
#SBATCH --mem=200gb
#SBATCH --cpus-per-task=24
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --output=%x-%j.out
#SBATCH --error=%x-%j.err

module load MATLAB/R2020b

matlab -nodisplay -nosplash -singleCompThread < script.m > output.log

The option nodisplay instructs Matlab to run without the GUI, while nosplash prevents the display of the Matlab logo.

Running Matlab on parallel hardware

Users can exploit parallel processing through a series of explicit programming techniques. The following techniques are briefly discussed below, with examples given:

  • Using the Matlab toolbox Parallel Computing Toolbox.
  • Trivial parallelism through many independent Matlab processes.

At DIPC we have two licenses for the Parallel Computing Toolbox. The Parallel Computing Toolbox is designed for programming multi-core architectures (distributed computing is not supported)

Standalone executables with MATLAB

To deploy the script as a standalone application, load the modules for MATLAB:

$ module load MATLAB/R2020b

Then, compile the script using mcc and the command:

$ mcc -v -R -singleCompThread -m myfile.m
If you know what you are doing you can enable multithreading by getting rid of the -singleCompThread option.

The mcc compilation creates an executable called myfile. In addition to this, the process generates the files mccExcludedFiles.log and readme.txt, which can be safely discarded. Also, a wrapper script .sh is generated; this can be used to launch the executable into execution as it ensures the correct environment (paths to shared libraries and other environment variables) is set before execution. However, since loading the MATLAB module does this for you, you do not really need to use it.

On the other hand, MATLAB compiler lets you build standalone applications that are completely independent of the MATLAB core installation. What is more, all applications created with MATLAB Compiler use the MATLAB Runtime, which enables royalty-free deployment to users who do not need MATLAB. This means that every instance or execution of these applications DOES NOT make use of the license server. Therefore, since the floating licenses will be shared among all the users based at DIPC, please, make use of it as long as it is possible.