I am writing a program in matlab which basically runs in a
loop and calls a few MEX functions among other things. (The
loop is the only way I can do it, cannot vectorized more).
When I look a the profiler it seems that matlab spends a lot
of time on function calling. for example one MEX function
ran 1.8 seconds and the entire call took 18 seconds. Is this
a lot of for overhead? Is there a way to accelerate it? for
example my somehow inlining the MEX function?
> Hello,
>
> I am writing a program in matlab which basically runs in a
> loop and calls a few MEX functions among other things. (The
> loop is the only way I can do it, cannot vectorized more).
> When I look a the profiler it seems that matlab spends a lot
> of time on function calling. for example one MEX function
> ran 1.8 seconds and the entire call took 18 seconds. Is this
> a lot of for overhead? Is there a way to accelerate it? for
> example my somehow inlining the MEX function?
I don't understand what you mean by your numbers. If one call of the
MEX function takes 1.8 seconds (is that what you mean?), then the
function call overhead is minimal.
MATLAB's function call overhead is substantial (compared to C), but it
is only an issue if there are few operations *inside* the function. If
there are tens of thousands of operations inside the function then the
overhead can probably be neglected.
> MATLAB's function call overhead is substantial (compared
to C), but it
> is only an issue if there are few operations *inside* the
function. If
> there are tens of thousands of operations inside the
function then the
> overhead can probably be neglected.
>
> -Peter
The overhead is usually substantial because of allocating
memory, e.g.:
A = mexfcn1(B,C);
A = mexfcn2(A,D);
Now A has to be allocated twice.
Back to the original question: you can of course combine the
mex files, if you have the source code. If not, you have to
be more clear about your program...
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 Disclaimer prior to use.