Close menu Resources for... William & Mary
W&M menu close William & Mary

Matlab

For instructions on how to install MATLAB on your personal computer through W&M’s educational license, please visit W&M’s software distribution website. MATLAB can also be used on VDI Remote Desktop. 

MATLAB basics on W&M/VIMS HPC clusters:

MATLAB can have a huge memory footprint and is often computationally demanding. For these reasons, it is never appropriate to run it directly on cluster front-end/login nodes, such as bora or james, etc. Instead, it should be run on a compute node via the job scheduler. 

Loading the MATLAB software:

Multiple versions of MATLAB are available are available throughout the HPC clusters.   Matlab can be loaded using e.g.  module load matlab

Note: not specifiying the version of MATLAB (i.e. module load MATLAB/R2023a) will load the newest version on that cluster.   For more information on loading sofware with modules, see: Environment modules

Using MATLAB with Slurm:

Interactive jobs with Slurm:

In order to use the MATLAB GUI remotely from one of SciClone's compute nodes, follow these steps: 

  1. Make sure that you have an X Window server installed and running on your local desktop or laptop computer and enable X11 Forwarding in your ssh command or your SSH client software. If you do not intend to use the MATLAB GUI, skip this step.  For more information see our help on connecting to the cluster with X11 Forwarding for Windows, Mac, or Linux.
  2. On a cluster front-end, use the srun command to obtain an interactive shell on a compute node. Make sure you have already loaded a MATLAB module into your environment: 
    salloc -N 1 -n 8 -t 1:00:00 --x11
    Note:  The '--x11' is necessary if you want to enable use of the matlab GUI
  3. At the shell prompt, cd to the appropriate directory and start MATLAB as you normally would:
    matlab &
  4. When you are finished, be sure to logout from your compute node shell so that the computing resources will be available for other users. If your session exceeds the walltime specified on your salloc command, it will be killed. 

Batch jobs with Slurm:

Use a text editor to create a job script in your MATLAB directory. In this example, we'll call it run_matlab. 

#!/bin/tcsh
#SBATCH --job-name=myjob
#SBATCH --time=01:00:00 
#SBATCH --nodes=1 --ntasks-per-node=1  

module load matlab  
matlab -nodisplay < myprog.m > myprog.out 
 --nodes=1 and --ntasks-per-node=1 requests one node with one core. 
  1. Save the above batch script to a file, lets call it run_matlab.
  2. Submit this script to the Slurm scheduler:
    sbatch run_matlab
  3. Monitor the status of your job in the batch system with 
    squeue -u <username>
  4. Also check the progress of your job by checking myprog.out
  5. When the job completes, there will be one output file named:
    slurm-XXXX.out
    Where XXXX is the job id assigned to it by the batch system.