Products & Services Solutions Academia Support User Community Company

Learn more about Parallel Computing Toolbox   

Distributing Arrays

Distributed Versus Codistributed Arrays

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.

Creating Distributed Arrays

You can create a distributed array in any of several ways:

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 close

Creating Codistributed Arrays

You can create a codistributed array in any of several ways:

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 close

For more details on codistributed arrays, see Math with Codistributed Arrays, and Interactive Parallel Computation with pmode.

  


Recommended Products

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