User`s guide
2 Parallel for-Loops (parfor)
2-30
However, if it is clear that in every iteration, every reference to an array element is
set before it is used, the variable is not a sliced input variable. In this example, all the
elements of A are set, and then only those fixed values are used:
parfor ii = 1:n
if someCondition
A(ii) = 32;
else
A(ii) = 17;
end
loop code that uses A(ii)
end
Even if a sliced variable is not explicitly referenced as an input, implicit usage might
make it so. In the following example, not all elements of A are necessarily set inside the
parfor-loop, so the original values of the array are received, held, and then returned
from the loop, making A both a sliced input and output variable.
A = 1:10;
parfor ii = 1:10
if rand < 0.5
A(ii) = 0;
end
end
More About
• “Classification of Variables in parfor-Loops” on page 2-23