Skip to Main Content Skip to Search
Product Documentation

codistributed.build - Create codistributed array from distributed data

Syntax

D = codistributed.build(L, codist)
D = codistributed.build(L, codist, 'noCommunication')

Description

D = codistributed.build(L, codist) forms a codistributed array with getLocalPart(D) = L. The codistributed array D is created as if you had combined all copies of the local array L. The distribution scheme is specified by codist. Global error checking ensures that the local parts conform with the specified distribution scheme. For information on constructing codistributor objects, see the reference pages for codistributor1d and codistributor2dbc.

D = codistributed.build(L, codist, 'noCommunication') builds a codistributed array, without performing any interworker communications for error checking.

codist must be complete, which you can check by calling codist.isComplete(). The requirements on the size and structure of the local part L depend on the class of codist. For the 1-D and 2-D block-cyclic codistributors, L must have the same class and sparsity on all labs. Furthermore, the local part L must represent the region described by the globalIndices method on codist.

Examples

Create a codistributed array of size 1001-by-1001 such that column ii contains the value ii.

spmd
    N = 1001;
    globalSize = [N, N];
    % Distribute the matrix over the second dimension (columns),
    % and let the codistributor derive the partition from the 
    % global size.
    codistr = codistributor1d(2, ...
                 codistributor1d.unsetPartition, globalSize)
 
    % On 4 labs, codistr.Partition equals [251, 250, 250, 250].
    % Allocate storage for the local part.
    localSize = [N, codistr.Partition(labindex)];
    L = zeros(localSize);
    
    % Use globalIndices to map the indices of the columns 
    % of the local part into the global column indices.
    globalInd = codistr.globalIndices(2); 
    % On 4 labs, globalInd has the values:
    % 1:251    on lab 1
    % 252:501  on lab 2
    % 502:751  on lab 3
    % 752:1001 on lab 4
    
    % Initialize the columns of the local part to 
    % the correct value.
    for localCol = 1:length(globalInd)
        globalCol = globalInd(localCol);
        L(:, localCol) = globalCol;
    end
    D = codistributed.build(L, codistr)
end

See Also

codistributor1d | codistributor2dbc | gather | getLocalPart | globalIndices | redistribute | size | subsasgn | subsref

  


Free Parallel Computing Interactive Kit

See how to solve large problems with minimal effort and reduce simulation time.

Get free kit

Trials Available

Try the latest versions of parallel computing products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS