randi - Create codistributed array of uniformly distributed random integers - MATLAB (original) (raw)

Create codistributed array of uniformly distributed random integers

Syntax

Description

`cR` = randi([r](#mw%5F03c40910-3dc5-4a1e-87bb-887d4f55e5eb),[n](#mw%5F8e758702-cd75-4bf2-ba82-f429d4693d64),[codist](#mw%5Fb795333a-2e81-424e-bb51-7858b86f2e58)) creates an n-by-n codistributed matrix of uniformly distributed random integers in the range defined byr and uses codist to specify the distribution of the array values across the workers.

Specify codist as "codistributed" to use the default codistributor1d distribution scheme or the distribution scheme defined by a codistributor1d or codistributor2dbc object.

When you create the codistributed array in a communicating job or spmd block, the function creates an array on each worker. If you create a codistributed array outside of a communicating job or spmd block, the array is stored only on the worker or client that creates the codistributed array.

By default, the codistributed array has the underlying type double.

example

`cR` = randi([r](#mw%5F03c40910-3dc5-4a1e-87bb-887d4f55e5eb),[sz](#mw%5F3aecd0b0-74f0-4077-9d32-6b27cc83f35d),[codist](#mw%5Fb795333a-2e81-424e-bb51-7858b86f2e58)) creates a codistributed array of uniformly distributed random integers where the size vector sz defines the size of cR. For example, randi(5,[2 3],"codistributed") creates a 2-by-3 codistributed array of random integers between 1 and5.

`cR` = randi([r](#mw%5F03c40910-3dc5-4a1e-87bb-887d4f55e5eb),[sz1,...,szN](#mw%5F28062e06-0243-44a2-b6ba-bfaeeb0faee6),[codist](#mw%5Fb795333a-2e81-424e-bb51-7858b86f2e58)) creates an sz1-by-...-by-szN codistributed array of uniformly distributed random integers between 1 tor. sz1,...,szN indicates the size of each dimension.

`cR` = randi(___,[datatype](#mw%5F5e05fc03-1aa0-46c1-8869-0dd6657a7f2f),[codist](#mw%5Fb795333a-2e81-424e-bb51-7858b86f2e58)) creates a codistributed array of uniformly distributed random integers with the underlying type datatype. For example,randi([1,5],1,"int8","codistributed") creates a codistributed 8-bit random integer between 10 and50. You can use this syntax with any of the size arguments in the previous syntaxes. You must specify codist after the array size and data type arguments.

`cR` = randi(___,"noCommunication") creates a codistributed array of uniformly distributed random integers without using communication between workers.

When you create very large arrays or your communicating job or spmd block uses many workers, worker-worker communication can slow down array creation. Use this syntax to improve the performance of your code by removing the time required for worker-worker communication.

Tip

When you use this syntax, some error checking steps are skipped. Use this syntax to improve the performance of your code after you prototype your code without specifying "noCommunication".

You must specify "noCommunication" after the size, data type and codist arguments.

`cR` = randi(___,like=[p](#mw%5Fb558251e-30f8-4dfb-bcda-dc32abefcc9f)) uses the array p to create a codistributed array of uniformly distributed random integers. You can also specify"noCommunication" as part of the function call.

The returned array cR has the same underlying type, sparsity, and complexity (real or complex) as p.

Examples

collapse all

Create a 1000-by-1000 codistributed double matrix ofrandi values from 0 to 12, distributed by its second dimension (columns).

spmd(4) C = randi([0 12],1000,"codistributed"); end

With four workers, each worker contains a 1000-by-250 local piece ofC.

Create a 1000-by-1000 codistributed single matrix ofrandi values from 1 to 4, distributed by its columns.

spmd(4) codist = codistributor1d(2,100*[1:spmdSize]); C = randi(4,1000,1000,"single",codist); end

Each worker contains a 100-by-spmdIndex local piece ofC.

Input Arguments

collapse all

Range of output values, specified as an integer scalar or vector.

Size of the square matrix, specified as an integer.

Distribution scheme for codistributed array, specified as one of these options:

Size of each dimension, specified as an integer row vector. Each element of this vector indicates the size of the corresponding dimension:

Example: [2 3 4] creates a 2-by-3-by-4 codistributed array.

Size of each dimension, specified as separate arguments of integer values.

Underlying data type of the returned array, specified as one of these options:

Prototype of array to create, specified as a codistributed array.

If you do not specify the datatype, the resulting codistributed array has the same underlying type, sparsity, and complexity (real or complex) as p.

Version History

Introduced in R2014a