MATLAB on Graham

From Fluids Wiki
Jump to: navigation, search

There are two ways to run MATLAB on Graham. The first is interactively through VNC, while the second is as a submitted job. Depending on the speed of your internet connection, it could be impractical to use the first. The second is also useful for running time-consuming scripts like diagnostics, or movie making functions. Submitted jobs must be configured to run entirely on their own as there is no possibility of manually giving inputs.


Many details are in Running Matlab on Graham, but the main points are presented here.

It is a good idea to run a start-up file which adds paths to your work space and sets defaults. Add these commands to startup.m, which must exist on the Matlab path (~/matlab should work). If using SPINS, a good command to have in the start-up file is:


or whatever the directory the SPINS matlab files are in. This will allow you to use the built in SPINS commands from any directory. Add other commands you want into this file as well (for example: set default figure settings, or auto-loading of SPINS Matlab functions). This functionality will also apply to non-interactive jobs submitted to the regular queue.

Interactive Job

Running Matlab interactively requires the use of a VNC. See VNC on how to set-up and run a VNC.

Once you have the virtual desktop running, start matlab with these steps:

$ module load nixpkgs
$ module load matlab/2018b
$ matlab

There are multiple version of Matlab to chose from. module spider matlab will give you information on what is available.

Submitted Job

Use the following script to submit a job (it is like the submit script for a regular job, but built for matlab). You will need to replace <USER> with your user ID, or replace that line with the location of the matlab run file. This script can be told to wait for another submitted job to complete before running (remove one # from the dependency line, and include the job ID number

# bash script for submitting a Matlab job to the sharcnet Graham queue

#SBATCH --mem-per-cpu=6G        # memory per processor (default in Mb)
#SBATCH --time=01-00:00         # time (DD-HH:MM)
#SBATCH --job-name="A name"     # job name
#SBATCH --input=matlab_test.m   # Matlab script
##SBATCH —dependency=afterok:<jobid>  # Wait for job to complete

#SBATCH --ntasks=1              # number of processors
#SBATCH --output=mat-%j.log                 # log file
#SBATCH --error=mat-%j.err                  # error file
#SBATCH --mail-user=<USER>     # who to email
#SBATCH --mail-type=FAIL                    # when to email
#SBATCH --account=ctb-mmstastn              # UW Fluids designated resource allocation
module load matlab/2018a 
srun matlab -nodisplay -nosplash -singleCompThread