Will a MEX file increase performance for this loop example

Hello everyone, I have two for loops and I want to convert the inner one to a MEX file. The outer loop contains a lot of matrix multiplications and use of bsxfun, so converting the outer one is probably not giving me any benefit.
%outer loop
for k=1:5000
%matrix multiplications, bsxfun, etc.
%inner loop
for r=4460:5036
curdata(:,r)=sum(data(curBin(r,:) + (intpos-1)*size(data,1)).*phase(r,:));
end %end inner loop
end
Do you think converting the inner loop will give me a significant performance improvement? If so, how do I do it without the CODER toolbox? Any help?
Thank you!

1 comentario

dpb
dpb el 23 de Jun. de 2018
Editada: dpb el 23 de Jun. de 2018
What's intpos, just another constant? IOW, is
C=(intpos-1)*size(data,1);
for r=r1:r2
curdata(:,r)=sum(data(curBin(r,:)+C*phase(r,:));
end
not equivalent?
Also, has profiling shown the specific loop to be a significant bottleneck? Until have shown so, may be wouldn't help anyways and I really don't think it's likely here to be so much help as the indirect addressing is probably not going to go away.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 23 de Jun. de 2018
What about omitting the loop:
c = (intpos-1) * size(data,1); % Before the loops if possible
d = sum(data(curBin(4460:5036, :) + c) .* phase(4460:5036, :), 2).';
curdata(:, 4460:5036) = d;
Or maybe
curdata(:, 4460:5036) = repmat(d, size(curdata, 1), 1);
Please post the dimensions and types of the used variables, preferably some running code. It is easier to improve code, when you do not have to guess on which data it operates.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 23 de Jun. de 2018

Respondida:

Jan
el 23 de Jun. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by