MATLAB on the ACCRE Cluster

From ACCRE Wiki

MATLAB Logo

MATLAB is a commercial programming language and computing environment that is widely popular in many areas of engineering and science. Since 2018, MATLAB has been free to use on the cluster for all ACCRE users.

Versions of MATLAB on the ACCRE Cluster

To see a list of installed versions of MATLAB on the cluster, use Lmod:

[jill@vmps12 ~]$ module avail matlab
If you need to request software, please submit your request through the PI Dashboard:
https://dashboard.accre.vanderbilt.edu/#/rtticket/create

Note: We are unable to install Python or R packages. For guidance on how to install Python or R packages, please
refer to https://help.accre.vanderbilt.edu.


-------------------------------------------- ACCRE specific Core modules --------------------------------------------
   matlab/2020a (t)    matlab/2021a (t)    matlab/2022a (t)    matlab/2023a (t)
   matlab/2020b (t)    matlab/2021b (t)    matlab/2022b (t)    matlab/2023b (t,D)

  Where:
   t:  Tools for development
   D:  Default Module

If the avail list is too long consider trying:

"module --default avail" or "ml -d av" to just list the default modules.
"module overview" or "ml ov" to display the number of modules for each name.

Use "module spider" to find all possible modules and extensions.
Use "module keyword key1 key2 ..." to search for all possible modules matching any of the "keys".

Multiple versions of MATLAB are available on the cluster. We encourage users to use the most recent version of MATLAB installed, if possible, as we will not offer support for older versions indefinitely.

To load a particular version of MATLAB, use the module load command:

[jill@vmps12 ~]$ module load matlab/2023b
[jill@vmps12 ~]$ which matlab
/panfs/accrepfs.vampire/accre/software/easybuild/software/2023/x86-64-v3/Core/matlab/2023b/bin/matlab

In order to run MATLAB interactively, simply type `matlab` from the Linux command line:

[jill@vmps12 ~]$ matlab
MATLAB is selecting SOFTWARE OPENGL rendering.
Picked up JAVA_TOOL_OPTIONS: -Xmx2g
Unable to open file for Java VM logging

                                               < M A T L A B (R) >
                                     Copyright 1984-2023 The MathWorks, Inc.
                                R2023b Update 3 (23.2.0.2409890) 64-bit (glnxa64)
                                                 October 4, 2023


To get started, type doc.
For product information, visit www.mathworks.com.

>>

Note that the MATLAB command prompt may take ~30-60 seconds to completely load, depending on which version you are using and whether you’ve loaded it previously in your current shell session. You can also load the full graphical user interface (GUI) to your local machine by logging into the cluster with X11 forwarding enabled (ssh -X <vunetid>@login.accre.vu). In general, using the MATLAB GUI from the cluster will be very slow, especially if you are outside the Vanderbilt network, so we do not recommend it. Instead, most users develop their MATLAB code locally (from a laptop or desktop environment) for testing and then submit jobs to the cluster for batch (non-interactive) processing. Another option is to run MATLAB through a virtual desktop through the ACCRE Visualization Portal.

To see a list of the available Matlab toolboxes on the cluster, use the ver command from the MATLAB command prompt:

