Thread Subject: MEX inline

Subject: MEX inline

From: s a

Date: 11 Jun, 2008 14:20:03

Message: 1 of 3

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?

Thanks,
Sharon

Subject: MEX inline

From: Peter Boettcher

Date: 11 Jun, 2008 18:05:47

Message: 2 of 3

"s a" <shaec47@walla.co.il> writes:

> 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.

-Peter

Subject: MEX inline

From: Sebastiaan

Date: 12 Jun, 2008 07:21:01

Message: 3 of 3


> 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...

Greetz,
Sebastiaan

Tags for this Thread

Everyone's Tags:

mex

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
mex s a 11 Jun, 2008 10:25:03
rssFeed for this Thread

Public Submission Policy

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.

Contact us at files@mathworks.com