MATLAB is a technical computing environment for high-performance numeric computation and visualization. MATLAB integrates numerical analysis, matrix computation, signal processing, and graphics in an easy-to-use environment where problems and solutions are expressed just as they are written mathematically--without traditional programming.
Availability and Restrictions
Versions
MATLAB is available on Pitzer and Owens Clusters. The versions currently available at OSC are:
Version | Owens | Pitzer | Notes |
---|---|---|---|
r2015b | X | ||
r2016b | X | ||
r2017a | X | ||
r2018a | X | X | |
r2018b | X | X | |
r2019a | X | ||
r2019b | X | X | |
r2020a | X* | X* | |
r2021b | X | X | |
r2022a | X | X |
You can use module spider matlab
to view available modules for a given machine. Feel free to contact OSC Help if you need other versions for your work.
Access: Academic Users Only (non-commercial, non-government)
Academic users can use Matlab at OSC. All users must be added to the license server before using MATLAB. Please contact OSC Help to be granted access or for any license related questions.
Publisher/Vendor/Repository and License Type
MathWorks, Commercial (University site license)
Usage
Usage on Owens
Set-up
module load matlab
. For a list of all available MATLAB versions and the format expected, type: module spider matlab
. To select a particular software version, use module load matlab/version
. For example, use module load matlab/r2015b
to load MATLAB version r2015b. Running MATLAB
The following command will start an interactive, command line version of MATLAB:
matlab -nodisplayIf you are able to use X-11 forwarding and have enabled it in your SSH client software preferences, you can run MATLAB using the GUI by typing the command
matlab
. For more information about the matlab command usage, type matlab –h
for a complete list of command line options.
The commands listed above will run MATLAB on the login node you are connected to. As the login node is a shared resource, running scripts that require significant computational resources will impact the usability of the cluster for others. As such, you should not use interactive MATLAB sessions on the login node for any significant computation. If your MATLAB script requires significant time, CPU power, or memory, you should run your code via the batch system.
Batch Usage
When you log into owens.osc.edu you are actually logged into a Linux box referred to as the login node. To gain access to the multiple processors in the computing environment, you must submit your job to the batch system for execution. Batch jobs can request multiple nodes/cores and compute time up to the limits of the OSC systems. Refer to Queues and Reservations and Batch Limit Rules for more info.
Interactive Batch Session
For an interactive batch session using the command line version of MATLAB, one can run the following command:sinteractive -A <project-account> -N 1 -n 28 -t 00:20:00
which requests one whole node with 28 cores ( -N 1 -n 28
), for a walltime of 20 minutes ( -t 00:20:00
). Here you can run MATLAB interactively by loading the MATLAB module and running MATLAB with the options of your choice as described above. You may adjust the numbers per your need.
Usage on Pitzer
Set-up
module load matlab
.Running MATLAB
The following command will start an interactive, command line version of MATLAB:
matlab -nodisplayIf you are able to use X-11 forwarding and have enabled it in your SSH client software preferences, you can run MATLAB using the GUI by typing the command
matlab
. For more information about the matlab command usage, type matlab –h
for a complete list of command line options.
The commands listed above will run MATLAB on the login node you are connected to. As the login node is a shared resource, running scripts that require significant computational resources will impact the usability of the cluster for others. As such, you should not use interactive MATLAB sessions on the login node for any significant computation. If your MATLAB script requires significant time, CPU power, or memory, you should run your code via the batch system.
Batch Usage
When you log into pitzer.osc.edu you are actually logged into a Linux box referred to as the login node. To gain access to the multiple processors in the computing environment, you must submit your job to the batch system for execution. Batch jobs can request multiple nodes/cores and compute time up to the limits of the OSC systems. Refer to Queues and Reservations and Batch Limit Rules for more info.
Interactive Batch Session
For an interactive batch session using the command line version of MATLAB, one can run the following command:sinteractive -A <project-account> -N 1 -n 40 -t 00:20:00
which requests one whole node with 40 cores ( -N 1 -n 40
), for a walltime of 20 minutes ( -t 00:20:00
). Here you can run MATLAB interactively by loading the MATLAB module and running MATLAB with the options of your choice as described above. You may adjust the numbers per your need.
Parallel Processing in MATLAB
MATLAB supports implicit multithreading on a single node, as well as MPI accross multiple nodes via MatLab Parallel Server's built-in implementation of MPI.
Multithreading
Multithreading allows some functions in MATLAB to distribute the work load between cores of the node that your job is running on. By default, all of the current versions of MATLAB available on the OSC clusters have multithreading enabled.
The system will run as many threads as there are cores on the nodes requested.
Multithreading increases the speed of some linear algebra routines, but if you would like to disable multithreading you may include the option " -singleCompThread
" when running MATLAB. An example is given below:
#!/bin/bash #SBATCH --job-name disable_multithreading #SBATCH --time=00:10:00 #SBATCH --nodes=1 --ntasks-per-node=40 #SBATCH --account=<project-account> module load matlab matlab -singleCompThread -nodisplay -nodesktop < hello.m # end of example file
Single node parallelization with 'parpool'
To parallelize MatLab processes across a single node, we will write a MatLab script that uses "parcluster" and "parpool" to setup a pool of workers. Here is an example "Hello World" code for illustration:
% specify timezone to prevent warnings about timezone ambiguity setenv('TZ', 'America/New_York') % open the local cluster profile for a single node job p = parcluster('local'); % open the parallel pool, recording the time it takes tic; parpool(p, 40); % open the pool using 40 workers fprintf('Opening the parallel pool took %g seconds.\n', toc) % "single program multiple data" spmd fprintf('Worker %d says Hello World!\n', labindex) end delete(gcp); % close the parallel pool exit
Since we will only be using a single node, we will use the "local" cluster profile and set the parpool size to be equal to the number of cores on the compute node we'll be running on.
Let's save this MatLab script as "helloworld.m" and then write a Slurm batch script to execute it:
#!/usr/bin/env bash #SBATCH -N 1 #SBATCH --ntasks-per-node=40 #SBATCH --job-name=matlab_helloworld #SBATCH --output=MatLabHello40.log # load a MatLab module module load matlab/r2020a # create a variable for the basename of the script to be run BASE_MFILE_NAME=helloworld # execute code without a GUI cd $SLURM_SUBMIT_DIR matlab -nodisplay -r $BASE_MFILE_NAME
In the above batch script, we load a MatLab module, create a variable to specify the basename of Hello World script, and then execute the script with the "-nodisplay" flag to prevent the GUI from trying to load. The script uses 40 workers since Pitzer nodes have 40 or 48 cores.
Next, let's save this file as "helloworld.slurm" and submit the job script to the Slurm scheduler with "sbatch helloworld.slurm."
The output will be found in the log file "MatLabHello40.log":
< M A T L A B (R) > Copyright 1984-2022 The MathWorks, Inc. R2020a Update 5 (9.10.0.1739362) 64-bit (glnxa64) April 18, 2022 To get started, type doc. For product information, visit www.mathworks.com. Starting parallel pool (parpool) using the 'local' profile ... Connected to the parallel pool (number of workers: 40). Opening the parallel pool took 24.7213 seconds. Lab 1: Worker 1 says Hello World! .... Lab 40: Worker 40 says Hello World! Parallel pool using the 'local' profile is shutting down.
We can see from the above that there is a "Hello World" statement from each of the 40 workers.
Multi-Node Processing
It's also possible to use multiple nodes to run MatLab code via MatLab Parallel Server's built-in implementation of MPI, but this process requires a bit of intial setup:
1. First we need to load the matlab module and run the matlab executable in GUI mode:
module load matlab/r2020a matlab
2. Next, within the matlab GUI, navigate to HOME->Environment->Parallel->Create and Manage Clusters:
3. Next, we create a new cluster profile by navigating to "Add Cluster Profile" and choosing the Slurm scheduler:
4. Finally, we edit the cluster profile to suite the needs of the job we will be running. Most of the settings can be left as default, though the following should be set:
Resource arguments for job submission - these are the SBATCH flags used to control the job's behavior and resources utilized. At a minimum, the "--account" flag should be set to a valid account name.
Finally, after editing the Slurm cluster profile to specify the resources neeed for your job, we can launch the job with by executing a MatLab script at the command line (note that this can also be done within the MatLab GUI):
% specify timezone to prevent warnings about timezone ambiguity setenv('TZ', 'America/New_York') % open the desired Slurm cluster profile p = parcluster('SlurmProfile1'); % open the parallel pool, recording the time it takes tic; parpool(p, 80); % open the pool using 80 workers which will be spread across 2 nodes fprintf('Opening the parallel pool took %g seconds.\n', toc) % "single program multiple data" spmd fprintf('Worker %d says Hello World!\n', labindex) end delete(gcp); % close the parallel pool exit
This time, we've specified the 'SlurmProfile1' profile to the parcluster command. In addition, since the cluster profile is set to use 2 nodes on Pitzer, when we open the parallel pool we set the worker count to 80 workers.
Let's save this file as 'helloworld_slurm.m' and execute it:
matlab -nodisplay -r helloworld_slurm > helloworld_slurm.log
This will use MatLab's Slurm cluster profile to submit the code to the scheduler. The job may sit in the queue if the cluster is busy, but once it has run, we see a Hello World statement printed from 80 different workers printed in the log file:
... Lab 45: Worker 45 says Hello World! Lab 46: Worker 46 says Hello World! Lab 47: Worker 47 says Hello World! ...
Multi-node Slurm MatLab jobs can also be submitted using a specific Slurm MatLab plugin, which may offer more scriptable flexibility. To learn more about that option, please see here.
Concurrent jobs on OSC clusters
When you run multiple jobs concurrently, each job will try to access your preference files at the same time. It may create a race condition issue and may cause a negative impact on the system and the failure of your jobs. In order to avoid this issue, please add the following in your job script:
export MATLAB_PREFDIR=$TMPDIR
It will reset the preference directory to the local temporary directory, $TMPDIR
. If you wish to start your Matlab job with the preference files you already have, add the following before you change MATLAB_PREFDIR
.
cp -a ~/.matlab/{matlab version}/* $TMPDIR/
If you use matlab/r2020a
, your matlab version is "R2020a".
MATLAB with a GPU
A GPU can be utilized for MATLAB. You can acquire a GPU by
#SBATCH --gpus-per-node=1
for Owens, or Pitzer. For more detail, please read here.
You can check the GPU assigned to you using:
gpuDeviceCount # show how many GPUs you have gpuDevice # show the details of the GPU
You can replace an array to gpuArray, for example:
A = gpuArray(A)
where A is a regular MATLAB array. This transfers the array data to the GPU memory. Then, you can use the gpuArray variable in GPU supported built-in functions. You can find the full list of GPU supported built-in functions from here. For more information about GPU programming for MATLAB, please read "GPU Computing" from Mathworks.
Toolboxes and Features
OSC's current licenses support the following MATLAB toolboxes and features (please contact OSC Help for license-specific questions):
MATLAB Simulink 5G Toolbox AUTOSAR Blockset Aerospace Blockset Aerospace Toolbox Antenna Toolbox Audio Toolbox Automated Driving Toolbox Bioinformatics Toolbox Communications Toolbox Computer Vision Toolbox Control System Toolbox Curve Fitting Toolbox DDS Blockset DSP System Toolbox Data Acquisition Toolbox Database Toolbox Datafeed Toolbox Deep Learning HDL Toolbox Deep Learning Toolbox Econometrics Toolbox Embedded Coder Filter Design HDL Coder Financial Instruments Toolbox Financial Toolbox Fixed-Point Designer Fuzzy Logic Toolbox GPU Coder Global Optimization Toolbox HDL Coder HDL Verifier Image Acquisition Toolbox Image Processing Toolbox Instrument Control Toolbox LTE Toolbox Lidar Toolbox MATLAB Coder MATLAB Compiler SDK MATLAB Compiler MATLAB Report Generator Mapping Toolbox Mixed-Signal Blockset Model Predictive Control Toolbox Model-Based Calibration Toolbox Motor Control Blockset Navigation Toolbox OPC Toolbox Optimization Toolbox Parallel Computing Toolbox Partial Differential Equation Toolbox Phased Array System Toolbox Powertrain Blockset Predictive Maintenance Toolbox RF Blockset RF PCB Toolbox RF Toolbox ROS Toolbox Radar Toolbox Reinforcement Learning Toolbox Risk Management Toolbox Robotics System Toolbox Robust Control Toolbox Satellite Communications Toolbox Sensor Fusion and Tracking Toolbox SerDes Toolbox Signal Integrity Toolbox Signal Processing Toolbox SimBiology SimEvents Simscape Driveline Simscape Electrical Simscape Fluids Simscape Multibody Simscape Simulink 3D Animation Simulink Check Simulink Code Inspector Simulink Coder Simulink Compiler Simulink Control Design Simulink Coverage Simulink Design Optimization Simulink Design Verifier Simulink Desktop Real-Time Simulink PLC Coder Simulink Real-Time Simulink Report Generator Simulink Requirements Simulink Test SoC Blockset Spreadsheet Link Stateflow Statistics and Machine Learning Toolbox Symbolic Math Toolbox System Composer System Identification Toolbox Text Analytics Toolbox UAV Toolbox Vehicle Dynamics Blockset Vehicle Network Toolbox Vision HDL Toolbox WLAN Toolbox Wavelet Toolbox Wireless HDL Toolbox
See this page if you need to install additional toolbox by yourself.
Further Reading
Official PDF documentation can be obtained from the MathWorks Website.
References
1. Using MatLab's Parallel Server for multi-core and multi-node jobs