필터 지우기
필터 지우기

Parfor or parfeval, what is better?

조회 수: 26 (최근 30일)
Andrea Stevanato
Andrea Stevanato 2018년 7월 14일
답변: Edric Ellis 2018년 7월 16일
if I have some code that could be writed in same way with parfeval o parfor, what i have to use? What is better? Which is more advantageous, faster... e.g:
parfor i = 1:n
result = function(data);
end
or
for i = 1:n
F(i) = parfeval(@function, 1, data);
end
for i = 1:n
[index, value] = fetchNext(F);
end
  댓글 수: 2
Rik
Rik 2018년 7월 14일
I couldn't find any comparisons with a quick search, although I did find that parfeval is (or used to be?) 'plagued by memory a leak'. I checked the release notes for mentions of parfeval, but nothing popped up.
In general I would assume that parfor is a better choice, but that might be a knee jerk reaction because of the feval part of its name.
Edric Ellis
Edric Ellis 2018년 7월 16일
The memory leak described in that bug report is shown as being fixed in R2015a.

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

채택된 답변

Edric Ellis
Edric Ellis 2018년 7월 16일
At least some of the trade-offs are:
  • parfor is generally easier to use, and the code probably looks much more like your serial code
  • parfor loops can be used by people who don't have Parallel Computing Toolbox
  • parfor loops perform a degree of load-balancing to try and minimise overheads
  • parfeval gives you complete control over how the work is chunked up for the workers
  • parfeval is asynchronous, and lets the MATLAB client get on with other stuff while the workers are busy (e.g. updating plots or other visualisations)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Asynchronous Parallel Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by