Composite
Create and access nondistributed variables on multiple workers from client
Description
Composite objects contain references to variables stored on parallel workers
running an spmd statement. A Composite
object resembles a cell array with one element for each worker and can contain different
values for each worker. You can retrieve values using cell-array indexing and define values
for the entries using indexing or an spmd block. The actual data on the
workers remains available for subsequent spmd execution, while the
Composite exists on the client and the parallel pool remains
open.
Creation
spmd statements automatically create composite variables on the
client when the body of an spmd statement returns values. Therefore, you
rarely need to create Composite objects directly.
You can also create Composite objects explicitly with the
Composite function.
Description
creates a
c = CompositeComposite object on the client using workers from the current parallel
pool.
The actual number of workers that the object references depends on the size of the
pool and any existing Composite objects. If a parallel pool is not open,
the Composite function starts a parallel pool of workers using the
default profile.
To create a Composite object manually, you must do so outside any
spmd statements. Initially, each entry of the manually created
Composite object contains no data. Define values for the entries by
using indexing or an spmd block.
specifies the number of workers to use to create a c = Composite(nworkers)Composite object. The
actual number of workers is the maximum number of workers compatible with the size of the
current parallel pool and with any other existing Composite objects. The
software returns an error if it cannot meet the constraints on the number of
workers.
creates a c = Composite(pool,___)Composite object using workers from the parallel pool specified
by the parallel.Pool object
pool. Use this syntax when you want to create
Composite objects on a pool other than the pool the gcp function returns. (since R2025a)
Input Arguments
Output Arguments
Object Functions
| exist | Check whether Composite is defined on workers |
| gather | Transfer distributed array, Composite object, or
gpuArray object to local workspace |
| subsasgn | Subscripted assignment for Composite |
| subsref | Subscripted reference for Composite |
Other object functions of a Composite object behave similarly to these
MATLAB® array functions:
Examples
Tips
The
Compositefunction creates aCompositeobject on the workers of the existing parallel pool. If no pool exists, theCompositefunction starts a new parallel pool unless automatically starting pools is disabled in your parallel settings. If no parallel pool exists andCompositecannot start one, the result is a 1-by-1Compositeobject in the client workspace.