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 件)
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 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!