MATLAB on Graham: Difference between revisions

From Fluids Wiki
Jump to navigation Jump to search
m (Update interactive matlab)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
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.
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.


== Set-up ==
== Set-up ==
Line 9: Line 9:
addpath('/work/<USER>/spins/matlab')
addpath('/work/<USER>/spins/matlab')
</syntaxhighlight>
</syntaxhighlight>
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 plotter| SPINS Matlab]] functions). This functionality will also apply to non-interactive jobs submitted to the regular queue.
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 tools| SPINS Matlab]] functions). This functionality will also apply to non-interactive jobs submitted to the regular queue.


== Interactively ==
== Interactive Job ==


Running Matlab interactively is easy:
Running Matlab interactively requires the use of a VNC. See [[Graham Tips#VNC|VNC]] on how to set-up and run a VNC.
 
Once you have the virtual desktop running, start matlab with these steps:
<syntaxhighlight>
<syntaxhighlight>
$ ssh -X graham.sharcnet.ca
$ module load nixpkgs
$ salloc --x11 --time=1:0:0 --ntasks=1 --account=def-<superID> --mem-per-cpu=12G
$ module load matlab/2018b
$ module load matlab/2017a
$ matlab
$ matlab
</syntaxhighlight>
</syntaxhighlight>
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.
There are multiple version of Matlab to chose from. <code>module spider matlab</code> will give you information on what is available.


== Submitted Job ==
== Submitted Job ==
Line 43: Line 43:
#SBATCH --mail-type=FAIL                    # when to email
#SBATCH --mail-type=FAIL                    # when to email
#SBATCH --account=ctb-mmstastn              # UW Fluids designated resource allocation
#SBATCH --account=ctb-mmstastn              # UW Fluids designated resource allocation
module load matlab/2017a
module load matlab/2018a
srun matlab -nodisplay -nosplash -singleCompThread
srun matlab -nodisplay -nosplash -singleCompThread
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 18:40, 7 March 2019

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.

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.

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

#!/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/2018a 
srun matlab -nodisplay -nosplash -singleCompThread