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:
strange difference in profile times

Subject: strange difference in profile times

From: Nike Dattani

Date: 5 Sep, 2010 22:51:04

Message: 1 of 4

Hi!

I have a function in which the dominant operation (i think) in two different lines is Matrix-Vector multiplication.

In the first of these two lines, the result of the matrix-vector multiplication is multiplied by a scalar (should take negligable time)

In the second of these two lines, a vector is subtracted from the result, then I'm doing the absolute value of the answer and then finding the max element in the result.

Both of these lines are called 7800000 times, and the sizes of the matrices and vectors are the exact same, yet the first line takes 138055 seconds and the second takes 24899 seconds.

I used matlab's profiler and it gave me this output (line 57 is the first line mentioned above, and line 61 is the second):

http://bayimg.com/gaOlAAAcM


Is this not a surprising result ? I would like to read what others think about why there is such a big difference.

My only guess is that perhaps the matrix A is stored in the cache while the matrix Cinv is not stored in the cache, simply because A is constant throughout this program, and Cinv changes 5200 times. But this theory is weak because dividing 7800000 by 5200, we get that each new value of Cinv is reused 1500 times, so if the JIT compiler was smart it would store Cinv in the cache as well. Also, since both A and Cinv are about 6MB in size, I doubt they would even fit in the L3 cache.

Looking forward to figuring this out,
Nike

Subject: strange difference in profile times

From: Nike Dattani

Date: 5 Sep, 2010 23:08:03

Message: 2 of 4

Or maybe it's just that multiplying a 900 element vector by a scalar takes 5 times as long as subtracting a 900 element vector from a 900 element vector and searching for the largest element in the answer. I understand that multiplication takes longer than subtraction, but I thought the search for the largest number would take longer than the multiplication.

Subject: strange difference in profile times

From: TideMan

Date: 6 Sep, 2010 02:48:50

Message: 3 of 4

On Sep 6, 10:51 am, "Nike Dattani" <dattani.n...@gmail.com> wrote:
> Hi!
>
> I have a function in which the dominant operation (i think) in two different lines is Matrix-Vector multiplication.
>
> In the first of these two lines, the result of the matrix-vector multiplication is multiplied by a scalar (should take negligable time)
>
> In the second of these two lines, a vector is subtracted from the result, then I'm doing the absolute value of the answer and then finding the max element in the result.
>
> Both of these lines are called 7800000 times, and the sizes of the matrices and vectors are the exact same, yet the first line takes 138055 seconds and the second takes 24899 seconds.
>
> I used matlab's profiler and it gave me this output (line 57 is the first line mentioned above, and line 61 is the second):
>
> http://bayimg.com/gaOlAAAcM
>
> Is this not a surprising result ? I would like to read what others think about why there is such a big difference.
>
> My only guess is that perhaps the matrix A is stored in the cache while the matrix Cinv is not stored in the cache, simply because A is constant throughout this program, and Cinv changes 5200 times.  But this theory is weak because dividing 7800000 by 5200, we get that each new value of Cinv is reused 1500 times, so if the JIT compiler was smart it would store Cinv in the cache as well. Also, since both A and Cinv are about 6MB in size, I doubt they would even fit in the L3 cache.
>
> Looking forward to figuring this out,
> Nike

Of course, alpha and beta have been pre-allocated, right?

Subject: strange difference in profile times

From: Nike Dattani

Date: 6 Sep, 2010 13:19:05

Message: 4 of 4

TideMan <mulgor@gmail.com> wrote in message <de7bf157-efac-47fa-a190-4375d63c0951@t5g2000prd.googlegroups.com>...

> Of course, alpha and beta have been pre-allocated, right?


Yes of course.
alpha=zeros(N^2,numberOfSteps+1);beta=alpha;

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