Main Content

codistributor1d

1-D distribution scheme for codistributed array

    Description

    Use a codistributor1d object to define the one-dimensional distribution scheme for a codistributed array. The one-dimensional codistributor distributes arrays along a single specified dimension, the distribution dimension, in a noncyclic, partitioned manner.

    Creation

    Description

    codist = codistributor1d returns a codistributor1d object using the default dimension and partition. The default dimension is the last nonsingleton dimension of the codistributed array. The default partition distributes the array along the default dimension as evenly as possible.

    example

    codist = codistributor1d(Dimension) returns a 1-D codistributor object for distribution along the dimension specified by the Dimension property. For example, if Dimension is 1, the function distributes the object along rows.

    codist = codistributor1d(Dimension,Partition) also returns a 1-D codistributor object for distribution according to the partition vector specified by the Partition property. For example, C1 = codistributor1d(1,[1,2,3,4]) distributes an array of 10 rows to four workers, with one row to the first worker, two rows to the second worker, three rows to the third worker, and four rows to the fourth worker.

    The resulting codistributor of any of the above syntaxes is incomplete because its global size is not specified. Use a codistributor constructed this way as an argument to other functions as a template codistributor when creating codistributed arrays.

    example

    codist = codistributor1d(Dimension,Partition,gsize) returns a codistributor object with the global size gsize.

    You can use the resulting codistributor object to build a codistributed array from its local parts with codistributed.build. To use a default dimension, specify codistributor1d.unsetDimension for the Dimension property; the function derives the distribution dimension from gsize and selects the last nonsingleton dimension as the default dimension. Similarly, to use a default partition, specify codistributor1d.unsetPartition for the Partition property; the function derives the default partition from the global size and distribution dimension.

    The local part on worker workerIndex of a codistributed array using such a codistributor is of size gsize in all dimensions except dimension, where the size is part(workerIndex). The local part has the same class and attributes as the overall codistributed array. The overall global array can be reconstructed by concatenating the various local parts along dimension dimension.

    Input Arguments

    expand all

    Global size of the codistributed array, specified as an integer.

    Properties

    expand all

    Distribution dimension, specified as a scalar integer. The distribution dimension specifies the dimension over which you distribute the codistributed array.

    Partitioning vector, specified as an integer row vector. The partitioning vector specifies the distribution of the codistributed array to the workers.

    Object Functions

    codistributed.cellCreate codistributed cell array
    codistributed.colonDistributed colon operation
    codistributed.spallocAllocate space for sparse codistributed matrix
    codistributed.speyeCreate codistributed sparse identity matrix
    codistributed.sprandCreate codistributed sparse array of uniformly distributed pseudo-random values
    codistributed.sprandnCreate codistributed sparse array of normally distributed pseudo-random values
    eyeCreate codistributed identity matrix
    falseCreate codistributed array of logical 0 (false)
    globalIndicesGlobal indices for local part of codistributed array
    InfCreate codistributed array of all Inf values
    isCompleteTrue if codistributor object is complete
    NaNCreate codistributed array of all NaN values
    onesCreate codistributed array of all ones
    randCreate codistributed array of uniformly distributed random numbers
    randnCreate codistributed array of normally distributed random numbers
    sparseCreate codistributed sparse matrix
    trueCreate codistributed array of logical 1 (true)
    zerosCreate codistributed array of all zeros

    Examples

    collapse all

    Use a codistributor1d object to create an N-by-N matrix of ones, distributed by rows.

    N = 1000;
    spmd
        codistr = codistributor1d(1); % 1st dimension (rows)
        C = ones(N,codistr);
    end

    Use a fully specified codistributor1d object to create a N-by-N codistributed matrix from its local parts. Then visualize which elements are stored on worker 2.

    Start with full sized array on each worker then set myLocalSize to default part of whole array.

    N = 1000;
    spmd
        codistr = codistributor1d( ...
                        codistributor1d.unsetDimension, ...
                        codistributor1d.unsetPartition, ...
                        [N N]);
        myLocalSize = [N N]; % 
        myLocalSize(codistr.Dimension) = codistr.Partition(spmdIndex);
        myLocalPart = spmdIndex*ones(myLocalSize);
        D = codistributed.build(myLocalPart,codistr);
    end
    spy(D==2);

    Version History

    Introduced in R2009b