eye - Create codistributed identity matrix - MATLAB (original) (raw)
Create codistributed identity matrix
Syntax
Description
`cI` = eye([n](#mw%5Fa1c27e11-c03b-409f-bd07-be09259287a7),[codist](#mw%5Ff9e54a6e-f69b-49a5-a171-1ed3b854a5ee))
creates an n
-by-n
codistributed identity matrix 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
.
`cI` = eye([n](#mw%5Fa1c27e11-c03b-409f-bd07-be09259287a7),[m](#mw%5F1fcf3d03-b26d-4980-914b-dca6e75b0487),[codist](#mw%5Ff9e54a6e-f69b-49a5-a171-1ed3b854a5ee))
creates an n
-by-m
codistributed identity matrix with ones on the main diagonal and zeros elsewhere. For example,eye(2,3,"codistributed")
creates a 2-by-3 codistributed array.
`cI` = eye([sz](#mw%5F659262be-ff96-49d3-875a-3e381f0f1a77),[codist](#mw%5Ff9e54a6e-f69b-49a5-a171-1ed3b854a5ee))
creates a codistributed identity matrix where the size vector sz
defines the size of cI
. For example, eye([2 3],"codistributed")
also creates a 2-by-3 codistributed identity matrix.
`cI` = eye(___,[datatype](#mw%5F08113a66-3c19-4af2-8cfa-7c6b0d8920b9),[codist](#mw%5Ff9e54a6e-f69b-49a5-a171-1ed3b854a5ee))
creates a codistributed identity matrix with the underlying data typedatatype
. For example,eye(1,"int8","codistributed")
creates a codistributed 8-bit scalar integer 1
. 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.
`cI` = eye(___,"noCommunication")
creates a codistributed identity matrix 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 andcodist arguments.
`cI` = eye(___,like=[p](#mw%5Fc4cd22a0-7736-4581-8c88-89dd328ff882))
uses the array p
to create a codistributed identity matrix. You can also specify "noCommunication"
as part of the function call.
The returned array cI
has the same underlying type, sparsity, and complexity (real or complex) as p
.
Examples
Create a 1000-by-1000 codistributed identity matrix, distributed using the default distribution scheme.
spmd(4) C = eye(1000,"codistributed"); end
With four workers, each worker contains a 1000-by-250 local piece ofC
.
Create a 1000-by-1000 codistributed uint16
identity matrix, distributed by its columns. Use a codistributor1d
object to define the distribution scheme.
spmd(4) codist = codistributor1d(2,100*[1:spmdSize]); C = eye(1000,1000,"uint16",codist) end
Worker 1: This worker stores C(:,1:100). LocalPart: [1000x100 uint16] Codistributor: [1x1 codistributor1d] Worker 2: This worker stores C(:,101:300). LocalPart: [1000x200 uint16] Codistributor: [1x1 codistributor1d] Worker 3: This worker stores C(:,301:600). LocalPart: [1000x300 uint16] Codistributor: [1x1 codistributor1d] Worker 4: This worker stores C(:,601:1000). LocalPart: [1000x400 uint16] Codistributor: [1x1 codistributor1d]
Each worker contains a 1000-by-100*spmdIndex
local piece ofC
.
You can also get the same codistributed array specifying the size vector.
spmd(4) C = eye([1000 1000],"uint16",codist); end
First, create a codistributed array. Specify the underlying data type as single
and use the default distribution scheme.
spmd(4) p = eye(1000,"single","codistributed"); end
Create a new codistributed array that is the same size and data type asp
. Use the 2-D block-cyclic codistributor2dbc
function to define the distribution scheme.
spmd C = eye(size(p),codistributor2dbc,"noCommunication",like=p); end
Input Arguments
Size of the first dimension of the identity matrix, specified as an integer.
- If
n
is the only integer input argument, thencI
is a square n-by-n codistributed identity matrix. - If
n
is0
, thencI
is an empty matrix. - If
n
is negative, then the function treats it as0
.
Distribution scheme for codistributed array, specified as one of these options:
"codistributed"
— Uses the default distribution scheme defined by the defaultcodistributor1d
object.- codistributor1d object — Uses the one-dimensional distribution scheme defined in a
codistributor1d
object. To use the default 1-D distribution scheme, you can specify thecodistributor1d
function without arguments. - codistributor2dbc object — Uses the two-dimensional block-cyclic distribution scheme defined in a
codistributor2dbc
object. To use the default 2-D block-cyclic distribution scheme, you can specify thecodistributor2dbc
function without arguments.
Size of the second dimension of the codistributed identity matrix, specified as an integer.
- If
m
is0
, thencI
is an empty matrix. - If
m
is negative, then the function treats it as0
.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Size of each dimension, specified as an integer row vector. Each element of this vector indicates the size of the corresponding dimension:
- If the size of any dimension is
0
, thencI
is an empty array. - If the size of any dimension is negative, then the function treats it as
0
. - Beyond the second dimension,
eye
ignores trailing dimensions with a size of1
. For example,eye([3 1 1 1],"codistributed")
produces a 3-by-1 codistributed identity matrix.
Example: sz = [2 3 4]
creates a 2-by-3-by-4 codistributed array.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Underlying data type of the returned array, specified as one of these options:
"double"
"single"
"logical"
"int8"
"uint8"
"int16"
"uint16"
"int32"
"uint32"
"int64"
"uint64"
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) asp
.
Version History
Introduced in R2006b