The Helix Systems have a license for the Matlab Compiler. All Helix, Biowulf and Sciware users are invited to
utilize the Compiler. Please send feedback to email@example.com.
The Matlab Compiler can be used to create stand-alone executables from a Matlab application. This executable can then be run on Helix, Biowulf or your local machine without utilizing a Matlab license. Thus, the compiler can be used to build an executable which can then be run as swarms of jobs on 100 or more processors on Biowulf.
|The compiler can also be used to deploy C or C++ code that interfaces with Matlab, or incorporate Matlab-based algorithms into applications built using other languages and technologies.
The Matlab ".m" files used in these examples, along with other sample files, can be found on Helix in the /usr/local/matlab64/extern/examples/compiler directory.
It is best to create a new directory in which to compile the executable, as several files are produced by the compilation process. Compilation involves one simple command:
mcc -m matlab_file
The following example uses the example file magicsquare.m which contains:
%MAGICSQUARE generates a magic square matrix of the size % specified by the input parameter n. % Copyright 2003-2007 The MathWorks, Inc. n=3; if ischar(n) n=str2num(n); end m = magic(n); disp(m);
Sample session: (user input in bold):
helix% mkdir mytest helix% cd mytest helix% ls -l -rw-r--r-- 1 susanc staff 202 May 13 14:15 magicsquare.m helix% mcc -m magicsquare.m which: no ifconfig in (/usr/local/matlab_2010a-64/bin:/usr/local/matlab64/bin:/usr/local/etc:/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/local/bin:/usr/local/bin:/bin:/usr/bin:/usr/NX/bin:/home/susanc/bin) helix% ls -l total 96 -rwxr-xr-x 1 susanc staff 48008 May 13 14:18 magicsquare -rw-r--r-- 1 susanc staff 202 May 13 14:15 magicsquare.m -rw-r--r-- 1 susanc staff 12801 May 13 14:18 magicsquare.prj -rw-r--r-- 1 susanc staff 3653 May 13 14:18 magicsquare_main.c -rw-r--r-- 1 susanc staff 6209 May 13 14:18 magicsquare_mcc_component_data.c -rw-r--r-- 1 susanc staff 706 May 13 14:18 mccExcludedFiles.log -rw-r--r-- 1 susanc staff 3790 May 13 14:18 readme.txt -rwxr--r-- 1 susanc staff 1028 May 13 14:18 run_magicsquare.sh helix% ./run_magicsquare.sh /usr/local/matlab64 Setting up environment variables --- LD_LIBRARY_PATH is .:/usr/local/matlab64/runtime/glnxa64:/usr/local/matlab64/bin/glnxa64:/usr/local/matlab64/sys/os/glnxa64:/usr/local/matlab64/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/matlab64/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/matlab64/sys/java/jre/glnxa64/jre/lib/amd64/client:/usr/local/matlab64/sys/java/jre/glnxa64/jre/lib/amd64 8 1 6 3 5 7 4 9 2
Open an Xwindows connection to Helix and start up Matlab. It is a good idea to test your Matlab script before compilation by running it at the prompt.
Type 'deploytool' to start the deploytool GUI. In the window that appears, enter a project name and the location of the project, and select 'Standalone Application' as the Target. Of course, you should select one of the other options for Target if you want to build a C shared library or a C++ shared library.
The deployment tool will appear on the right side of your Matlab window.
Select 'Add main file' and in the resultant window, select the Matlab file that you want to compile.
Click the 'Build' button, which is second from left in the Deployment tool window.
The compiled executable is 64-bit, and can run on Helix or any node in the Biowulf cluster.
Set up a batch script along the following lines:
--- this file is mcc.bat------ #!/bin/bash #PBS -N Matlab_compiler cd mytest ./run_magicsquare.sh /usr/local/matlab64
Submit this job with
biowulf% qsub -l nodes=1 mcc.bat
Interactive example (this would be used for debugging purposes only):
biowulf% qsub -I -l nodes=1 qsub: waiting for job 1179941.biobos to start qsub: job 1179941.biobos ready [susanc@p275 ~]$ cd mytest [susanc@p275 matlab_compiler]$ ./run_magicsquare.sh /usr/local/matlab64 ------------------------------------------ Setting up environment variables --- LD_LIBRARY_PATH is .:/usr/local/matlab64/runtime/glnxa64:/usr/local/matlab64/bin/glnxa64:/usr/local/matlab64/sys/os/glnxa64:/usr/local/matlab64/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/matlab64/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/matlab64/sys/java/jre/glnxa64/jre/lib/amd64/client:/usr/local/matlab64/sys/java/jre/glnxa64/jre/lib/amd64 Warning: No display specified. You will not be able to display graphics on the screen. 8 1 6 3 5 7 4 9 2
The great advantage of a compiled executable is that a large number of simultaneous jobs can be run on the Biowulf cluster without requiring the use of a Matlab license. For example, a program could be run with several hundred different sets of parameters.
In the following example, the Matlab program statcalc takes 3 parameters as input. Once the program has been compiled either on the command line or using the GUI, a swarm command file can be set up along the following lines:
cd /data/user/test; ./run_statcalc.sh 10 20 30 cd /data/user/test; ./run_statcalc.sh 10 15 30 cd /data/user/test; ./run_statcalc.sh 20 25 35 [...]
This swarm file can be submiited to the Biowulf cluster with
biowulf% swarm -f swarmfile