This document describes how to use the Matlab compiler to compile and run Matlab M-files as multiple concurrent standalone applications on the Aspen Linux cluster, the Cedar Linux cluster, and the Oak Solaris cluster. This allows users to run the same Matlab program with different inputs (e.g. parameter space studies) effectively in parallel, and without using multiple Matlab network licenses.
This page will be modified to include the Oak Solaris cluster.
The Matlab Compiler takes function M-files as input and creates redistributable, stand-alone applications or software components that are platform specific. The Matlab Compiler can generate
The advantages of compiling matlab M-Files as stand-alone executables to run on the Linux clusters are,
The following is a link to the MathWorks
Matlab Compiler Documentation.
This module sets the LD_LIBRARY_PATH variable for the Matlab libraries and will auotmatically be updated with each new version of the compiler.# Set LD_LIBRARY_PATH for Matlab standalone executable module add mcc
If you have previously set LD_LIBRARY_PATH using the version specific directory paths to the Matlab libraries, e.g.
OS=`/uva/bin/cpuarch`
case $OS in
Linux ) LD_LIBRARY_PATH=/common/matlab/7.01/bin/glnx86:\
/common/matlab/7.01/sys/os/glnx86:\
/common/matlab/7.01/sys/java/jre/glnx86/jre1.4.2/lib/i386/client:\
/common/matlab/7.01/sys/java/jre/glnx86/jre1.4.2/lib/i386:\
/common/matlab/7.01/sys/opengl/lib/glnx86:${LD_LIBRARY_PATH}
XAPPLRESDIR=/common/matlab/7.01/X11/app-defaults ;;
esac
you should delete these lines from your startup file.
rm ~/.matlab/R14/mbuildopts.sh
To test the compiler and account configuration copy the example M-file /common/matlab/7.1/extern/examples/compiler/magicsquare.m to your own account, From within Matlab compile the function magicsquare.m as follows:
>> mcc -m -v magicsquare
The results should be displayed asmagicsquare 4
ans =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
function matlab_sim()
% Read in program initialization parameters from text file
% e.g. see sim_input1 below
% First read in a character string to be used to identify the simulation number
% e.g. the character 1.
sim_num=input('simulation identifier > ','s')
% Example of reading in numeric vector used for initialization for simulation
vector_input=eval(input('vector input > ','s'))
% Example of loading data from .mat file with filename based on simulation number,
% e.g. file_in1.mat
% This assumes the .mat file already exists containing some data.
load(['file_in',sim_num,'.mat'])
% Other Matlab code can be included in the body of this function M-file.
% Create some matrix a
a=rand(5,5);
% Save variable a to .mat file with filename based on simulation number
% e.g. file_out1.mat
save(['file_out',sim_num], 'a')
% Alternatively, save variable a to ascii file with filename based on simulation number
% e.g. junk1
fid = fopen(['junk',sim_num],'w');
fprintf(fid,'%12.8f %12.8f %12.8f %12.8f %12.8f \n',a);
fclose(fid);
If this function were run from the Matlab prompt, Matlab would prompt
the user for the input information. Once this M-file is compiled as a
standalone, it can get its simulation
specific data from a text file (e.g. sim_input1) with the Unix redirect command
like the following:
matlab_sim < sim_input1
The input file for matlab_sim is sim_input1 and contains the following data:
1 [3 6 9]The first line is read in as a character string to identify specific input and output files for the simulation run. The next line is an example of a vector of numeric initialization data for the simulation.
This way you can run different concurrent simulations by using different versions of
the text file sim_input1 (e.g. sim_input2, sim_input3, etc.) without having to
recompile your code.
The following is an example of a PBS command file used to submit
the Matlab stand-alone exectuable matlab_sim (after compilation)
for the specific simulation defined by the input file sim_input1 to
the Linux clusters. Further information on PBS command files can be found
in the
Aspen Cluster Tutorial
#!/bin/sh #PBS -l nodes=1:ppn=1 #PBS -l walltime=12:00:00 #PBS -o output_filename #PBS -j oe #PBS -m bea #PBS -M userid@virginia.edu cd $PBS_O_WORKDIR ./matlab_sim < sim_input1