Matlab

General Information

To use MATLAB on the cluster, load the appropriate module for the version you want to use. The following example shows how to load the default MATLAB module (the $ is the prompt; do not type it).

$ module load matlab

To see which MATLAB versions are available, use the following command:

$ module avail matlab

You can then load a specific version if needed. Please see our page on Lmod for more information on loading modules.

To start MATLAB interactively from the command line:

$ matlab

This will start either the text interface or the MATLAB desktop if an appropriate display is available.

Running MATLAB from the Command Line

The cluster is designed to run jobs in the background. MATLAB scripts should therefore be written so they can run non-interactively.

Suppose you have a MATLAB script called my_simulation.m. You can run it from the command line using MATLAB's -r option:

$ matlab -r ./my_simulation

You may run MATLAB on a login node as long as it does not consume significant CPU or memory resources. This generally means using small datasets and running short test cases.

As a guideline:

  • Use no more than 4 GB of memory
  • Run for no more than 5–10 minutes
  • Use login nodes only for testing and debugging

Larger jobs should always be submitted through the scheduler.

Before submitting a job, test your script using the same command you plan to run inside the job script:

matlab -nodisplay -r ./my_simulation

Your MATLAB script should contain an exit command. If it does not, MATLAB will remain idle until the job's walltime expires.

If your script does not include exit, you can add it on the command line:

matlab -nodisplay -r "./my_simulation; exit"

Note that the quotes are required.

If your script accepts arguments (for example, number of iterations and mesh size), you can pass them on the command line:

matlab -nodisplay -r "./my_simulation(2,10)"

Again, quotes are required so the shell does not interpret the parentheses.

Parallel Computing with MATLAB

MATLAB supports parallel computing through worker pools created using the Parallel Computing Toolbox. To use parallel workers on the cluster, a cluster profile must be defined.

By default, MATLAB provides a local profile, which runs workers on the same machine where MATLAB is executing.

Using the Local Profile

The local profile always exists. You can start a worker pool with:

thePool = parpool('local', NP);

where NP is the number of workers to start.

At the end of your MATLAB script, you should close the pool:

delete(thePool)

This ensures the pool shuts down cleanly and avoids issues with future jobs.

Using the Current SLURM Profile

When running inside a SLURM job, you can use the resources allocated to your job by initializing the ARC MATLAB cluster profile.

%%%% Initialize the UMich cluster profiles
setupUmichClusters

%%%% Determine number of processors allocated to the job
NP = str2num(getenv('SLURM_NTASKS'));

%%%% Create the worker pool
thePool = parpool('current', NP);

As with the local profile, remember to close the pool at the end of your script:

delete(thePool)

MPI Configuration for MATLAB R2025b and Newer

Beginning with MATLAB R2025b, the default MPI implementation used by the cluster profile no longer uses Intel MPI.

If your workflow requires Intel MPI, it can be enabled manually by configuring the cluster object before starting the worker pool.

setupUmichClusters

c = parcluster('current')
c.AdditionalProperties.MPIImplementation = "IntelMPI"

p = c.parpool()

This overrides the default MPI implementation and enables Intel MPI for the worker pool.