필터 지우기
필터 지우기

my code is slower with a parfor loop

조회 수: 1 (최근 30일)
emar
emar 2017년 4월 21일
댓글: Walter Roberson 2017년 4월 21일
Hello,
I ran this code in a computer with 44 workers. However, it's slower than the for version.
template=cell(31,1);
for i=1:31
template{i}=rand(i+24);
end
parfor i=1:5
img=rand(800,1280+i); % It's an other function that gives me the values of img ,here it's just an example
tic
cellfun (@(t) normxcorr2 ( t ,img),template,'UniformOutput',0);
toc
end
As a result, elapsed time in each loop is approximately 18 s . When i change the parfor to for , the time elapsed is approximately 6.7 s in each loop .
Can you explain me why the parfor loop is slower than the for loop?
I checked Matlab documentation and also similar questions on Matlab answers, but it didn't help me.
Note : the total time of execution of the script is faster for the parfor version, i just want to understand why the function cellfun is 3 times slower in parallel version.
Thanks in advance

채택된 답변

Walter Roberson
Walter Roberson 2017년 4월 21일
normxcorr2 for large enough matrices probably ends up invoking the high performance libraries such as LINPACK or BLAS. Those high performance libraries are threaded and will use all available threads, even if you do not have the Parallel Computing Toolbox. When you use parfor then unless you are using R2017a or later and have specifically set the number of threads, then your parfor worker will only have a single thread available to it. That leads to the worker taking longer for that task.
  댓글 수: 3
emar
emar 2017년 4월 21일
But you are right, fft2 is calculated with multicores ! thank you for your explanation
Walter Roberson
Walter Roberson 2017년 4월 21일
Remember to account for communications overhead.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by