HPC/Applications/matlab/Compiler

From CNM Wiki
< HPC‎ | Applications‎ | matlab
Jump to navigation Jump to search

Introduction

As of R2013a, we have available a MATLAB compiler on Carbon. This compiler allows you to create standalone Linux binaries that do not need a MATLAB license token in order to run. It is therefore highly recommended to use this tool to enable your MATLAB scripts to run when you need them, regardless of other users' demands on our MATLAB license.

Note that the compiler is, unfortunatley, rather slow and unwieldy to use and leaves much to be desired. Compilation of a simple "hello world" script takes several minutes.

Documentation

Consult the vendor site for full documentation. Useful starting points:

Quickstart

  • Connect to clogin5 .
  • Locate your toplevel file and function, say file myfunc.m.
  • Create a target directory, deploydir.
mkdir deploydir

Basic compiler options

mcc -v \
	-o myname \
	-W main \
	-T link:exe \
	-d deploydir \
	myfunc.m
  • You must use a separate deploydir, and it must be a directory other than $PWD or "." Attempting to deploy into the current directory leads to an obscure runtime error "Compiled parallel application fails: distcompdeserialize".
  • -v is optional but useful to get progress info during the lengthy compile process.
  • You only need to give the toplevel file myfunc.m - mcc will locate and compile dependencies in the MATLAB search path.

Additional options

You can include the following lines, before naming your own .m file:

  • To always write a log file upon execution:
	-R '-logfile,myfile.log' \
  • The compilation is very slow, but may be sped up by removing toolboxes that are not used, and only adding those that are:
 	-N -p distcomp -p images \
    • The toolboxes that can be given for the -p option are:
$ ls $MATLAB_HOME/toolbox/
compiler  curvefit  distcomp  images  local  matlab  optim  shared  stats

Cleanup

  • The compiler places the binary as deploydir/myname, and a couple of other files that you can remove or ignore:
cd deploydir
rm mccExcludedFiles.log readme.txt

Running the executable

cd deploydir
./run_myname.sh $MATLAB_HOME args-for-your-program

The run_myname.sh script will be generated by the compiler. It expects as its first argument a path to a MATLAB runtime. On Carbon, the main MATLAB installation directory can be used, whose path is provided by the matlab module file in the environment variable shown, following local conventions.