Updates from June, 2005 Toggle Comment Threads | Keyboard Shortcuts

  • Robert 21:36 on June 28, 2005 Permalink | Reply  

    Matlab compiler #2 

    I discovered another problem with the matlab compiler (version 3, which is included with Matlab 6.5), namely that it will not translate an m-file to c-code when that m-file tries to read a variable from a mat-file.

    Mathworks does specify that one of the things that is not supported by the compiler (see here) are m-files that dynamically name variables to be loaded or saved. They give this example which is disallowed by the compiler:

    x= 'f';
    load('foo.mat',x);

    However, this function also will not compile:

    function testload(cfg);
    b = load(cfg.filename);
    c = getfield(b, 'a');
    disp(c);
    

    giving the following error

    >> mcc -m testload
    testload.c: In function `Mtestload':
    testload.c:103: error: `mlxLoadStruct' undeclared (first use in this function)
    testload.c:103: error: (Each undeclared identifier is reported only once
    testload.c:103: error: for each function it appears in.)
        mbuild: compile of 'testload.c' failed.
    

    If I slightly rewrite the function it does work. The alternative function that has the desired functionality and that does compile correctly is

    function testload(cfg);
    filename = cfg.filename;
    b = load(filename);
    c = getfield(b, 'a');
    disp(c);
    

    At least this gives me a handle on how to modify my code with little effort to make it compatible with the Matlab compiler

     
  • Robert 18:43 on June 2, 2005 Permalink | Reply  

    Matlab compiler 

    Currently I am testing out the use of my mentat toolbox for parallell computing within Matlab in combination with GridEngine on our linux cluster. Initially it worked fine, but that was because I was testing it with simple level Matlab functions like “rand” and “fft”. However, I am now trying to get it to work with more complex real-world scripts for EEG and MEG analysis that use the FieldTrip toolbox and I am running into a few problems:

    I had to edit the file /opt/matlab-6.5.1/toolbox/matlab/iofun/private/readavi.m and rename the output argument “varargin” into “varargout”. I think that this is a plain bug in that function, which only becomes apparent after translating the code to c. The original file resulted in a compilation error, changing the output variable name fixed that.

    Somehow, the code wants to include the Matlab function wk1read in the stand-alone executable. I cannot determine where that happens, because all functions are very deeply nested: mcc generates ~350 c-files on which my analysis function depends. The problem is that, after compilation, wk1read results in a unresolved symbol error. Since I am not interested in reading Lotus database stuff (which is what that particular function does), I have simply replaced it on my own Matlab search path with an alternative (empty) implementation for wk1read. That solved the unresolved symbol error.

    Furthermore, I encountered a problems with the exist function. In the stand-alone executable, it does not seem to detect the existence of a variable. Since I am using that function on multiple locations throughout the code, I have to think of a nice workaround. Related to this problem I found this page which gives some relevant hints on using the Matlab compiler:

    1. The following things cause a warning in compilation and may cause a runtime error if the offending statement is executed: objects, most toolboxes, inline, whos, some graphics functions that are passed functions by string.
    2. Program compiled with graphics will not run without X windows. This includes running on beowulf nodes from PBS scripts.
    3. Program containing graphics commands and compiled without graphics will produce compile time warning but will run fine as long as the graphics commands are not executed.
    4. The following commands work differently: eval, feval, exist, global.
    5. Use handles to pass functions rather than strings.
    6. Do not use exist to check for the presence of arguments in a function.
     
    • Matthew Simoneau 16:57 on June 9, 2005 Permalink

      You’re right about readavi.m. I just entered this into our bug tracking system. I’m not sure about the other stuff, but MATLAB 6.5 is now pretty out of date.

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel