User`s guide

5 Math with Codistributed Arrays
5-16
Element is in position 25000 on worker 2.
Notice if you use a pool of a different size, the element ends up in a different location on a
different worker, but the same code can be used to locate the element.
2-Dimensional Distribution
As an alternative to distributing by a single dimension of rows or columns, you can
distribute a matrix by blocks using '2dbc' or two-dimensional block-cyclic distribution.
Instead of segments that comprise a number of complete rows or columns of the matrix,
the segments of the codistributed array are 2-dimensional square blocks.
For example, consider a simple 8-by-8 matrix with ascending element values. You can
create this array in an spmd statement, communicating job, or pmode. This example uses
pmode for a visual display.
P>> A = reshape(1:64, 8, 8)
The result is the replicated array:
1 9 17 25 33 41 49 57
2 10 18 26 34 42 50 58
3 11 19 27 35 43 51 59
4 12 20 28 36 44 52 60
5 13 21 29 37 45 53 61
6 14 22 30 38 46 54 62
7 15 23 31 39 47 55 63
8 16 24 32 40 48 56 64
Suppose you want to distribute this array among four workers, with a 4-by-4 block as
the local part on each worker. In this case, the lab grid is a 2-by-2 arrangement of the
workers, and the block size is a square of four elements on a side (i.e., each block is a 4-
by-4 square). With this information, you can define the codistributor object:
P>> DIST = codistributor2dbc([2 2], 4)