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 server 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.

Note:  The MATLAB graphical interface is strongly dependent on your network speed.  A slow network connection to the cluster can cause the GUI to be very slow to respond.  Using the GUI from the cluster from an on-campus connection will be much better than one to off-campus.

Using MATLAB with Torque:

Interactive jobs with Torque:

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 SciClone, use the qsub command to obtain an interactive shell on a compute node: 
    qsub -I –Y -l walltime=1:00:00,nodes=1:vortex:ppn=1 –q matlab 

    Note:  The '-Y' 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:      
    cd my_matlab_dir 
    matlab & 

  4. When you are finished, be sure to logout from your qsub shell so that the computing resources will be available for other users. If your session exceeds the walltime specified on your qsub command, it will be killed after a two-minute grace period. 

Batch jobs with Torque:

For batch mode operation, you will need to create a simple job script and submit it to the queuing system. 

Use a text editor to create a job script in your MATLAB directory. In this example, we'll call it run_matlab.sh.   Please see our pages on using Torque for more information.

#!/bin/tcsh  
#PBS -N myprog 

#PBS -l nodes=1:vortex:ppn=1 
#PBS -l walltime=1:00:00 
#PBS -j oe 
#PBS -q matlab 

cd $PBS_O_WORKDIR
matlab -nodisplay <myprog.m >myprog.out 

The one key thing to point out is that on PBS/Torque cluster, you must specify the matlab queue (#PBS -q matlab).

The "-nodisplay" option is useful in batch mode because there is no display device associated with the job. 

In this example, a job named "myprog" will be submitted to a single processor on any available compute node with a time limit of one hour. The "-j oe" option consolidates output from the job script into a single file (for less clutter); output from MATLAB will go to "myprog.out" rather than both an output and error file. 

To run this job on a Torque cluster node, do the following:

  1. Save the above batch script to a file, lets call it run_matlab.
  2. Submit this script to the Torque job scheduler:
    qsun run_matlab
  3. Monitor the status of your job in the batch system with 
    qstat -u <username>
  4. Also check the progress of your job by checking myprog.out
  5. When the job completes, two batch output files will be created:
    myprog.oNNNNNN
    myprog.eNNNNNN
    where NNNNNN is the job ID assigned by the batch system.
    (if you use '-j oe' as mentioned above only myprog.oNNNNNN will be created).
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: 
    srun –-x11 –-pty –N 1 –n 4 matlab 
    Note:  The '-Y' 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:
    cd my_matlab_dir 
    matlab &
  4. When you are finished, be sure to logout from your qsub shell so that the computing resources will be available for other users. If your session exceeds the walltime specified on your qsub command, it will be killed after a two-minute grace period. 

Batch jobs with Slurm:

SLURM batch mode: 

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  
cd my_matlab_dir  
matlab -nodisplay < myprog.m > myprog.out 

The --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:
    srun 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. 

 

 

Links to old documentation:

Matlab Basics - http://newhpc.wm.edu/doc/matlab/matlabbasiscs.html

Matlab Scripting - http://newhpc.wm.edu/doc/matlab/matlabscripting.html