Tags:
create new tag
view all tags

Using Matlab

This page is part of the EmpiricalAlgorithmics web.

Compiling Matlab

  • Code modification:
    • the 'main' function is an m-file (myFunction.m) that needs to be a function.
    • since all arguments are passed as strings, you need to convert numeric arguments to double when 'deployed':

if isdeployed

myArg1 = str2double(myArg1);

end

    • no 'addpath' calls allowed
    • for functions called by 'feval', you need to get them included by adding the following to myFunction.m: %#function myAnnonymousFunction

  • Compilation:
To compile a function for stand-alone execution, start Matlab in the appropriate directory and type:

addpath(genpath(pwd)); % Add stuff to the path so compiler can find functions

mcc -m myFunction.m % Compile into a stand-alone

(you can call mcc from outside matlab, but it needs to be called from within matlab to add anything to the path)

  • Execution:
    • Set the library environment variable so that it can find the matlab libraries:

setenv LD_LIBRARY_PATH /cs/local/generic/lib/pkg/matlab-7.3/bin/glnx86 (or wherever matlab is installed, this can be added to .cshrc)

    • Run the stand-alone: myFunction

Submitting Compiled Matlab to the Arrow Cluster

The configuration that has worked was compiling on arrow50@cs with Matlab 7.3 compiler/libraries.

Here is a compile.sh file (run from the 'root' code directory, where $1 is the function you want to compile):

#!/bin/sh

/cs/local/generic/lib/pkg/matlab-7.3/bin/matlab -nojvm -nosplash -nodesktop -nodisplay -r "addpath(genpath(pwd));mcc -m $1;exit;"

Also, the arrow cluster uses bash instead of cshell, so the library command needs to be:

export LD_LIBRARY_PATH=/cs/local/generic/lib/pkg/matlab-7.3/bin/glnx86

It appears that the right way to get environment variables set is to set them on the qsub command line. So on samos, set your LD_LIBRARY_PATH to be what you want (adding in the matlab directory) and then use the command

qsub -v LD_LIBRARY_PATH=$LD_LIBRARY_PATH -o . -e . -cwd -t 4 ./script

to submit the job. $SGE_TASK_ID causes a complaint from Matlab, so you may need to send explicit integers instead.

-- Main.jtillett - 19 Apr 2007

Common Errors

Problem: You compiled initially without a problem. You try recompiling and you get this:

??? Error: File: somefile Line: 1 Column: 25

The input character is not valid in MATLAB statements or expressions.

Solution: Delete the mcr directory.

Problem: You're trying to load a file that has an array of user objects, and when you run it you get an error message like:

Warning: Class ':all:' is an unknown object class.  Element(s) of this class in array '' have been converted to structures.

Solution: Use the line "%#function my_object" in your code

Problem: You're trying to compile a MATLAB code, and you get error like:

connect xxx.cs.ubc.ca port 6000: Connection refused.

Solution: run "setenv DISPLAY fake_display" before run MATLAB

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r5 - 2009-03-06 - xulin730
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback