MATLAB: Difference between revisions

From SciNet Users Documentation
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
We often get questions about running MATLAB on Trillium.  With a few exceptions for compilers and debuggers, SciNet does not purchase licenses for commercial software.  As such, SciNet does not have a license for MATLAB, nor will it in the future.  If users wish to run MATLAB they must supply their own license, or explore alternative options.  This page gives information about the options for getting your MATLAB code to run, in recommended order.  
We often get questions about running MATLAB on Trillium.  With a few exceptions for compilers and debuggers, SciNet does not purchase licences for commercial software.  However, the University of Toronto supplies a MATLAB licence that can be used on Trillium, so U of T students, faculty, and researchers can run MATLAB directly.  If you are not covered by that licence, you must supply your own, or use one of the alternatives below.  This page describes the options.


== Running MATLAB on Trillium ==
Because the University of Toronto licence is already available on Trillium, you do not need to tunnel to an external licence server.  To check whether your account is covered, load the module and ask MATLAB to report its licence:
<source lang="bash">
module load matlab
matlab -nojvm -nodisplay -batch license
</source>
If a licence number is printed, you can run MATLAB directly.  If you get an error instead, your account is not covered and you should use one of the alternatives below, or ask your institution whether it has a licence that can be used on Trillium.
The general instructions for running MATLAB, including serial and parallel job scripts and the MATLAB Compiler, are on the [https://docs.alliancecan.ca/wiki/MATLAB Alliance MATLAB page].


== Not using MATLAB ==
== Not using MATLAB ==
Line 12: Line 24:
=== Creating a MATLAB stand-alone executable ===
=== Creating a MATLAB stand-alone executable ===


If MATLAB must be used, you may be able to compile your MATLAB code into a stand-alone executable, and run this on a Niagara compute node.  The version of MATLAB being used will require a compiler license, and the compilation must be done on a Linux machine (not Niagara).   
If MATLAB must be used, you may be able to compile your MATLAB code into a stand-alone executable, and run this on a compute node.  The version of MATLAB being used will require a compiler license, and the compilation must be done on a Linux machine (not Trillium).   


Note: The compilation of a matlab code produces two files, e.g., compiling <tt>myscript.m</tt> will produce a file <tt>myscript</tt> and a file <tt>run_myscripts.sh</tt>. You will need both files.
Note: The compilation of a matlab code produces two files, e.g., compiling <tt>myscript.m</tt> will produce a file <tt>myscript</tt> and a file <tt>run_myscripts.sh</tt>. You will need both files.


=== Using a MATLAB stand-alone executable on Niagara ===
=== Using a MATLAB stand-alone executable on Trillium ===


Once the compilation is done, the executable and its run script (<tt>run_SOMETHING.sh</tt>) can be copied to SciNet, and run using the MATLAB Compiler Runtime (MCR), which can be accessed using the MCR module.  The MCR used must be the same version of MATLAB as the compiler.  If the version of MCR that you need is not listed among the MCR module versions, contact us and we will install the version which you require.
Once the compilation is done, the executable and its run script (<tt>run_SOMETHING.sh</tt>) can be copied to SciNet, and run using the MATLAB Compiler Runtime (MCR), which can be accessed using the MCR module.  The MCR used must be the same version of MATLAB as the compiler.  If the version of MCR that you need is not listed among the MCR module versions, contact us and we will install the version which you require.
Line 51: Line 63:
=== Available MATLAB runtime versions ===
=== Available MATLAB runtime versions ===


Below is a list of the available MATLAB runtime versions on Niagara, with the required module command:
Available version of MATLAB can be found using the command
 
module load NiaEnv/2018a mcr/R2018a
module load NiaEnv/2019b mcr/R2019a
module load CCEnv nixpkgs/16.09 mcr/R2013a
module load CCEnv nixpkgs/16.09 mcr/R2013b
module load CCEnv nixpkgs/16.09 mcr/R2014a
module load CCEnv nixpkgs/16.09 mcr/R2014b
module load CCEnv nixpkgs/16.09 mcr/R2015a
module load CCEnv nixpkgs/16.09 mcr/R2015b
module load CCEnv nixpkgs/16.09 mcr/R2016a
module load CCEnv nixpkgs/16.09 mcr/R2016b
module load CCEnv nixpkgs/16.09 mcr/R2017a
module load CCEnv nixpkgs/16.09 mcr/R2017b
module load CCEnv nixpkgs/16.09 mcr/R2018a
module load CCEnv nixpkgs/16.09 mcr/R2018b
module load CCEnv nixpkgs/16.09 mcr/R2019a
module load CCEnv nixpkgs/16.09 mcr/R2019b
module load CCEnv gentoo/2020 mcr/R2020b
 
== Tunneling to a license server ==
 
If you have access to a non-SciNet MATLAB license server, and have installed MATLAB in your $HOME directory, you can [[SSH_Tunneling|setup your submission script]] to access the external license server.  The following lines should be added to the beginning of your submission script, after the #SBATCH commands:
 
<pre>
PORT=XXX                                        # port number of the license server
LICENSE_IP=AAA.BBB.CCC.DDD                      # IP address of the license server
ssh tri-gw -L${PORT}:${LICENSE_IP}:${PORT} -N &
</pre>
 
This last line will tunnel the port from the compute node back to the license server, through nia-gw.  The port number and IP address of the licence server must be supplied by the system administrator of the license server.


== Using a different Consortium ==
module spider matlab


Both [https://www.sharcnet.ca/my/software/show/54 Sharcnet] and [https://www.westgrid.ca/support/software/matlab Westgrid] have purchased different types of MATLAB licenses.  Users can contact those consortia if they wish to attempt to run on those systems.
The latest version as of November 2026 is <code>matlab/2026a.3</code>.

Revision as of 19:59, 6 November 2026

We often get questions about running MATLAB on Trillium. With a few exceptions for compilers and debuggers, SciNet does not purchase licences for commercial software. However, the University of Toronto supplies a MATLAB licence that can be used on Trillium, so U of T students, faculty, and researchers can run MATLAB directly. If you are not covered by that licence, you must supply your own, or use one of the alternatives below. This page describes the options.

Running MATLAB on Trillium

Because the University of Toronto licence is already available on Trillium, you do not need to tunnel to an external licence server. To check whether your account is covered, load the module and ask MATLAB to report its licence:

module load matlab
matlab -nojvm -nodisplay -batch license

If a licence number is printed, you can run MATLAB directly. If you get an error instead, your account is not covered and you should use one of the alternatives below, or ask your institution whether it has a licence that can be used on Trillium.

The general instructions for running MATLAB, including serial and parallel job scripts and the MATLAB Compiler, are on the Alliance MATLAB page.

Not using MATLAB

Users can attempt to run MATLAB code using the open-source program Octave, accessible through the octave module. Though there are some differences between the two programs, Octave has been designed to interpret MATLAB code and can often be used in place of MATLAB. If your MATLAB code does not use some of the more-fancy MATLAB toolboxes, you may be able to get away with using Octave instead. Be sure to test your implementation in Octave thoroughly before committing to this option.

It is worth observing that, while convenient for prototyping and running on a single workstation, there are reasons to avoid using MATLAB for larger HPC/ARC projects. These include the prohibitive license cost for large-scale work, poor performance at scale, and portability issues. If you can switch to a license-free option, such as Python, it may be worth the effort.

Using stand-alone MATLAB executables

Creating a MATLAB stand-alone executable

If MATLAB must be used, you may be able to compile your MATLAB code into a stand-alone executable, and run this on a compute node. The version of MATLAB being used will require a compiler license, and the compilation must be done on a Linux machine (not Trillium).

Note: The compilation of a matlab code produces two files, e.g., compiling myscript.m will produce a file myscript and a file run_myscripts.sh. You will need both files.

Using a MATLAB stand-alone executable on Trillium

Once the compilation is done, the executable and its run script (run_SOMETHING.sh) can be copied to SciNet, and run using the MATLAB Compiler Runtime (MCR), which can be accessed using the MCR module. The MCR used must be the same version of MATLAB as the compiler. If the version of MCR that you need is not listed among the MCR module versions, contact us and we will install the version which you require.

Here is an example script which uses the MCR. Note that the "run_myscript.sh" script is produced by the MATLAB compiler, together with the "myscript" executable (assuming you were working on the myscript.m MATLAB code):

#!/bin/bash
#SBATCH --nodes=1
#SBATCH --cpus-per-task=40
#SBATCH --time=1:00:00
#SBATCH --job-name test_matlab
#SBATCH --output=matlab_output_%j.txt

# DIRECTORY TO RUN - $SLURM_SUBMIT_DIR is the directory from which the job was submitted
cd $SLURM_SUBMIT_DIR

# load module
module load mcr/R2018a

# Directory for the MCR to use to write temporary files.  Use whatever directory you wish.
# We specify a unique directory in case multiple jobs are running simultaneously.
mkdir -p $SCRATCH/temp/$SLURM_JOB_ID
export MCR_CACHE_ROOT=$SCRATCH/temp/$SLURM_JOB_ID

# EXECUTION COMMAND (note that the MATLAB script may require that LD_LIBRARY_PATH be added
# to the script arguments).  Note that, if the calculations are serial, you must bundle 40 such
# calculations together for production runs!
./run_myscript.sh $MATLAB

rm -rf $SCRATCH/temp/$SLURM_JOB_ID

Available MATLAB runtime versions

Available version of MATLAB can be found using the command

module spider matlab

The latest version as of November 2026 is matlab/2026a.3.