MATLAB sbatch
Overview
The most common way to use MATLAB on a desktop computer is through its graphical user interface (GUI). MATLAB can also be run in this manner on the supercomputer. To use the MATLAB GUI, visit the dedicated interactive web portal and fill out the form to get started. (See Connecting with the Web Portal to get started running GUI applications).
However, the most powerful way to use MATLAB on the supercomputer is through a sbatch script. This allows MATLAB jobs to be submitted to the scheduler and run "in the background."
Steps
Check for the MATLAB module you would like to use:
module avail matlab
Load the MATLAB module (example):
module load matlab/2023a
Running as a script
A few key options have to be passed to the MATLAB executable, along with the MATLAB program script you wish to run. An example of this is shown below:
matlab -batch "script"
Here is an explanation of what these options mean:
-batch "script"
Start MATLAB in ‘batch’ mode and run the statement, in this case execute
script.m
This option implicitly turns on many options, such as
-nodesktop
and-nosplash
. See the Mathworks documentation for more information (screenshot below)
Â
Sample Sbatch
Below is an example sbatch
script, myjob.sh
, which runs a MATLAB script script_with_plotting.m
using four cores in the htc partition. Note that script_with_plotting.m
is in the same directory as this calling sbatch
script.
The contents of script_with_plotting.m
follow
Which generates the following spiral plot:
Â
This job may be submitted to the scheduler with the shell command, sbatch myjob.sh
.
More MATLAB Command Line Options
Many more options and parameters can be passed to MATLAB to control how it operates. Mathworks provides some documentation here.
More information on MATLAB's command line options and parameters can be found here
Additional Help
Â