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 F to finish, and then returns the index of that future in array F as idx, along with the future's results in B1,B2,...,Bn. Before this call, the 'Read' property of the particular future is false; afterward it is true.
[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 F whose 'Read' property is 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 fetchNext. However, that future's 'Read' property is set true, so that any subsequent calls to fetchNext can proceed.
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)