Skip to Main Content Skip to Search
Product Documentation

codistributed.sprand - Create codistributed sparse array of uniformly distributed pseudo-random values

Syntax

CS = codistributed.sprand(m, n, density)
CS = sprand(n, codist)

Description

CS = codistributed.sprand(m, n, density) creates an m-by-n sparse codistributed array with approximately density*m*n uniformly distributed nonzero double entries.

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

CS = sprand(n, codist) is the same as CS = codistributed.sprand(n, codist). You can also use the optional arguments with this syntax. To use the default distribution scheme, specify a codistributor constructor without arguments. For example:

spmd
    CS = codistributed.sprand(8, 8, 0.2, codistributor1d());
end

Tips

When you use sprand on the workers in the MATLAB pool, or in a distributed or parallel job (including pmode), each worker or lab sets its random generator seed to a value that depends only on the lab index or task ID. Therefore, the array on each lab is unique for that job. However, if you repeat the job, you get the same random data.

Examples

With four labs,

spmd(4)
    CS = codistributed.sprand(1000, 1000, .001);
end

creates a 1000-by-1000 sparse codistributed double array CS with approximately 1000 nonzeros. CS is distributed by its second dimension (columns), and each lab contains a 1000-by-250 local piece of CS.

spmd(4)
    codist = codistributor1d(2, 1:numlabs);
    CS = sprand(10, 10, .1, codist);
end

creates a 10-by-10 codistributed double array CS with approximately 10 nonzeros. CS is distributed by its columns, and each lab contains a 10-by-labindex local piece of CS.

See Also

codistributed.rand | distributed.sprandn | sprand

  


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