Matlab is installed on the HPC clusters for Leeds researchers who have access to either their own or a departmental license.

Please note that the University does not have a site licence so Matlab can only be used by staff in certain faculties. Contact your local IT support for further information.

Setting up the license

Please note that the $ symbol represents the command prompt. You do not type this in.

As Matlab is a licensed product, you will first need to contact your Faculty IT support to obtain their licence server details.

The license is validated by Matlab through setting the MLM_LICENSE_FILE or LM_LICENSE_FILE environment variable. To set it in the Bash shell, enter:


To obtain the values of LM_LICENSE_FILE specific to your group/department please contact your local IT support. We are not able to supply this information.

Setting up the environment

All required environment variables can be set by loading the Matlab module, to do this type the command:

Running on the login nodes

Matlab can be launched by entering its name at the command prompt; i.e.:

Please note that this method should not be used for long computational use.

Running through the batch scheduler

The batch scheduler allows both interactive and batch jobs to be submitted during which users will have exclusive access to the resources they request.

Running through an interactive shell

The following will launch Matlab interactively, displaying the full GUI:

In the above command:
hh:mm:ss is the length of real-time the shell will exist for,
-cwd indicates the job will run from the current working directory
-V exports the the current environment.

The paramemter  -singleCompThread ensures that Matlab will run only on a single thread, since the default multiple threaded behaviour can cause problems.

e.g. to run Matlab for 6 hours:

This will run Matlab within the terminal from which it was launched.

Running the command line version of Matlab

The following will launch an interactive session where the interaction is via a command prompt interface only:

Where, hh:mm:ss is the length of real-time the shell will exist for.

Batch Execution

To run matlab in batch-mode you must first generate a list of commands for matlab to process in a file; e.g. file cosplot.m:

The % symbol denotes a comment in Matlab scripts

Please note that the last line must be ” quit; “!

A script must then be created that will request resources from the queuing system and launch the matlab executable; script

This can be submitted to the batch scheduler system using:

The output file can be viewed with Ghostscript using the command gs

Parallel Matlab jobs

On version 2012a of Matlab, parallel pools of threads are initiated using the matlabpool command. In version 2013a onwards, this was replaced with the parpool command. You may need to adjust code to work properly on ARC2.

Parallel Matlab jobs will work on up to 12 cores (1 thread per cores). This should be requested in the job  submission script, so to request 8 cores:

The scheduler sets an environment variable $NSLOTS to be equal to the number of cores (so 8 in this case) which the Matlab script will need to read in order to set up a worker pool of the correct size. Lines similar to these should be included in the Matlab script:

Compiling Matlab

To run a large number of matlab jobs simultaneously it may be necessary to use the matlab compiler to create a stand-alone application. This will also avoid using too many licenses. For a full description of the compiler please look at the in-program help or the Matlab compiler user’s guide.

Code preperation

Script m-files cannot be compiled directly, first they have to be converted to function m-files. In general, this is a case of wrapping the main section of code within a function. For more details look at converting script m-files section in the user guide.


The Matlab compiler makes use of the GNU C compilers and as the Intel compiler is loaded by default you can switch to the correct version of GNU compiler via the command:

The compiler can be invoked from within Matlab or directly from the command line via the tool mcc . However, to get the code to compile in single threaded mode the compiler should be invoked directly from the command line. In general this would take the form:

It is very important that you include the -R singleCompThread, otherwise matlab will run in multi-threaded mode and cause problems when running through the batch queues.

This compilation will yield two files of interest

  • your_program , which is the compiled code
  • , which is the wrapper to run your compiled code.

Running the application

Once the matlab module is loaded, you can run your stand-alone application via the wrapper and specifing the correct path to various Matlab components. This can easily be done via the environment variable $MATLAB_HOME. An example job script for submission to the batch queue would look like: