Main Content

Create codistributed array from distributed data


D =,codist)
D =,codist,'noCommunication')


D =,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 =,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 workers. Furthermore, the local part L must represent the region described by the globalIndices method on codist.


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

    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, ...
    % On 4 workers, codistr.Partition equals [251,250,250,250].
    % Allocate storage for the local part.
    localSize = [N, codistr.Partition(spmdIndex)];
    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 workers, globalInd has the values:
    % 1:251    on worker 1
    % 252:501  on worker 2
    % 502:751  on worker 3
    % 752:1001 on worker 4
    % Initialize the columns of the local part to 
    % the correct value.
    for localCol = 1:length(globalInd)
        globalCol = globalInd(localCol);
        L(:,localCol) = globalCol;
    D =,codistr)

Version History

Introduced in R2009b