NERSCPowering Scientific Discovery Since 1974

MATLAB Compiler

MATLAB compiler

*Under construction*

MATLAB Compiler™ lets you share MATLAB® programs as standalone applications. 

All applications created with MATLAB Compiler use the MATLAB Runtime, which enables royalty-free deployment to users who do not need MATLAB. You can package the runtime with the application, or have your users download it during installation.

Learn more about MATLAB Compiler support for MATLAB and toolboxes.

The following examples show a general approach on how to build MATLAB stand-alone applications from scripts, this examples can also be found under path $MATLAB_EXAMPLES which is set by loading the MATLAB module.


On Cori over NX:

module load matlab; module load matlab/MCRv901

Copy the examples to your home directory

cp -r $MATLAB_EXAMPLES $HOME; cd $HOME/matlab_examples

And launch MATLAB


Example 1. Matrix factorization

Read data from and write results to CSV files. Given a function that performs a Cholesky decomposition:

% decomposition.m
function R = decomposition(A_path, outpath)
% A_path: Path to CSV data
% A: Matrix positive definite
% R: upper triangular matrix R from the diagonal and upper
% triangle of matrix A, satisfying the equation R'*R=A
A = csvread(A_path);
R = chol(A);

The example script above produces an upper triangular matrix R from the diagonal and upper triangle of matrix A, satisfying the equation R'*R=A. A_path is the path to CSV-formated data for A and outpath is where R will be written to as a CSV file too.

Otherwise in the command line, one can also use the MATLAB compiler as follows:

mkdir build; cd build

mcc -m ../decomposition.m

After the build process is completed, execute the program with the following syntax and the needed input arguments. For this particular example the variables are A: Matrix positive definite and outpath: path to where results will be written to:


$HOME/matlab_examples/build/decomposition/for_testing if GUI was used


under $HOME/matlab_examples/build if mcc was used:

./ $MCR_ROOT $HOME/matlab_examples/data.csv ./out.csv

Note that the MCR_ROOT variable is set by module load matlab/MCRv901, it is recommended to copy this libraries to Lustre if your application is very IO intensive.

The complete documentation for mcc can be found here.

Example 2. Frobenius inner product

Read data from and write results to HDF5 files. In this example we show how to compute the A:B product between two matrices which values are read from separate HDF5 files.

Example 3. Integration with MEX libraries and other third-party dependencies

Read data, use third-party MEX routines and write results out as a Numpy array. The following is a more complex example on how to build a stand-alone application of a MATLAB script that uses third-party packages in the form of MEX files, for this particular case we will show how to compile an application that uses nonequispaced FFTs in the spherical domain and write out a Numpy array for posterior processing in Python.