MATLAB on Graham: Difference between revisions

From Fluids Wiki
Jump to navigation Jump to search
(Created page with "There are two ways to run MATLAB on Graham. The first is interactively through the a compute node using the salloc command, while the second is as a submitted job. Depending o...")
 
Line 31: Line 31:
# bash script for submitting a Matlab job to the sharcnet Graham queue
# bash script for submitting a Matlab job to the sharcnet Graham queue


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


#SBATCH --ntasks=1              # number of processors
#SBATCH --output=mat-%j.log                # log file
#SBATCH --output=mat-%j.log                # log file
#SBATCH --error=mat-%j.err                  # error file
#SBATCH --error=mat-%j.err                  # error file

Revision as of 10:38, 12 January 2018

There are two ways to run MATLAB on Graham. The first is interactively through the a compute node using the salloc command, 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.

Set-up

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:

addpath('/work/<USER>/spins/matlab')

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.

Interactively

Running Matlab interactively is easy:

$ ssh -X graham.sharcnet.ca
$ salloc --x11 --time=1:0:0 --ntasks=1 --account=def-<superID> --mem-per-cpu=12G
$ module load matlab/2017a
$ matlab

where <superID> is the ID of your supervisor. The ctb-mmstastn account could also be used, but since the requirements (both memory and processors) is small, your default account will spend an equal amount of time in queue, and no benefit will be gained by using the contributed account.

If the X-forwarding is taking too long, the job can be submitted as a job, or the X-forwarding can be turned off. Without X-forwarding the figures will need to be saved, and then copied to your local machine.

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

#!/bin/bash
# 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>@uwaterloo.ca     # who to email
#SBATCH --mail-type=FAIL                    # when to email
#SBATCH --account=ctb-mmstastn              # UW Fluids designated resource allocation
module load matlab/2017a 
srun matlab -nodisplay -nosplash -nojvm -singleCompThread