zeros - Create codistributed array of all zeros - MATLAB (original) (raw)

Create codistributed array of all zeros

Syntax

Description

`cZ` = zeros([n](#mw%5F9bcb8f1c-9787-434f-ac78-cb60afdbabf1),[codist](#mw%5Fb46e723e-b965-4985-a2cf-d95666d5e95a)) creates an n-by-n codistributed matrix of zeros 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

`cZ` = zeros([sz](#mw%5F092d1ae5-47a8-4652-8bf1-5d877ef30853),[codist](#mw%5Fb46e723e-b965-4985-a2cf-d95666d5e95a)) creates a codistributed array of zeros where the size vector sz defines the size of cZ. For example, zeros([2 3],"codistributed") creates a 2-by-3 codistributed array.

`cZ` = zeros([sz1,...,szN](#mw%5F83305120-4d59-4dc3-861b-fd5e4514bb8f),[codist](#mw%5Fb46e723e-b965-4985-a2cf-d95666d5e95a)) creates an sz1-by-...-by-szN codistributed array of zeros where sz1,...,szN indicates the size of each dimension.

`cZ` = zeros(___,[datatype](#mw%5F6dbd78e8-e5d6-4bba-a06a-5c2081ba4273),[codist](#mw%5Fb46e723e-b965-4985-a2cf-d95666d5e95a)) creates a codistributed array of zeros with the underlying typedatatype. For example,zeros(1,"int8","codistributed") creates a codistributed 8-bit scalar integer 0. 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.

`cZ` = zeros(___,"noCommunication") creates a codistributed array of zeros 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.

`cZ` = zeros(___,like=[p](#mw%5F1add679a-362c-4bc0-a504-d578b5af6feb)) uses the array p to create a codistributed array of zeros. You can specify datatype or "like", but not both. You can also specify "noCommunication" as part of the function call.

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

Examples

collapse all

Create Codistributed Zeros Matrix

Create a 1000-by-1000 codistributed double matrix of zeros, distributed by its second dimension (columns).

spmd(4) C = zeros(1000,"codistributed"); end

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

Create a 1000-by-1000 codistributed uint16 matrix of zeros, distributed by its columns.

spmd(4) codist = codistributorId(2,100*[1:spmdSize]); C = zeros(1000,1000,"uint16",codist); end

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

Input Arguments

collapse all

n — Size of square matrix

integer

Size of the square matrix, specified as an integer.

codist — Distribution scheme for codistributed array

"codistributed" | codistributor1d object | codistributor2dbc object

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

sz — Size of each dimension (as a row vector)

integer row vector

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

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

sz1,...,szN — Size of each dimension (as separate arguments)

integer values

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

datatype — Array underlying data type

"double" (default) | "single" | "logical" | "int8" | "uint8" | ...

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

p — Prototype of array to create

codistributed array

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