필터 지우기
필터 지우기

Trying to use 'parfor', but it is very slow

조회 수: 2 (최근 30일)
Lee Hwihyeong
Lee Hwihyeong 2015년 2월 20일
댓글: Adam 2015년 2월 20일
Hello, I am trying to use parfor as below.
-------------------------
parpool(2)
A=zeros(10,10);
for iX=1:10
parfor iY=1:10
A(iY,:)=rand(1,10);
end
end
----------------------
However, the case of replacing the 'parfor' with 'for' is 20 times faster. Above code is simplified version of what I'm using. In my real case, 'parfor' should be inside 'for'. Is this a problem?
Could anyone explain why?
Thank you in advance.
  댓글 수: 1
Adam
Adam 2015년 2월 20일
As per Doug's answer since you also only have 2 cores (or are only using 2 cores) you will have to be doing more work to make the parfor setup worthwhile than if you had e.g. 8 cores because the absolute maximum theoretical speedup factor will only be 2 and realistically it is obviously lower than that even when running optimally.

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

답변 (1개)

Doug
Doug 2015년 2월 20일
You're not doing enough work in the parfor loop. Since there is an overhead associated with parfor, you have to perform enough operations in the loop to make it worthwhile. Also, it's better if your parfor is not inside a for loop, since otherwise you incur the parfor startup overhead each iteration. You may want to try an example such as http://www.mathworks.com/help/distcomp/examples/simple-benchmarking-of-parfor-using-blackjack.html .

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by