Matlab on Condor: a recipe

Compiled Matlab on Condor:
a recipe
Clare Giacomantonio
30th October 2007
How to format your m-file
turn it into a function
function testfunction(input1,input2)
% change arguments to numerics if necessary
input1 = num2str(input1);
all arguments are strings
input2 = num2str(input2);
- change to numerics if necessary
% computation
sumofinputs = input1 + input2; use a dynamic filename for the
output or make it one of the input
arguments
% save output
outputfilename = ['testfunction_' num2str(input1)
'_' num2str(input2)];
save(outputfilename, 'input1', 'inputs2', 'sumofinputs')
don’t create figures
Motivation
• Each instance of Matlab uses up a license so
logging lots of Matlab jobs can quickly use up all
the licenses stopping more of your jobs running
and/or preventing others from using Matlab.
• Compiled Matlab does not use a license.
- Matlab or the Matlab Component Runtime
(MCR) still need to be installed.
- All machines in the Condor pool have Matlab
installed.
Compile your m-file
• Must compile on the same operating system as you want
to run on.
• At the Matlab command line
>> mcc -m testfunction.m -R -nojvm
• This creates a single executable and a testfunction.ctf
file.
- It also creates a lot of other files which we don’t need.
• There’s only one compiler license!
- Don’t forget to close Matlab after you finish compiling to
release the license.
• Not all Matlab functions compile. See list at
http://www.mathworks.com/products/compiler/compiler_s
upport.html
Running compiled Matlab from
the terminal
• If you want to check that your function runs as
desired from the command line, need to run from
a script which sets the library path first.
#!/bin/bash
export MATLAB_ROOT=/opt/matlab-7.4
export
LD_LIBRARY_PATH=${MATLAB_ROOT}/sys/opengl/lib/glnx86:
${MATLAB_ROOT}/sys/java/jre/glnx86/jre1.5.0/lib/i386:
${MATLAB_ROOT}/sys/java/jre/glnx86/jre1.5.0/lib/i386/
server:${MATLAB_ROOT}/sys/java/jre/glnx86/jre1.5.0/li
b/i386/client:${MATLAB_ROOT}/sys/java/jre/glnx86/jre1
.5.0/lib/i386/native_threads:${MATLAB_ROOT}/bin/glnx8
6:${MATLAB_ROOT}/sys/os/glnx86:
export XAPPLRESDIR=${MATLAB_ROOT}/X11/app-defaults
./testfunction 10 20
Condor submit script
• To schedule jobs in Condor you need a condor
submit script.
• In this script
- You must include executable and .ctf at
transfer_input_files.
- You must set the environment variable
LD_LIBRARY_PATH.
• Other methods may work! This is just one way
that I found works.
Now submit your jobs
• Put Matlab executable, .ctf, any data files used
as inputs and condor_submit script in the
directory InputDir.
• Make sure OutputDir exists.
• Submit your jobs to Condor at the command line
condor_submit testfunction.sub
Outputs
• Any text normally written to the Matlab command
window is saved in the output file.
• Any data files generated will appear in OutputDir.
What happens when an owner
interrupts your job?
• The job re-starts again on another machine.
• It may be possible to implement checkpointing in
your function by periodically saving the
workspace and loading the workspace as a input
if it exists.
Using Matlab on Condor
• Pros
• Cons
- Easy to set-up if your
- Some Matlab
code compiles.
functions don’t
- Can access DICE
compile.
home directory.
- Jobs restart if
- Compiled Matlab
machine is reclaimed
doesn’t use up Matlab
so only good for < 12
licenses.
hour jobs.