>>>> ver
---------------------------------------------------------------------------------------------------------------
MATLAB Version: 23.2.0.2409890 (R2023b) Update 3
MATLAB License Number: 299681
Operating System: Linux 5.14.0-427.35.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Sep 12 18:24:53 UTC 2024 x86_64
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
---------------------------------------------------------------------------------------------------------------
MATLAB                                                Version 23.2        (R2023b)
Simulink                                              Version 23.2        (R2023b)
5G Toolbox                                            Version 23.2        (R2023b)
AUTOSAR Blockset                                      Version 23.2        (R2023b)
Aerospace Blockset                                    Version 23.2        (R2023b)
Aerospace Toolbox                                     Version 23.2        (R2023b)
Antenna Toolbox                                       Version 23.2        (R2023b)
Audio Toolbox                                         Version 23.2        (R2023b)
Automated Driving Toolbox                             Version 23.2        (R2023b)
Bioinformatics Toolbox                                Version 23.2        (R2023b)
Bluetooth Toolbox                                     Version 23.2        (R2023b)
C2000 Microcontroller Blockset                        Version 23.2        (R2023b)
Communications Toolbox                                Version 23.2        (R2023b)
Computer Vision Toolbox                               Version 23.2        (R2023b)
Control System Toolbox                                Version 23.2        (R2023b)
Curve Fitting Toolbox                                 Version 23.2        (R2023b)
DDS Blockset                                          Version 23.2        (R2023b)
DSP HDL Toolbox                                       Version 23.2        (R2023b)
DSP System Toolbox                                    Version 23.2        (R2023b)
Database Toolbox                                      Version 23.2        (R2023b)
Datafeed Toolbox                                      Version 23.2        (R2023b)
Deep Learning HDL Toolbox                             Version 23.2        (R2023b)
Deep Learning Toolbox                                 Version 23.2        (R2023b)
Econometrics Toolbox                                  Version 23.2        (R2023b)
Embedded Coder                                        Version 23.2        (R2023b)
Filter Design HDL Coder                               Version 23.2        (R2023b)
Financial Instruments Toolbox                         Version 23.2        (R2023b)
Financial Toolbox                                     Version 23.2        (R2023b)
Fixed-Point Designer                                  Version 23.2        (R2023b)
Fuzzy Logic Toolbox                                   Version 23.2        (R2023b)
GPU Coder                                             Version 23.2        (R2023b)
Global Optimization Toolbox                           Version 23.2        (R2023b)
HDL Coder                                             Version 23.2        (R2023b)
HDL Verifier                                          Version 23.2        (R2023b)
Image Acquisition Toolbox                             Version 23.2        (R2023b)
Image Processing Toolbox                              Version 23.2        (R2023b)
Industrial Communication Toolbox                      Version 23.2        (R2023b)
Instrument Control Toolbox                            Version 23.2        (R2023b)
LTE Toolbox                                           Version 23.2        (R2023b)
Lidar Toolbox                                         Version 23.2        (R2023b)
MATLAB Coder                                          Version 23.2        (R2023b)
MATLAB Compiler                                       Version 23.2        (R2023b)
MATLAB Compiler SDK                                   Version 23.2        (R2023b)
MATLAB Report Generator                               Version 23.2        (R2023b)
MATLAB Test                                           Version 23.2        (R2023b)
Mapping Toolbox                                       Version 23.2        (R2023b)
Medical Imaging Toolbox                               Version 23.2        (R2023b)
Mixed-Signal Blockset                                 Version 23.2        (R2023b)
Model Predictive Control Toolbox                      Version 23.2        (R2023b)
Motor Control Blockset                                Version 23.2        (R2023b)
Navigation Toolbox                                    Version 23.2        (R2023b)
Optimization Toolbox                                  Version 23.2        (R2023b)
Parallel Computing Toolbox                            Version 23.2        (R2023b)
Partial Differential Equation Toolbox                 Version 23.2        (R2023b)
Phased Array System Toolbox                           Version 23.2        (R2023b)
Powertrain Blockset                                   Version 23.2        (R2023b)
Predictive Maintenance Toolbox                        Version 23.2        (R2023b)
RF Blockset                                           Version 23.2        (R2023b)
RF PCB Toolbox                                        Version 23.2        (R2023b)
RF Toolbox                                            Version 23.2        (R2023b)
ROS Toolbox                                           Version 23.2        (R2023b)
Radar Toolbox                                         Version 23.2        (R2023b)
Reinforcement Learning Toolbox                        Version 23.2        (R2023b)
Requirements Toolbox                                  Version 23.2        (R2023b)
Risk Management Toolbox                               Version 23.2        (R2023b)
Robotics System Toolbox                               Version 23.2        (R2023b)
Robust Control Toolbox                                Version 23.2        (R2023b)
Satellite Communications Toolbox                      Version 23.2        (R2023b)
Sensor Fusion and Tracking Toolbox                    Version 23.2        (R2023b)
SerDes Toolbox                                        Version 23.2        (R2023b)
Signal Integrity Toolbox                              Version 23.2        (R2023b)
Signal Processing Toolbox                             Version 23.2        (R2023b)
SimBiology                                            Version 23.2        (R2023b)
SimEvents                                             Version 23.2        (R2023b)
Simscape                                              Version 23.2        (R2023b)
Simscape Battery                                      Version 23.2        (R2023b)
Simscape Driveline                                    Version 23.2        (R2023b)
Simscape Electrical                                   Version 23.2        (R2023b)
Simscape Fluids                                       Version 23.2        (R2023b)
Simscape Multibody                                    Version 23.2        (R2023b)
Simulink 3D Animation                                 Version 23.2        (R2023b)
Simulink Check                                        Version 23.2        (R2023b)
Simulink Code Inspector                               Version 23.2        (R2023b)
Simulink Coder                                        Version 23.2        (R2023b)
Simulink Compiler                                     Version 23.2        (R2023b)
Simulink Control Design                               Version 23.2        (R2023b)
Simulink Coverage                                     Version 23.2        (R2023b)
Simulink Design Optimization                          Version 23.2        (R2023b)
Simulink Design Verifier                              Version 23.2        (R2023b)
Simulink Desktop Real-Time                            Version 23.2        (R2023b)
Simulink Fault Analyzer                               Version 23.2        (R2023b)
Simulink PLC Coder                                    Version 23.2        (R2023b)
Simulink Real-Time                                    Version 23.2        (R2023b)
Simulink Report Generator                             Version 23.2        (R2023b)
Simulink Test                                         Version 23.2        (R2023b)
SoC Blockset                                          Version 23.2        (R2023b)
Stateflow                                             Version 23.2        (R2023b)
Statistics and Machine Learning Toolbox               Version 23.2        (R2023b)
Symbolic Math Toolbox                                 Version 23.2        (R2023b)
System Composer                                       Version 23.2        (R2023b)
System Identification Toolbox                         Version 23.2        (R2023b)
Text Analytics Toolbox                                Version 23.2        (R2023b)
UAV Toolbox                                           Version 23.2        (R2023b)
Vehicle Dynamics Blockset                             Version 23.2        (R2023b)
Vehicle Network Toolbox                               Version 23.2        (R2023b)
Vision HDL Toolbox                                    Version 23.2        (R2023b)
WLAN Toolbox                                          Version 23.2        (R2023b)
Wavelet Toolbox                                       Version 23.2        (R2023b)
Wireless HDL Toolbox                                  Version 23.2        (R2023b)
Wireless Testbench                                    Version 23.2        (R2023b)

