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!