how MATLAB's parfeval function works?

조회 수: 1 (최근 30일)
Jack
Jack 2015년 2월 12일
댓글: Edric Ellis 2015년 2월 13일
In MATLAB documentation we have a code example for parfeval function. I have some questions about it. This is the code:
p = gcp();
% To request multiple evaluations, use a loop.
for idx = 1:10
f(idx) = parfeval(p,@magic,1,idx); % Square size determined by idx
end
% Collect the results as they become available.
magicResults = cell(1,10);
for idx = 1:10
% fetchNext blocks until next results are available.
[completedIdx,value] = fetchNext(f);
magicResults{completedIdx} = value;
fprintf('Got result with index: %d.\n', completedIdx);
end
1. How parfeval works? This function send every (idx) evaluational of magicfunction to a specific worker?
2. If we have only one line code f = parfeval(p,@magic,1,10); . How this code works? It will send evaluation only to one worker and returns the output? So what is difference between parfeval and parfevalOnAll?
3. What is difference between fetchNext and fetchOutputs? Why after first for loop we need fetchNext and a second loop to get the results? We don't have all results after first loop? why? I think we are waiting for workers to complete the process in second loop. Is this true? We can't do it without any loop?
4. I think we can use magicResults{idx} = fetchOutputs(f(idx)); in second loop. We have same results. what is difference between these two structures?
  댓글 수: 1
Edric Ellis
Edric Ellis 2015년 2월 13일
This question was fairly comprehensively answered over on stack overflow. Is there any more detail you need?

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

답변 (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