Note that ACCRE has a license for the Parallel Computing Toolbox, which allows for processing across multiple CPU cores and/or GPUs, and can therefore enable better performance (faster execution time) depending on the application.

Example Scripts

Running a MATLAB script within a SLURM job is generally straightforward. Unless you are attempting to run across multiple CPU cores using MATLAB’s Parallel Computing Toolbox, you will want to request a single task, load the appropriate version of MATLAB from your SLURM script, and then launch your MATLAB job. The following example runs a simple MATLAB script that demonstrates the utility of writing vectorized Matlab code:

[jill@vmps12 run1]$ ls
matlab.slurm  vectorization.m

[jill@vmps12 run1]$ cat matlab.slurm 
#!/bin/bash
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --time=00:10:00
#SBATCH --mem=2G
#SBATCH --output=matlab_job_slurm.out

module load matlab   # load the default version of Matlab

matlab -nodisplay -nosplash < vectorization.m

The -nodisplay flag informs MATLAB you are operating in batch mode, while the -nosplash flag will prevent the splash screen from being displayed during startup. Additionally, you might try passing the -nojvm flag, which informs MATLAB that you do not need Java features for processing. Passing this flag often leads to faster MATLAB load-up times, but some I/O operations may depend on Java support so use this flag with caution. More information can be found on MATLAB Documentation.

[jill@vmps12 run1]$ cat vectorization.m
% surrounding a block of code with tic and toc
% will time its execution

% non-vectorized code
tic
i = 0;
for t = 0:.00001:10
i = i + 1;
y(i) = sin(t);
end
toc

% vectorized code
tic
t = 0:.00001:10;
y = sin(t);
toc
[jill@vmps12 run1]$ sbatch matlab.slurm 
Submitted batch job 1424671

After waiting a few minutes:

[jill@vmps12 run1]$ ls
matlab_job_slurm.out  matlab.slurm  vectorization.m
[jill@vmps12 run1]$ cat matlab_job_slurm.out 
Picked up JAVA_TOOL_OPTIONS: -Xmx2g
Unable to open file for Java VM logging

                            < M A T L A B (R) >
                  Copyright 1984-2023 The MathWorks, Inc.
             R2023b Update 3 (23.2.0.2409890) 64-bit (glnxa64)
                              October 4, 2023


To get started, type doc.
For product information, visit www.mathworks.com.

>> >> >> >> >> >> >> >>>>>>>> Elapsed time is 0.287125 seconds.
>> >> >> >> >> >> Elapsed time is 0.049262 seconds.

In this particular example no functions were defined in the vectorization.m file. Often users write scripts with functions, and need to call a function from the Linux command line. This can be accomplished by passing the MATLAB interpreter the -r option. For example:

matlab -nodisplay -nosplash -r "myFunc(1),quit()"

Here we are calling myFunc() and passing a single argument (1) to the function. It’s also necessary to call quit() afterwards to ensure your job ends once MATLAB processing has completed. You may also need to update your MATLAB path to include directories containing .m files and their function definitions. There are a few ways to accomplish this. The first way is to update your MATLABPATH Bash environment variable. Something like the following can be done within a SLURM script before MATLAB is launched:

export MATLABPATH=/home/jill/myDir

Alternatively, the path can be updated at runtime like so:

matlab -nodisplay -nosplash -r "addpath(genpath('/home/jill/myDir')),myFunc(1),quit()"

Contributing New Examples

In order to foster collaboration and develop local MATLAB expertise at Vanderbilt, we encourage users to submit examples of their own to ACCRE’s MATLAB Github repository. Furthermore, ACCRE slack can be used as community help material as well. Please report any inconsistencies to this article via the Helpdesk