Matlab

Overview

Matlab is the computational software package developed by The MathWorks.

Restrictions on use

Matlab may not be used for commercial purposes including being used by consultants or subcontractors. A detailed list of the license restrictions is available on the IT Services Applications website.

Versions installed

Version installed HTCondor ClassAd Location of Matlab runtimes
2019a HAS_MATLAB_2019 /opt/MATLAB/MATLAB_Compiler_Runtime/v96
2021a HAS_MATLAB_2021 /opt/MATLAB/MATLAB_Compiler_Runtime/v910
2024a HAS_MATLAB_2024 /opt/MATLAB/MATLAB_Compiler_Runtime/R2024a

Set up procedure on submit node

To access the software you must first run the command:

module load matlab/<version>

Running the application

In order to run Matlab jobs on HTCondor, it is first necessary to compile the Matlab script file using the Matlab compiler. Whilst this has the advantage that compiled Matlab programs do not use any Matlab licenses when running, some Matlab toolbox functionality may be unavailable.

Step 1 – Compiling your Matlab script file

To ensure that your compiled Matlab code will run on HTCondor, it is essential that you compile your Matlab code on the HTCondor submit node.

From a linux terminal prompt, run the command

mcc -R -singleCompThread -m <script.m>

where

  • mcc is the name of the Matlab compiler command.
  • -R -singleCompThread tells the compiler to produce a single-threaded executable.
  • -m <script.m> specifies the name of the Matlab script file to compile.

The reason for the -R -singleCompThread flag is to avoid problems with Matlab trying to use multiple threads. By default Matlab will detect the number of CPU cores on a PC and then attempt to use that many threads. This can cause problems unless your HTCondor submit file has requested to use all the available cores on the compute node. The maximum number of threads can be specified in your Matlab script file using the maxNumCompThreads command.

After successful compilation, a shell script run_<script>.sh and executable file <script> should exist in the current directory.

Step 2 – Submitting your job to run on HTCondor

The following lines are the contents of a simple generic HTCondor submit text file:

Universe = vanilla

Requirements = (Target.Opsys == "LINUX" && Target.Arch == "X86_64" && <HTCondor ClassAd>=?=True)
Request_memory = 1000

Log = matlab.log
Output = matlab.out
Error = matlab.error
Notification = Error

Should_Transfer_Files = Yes
When_To_Transfer_Output = ON_EXIT

Executable = run_<script>.sh
Transfer_Executable = True
Arguments = <Location of Matlab runtimes> <input arguments>
Transfer_Input_Files = <script>

Queue

If your submit file is called submit.txt then your job can be submitted to HTCondor using the command condor_submit submit.txt.

Using MEX files with compiled Matlab

Whilst it is possible to use MEX files in compiled Matlab codes, each version of Matlab supports a very limited range of the GNU compiler suite. The supported versions are listed in the following table:

Matlab version GNU C/C++ version GNU gfortran version
2019a 6.3.x 6.3.x
2021a 7.x/8.x/9.x 8.x
2024a 8.x/9.x/10.x/11.x 10.x

Please be aware that even if the mex command produces a MEX file, this does not necessarily mean that it will work with the Matlab compiler unless it was compiled using a supported version of the GNU compiler suite.

Sample Matlab HTCondor jobs

  1. Matlab code for calculating Pi using n terms of the Gregory series.
  2. Matlab code demonstrating one way to conduct a 1-D parameter sweep.

Last modified on February 4, 2025 at 12:39 pm by Chris Paul