parallel.pool.Constant
Build and use constant from data or function handle
Description
Use a Constant
object to avoid unnecessarily copying data
multiple times from your current MATLAB® session to workers in a parallel pool. You can build a Constant
object once on a client and transfer the constant to the workers once. Access the
Constant
in multiple parfor
-loops, spmd
blocks, or parfeval
calls. The value you access in a Constant
object is
constant. You can share your parallel code that uses Constant
objects with
MATLAB users who do not have Parallel Computing Toolbox™. For more information, see parallel.pool.Constant
.
Creation
Use parallel.pool.Constant
to create a Constant
object
from an array, a function handle, or a composite object. Use the Value
property to access underlying data.
Syntax
Description
copies the array C
= parallel.pool.Constant(X
)X
to each worker and returns a
Constant
object.
Each worker can access the array X
within a parallel language
construct (parfor
, spmd
,
parfeval
) using the Value
property to read the
data.
evaluates the function handle C
= parallel.pool.Constant(FH
)FH
on each worker and stores the
results in the Constant
object C
. Use the
Value
property to access the result from running
FH()
with one output.
Use this syntax to create and use any handle-type resources on a parallel pool, such
as file handles and database connections. If you want to evaluate a function on each
worker to set up workers before computations, use parfevalOnAll
instead.
stores the values in the entries of the C
= parallel.pool.Constant(COMP
)Composite
object
COMP
in the Constant
object C
on each worker.
Use this syntax when you want to construct data only on the workers, such as when the
data is too large to conveniently fit in the client, or when you load the data from a file
that only the workers can access. Access the values using the Value
property.
Input Arguments
Properties
Examples
Tips
You must use the parallel.pool.Constant
function in the MATLAB client session.
You can use a Constant
object with an already running parallel pool or
subsequent parallel pools.
Extended Capabilities
Version History
Introduced in R2015bSee Also
parfor
| spmd
| parpool
| parcluster
| parfeval
| tempname
| fclose
| spmdBroadcast