User`s guide
Access Worker Variables with Composites
3-7
3 5 7
4 9 2
MM{2}
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
A variable might not be defined on every worker. For the workers on which a variable
is not defined, the corresponding Composite element has no value. Trying to read that
element throws an error.
spmd
if labindex > 1
HH = rand(4);
end
end
HH
Lab 1: No data
Lab 2: class = double, size = [4 4]
Lab 3: class = double, size = [4 4]
You can also set values of Composite elements from the client. This causes a transfer of
data, storing the value on the appropriate worker even though it is not executed within
an spmd statement:
MM{3} = eye(4);
In this case, MM must already exist as a Composite, otherwise MATLAB interprets it as a
cell array.
Now when you do enter an spmd statement, the value of the variable MM on worker 3 is as
set:
spmd
if labindex == 3, MM, end
end
Lab 3:
MM =
1 0 0 0
0 1 0 0