how MATLAB's parfeval function works?

2 次查看(过去 30 天)
Jack
Jack 2015-2-12
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