User`s guide

3 Single Program Multiple Data (spmd)
3-8
0 0 1 0
0 0 0 1
Data transfers from worker to client when you explicitly assign a variable in the client
workspace using a Composite element:
M = MM{1} % Transfer data from worker 1 to variable M on the client
8 1 6
3 5 7
4 9 2
Assigning an entire Composite to another Composite does not cause a data transfer.
Instead, the client merely duplicates the Composite as a reference to the appropriate
data stored on the workers:
NN = MM % Set entire Composite equal to another, without transfer
However, accessing a Composite’s elements to assign values to other Composites does
result in a transfer of data from the workers to the client, even if the assignment then
goes to the same worker. In this case, NN must already exist as a Composite:
NN{1} = MM{1} % Transfer data to the client and then to worker
When finished, you can delete the pool:
delete(gcp)
Variable Persistence and Sequences of spmd
The values stored on the workers are retained between spmd statements. This allows
you to use multiple spmd statements in sequence, and continue to use the same variables
defined in previous spmd blocks.
The values are retained on the workers until the corresponding Composites are cleared
on the client, or until the parallel pool is deleted. The following example illustrates data
value lifespan with spmd blocks, using a pool of four workers:
parpool('local',4)
spmd
AA = labindex; % Initial setting
end