Retrieve next available unread FevalFuture outputs
[idx,B1,B2,...,Bn] = fetchNext(F)
[idx,B1,B2,...,Bn] = fetchNext(F,TIMEOUT)
[idx,B1,B2,...,Bn] = fetchNext(F) waits
for an unread FevalFuture in the array of futures
finish, and then returns the linear index of that future in array
along with the future’s results in
Before this call, the
'Read' property of the particular
false; afterward it is
[idx,B1,B2,...,Bn] = fetchNext(F,TIMEOUT) waits
no longer than
TIMEOUT seconds for a result to
become available. If the timeout expires before any result becomes
available, all output arguments are empty.
If there are no futures in
false, then an error is reported. You can check
whether there are any unread futures using
anyUnread = ~all([F.Read]).
If the element of
F which has become finished
encountered an error during execution, that error will be thrown by
However, that future’s
'Read' property is
true, so that any subsequent calls to
Request several function evaluations, and update a progress bar while waiting for completion.
N = 100; for idx = N:-1:1 % Compute the rank of N magic squares F(idx) = parfeval(@rank,1,magic(idx)); end % Build a waitbar to track progress h = waitbar(0,'Waiting for FevalFutures to complete...'); results = zeros(1,N); for idx = 1:N [completedIdx,thisResult] = fetchNext(F); % store the result results(completedIdx) = thisResult; % update waitbar waitbar(idx/N,h,sprintf('Latest result: %d',thisResult)); end delete(h)
fetchNext function returns the linear
index of the future from its array. If instead, you need the subscript
values of a multidimensional array, you can use the
ind2sub function to convert the values.