fetchOutputs - Retrieve results from function running in the background - MATLAB (original) (raw)
Retrieve results from function running in the background
Syntax
Description
[[Y1,...,Ym](#mw%5F5bb50736-f285-4816-af51-143ac5aef6be)] = fetchOutputs([F](#mw%5F99069dba-6f36-49cd-bc09-227b66bf3129))
retrieves m
results from a Future
arrayF
.
Each element in F
must return at least m
output arguments. To check how many output arguments a Future
object has, use theNumOutputArguments
property.
MATLAB® waits for the function associated with each element in F
to finish before retrieving results from that element. The State
property of a Future
object is 'finished'
when the associated function is finished. When you use fetchOutputs
, MATLAB sets the Read
property of each element inF
to true
.
You create a Future
object when you use parfeval,parfevalOnAll
, afterEach, orafterAll to:
- Run a function in the background using backgroundPool.
- Run a function on a parallel pool worker when you use Parallel Computing Toolbox™.
If F
is an array of Future
objects, the jth output from each element in F
is concatenated to form the output Yj
. Use this syntax only if the jth output from each element can be concatenated along the first dimension.
[[Y1,...,Ym](#mw%5F5bb50736-f285-4816-af51-143ac5aef6be)] = fetchOutputs([F](#mw%5F99069dba-6f36-49cd-bc09-227b66bf3129),UniformOutput=false)
retrieves m
results as cell arrays from a Future
arrayF
.
If F
is an array of Future
objects, the jth output from each element in F
is concatenated in a cell array to form the output Yj
. Use this syntax if, for any output of Yj
, you are unable to concatenate the output from each element along the first dimension.
Examples
This example shows how to run a function in the background using parfeval
and backgroundPool
. When you run a function in the background, you can run other MATLAB® code at the same time.
Use parfeval
to run the function magic(3)
and retrieve one output. Specify backgroundPool
as the first argument to run the function in the background. When you use parfeval
, you create a Future
object.
f = parfeval(backgroundPool,@magic,1,3);
To retrieve the output from the background, use fetchOutputs
. MATLAB returns the output once the execution of magic
is complete.
ans = 3×3
8 1 6
3 5 7
4 9 2
Input Arguments
Input Future
, specified as a parallel.Future
scalar or array.
Example: F = parfeval(backgroundPool,@magic,1,3);
Output Arguments
Output arguments from futures. The type of the outputs depends on theFuture
scalar or array f
, and the functions eachFuture
is associated with.
- If
UniformOutput
is specified asfalse
, the jth output argument is a cell array containingn
elements, wheren
is the number of elements in F. - Otherwise, the jth output argument is an array of type returned by the jth output of each element in
F
.
Each element in F
must return at least m
output arguments. To check how many output arguments a Future
has, use the NumOutputArguments
property.
Version History
Introduced in R2013b