필터 지우기
필터 지우기

Why accessing 2d matrix in parfor so slow?

조회 수: 1 (최근 30일)
asdf
asdf 2018년 8월 8일
편집: Stephen23 2018년 8월 9일
Let's say I have a large matrix A:
A = rand(10000,10000);
The following serial code took around 0.5 seconds
tic
for i=1:5
r=9999*rand(1);
disp(A(round(r)+1, round(r)+1))
end
toc
Whereas the following code with parfor took around 47 seconds
tic
parfor i=1:5
r=9999*rand(1);
disp(A(round(r)+1, round(r)+1))
end
toc
How can I speed this up?

답변 (1개)

Stephen23
Stephen23 2018년 8월 9일
편집: Stephen23 2018년 8월 9일
"How can I speed this up?"
  1. Do you have a parallel pool open? I.e. created using parpool, or automatically? If no pool is open then a parfor loop will not be run in parallel anyway.
  2. Don't use parfor.
Why do you think that parfor should be faster? The only time that parfor is faster is when the time saved doing the operations in parallel is greater than the overhead required. This topic has been discussed many time on this forum, which also suggest possible improvements to your code:
This is also explained in the documentation:
Your loop contains very fast commands anyway, mostly just round and indexing, so it is quite possible that you will not see any benefit from parfor.

카테고리

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