| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Parallel Computing Toolbox |
| Contents | Index |
| Learn more about Parallel Computing Toolbox |
| On this page… |
|---|
You can create a distributed array in the MATLAB client, and its data is stored on the labs of the open MATLAB pool. A distributed array is distributed in one dimension, along the last nonsingleton dimension, and as evenly as possible along that dimension among the labs. You cannot control the details of distribution when creating a distributed array.
You can create a codistributed array by executing on the labs themselves, either inside an spmd statement, in pmode, or inside a parallel job. When creating a codistributed array, you can control all aspects of distribution, including dimensions and partitions.
The relationship between distributed and codistributed arrays is one of perspective. Codistributed arrays are partitioned among the labs from which you execute code to create or manipulate them. Distributed arrays are partitioned among labs from the client with the open MATLAB pool. When you create a distributed array in the client, you can access it as a codistributed array inside an spmd statement. When you create a codistributed array in an spmd statement, you can access is as a distributed array in the client. Only spmd statements let you access the same array data from two different perspectives.
You can create a distributed array in any of several ways:
Use the distributed function to distribute an existing array from the client workspace to the labs of an open MATLAB pool.
Use any of the overloaded distributed object methods to directly construct a distributed array on the labs. This technique does not require that the array already exists in the client, thereby reducing client workspace memory requirements. These overloaded functions include distributed.eye, distributed.rand, 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:
mablabpool open local 2
W = ones(6,6);
W = distributed(W); % Distribute to the labs
spmd
T = W*2; % Calculation performed on labs, in parallel.
% T and W are both codistributed arrays here.
end
T % View results in client.
% T and W are both distributed arrays here.
matlabpool closeYou can create a codistributed array in any of several ways:
Use the codistributed function inside an spmd statement, a parallel job, or pmode to codistribute data already existing on the labs running that job.
Use any of the overloaded codistributed object methods to directly construct a codistributed array on the labs. This technique does not require that the array already exists in the labs. These overloaded functions include codistributed.eye, codistributed.rand, 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 MATLAB 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 lab 1, and 12 parts on lab 2. Then create a 3-by-3-by-16 array of zeros.
matlabpool open local 2
spmd
codist = codistributor1d(3, [4, 12]);
Z = codistributed.zeros(3, 3, 16, codist);
Z = Z + labindex;
end
Z % View results in client.
% Z is a distributed array here.
matlabpool closeFor more details on codistributed arrays, see Math with Codistributed Arrays, and Interactive Parallel Computation with pmode.
![]() | Accessing Data with Composites | Programming Considerations | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |