The Matlab compiler allows you to convert user-written Matlab programs into stand-alone applications that do not need to be run within the Matlab environment. These applications can be run repeatedly and directly on the SSCC cluster. When you run these applications on the cluster, they do not require the use of multiple MATLAB licenses. That could be quite beneficial if you are using a toolbox with a limited number of licensed concurrent uses!
Complete Matlab Compiler Documentation is available from Mathworks at Matlab Compiler Documentation. This document describes the basic steps for setting up and using the Compiler on Northwestern University's Social Sciences Computing Cluster. Many, but not all, licensed toolboxes may be compiled. Review the MATLAB Compiler Support page to be sure.
To set up your account to use the Matlab compiler, follow these steps:
- Login to your SSCC account on Seldon or Hardin and switch to the directory where you would like the executable file to be created (In the example below, the directory is named MC and it is located in my home directory).
- Copy the relevant M-file to this directory. Note that the compiler can only be used to create executable files from Function M-Files. If you have a script M-file, convert it with mcc into a function M-File. As a working example we shall use the MATLAB example MagicSquare M-file which you can copy into your target directory by executing a variation on the following commands. First, find the location of the matlab command, then change to the MATLAB installation directory (which changes with each release or update), and finally copy the example file to your MC subdirectory:
[ach131@seldon MC]$ which matlab /sscc/opt/matlab.r2008b/bin/matlab
[ach131@seldon MC]$ cd /sscc/opt/matlab.r2008b
[ach131@seldon matlab.r2008b]$ cp extern/examples/compiler/magicsquare.m ~/MC
[ach131@seldon MC]$ cd ~/MC
- Start Matlab and type the following (one-time) setup command
>> mbuild -setup
- Type the following command to compile the relevant M-file, in this case magicsquare.m (Replace 'magicsquare' below with the name of the M-file you are trying to compile).
>> mcc -m -v -R -nojvm magicsquare
If your program uses graphics then instead of the command above, submit the modified command: >> mcc -m -v magicsquare
- Get the Library Path Information with the following command and then quit Matlab.
- In the shell environment, submit the following command (note the use of back-tics ):
[ach131@seldon MC]$ export LD_LIBRARY_PATH=`cat SAVE`
This command sets up a list of libraries needed by the compiled MATLAB program for execution. You must perform this setup whenever you run your compiled MATLAB program. Note also that upgrades of either the MATLAB program or the operating system may very well break your saved LD_LIBRARY_PATH in the file SAVE . When that happens, you should recompile and use MATLAB again to obtain the library path information.
- The executable file is ready to run. List the files to check that the executable file has been created and then run it, making sure to specify that the executable file is in the current directory (this is achieved by the "./" before the name of the executable file). The input parameter "5" specifies the size of the matrix to generate.
[ach131@seldon MC]$ ll
-rw------- 1 ach131 users 367 Feb 1 18:53 SAVE
-rwx------ 1 ach131 users 9441 Feb 1 18:53 magicsquare
-rw------- 1 ach131 users 39285 Feb 1 18:53 magicsquare.ctf
-rw------- 1 ach131 users 206 Feb 1 18:43 magicsquare.m
-rw------- 1 ach131 users 3971 Feb 1 18:52 magicsquare_main.c
-rw------- 1 ach131 users 14659 Feb 1 18:53 magicsquare_mcc_component_data.c
-rw------- 1 ach131 users 826 Feb 1 18:53 mccExcludedFiles.log
[ach131@seldon MC]$ ./magicsquare 5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Last Updated: 30 November 2011