Child pages
  • MATLAB Compiler Runtime (MCR)
Skip to end of metadata
Go to start of metadata




Matlab Compile Runtime



Last update



Due to licensing issues Matlab can't be directly use in the FGI environment. However, many Matlab codes can be translated to C coded executables. This executable can be used in FGI when the Matlab Compiler Runtime (MCR) is available. When Matlab code is executed this way it does not require license and thus large amounts of C converted Matlab codes can be executed simultaneously. 

MCR-R2013A Runtime Environment supports c-converted Matlab codes that have been created with the mcc command of Matlab version R2013A (other Matlab versions are not compatible with the Runtime Environment).This Matlab version is available in the server of CSC. 

A simple Matlab code ( testjob.m) is converted to C exeutable with command:  ( download the sample case from here):

mcc -mv testjob.m

The conversion command produces C executable (testjob) and a shell scrip ( that can be used to launch the executable. These components, as well as any input files that the Matlab code uses, needs to be defined as input files in the grid job description file. In this sample case we don't have any input files so the job description file (matlab.xrsl) could look like following: 

( "testjob" "testjob" )
( "" "" )
  ( "matlabresults.txt" "matlabresults.txt" )

 In the command script ( execution permissions must first be defined for the compiled command and execution script. After this the compiled Matlab code is launched using the execution script ( The location of the MCR library must be given as the first argument for execution script. When the MCR-R2013A Runtime Environment is used, this location is stored to environment variable: $MCRROOT. The possible arguments of the Matlab code are added to the execution command after this.

In cases where large amounts of Matlab jobs are submitted it is advices to run the actual matlab task in the local temporary directory ($TMPDIR) of the computing node. To do this, the execution script must have steps where the input data is coped to $TMPDIR and the process is moves to the $TMPDIR before the actual execution of the Matlab task. The results must also be copied back to the original job directory when the actual matlab task has finished.

In this example the command script could look like following. :


echo "Hello Matlab!"

#copy data to temporary directory
cp -r * $TMPDIR/
#set execution permissions for the matlab script and executable
chmod u+x
chmod u+x testjob 
./ $MCRROOT > matlabresults.txt
#Copy results from the temporary directory
#back to the home directory of the grid job
mv matlabresults.txt $jobdir/
echo "Bye Matlab!"
exit $exitcode


Commands to submit the sample job in linux and MacOSX machines

Set up grid environment and submit the job


arcsub matlab.xrsl

Follow the progress of the job and retrieve the result when the job is finished,


arcstat job_id
arcget job_id

In the commands above, job_id should be replaced with the job identifier given by the the arcsub command for example:


arcstat gsi
arcget gsi

The arcget command will store the results of the job to a new directory named according to the job ID number. 


Interface definition

The runtime environment sets the following environment variables:

  • MCRROOT is set so that it points tro the MCR libraray location

System administrator guide for installing the RE

Download and install the MCR installation kits from:


Runtime environmen

Download runtime environment example for SLURM,

Modify the scripts as needed and save the main script in your ARC runtime directory as APPS/MATH/MRC-R2013A

As long as the interface requirements are satisfied, the implementation does not really matter. And some adaptation is needed anyway to accommodate differences in the cluster environment (batch queue systems, temporary directory location etc.)

  • No labels