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 个评论

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 个)

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