User`s guide

5 Math with Codistributed Arrays
5-22
D = eye(8, 8, codistributor())
E = zeros(8, 8, codistributor())
By default, these arrays are distributed by columns; that is, each of the four workers
contains two columns of each array. If you use these arrays in a for-drange loop, any
calculations must be self-contained within each worker. In other words, you can only
perform calculations that are limited within each worker to the two columns of the arrays
that the workers contain.
For example, suppose you want to set each column of array E to some multiple of the
corresponding column of array D:
for j = drange(1:size(D,2)); E(:,j) = j*D(:,j); end
This statement sets the j-th column of E to j times the j-th column of D. In effect, while
D is an identity matrix with 1s down the main diagonal, E has the sequence 1, 2, 3, etc.,
down its main diagonal.
This works because each worker has access to the entire column of D and the entire
column of E necessary to perform the calculation, as each worker works independently
and simultaneously on two of the eight columns.
Suppose, however, that you attempt to set the values of the columns of E according to
different columns of D:
for j = drange(1:size(D,2)); E(:,j) = j*D(:,j+1); end
This method fails, because when j is 2, you are trying to set the second column of E using
the third column of D. These columns are stored in different workers, so an error occurs,
indicating that communication between the workers is not allowed.
Restrictions
To use for-drange on a codistributed array, the following conditions must exist:
The codistributed array uses a 1-dimensional distribution scheme (not 2dbc).
The distribution complies with the default partition scheme.
The variable over which the for-drange loop is indexing provides the array
subscript for the distribution dimension.
All other subscripts can be chosen freely (and can be taken from for-loops over the
full range of each dimension).