Skip to content

MATLABĀ® combines a desktop environment tuned for iterative analysis and design processes with a programming language that expresses matrix and array mathematics directly. It includes the Live Editor for creating scripts that combine code, output, and formatted text in an executable notebook.

Available versions of MATLAB in ULHPC

To check available versions of MATLAB at ULHPC type module spider matlab. It will list the available versions:

bash math/MATLAB/<version>

Interactive mode

To open MATLAB in the interactive mode, start by connecting to the ULHPC login node with the -X (or -Y) option:

bash ssh -X iris-cluster # OR on Mac OS: ssh -Y iris-cluster

bash ssh -X aion-cluster # OR on Mac OS: ssh -Y aion-cluster

Then, you can reserve an interactive job, for instance with 4 cores. Don't forget to use the --x11 option if you intend to use the GUI.

```bash $ si --x11 -c4

Load the module MATLAB and needed environment

(node)$ module purge (node)$ module load math/MATLAB

Non-Graphical version (CLI)

(node)$ matlab -nodisplay -nosplash < M A T L A B (R) > Copyright 1984-2021 The MathWorks, Inc. R2021a (9.10.0.1602886) 64-bit (glnxa64) February 17, 2021 To get started, type doc. For product information, visit www.mathworks.com.

version() ans = '9.10.0.1602886 (R2021a)'

List of installed add-ons

matlab.addons.installedAddons ans = 96x4 table Name Version Enabled Identifier ___ __ _ __

"Mapping Toolbox"      "5.1"        true         "MG"
"Simulink Test"        "3.4"        true         "SZ"
[...]

quit()

To run the GUI version, over X11

(node)$ matlab & ```

Batch mode

For non-interactive or long executions, MATLAB can be ran in passive or batch mode, reading all commands from an input file (with .m extension) you provide (Ex: inputfile.m) and saving the results into an output file, for instance outputfile.out). You have two ways to proceed:

bash matlab -nodisplay -nosplash < inputfile.m > outputfile.out

```bash

/!\ IMPORTANT: notice the missing '.m' extension on -r !!!

matlab -nodisplay -nosplash -r inputfile -logfile outputfile.out ```

The following script uses one full socket in a compute node of Aion.

```bash

!/usr/bin/bash --login

SBATCH --job-name=MATLAB_job

SBATCH --nodes=1

SBATCH --ntasks-per-node=1

SBATCH --cpus-per-task=16

SBATCH --partition=batch

SBATCH --qos=normal

SBATCH --time=00:30:00

Uncomment if you use a non-default account to run your jobs

SBATCH --account=

Load the module MATLAB

module purge module load math/MATLAB

second form with CLI options '-r ' and '-logfile .out'

srun matlab -nodisplay -r my_matlab_script -logfile output.out

example for if you need to have a input parameters for the computations

matlab_script_serial_file(x,y,z)

srun matlab -nodisplay -r my_matlab_script(2,2,1)' -logfile output.out

Cleaunp MATLAB autogenerated files from your home directory

rm -rf ${HOME}/.matlab rm -rf ${HOME}/java* ```

Most matlab scripts cannot take advantage of more that one core (--cpus-per-task=1). If you want to use more than one core in your computations, use a parallel pool of threads.

A parallel pool of threads allows the allocation of threads form the local computing node to independent workers that then use the thread to evaluate functions in parallel. Create a parallel pool on using the parpool function. After you create the pool, parallel pool features, such as parfor or parfeval, run computations on independent workers in parallel. With the ThreadPool object, you can interact with the parallel pool.

Example

```bash

example for MATLAB ParFor (matlab_script_parallel_file.m)

p = parpool('local', str2num(getenv('SLURM_CPUS_PER_TASK'))) % set the default cores %as number of threads tic n = 50; A = 50; a = zeros(1,n); parfor i = 1:n a(i) = max(abs(eig(rand(A)))); end toc delete(gcp); % you have to delete the parallel region after the work is done exit; ```

Additional information

To know more information about MATLAB tutorial and documentation, please refer to MATLAB tutorial.

Tip

If you find some issues with the instructions above, please report it to us using support ticket.