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

dpb
dpb 2018년 6월 23일
편집: dpb 2018년 6월 23일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2018년 6월 23일
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.

카테고리

도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2018년 6월 23일

답변:

Jan
2018년 6월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by