skip to primary navigationskip to content
 

Matlab on CamGrid

Some pools have installed Matlab and a selection of its toolboxes (see below for details) on their execute hosts, making it available for general CamGrid use. Such pools advertise this fact by having their machines set the classad value HAS_MATLAB to TRUE and MATLAB_HOME set to point at the installation. These actions need to be carried out by the execute host's system administrator, details of which are given in a section below. By default one should assume that resources are meant for serial (as opposed to parallel) jobs. We will demonstrate job submission with an example. Suppose that the top Matlab file to be run is called main_script.m. Then the submit script will make use of a wrapper script, here called wrapper.sh, which ensures that an environement variable is set :

### Begin wrapper script ###
#!/bin/bash
export MATLAB_PREFDIR=`pwd`/.tmp
MATLAB_HOME=$1
shift
exec ${MATLAB_HOME}/bin/matlab "$@"
### End of wrapper ###

The job submit file now looks like:

### Begin submit script ###
Universe           = vanilla
Executable         = wrapper.sh
notification       = never

transfer_input_files = main_script.m <plus comma separated list of all other files>
should_transfer_files = YES
when_to_transfer_output = ON_EXIT_OR_EVICT
arguments             = $$(MATLAB_HOME) -singleCompThread -nojvm -nosplash -nodisplay -r main_script

Requirements = OpSys == "LINUX" && Arch == "X86_64" && HAS_MATLAB == TRUE && MATLAB_HOME =!= UNDEFINED

Output   = job.out
Log      = job.log
Error    = job.error
Queue
### End submit script ###

Important:

  • The -singleCompThread option is necessary in order to ensure that jobs are executed in serial mode.
  • The -nojvm option removes the Java virtual machine. Remove this option if you really need the JVM.
  • Your top Matlab file (main_script.m in this example) should have "exit;" as its last line in order to ensure that the job does not hang on completion.

System Adminstrator actions

System administrators that would like to Matlab-enable their execute hosts should initially get licenses for their machines from the UCS (email sales@ucs.cam.ac.uk). Once the software is installed, get Condor to advertise the fact by adding to a host's configuration:

MATLAB_HOME = "<path to the installation>"
HAS_MATLAB = TRUE
STARTD_ATTRS = $(STARTD_ATTRS), MATLAB_HOME, HAS_MATLAB

Parallel jobs

If you need to run multi-threaded Matlab jobs then you'll need to explicitly state how many  cores your job requires, and hope that a machine on CamGrid with enough cores has been configured to use dynamic slots and has Matlab installed. Your submission script can now dispense with the -singleCompThread argument, but must specify the correct number of processors (and memory) to use  explicitly by adding the following lines to your submit script:

request_cpus = <number of cores required>
request_memory = <RAM in MB required> 

You also need to use Matlab's (deprecated) maxNumCompThreads function to set the number of threads to the same value you requested in your job description file, otherwise Matlab will grab as many cores as it wants, irrespective of your request_cpus value.

Possible Issues

Some toolboxes depend on using the Java that ships with Matlab. For example, if you get the following error:

matlabpool is not supported because:
Java is not currently available.

then remove the -nojvm flag from the Requirements line of your submit file.

Toolboxes

The following toolboxes are available to Matlab jobs via the University's bundle:

Simulink, Bioinformatics Toolbox, Control System Toolbox, Curve Fitting Toolbox, DSP System Toolbox, Image Processing Toolbox, Instrument Control Toolbox, Optimization Toolbox, Parallel Computing Toolbox, Signal Processing Toolbox, SimMechanics, Simscape, Simulink Control Design, Stateflow, Statistics Toolbox, Symbolic Math Toolbox and Wavelet Toolbox.