User`s guide

Distribute Arrays
3-11
requirements. These overloaded functions include eye(___,'distributed'),
rand(___,'distributed'), etc. For a full list, see the distributed object
reference page.
Create a codistributed array inside an spmd statement, then access it as a distributed
array outside the spmd statement. This lets you use distribution schemes other than
the default.
The first two of these techniques do not involve spmd in creating the array, but you can
see how spmd might be used to manipulate arrays created this way. For example:
Create an array in the client workspace, then make it a distributed array:
parpool('local',2) % Create pool
W = ones(6,6);
W = distributed(W); % Distribute to the workers
spmd
T = W*2; % Calculation performed on workers, in parallel.
% T and W are both codistributed arrays here.
end
T % View results in client.
whos % T and W are both distributed arrays here.
delete(gcp) % Stop pool
Create Codistributed Arrays
You can create a codistributed array in any of several ways:
Use the codistributed function inside an spmd statement, a communicating job, or
pmode to codistribute data already existing on the workers running that job.
Use any of the overloaded codistributed object methods to directly construct
a codistributed array on the workers. This technique does not require that
the array already exists in the workers. These overloaded functions include
eye(___,'codistributed'), rand(___,'codistributed'), etc. For a full list,
see the codistributed object reference page.
Create a distributed array outside an spmd statement, then access it as a
codistributed array inside the spmd statement running on the same parallel pool.
In this example, you create a codistributed array inside an spmd statement, using a
nondefault distribution scheme. First, define 1-D distribution along the third dimension,
with 4 parts on worker 1, and 12 parts on worker 2. Then create a 3-by-3-by-16 array of
zeros.