MATLAB

MATLAB is available on Pegasus for interactive and batch workloads.

Important

MATLAB is not currently available on Triton.

Find and Load MATLAB

Check the available MATLAB versions:

module avail matlab

Load an available version:

module load matlab/<version>

Confirm that MATLAB is available:

which matlab
matlab -help

Interactive MATLAB

Start an interactive LSF shell before running MATLAB:

bsub -P <project> -q general -Is -W 01:00 -n 1
-R "rusage[mem=4000]" bash

After the job starts, load MATLAB:

module load matlab/<version>

For a command-line session without the desktop interface:

matlab -nodesktop

For a session without graphical display support:

matlab -nodisplay

To exit MATLAB:

exit

Warning

Do not run compute-intensive MATLAB workloads directly on a login node. Start an interactive LSF job or submit a batch job.

Graphical MATLAB

The MATLAB desktop requires graphical forwarding between the local computer, the login host, and the assigned compute node.

A graphical session may be started using an X11-enabled LSF job:

bsub -P <project> -q general -Is -XF -W 01:00 -n 1 \
   -R "rusage[mem=4000]" bash

After the job starts:

module load matlab/<version>
matlab

Note

Graphical MATLAB also requires a working local X server and an SSH connection with X11 forwarding enabled. Use command-line or batch MATLAB when the desktop interface is not required.

Batch MATLAB Jobs

Use an LSF batch job for longer or repeatable MATLAB workloads.

Create a job script such as matlab_job.lsf:

#!/bin/bash
#BSUB -P <project>
#BSUB -J matlab_job
#BSUB -q general
#BSUB -n 1
#BSUB -R "rusage[mem=4000]"
#BSUB -W 01:00
#BSUB -o matlab_job.%J.out
#BSUB -e matlab_job.%J.err

module load matlab/<version>

matlab -batch "my_script"

Submit the job:

bsub < matlab_job.lsf

Check its status:

bjobs

After the job finishes, review the output and error files:

less matlab_job.<job-id>.out
less matlab_job.<job-id>.err

The -batch option runs the specified MATLAB command and exits automatically. For example, the following command runs my_script.m from the current working directory:

matlab -batch "my_script"

Running a MATLAB Function

Arguments can be passed to a MATLAB function from the batch command:

matlab -batch "my_function('input.dat', 10)"

Make sure the function file is in the current directory or available on the MATLAB path.