Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Unaccounted overhead in MEX-function profile

Subject: Unaccounted overhead in MEX-function profile

From: darthshak

Date: 15 May, 2010 05:26:06

Message: 1 of 5

I am running MATLAB R2008b.

I have a MEX-function, calc_E, which runs 499500 times in a loop. This function is called in a statement in an M-function, 'E = calc_E(D)'.

The problem is, according to the profiler, calc_E itself took 3.383 s to execute, but the statement 'E = calc_E(D)' took 11.539 s. I tried running the profiler with -detail builtin (R2008b doesnt allow any further than this), but it didn't reveal anything more. Considering that this statement is the rate determining step in my program, it is important that I optimize it.

What is the cause of this extra overhead and how do I eliminate it?

Subject: Unaccounted overhead in MEX-function profile

From: Jan Simon

Date: 15 May, 2010 13:29:06

Message: 2 of 5

Dear Darthshak!

> I have a MEX-function, calc_E, which runs 499500 times in a loop. This function is called in a statement in an M-function, 'E = calc_E(D)'.
>
> The problem is, according to the profiler, calc_E itself took 3.383 s to execute, but the statement 'E = calc_E(D)' took 11.539 s. I tried running the profiler with -detail builtin (R2008b doesnt allow any further than this), but it didn't reveal anything more. Considering that this statement is the rate determining step in my program, it is important that I optimize it.

I assume that E is allocated in each run.
Does the size of E differ for each run?
Please post more code.

Jan

Subject: Unaccounted overhead in MEX-function profile

From: darthshak

Date: 3 Jun, 2010 09:31:58

Message: 3 of 5

Nopes, the size of E is fixed in each run.

I did try to make the memory persistent, but to no avail. I seem to be encountering this issue all over the place.

Subject: Unaccounted overhead in MEX-function profile

From: Jan Simon

Date: 3 Jun, 2010 11:18:04

Message: 4 of 5

Dear darthshak!

> Nopes, the size of E is fixed in each run.

Then try to reuse the memory reserved for E:
  E(:) = calc_E(...)
 
> I did try to make the memory persistent, but to no avail. I seem to be encountering this issue all over the place.

"All over the place" does not explain enough to reproduce the behaviour. Please post the relevant part of the source code!

Kind regards, Jan

Subject: Unaccounted overhead in MEX-function profile

From: Vishaka

Date: 4 Jun, 2010 04:13:05

Message: 5 of 5

Jan, sorry about forgetting to post the code.

I've figured out the problem myself though. I forgot to take into account the fact that MATLAB cant optimize away the overhead of repeatedly calling a MEX function (in this, case half a million times), as it doesnt quite know what the MEX function is doing.

Tags for this Thread

No tags are associated with this thread.

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.

Contact us