User`s guide
Nondistributed Versus Distributed Arrays
5-3
WORKER 1 WORKER 2 WORKER 3 WORKER 4
| | |
8 1 6 | 8 1 6 | 8 1 6 | 8 1 6
3 5 7 | 3 5 7 | 3 5 7 | 3 5 7
4 9 2 | 4 9 2 | 4 9 2 | 4 9 2
Variant Arrays
A variant array also resides in the workspaces of all workers, but its content differs on
one or more workers. When you create the array, MATLAB assigns a different value to
the same variable on all workers. If you display the value assigned to this variable, all
workers respond by showing their version of the array.
spmd, A = magic(3) + labindex - 1, end
WORKER 1 WORKER 2 WORKER 3 WORKER 4
| | |
8 1 6 | 9 2 7 | 10 3 8 | 11 4 9
3 5 7 | 4 6 9 | 5 7 9 | 6 8 10
4 9 2 | 5 10 3 | 6 11 4 | 7 12 5
A replicated array can become a variant array when its value becomes unique on each
worker.
spmd
B = magic(3); %replicated on all workers
B = B + labindex; %now a variant array, different on each worker
end
Private Arrays
A private array is defined on one or more, but not all workers. You could create this array
by using labindex in a conditional statement, as shown here:
spmd
if labindex >= 3, A = magic(3) + labindex - 1, end
end
WORKER 1 WORKER 2 WORKER 3 WORKER 4
| | |
A is | A is | 10 3 8 | 11 4 9
undefined | undefined | 5 7 9 | 6 8 10
| 6 11 4 | 7 12 5