codistributed.sprandn
Create codistributed sparse array of normally distributed pseudo-random values
Syntax
CS = codistributed.sprandn(m,n,density)
CS = sprandn(n,codist)
CS = distributed.sprandn(___,typename)
Description
CS = codistributed.sprandn(m,n,density)
creates an m
-by-n
sparse codistributed array with approximately density*m*n
normally distributed nonzero double entries.
Optional arguments to codistributed.sprandn
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. For information on constructing codistributor objects, see the reference pages forcodistributor1d
andcodistributor2dbc
.'noCommunication'
— Specifies that no interworker communication is to be performed when constructing the array, skipping some error checking steps.
CS = sprandn(n,codist)
is the same as CS =
codistributed.sprandn(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.sprandn(8,8,0.2,codistributor1d); end
CS = distributed.sprandn(___,typename)
also specifies
the data type (class) of any of the previous syntaxes. The typename
input can be either "single"
or "double"
. (since R2025a)
Examples
With four workers, create a 1000-by-1000 sparse codistributed double array
CS
with approximately 1000 nonzeros. CS
is
distributed by its second dimension (columns).
spmd(4) CS = codistributed.sprandn(1000,1000,0.001); end
Create a 10-by-10 codistributed double array CS
with approximately 10
nonzeros. CS
is distributed by its columns, and each worker contains
a 10-by-spmdIndex
local piece of CS
.
spmd(4) codist = codistributor1d(2,1:spmdSize); CS = sprandn(10,10,0.1,codist); end
Create a random 500-by-1000 sparse codistributed single-precision matrix with density 0.1.
spmd(5) DS = distributed.sprandn(500,1000,0.1,"single"); end
Tips
When you use sprandn
on the workers in the parallel pool, or in an independent or communicating job, each worker sets its random generator seed to a value that depends only on the spmdIndex
or task ID. Therefore, the array on each worker is unique for that job. However, if you repeat the job, you get the same random data.
Version History
Introduced in R2009bSee Also
sprandn
| rand
| randn
| sparse
| codistributed.speye
| codistributed.sprand
| distributed.sprandn