Got Questions? Get Answers.
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:
bad performance

Subject: bad performance

From: Andreas

Date: 16 Dec, 2010 19:31:06

Message: 1 of 4

Hi,

I used the profiler to identify the bottleneck in an multigrid application and the following peace of code was found:

  d_lm1 = d_l(1:n_lm1);
  for i = n_lm1+1:n_l
    idx1 = parents(1, i-n_lm1);
    idx2 = parents(2, i-n_lm1);
    d_lm1(idx1) = d_lm1(idx1) + 0.5*d_l(i); <==== BAD PERFORMANCE
    d_lm1(idx2) = d_lm1(idx2) + 0.5*d_l(i); <==== BAD PERFORMANCE
  end

Unfortunately I am not able to vectorize these two lines, which are called billions of times.

If you have any ideas to solve that problem, I would be glad to read your suggestions.

Regards,
Andi

Subject: bad performance

From: Sean de

Date: 16 Dec, 2010 19:55:06

Message: 2 of 4

"Andreas " <snanreit@am.uni-erlangen.de> wrote in message <iedpdq$660$1@fred.mathworks.com>...
> Hi,
>
> I used the profiler to identify the bottleneck in an multigrid application and the following peace of code was found:
>
> d_lm1 = d_l(1:n_lm1);
> for i = n_lm1+1:n_l
> idx1 = parents(1, i-n_lm1);
> idx2 = parents(2, i-n_lm1);
> d_lm1(idx1) = d_lm1(idx1) + 0.5*d_l(i); <==== BAD PERFORMANCE
> d_lm1(idx2) = d_lm1(idx2) + 0.5*d_l(i); <==== BAD PERFORMANCE
> end
>
> Unfortunately I am not able to vectorize these two lines, which are called billions of times.
>
> If you have any ideas to solve that problem, I would be glad to read your suggestions.
>
> Regards,
> Andi


Is d_lm1 preallocated?
Why can't you vectorize these two lines?

Subject: bad performance

From: Steven_Lord

Date: 16 Dec, 2010 20:23:14

Message: 3 of 4



"Andreas " <snanreit@am.uni-erlangen.de> wrote in message
news:iedpdq$660$1@fred.mathworks.com...
> Hi,
>
> I used the profiler to identify the bottleneck in an multigrid application
> and the following peace of code was found:
>
> d_lm1 = d_l(1:n_lm1);
> for i = n_lm1+1:n_l
> idx1 = parents(1, i-n_lm1);
> idx2 = parents(2, i-n_lm1);
> d_lm1(idx1) = d_lm1(idx1) + 0.5*d_l(i); <==== BAD
> PERFORMANCE
> d_lm1(idx2) = d_lm1(idx2) + 0.5*d_l(i); <==== BAD
> PERFORMANCE
> end
>
> Unfortunately I am not able to vectorize these two lines, which are called
> billions of times.
>
> If you have any ideas to solve that problem, I would be glad to read your
> suggestions.

Look at ACCUMARRAY or the accumulation behavior of SPARSE (depending on
whether you want d_lm1 to be full or sparse.)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: bad performance

From: Andreas

Date: 17 Dec, 2010 08:30:20

Message: 4 of 4

Thanks alot. ACCUMARRAY does the job.



"Steven_Lord" <slord@mathworks.com> wrote in message <iedsfi$r6i$1@fred.mathworks.com>...
>
>
> "Andreas " <snanreit@am.uni-erlangen.de> wrote in message
> news:iedpdq$660$1@fred.mathworks.com...
> > Hi,
> >
> > I used the profiler to identify the bottleneck in an multigrid application
> > and the following peace of code was found:
> >
> > d_lm1 = d_l(1:n_lm1);
> > for i = n_lm1+1:n_l
> > idx1 = parents(1, i-n_lm1);
> > idx2 = parents(2, i-n_lm1);
> > d_lm1(idx1) = d_lm1(idx1) + 0.5*d_l(i); <==== BAD
> > PERFORMANCE
> > d_lm1(idx2) = d_lm1(idx2) + 0.5*d_l(i); <==== BAD
> > PERFORMANCE
> > end
> >
> > Unfortunately I am not able to vectorize these two lines, which are called
> > billions of times.
> >
> > If you have any ideas to solve that problem, I would be glad to read your
> > suggestions.
>
> Look at ACCUMARRAY or the accumulation behavior of SPARSE (depending on
> whether you want d_lm1 to be full or sparse.)
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

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