Main Content


Allocate space for sparse codistributed matrix


SD = codistributed.spalloc(M,N,nzmax)
SD = spalloc(M,N,nzmax,codist)


SD = codistributed.spalloc(M,N,nzmax) creates an M-by-N all-zero sparse codistributed matrix with room to hold nzmax nonzeros.

Optional arguments to codistributed.spalloc must be specified after the required arguments, and in the following order:

  • codist — A codistributor object specifying the distribution scheme of the resulting array. If omitted, the array is distributed using the default distribution scheme. The allocated space for nonzero elements is consistent with the distribution of the matrix among the workers according to the Partition of the codistributor.

  • 'noCommunication' — Specifies that no communication is to be performed when constructing the array, skipping some error checking steps. You can also use this argument with SD = spalloc(M, N, nzmax, codistr).

SD = spalloc(M,N,nzmax,codist) is the same as SD = codistributed.spalloc(M,N,nzmax,codist). You can also use the optional arguments with this syntax.


Allocate space for a 1000-by-1000 sparse codistributed matrix with room for up to 2000 nonzero elements. Use the default codistributor. Define several elements of the matrix.

spmd  % codistributed array created inside spmd statement
    N = 1000;
    SD = codistributed.spalloc(N, N, 2*N);
    for ii=1:N-1
      SD(ii,ii:ii+1) = [ii ii];

Version History

Introduced in R2009b