Skip to Main Content Skip to Search
Product Documentation

parfor - Parallel for loop

Syntax

parfor loopvar = initval:endval; statements; end
parfor (loopvar = initval:endval, M); statements; end

Description

parfor loopvar = initval:endval; statements; end executes a series of MATLAB statements for values of loopvar between initval and endval, inclusive, which specify a vector of increasing integer values. The loop occurs in parallel when you open a pool of workers with Parallel Computing Toolbox™. Unlike a traditional for-loop, iterations are not executed in a guaranteed order.

parfor (loopvar = initval:endval, M); statements; end executes statements in a loop using a maximum of M workers, where M is a nonnegative integer.

Tips

Examples

Perform three large eigenvalue computations using three workers or cores with Parallel Computing Toolbox software:

matlabpool(3)
parfor i=1:3, c(:,i) = eig(rand(1000)); end

See Also

for

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS