parallel.pool.Constant
Description
Create a Constant
object to avoid unnecessarily copying data
multiple times from your current MATLAB® session to workers in a parallel pool or background pool. The value you access
in a Constant
object is constant.
If you have Parallel Computing Toolbox™, use a
Constant
object to avoid unnecessarily copying data to workers in a parallel pool. For more information, seeparallel.pool.Constant
(Parallel Computing Toolbox).If you do not have Parallel Computing Toolbox, you can still use
Constant
objects in the background pool. (since R2023a)If you do not have a parallel pool and do not want to use the background pool, you can still use
Constant
objects. TheConstant
is only created in your current MATLAB session. UseConstant
when you run portable parallel code designed to work with or without Parallel Computing Toolbox.
For more information about running parallel code without Parallel Computing Toolbox, see Run Parallel Language in MATLAB.
Creation
Use parallel.pool.Constant
to create a Constant
object
from an array or a function handle. Use the Value
property to access
underlying data.
Syntax
Description
uses the array C
= parallel.pool.Constant(X
)X
to create a Constant
. Use the
Value
property to read the data.
uses the function handle C
= parallel.pool.Constant(fcn
)fcn
to create a Constant
object C
. Use the Value
property to get the
result from running fcn()
with one output.
Note
Use this function handle syntax to create a Constant
object when
you want to have the same variable name for a handle-type resource in your current
MATLAB session and on a parallel pool. For example, use the function handle
syntax to set up a database connection both in your current MATLAB and on a parallel pool. If you want to evaluate a function on each
worker to set up workers before computations, use parfevalOnAll
(Parallel Computing Toolbox) instead.
runs C
= parallel.pool.Constant(fcn
,cleanupFcn
)cleanupFcn(C.Value)
when C
is cleared.
Input Arguments
Properties
Examples
Extended Capabilities
Version History
Introduced in R2021bSee Also
backgroundPool
| parfor
(Parallel Computing Toolbox) | spmd
(Parallel Computing Toolbox) | parpool
(Parallel Computing Toolbox) | parfeval