5.0

5.0 | 1 rating Rate this file 191 downloads (last 30 days) File Size: 1.67 KB File ID: #21756

compileAndRun

by Matt Dunham

 

15 Oct 2008 (Updated 16 Oct 2008)

No BSD License  

Easily compile and run a matlab function for significant speed improvements.

Download Now | Watch this File

File Information
Description

Newer version of Matlab let you compile Matlab code using emlmex, significantly improving the speed of certain functions, particularly those involving loops. However, the size and type of the inputs have to be fixed at compile time, limiting its use.

This function lets you compile functions dynamically at run time so that the size and types of the inputs don't have to be known before hand.

You simply call this function like you would feval:

[a,b,c] = runAndCompile('myfunc',X,Y,Z)

Note, however, that Matlab's emlmex only supports a subset of the Matlab language. This will not work with all functions and it might take some work to make functions eml compliant. See Matlab's emlmex help for details. A few minutes work, however, can save you hours or days of computer time depending on the size of the problem.

MATLAB release MATLAB 7.6 (R2008a)
Other requirements Requires emlmex - not sure if this is distributed with a vanilla Matlab install.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
26 Nov 2008 Arturo Serrano  
26 Nov 2008 Arturo Serrano

Thanks for the code. Very useful.

I like to use constant inputs, but these must be dropped when executing the mex file. I think that this can make the trick:

varargin(cellfun (@(x)isa(x, 'emlcoder.Example') && strcmp(x.Type, 'CONST'), varargin)) = [];

This gives an error when an old mex version exists. The catch block can be completed with

if exist(fname) == 3
    warning('compileAndRun:oldMex', '\n\nusing an old compiled version\n\n');
    varargin(cellfun... );
end

(I prefer to throw an error rather than a warning. I've not tested the catch block)

Cheers.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
compile Matt Dunham 22 Oct 2008 10:24:39
compiled matlab Matt Dunham 22 Oct 2008 10:24:39
eml Matt Dunham 22 Oct 2008 10:24:39
mex Matt Dunham 22 Oct 2008 10:24:39
emlmex Matt Dunham 22 Oct 2008 10:24:39
speed up tricks Matt Dunham 22 Oct 2008 10:24:40
fast Matt Dunham 22 Oct 2008 10:24:40
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com