I am having problem implementing parfor
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
I am using parfor to speed up my computation. But instead of getting speed up, it takes significantly longer. I don't know what I am doing wrong and I am new to matlab. Here's the code I have. I implemented the same with GPU and it takes like 20 secs but with two cores of my laptop it take 400s something seconds. And the surprising thing is that, I get answer in 60 secs with single core without parfor.
tic
for j2=1:screenpoints
for i2=1:screenpoints/vertscreen
temp=zeros(specimenpoints,specimenpoints);
for j=1:specimenpoints
parfor i=1:specimenpoints
kernelB=vortexpattern(i,j)*kernel1(i,j)* ...
exp(I*2.0*pi*(((i-specimenpoints/2.0-0.5)* ...
specimensize/specimenpoints- ...
(i2-screenpoints/2.0/vertscreen-0.5)* ...
screensize/screenpoints )^2.0+ ...
((j-specimenpoints/2.0-0.5)*...
specimensize/specimenpoints-...
(j2-screenpoints/2.0-0.5)*...
screensize/screenpoints)^2.0+...
(D-d)^2.0)^(1.0/2.0)/lambda);
temp(i,j)=kernelB;
end
end
kernel2(i2,j2)=sum(sum(temp));
end
end
timefork2=toc
0 件のコメント
回答 (1 件)
Edric Ellis
2013 年 6 月 18 日
0 投票
Generally, it's best to have the PARFOR loop at the highest level possible because there's an overhead to running each PARFOR loop. In your case, it seems as though you could make the outermost loop be a PARFOR, and revert the innermost loop to a FOR.
1 件のコメント
Matador
2013 年 6 月 19 日
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!