Wednesday, October 15, 2014

Running MATLAB on XSEDE Resources

MATLAB is one of the most popular prototyping systems available in research computing. It is a set of powerful tools all wrapped in a language similar to FORTRAN with object oriented features.

XSEDE is a set of national computing resources that researcher can apply for.  It is one in a set of national resources that powers a large share of national resources including DOE, Blue Waters, and others.

Currently it is very difficult to combine the two sets of resources. MATLAB is commercial and getting access to a license that you can use on XSEDE can be problematic due to license cost and technical complexity.

MCC - The MATLAB Compiler

MCC (Flux Docs) is a toolbox/add-on to MATLAB that allows the wrapping of mcode into a standalone executable. Features of this executable is that it can be ran anywhere using any functionality that was available at the site it was compiled at.  Thus MATLAB programs can be moved to a resource such as XSEDE within your license terms.

The downsides are you cannot modify your mcode on the XSEDE resource. You have to make any design changes where you have your MATLAB license and MCC license.  This limitation can be mitigated by the fact that MCC can compile functions and arguments can be passed on the command line.  Of course MCC compiled code can also read from files that regular MATLAB can.  So if your code is stable but you are running different inputs that is no problem.

The How-To

This is will be in two parts. What needs to be done on Flux or other machine with MATLAB and MCC installed, and what needs to be done to run the result on the XSEDE resource. In this example I am going to use Stampede at TACC.

The example code is implicitthreads.m which solves a system of equations using the \ operator in MATLAB.  It is implemented as a function, taking the number of unknowns. 

Compile on Flux
(GIST flux.sh)
#compile source on Flux
module load matlab/2014a
mcc -m implicitthreads.m
view raw flux.sh hosted with ❤ by GitHub



Setup MCR on Stampede
(GIST stampede.sh)
#install the correct MCR (MATLAB Compiler Runtime) for your MATLAB version
# http://www.mathworks.com/products/compiler/mcr/
#This need only be done once
#use $WORK to have sufficent space
mkdir $WORK/mcr
cd $WORK/mcr
wget http://www.mathworks.com/supportfiles/downloads/R2014a/deployment_files/R2014a/installers/glnxa64/MCR_R2014a_glnxa64_installer.zip
unzip MCR_R2014a_glnxa64_installer.zip
./install -mode silent -agreeToLicense yes -destinationFolder $WORK/mcr
view raw stampede.sh hosted with ❤ by GitHub


Run on Stampede
#use run_<programname>.sh <MCR root> <args>
#that file is created by the compiler and needs to be copied along with the executable
./run_implicitthreads.sh $WORK/mcr/v83 1000
view raw run-mcc.sh hosted with ❤ by GitHub