User`s guide
Nesting and Flow in parfor-Loops
2-17
Invalid Valid
disp(A(i, 1))
end
end
disp(v(1))
A(i, :) = v;
end
Inside a parfor, if you use multiple for-loops (not nested inside each other) to index
into a single sliced array, they must loop over the same range of values. Furthermore, a
sliced output variable can be used in only one nested for-loop. In the following example,
the code on the left does not work because j and k loop over different values; the code on
the right works to index different portions of the sliced array A:
Invalid Valid
A = zeros(4, 10);
parfor i = 1:4
for j = 1:5
A(i, j) = i + j;
end
for k = 6:10
A(i, k) = pi;
end
end
A = zeros(4, 10);
parfor i = 1:4
for j = 1:10
if j < 6
A(i, j) = i + j;
else
A(i, j) = pi;
end
end
end
Nested spmd Statements
The body of a parfor-loop cannot contain an spmd statement, and an spmd statement
cannot contain a parfor-loop.
Break and Return Statements
The body of a parfor-loop cannot contain break or return statements.
Consider instead using parfeval or parfevalOnAll.
P-Code Scripts
You can call P-code script files from within a parfor-loop, but P-code script cannot
contain a parfor-loop.