User`s guide

11 Functions — Alphabetical List
11-232
than that number, even if additional workers are available. If you request more resources
than are available, MATLAB uses the maximum number available at the time of the call.
If the parfor-loop cannot run on workers in a parallel pool (for example, if no workers
are available or M is 0), MATLAB executes the loop on the client in a serial manner. In
this situation, the parfor semantics are preserved in that the loop iterations can execute
in any order.
Note Because of independence of iteration order, execution of parfor does not guarantee
deterministic results.
The maximum amount of data that can be transferred in a single chunk between client
and workers in the execution of a parfor-loop is determined by the JVM memory
allocation limit. For details, see “Object Data Size Limitations” on page 6-52.
For a detailed description of parfor-loops, see “Parallel for-Loops (parfor)”.
Examples
Suppose that f is a time-consuming function to compute, and that you want to compute
its value on each element of array A and place the corresponding results in array B:
parfor i = 1:length(A)
B(i) = f(A(i));
end
Because the loop iteration occurs in parallel, this evaluation can complete much faster
than it would in an analogous for-loop.
Next assume that A, B, and C are variables and that f, g, and h are functions:
parfor i = 1:n
t = f(A(i));
u = g(B(i));
C(i) = h(t, u);
end
If the time to compute f, g, and h is large, parfor will be significantly faster than the
corresponding for statement, even if n is relatively small. Although the form of this
statement is similar to a for statement, the behavior can be significantly different.