User`s guide
Working with Codistributed Arrays
5-5
Working with Codistributed Arrays
In this section...
“How MATLAB Software Distributes Arrays” on page 5-5
“Creating a Codistributed Array” on page 5-7
“Local Arrays” on page 5-10
“Obtaining information About the Array” on page 5-11
“Changing the Dimension of Distribution” on page 5-12
“Restoring the Full Array” on page 5-13
“Indexing into a Codistributed Array” on page 5-14
“2-Dimensional Distribution” on page 5-16
How MATLAB Software Distributes Arrays
When you distribute an array to a number of workers, MATLAB software partitions
the array into segments and assigns one segment of the array to each worker. You can
partition a two-dimensional array horizontally, assigning columns of the original array to
the different workers, or vertically, by assigning rows. An array with N dimensions can
be partitioned along any of its N dimensions. You choose which dimension of the array is
to be partitioned by specifying it in the array constructor command.
For example, to distribute an 80-by-1000 array to four workers, you can partition it
either by columns, giving each worker an 80-by-250 segment, or by rows, with each
worker getting a 20-by-1000 segment. If the array dimension does not divide evenly over
the number of workers, MATLAB partitions it as evenly as possible.
The following example creates an 80-by-1000 replicated array and assigns it to variable
A. In doing so, each worker creates an identical array in its own workspace and assigns
it to variable A, where A is local to that worker. The second command distributes A,
creating a single 80-by-1000 array D that spans all four workers. Worker 1 stores
columns 1 through 250, worker 2 stores columns 251 through 500, and so on. The default
distribution is by the last nonsingleton dimension, thus, columns in this case of a 2-
dimensional array.
spmd
A = zeros(80, 1000);
D = codistributed(A)