User`s guide
parfor
11-231
parfor
Execute loop iterations in parallel
Syntax
parfor loopvar = initval:endval, statements, end
parfor (loopvar = initval:endval, M), statements, end
Description
parfor loopvar = initval:endval, statements, end allows you to write a
loop for a statement or block of code that executes in parallel on a cluster of workers,
which are identified and reserved with the parpool command. initval and endval
must evaluate to finite integer values, or the range must evaluate to a value that can be
obtained by such an expression, that is, an ascending row vector of consecutive integers.
The following table lists some ranges that are not valid.
Invalid parfor Range Reason Range Not Valid
parfor i = 1:2:25 1, 3, 5,... are not consecutive.
parfor i = -7.5:7.5 -7.5, -6.5,... are not integers.
A = [3 7 -2 6 4 -4 9 3 7];
parfor i = find(A>0)
The resulting range, 1, 2, 4,..., has
nonconsecutive integers.
parfor i = [5;6;7;8] [5;6;7;8] is a column vector, not a row vector.
You can enter a parfor-loop on multiple lines, but if you put more than one segment of
the loop statement on the same line, separate the segments with commas or semicolons:
parfor i = range; <loop body>; end
parfor (loopvar = initval:endval, M), statements, end uses M to specify
the maximum number of MATLAB workers that will evaluate statements in the body of
the parfor-loop. M must be a nonnegative integer. By default, MATLAB uses as many
workers as it finds available. If you specify an upper limit, MATLAB employs no more