Compile Matlab

If you do not compile your Matlab source, you will use a license from the Matlab UGent license server and these licenses are limited (at the moment only 150 for the whole University). If you compile your Matlab source, you will need 0 licenses, even if the Matlab license server is down, your program will still work! So, it is better you compile your Matlab code to a standalone program.

Suppose our Matlab program is called multiply.m:

function rc = display_product(a,b)
a = str2num(a);
b = str2num(b);
rc = 0;

Here is how we compile it (*):

$ mcc -m -R -nojvm -R -nodisplay -R -singleCompThread multiply.m -o multiply

* Use -I pathname1 -I pathname2 to include your personal search paths!

This will generate a number of files e.g. the executable multiply and the script With this last script, you can run your simulation called multiply in the correct Matlab environment:

$ nohup ./ $EBROOTMATLAB >& multiply.out &

However, in this example of multiply.m, we have to give 2 extra arguments for a and b, so that display(a*b) can be calculated. It will read a and b from the command line e.g. 3.1415 and 99, and you put these after the argument $EBROOTMATLAB:

$ nohup ./ $EBROOTMATLAB 3.1415 99 >& multiply.out &

$EBROOTMATLAB is the variable containing the root of the current installed Matlab version. This is analog to the variable used in the UGent HPC clusters. All output will be redirected to multiply.out in this example.

When compiling your Matlab programs, please use only one (1) machine to compile! You can run your compiled program on every machine in the lab, there is no problem with that! If you don’t, you will use up all Matlab compile licenses very quickly: there are only 5 available for the whole university, and ones you compile you have a linger time of 30 minutes!