Matlab
Matlab is a numerical computing and programming environment with a broad range of functionality (matrix manipulation, numerical linear algebra, general-purpose graphics, etc.). Additionally, special application areas are served by a large number of optional toolboxes.
CMU’s Campus-Wide License covers Matlab, so both a local desktop installation and use on the MIND Cluster are available to you.
To see the Matlab version currently installed on the cluster:
module avail matlab
As of this update, the cluster provides matlab_23.2. Load it with:
module load matlab_23.2
Running Matlab on the headnode
Users need to avoid using the head node for processing using Matlab or other software. All Matlab work — interactive or batch — should run on a compute node via SLURM, not directly on the login/head node.
Interactive Matlab: Two Options
There are two supported ways to work with Matlab interactively on the cluster: VS Code Remote-SSH (recommended) and X11 forwarding (traditional, still supported).
Option 1: VS Code Remote-SSH (recommended)
For the full setup (installing VS Code, configuring the required SSH ProxyJump, requesting a compute node, and connecting), see SSH and VSCode Setup.
Once you’re connected to a compute node in VS Code, open a terminal and load Matlab as usual:
module load matlab_23.2
matlab
This gives you a full graphical Matlab session running on the cluster’s compute hardware, displayed locally through VS Code.
Option 2: X11 Forwarding
X Window System (X11) forwarding is still supported for users who prefer a traditional remote-display graphical session, without installing VS Code.
You’ll need an X11 server on your local computer; how you get this depends on your local operating system. See Logging onto the Cluster for setup details.
Request an interactive session with X11 enabled:
srun --x11 -p cpu --cpus-per-task=1 --mem=10GB --time=4:00:00 --pty $SHELL
Adjust the partition, CPU count, memory, and time to match what your session needs.
Example session:
$ ssh -Y <your-andrew-id>@mind.cs.cmu.edu
[<you>@mind ~]$ srun --x11 -p cpu --cpus-per-task=1 --mem=10GB --time=4:00:00 --pty $SHELL
[<you>@mind-0-15 ~]$ module load matlab_23.2
[<you>@mind-0-15 ~]$ matlab
If you see:
srun: error: No DISPLAY variable set, cannot setup x11 forwarding.
make sure you’re connecting with -Y (enables trusted X11 forwarding), and that your local X11 server is running.
Non-Interactive (Batch) Matlab Jobs
For most production work, running Matlab non-interactively via a SLURM batch script is the preferred approach — it makes full use of cluster resources without tying up an interactive session.
Matlab can be run non-interactively using input/output redirection: matlab < myScript.m > myOutput.txt. Your main script should end with the exit command so Matlab quits automatically once finished.
Example: a script mystats.m containing a main function and two local helper functions:
function [avg, med] = mystats(x)
n = length(x);
avg = mymean(x,n);
med = mymedian(x,n);
end
function a = mymean(v,n)
% MYMEAN Example of a local function.
a = sum(v)/n;
end
function m = mymedian(v,n)
% MYMEDIAN Another example of a local function.
w = sort(v);
if rem(n,2) == 1
m = w((n + 1)/2);
else
m = (w(n/2) + w(n/2 + 1))/2;
end
end
SLURM batch script (run.sh), submitted with sbatch run.sh:
#!/bin/bash -l
#SBATCH --job-name=batch_matlab_example
#SBATCH --ntasks=1
#SBATCH -p cpu
#SBATCH --mem=10gb
#SBATCH --time=00-00:05:00
#SBATCH --output=/user_data/<your-andrew-id>/exampleOut.out
hostname
echo "job starting"
module load matlab_23.2
cd /path/to/your/script
echo "RUNNING MATLAB"
matlab -nodisplay -nosplash < mystats.m > run.log
module unload matlab_23.2
echo "job finished"
The -nodisplay flag runs Matlab without the GUI; -nosplash suppresses the startup logo. The < operator feeds in your script; > redirects output to a log file.
Note: don’t disable Java when launching Matlab (i.e. don’t use matlab -nojvm) — matlabpool/parallel functionality depends on the Java Virtual Machine.
Running Matlab on Parallel Hardware
Matlab can take advantage of parallel/multi-core hardware in a few different ways, covered below. See MathWorks’ Parallel Computing Toolbox documentation for full details.
Exploiting trivial parallelism
An easy way to exploit multi-core systems is to split your workflow into independent parts — the classic example being a parameter sweep, where the same script runs many times with different inputs. Since these runs don’t depend on each other, they can be scheduled as a batch of independent jobs. This approach pairs well with Matlab’s mcc compiler, which helps avoid excessive license checkouts when running many instances at once.
Multi-threaded MEX programming
Mex (Matlab EXecutable) files are compiled subroutines (C, C++, or Fortran) that run from within Matlab like built-in functions. Combining Mex with OpenMP multi-threading is a powerful way to accelerate performance-critical sections of a Matlab program.
Writing Mex files is most worthwhile when profiling identifies a specific, frequently-called bottleneck function. Operations that already rely on highly optimized libraries like FFTW (e.g. fftn) or BLAS/LAPACK (e.g. A\b) generally have little to gain from a Mex rewrite. See the MathWorks Mex programming guide for an introduction.
Connecting a Local Matlab Desktop to the Cluster (Parallel Server)
Matlab’s Parallel Computing Toolbox supports submitting jobs to a remote cluster directly from a local Matlab Desktop installation, without logging into the cluster at all. This is not yet a supported, self-serve workflow on the MIND Cluster. We haven’t validated the SLURM submission plugin or off-campus network behavior for this configuration, so we can’t currently offer setup support or guarantee it will work reliably.
For interactive, GUI-based Matlab work, use VS Code Remote-SSH instead — it gives you a responsive local editing experience backed by the cluster’s compute power, and it’s fully supported today.
If you have a strong need for direct desktop-to-cluster job submission, contact NI Support to discuss — we may be able to pilot this with you, but please expect some trial and error.