how MATLAB's parfeval function works?
2 views (last 30 days)
Show older comments
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 Comment
Edric Ellis
on 13 Feb 2015
This question was fairly comprehensively answered over on stack overflow. Is there any more detail you need?
Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!