MATLAB

From oldwiki.scinet.utoronto.ca
Jump to navigation Jump to search

WARNING: SciNet is in the process of replacing this wiki with a new documentation site. For current information, please go to https://docs.scinet.utoronto.ca

We often get questions about running MATLAB on GPC. 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.


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.


Creating a MATLAB 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 GPC compute node. The version of MATLAB being used will require a compiler license, and the compilation must be done on a Linux machine. Once the compilation is done, the executable 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:

<source lang="bash">

  1. !/bin/bash
  2. MOAB/Torque submission script for SciNet GPC
  3. PBS -l nodes=1:ppn=8,walltime=1:00:00
  4. PBS -N test_matlab
  5. PBS -q debug
  1. load modules (gcc is needed for MCR/2015a)

module load Xlibraries gcc/5.2.0 MCR/2015a

  1. DIRECTORY TO RUN - $PBS_O_WORKDIR is directory from which the job was submitted

cd $PBS_O_WORKDIR

  1. Directory for the MCR to use to write temporary files. Use whatever directory you wish.

mkdir -p $SCRATCH/temp export MCR_CACHE_ROOT=$SCRATCH/temp

  1. EXECUTION COMMAND (note that the MATLAB script may require that LD_LIBRARY_PATH be added
  2. to the script arguments). Note that, if the calculations are serial, you must bundle 8 such
  3. calculations together for production runs!

./run_myscript.sh $MCR:$LD_LIBRARY_PATH </source>

Tunnelling 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 setup your submission script to access the external license server. The following lines should be added to the beginning of your submission script:

PORT=XXX                                         # port number of the license server
LICENSE_IP=AAA.BBB.CCC.DDD                       # IP address of the license server
ssh gpc01 -L${PORT}:${LICENSE_IP}:${PORT} -N &

This last line will tunnel the port from the compute node back to the license server, through gpc01. 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

Both Sharcnet and Westgrid have purchased different types of MATLAB licenses. Users can contact those consortia if they wish to attempt to run on those systems.