Hi,
I'm trying to use parfeval and fetchNext, but I don't think I'm settling them up correctly. My parallel pool has 4 workers. I'm setting up parfeval in a for-loop, as shown in the manual, with fetchNext in a subsequent for-loop. I thought that fetchNext should be able to extract values from parfeval as they are produced, but it appears to only extract them once all iterations of the first loop are complete.
I'm practising with the code from the parfeval and fetchNext pages of the manual. When I put a breakpoint at the 'fetchNext' line of the code below, it always shows all of the FevalFuture items complete before the breakpoint is reached. If I include a "disp('par')" and "disp('fetch')" inside each loop then all the "disp('par')" are printed out first and then all the "disp('fetch')" are printed out afterwards.
Also, on this code using fetchNext is actually slower than fetchOutputs. The fetchNext version takes 73 seconds, whereas the fetchOutputs version at the bottom only takes 31 seconds.
Any help very much appreciated!
p = gcp();
tic
for idx = 1:10000
f(idx) = parfeval(@rand,1,1);
end
for idx = 1:10000
[completedIdx,value(completedIdx)] = fetchNext(f);
end
toc
p = gcp();
tic
for idx = 1:10000
f(idx) = parfeval(@rand,1,1);
end
R = fetchOutputs(f);
toc