Updated 2021-05-18

MATLAB

Overview

  • This guide will cover how to load and run matlab/r2019a

Summary

  • To load MATLAB:
    • module load matlab/r2019a
  • To run MATLAB:
    • matlab -nodisplay -batch <input file>

Part 1: The PBS Script

#!/bin/bash
#PBS -N testMATLAB
#PBS -A [Account] 
#PBS -l nodes=1:ppn=2
#PBS -l pmem=2gb
#PBS -l walltime=2:00
#PBS -q inferno
#PBS -j oe
#PBS -o testMATLAB.out

cd $PBS_O_WORKDIR
module load matlab/r2019a
matlab -nodisplay -batch testfile

In this case, our MATLAB file matlab_test.m will be very simple, but the process is similar for most MATLAB scripts.

fprintf("Hello World!")
  • The #PBS directives are standard, requesting just 2 minutes of walltime and 1 node with 2 cores. More on #PBS directives can be found in the PBS guide
  • $PBS_O_WORKDIR is simply a variable that represents the directory you submit the PBS script from.

Warning

Make sure the .m file you want to run is in the same directory you put the PBS script. Additionally, make sure not to include the extension for the file in the PBS script.

  • Output Files will also show up in the same directory as the PBS script.
  • module load matlab/r2019a loads the specified MATLAB version
  • matlab -nodisplay -batch matlab_test runs MATLAB without the display and executes a non-interactive batch script named testfile.m

Part 2: Submit Job and Check Status

  • Make sure you're in the directory that contains the PBS script and the .m file
  • Submit as normal, with qsub <pbs script name>. In this case qsub testMATLAB.pbs
  • Check job status with qstat -u username -n, replacing "username" with your gtusername
  • You can delete the job with qdel #, replacing the number with the jobid returned after running qsub

Part 3: Collecting Results

  • In the directory where you submitted the PBS script, you should see a newly generated file once your job is completed named testMATLAB.out
  • Take a look at testMATLAB.out using any text editor, such as vim with vim testMATLAB.out or output to the terminal using cat testMATLAB.out
  • It should include the printed "Hello World!" statement.

To Run MATLAB Interactively On Cluster

Screenshot

  • Please see the VNC guide for instructions on how to set up the Interactive VNC session

Start Matlab on VNC

  • Open terminal in vnc window by clicking top left Applications > System Tools > scroll down to Terminal
  • All commands here on will be typed in terminal in VNC
  • To see available versions of matlab run
module avail matlab
  • Load matlab module and start matlab
module load <version of matlab>  #example: module load matlab/r2020b
matlab
  • The MATLAB GUI will load on screen.

Screenshot

Set Up Parallel Environment MATLAB

  • For larger or longer multi-node jobs, use distributed MATLAB for parallel computing. This is the recommended path.
  • You can also use a parallel pool within your single interactive job, based on the number of cores you requested on a single node for your interactive job.
  • It will start automatically when functions such as parfor are run.
  • Read more about managing parallel pools here.
Control the Parallel Pool from the Matlab Desktop
  • Access pool preferences in the Home tab in the Environment section, go to Parallel > Parallel Preferences Screenshot
Programming Interface
  • To open a parallel pool based on your preference settings, use parpool
  • To open a pool of a specific size, use parpool(4)
  • These can be used in the command-line interface or when writing a Matlab script
  • More information about using parpool can be found here