Composite

Create Composite object

Syntax

C = Composite()
C = Composite(nlabs)

Description

C = Composite() creates a Composite object on the client using workers from the parallel pool. The actual number of workers referenced by this Composite object depends on the size of the pool and any existing Composite objects. Generally, you should construct Composite objects outside any spmd statement.

C = Composite(nlabs) creates a Composite object on the parallel pool set that matches the specified constraint. nlabs must be a vector of length 1 or 2, containing integers or Inf. If nlabs is of length 1, it specifies the exact number of workers to use. If nlabs is of size 2, it specifies the minimum and maximum number of workers to use. The actual number of workers used is the maximum number of workers compatible with the size of the parallel pool, and with other existing Composite objects. An error is thrown if the constraints on the number of workers cannot be met.

A Composite object has one entry for each lab; initially each entry contains no data. Use either indexing or an spmd block to define values for the entries.

Tips

  • A Composite is created on the workers of the existing parallel pool. If no pool exists, Composite starts a new parallel pool, unless the automatic starting of pools is disabled in your parallel preferences. If there is no parallel pool and Composite cannot start one, the result is a 1-by-1 Composite in the client workspace.

Examples

The following examples all use a local parallel pool of four workers, opened with the statement:

p = parpool('local',4);

This example shows how to create a Composite object with no defined elements, then assign values using a for-loop in the client.

c = Composite();  % One element per worker in the pool
for w = 1:length(c)
    c{w} = 0;    % Value stored on each worker
end

This example shows how to assign Composite elements in an spmd block.

c = Composite();
spmd
    c = 0;    % Value stored on each worker
end

This example shows how to assign the elements of a Composite with a value from each worker.

c = Composite();
spmd
    c = labindex;
end
c{:}
     1


     2


     3


     4

This example shows how to use a distributed array vector to set the values of a Composite.

d = distributed([3 1 4 2]); % One integer per worker
spmd
    c = getLocalPart(d);    % Unique value on each worker
end
c{:}
     3


     1


     4


     2
Was this topic helpful?