This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Parallel for-Loops (parfor)

Exploit parallel processing by running parfor on workers in a parallel pool

Parallel Computing Toolbox™ supports interactive parallel computing and enables you to accelerate your workflow by running on multiple workers in a parallel pool. When you have profiled your code and identified slow for-loops, you can try parfor to increase your throughput.

For more details, see the video From for to parfor.


parfor Execute loop iterations in parallel
parpool Create parallel pool on cluster


Creating parfor-Loops

When to Use parfor

Discover basic concepts of a parfor-loop, and decide when to use it.

Create a parfor-Loop

Learn how to turn a for-loop into a parfor-loop.

Interactively Run a Loop in Parallel Using parfor

Modify a simple for-loop so that it runs in parallel.

Compare for-Loops and parfor-Loops

Learn the intricacies of using dependent and nonindexed variables in a parfor-loop.

Dealing with Variables in parfor-Loops

Use Objects and Handles in parfor-Loops

Discover how to use objects, handles, and sliced variables in parfor-loops.

Use Nested Functions and Variables in parfor-Loops

Use function handles and function calls to deal with nesting limitations in parfor-loops.

Specify Variables in parfor-Loops

Use unambiguous variable names and struct functions in parfor-loops.

Classify Variables in parfor-Loops

Distinguish between loop, sliced, broadcast, reduction, and temporary variables in parfor-loops.

Ensure Transparency in parfor-Loops

All references to variables in parfor-loops must be visible in the body of the program.

Running parfor-Loops

Improve parfor Performance

Create arrays inside or outside parfor-loops to speed up code.

Run Code on Parallel Pools

Learn about starting and stopping parallel pools, pool size, and cluster selection.

Specify Your Parallel Preferences

Specify your preferences, and automatically create a parallel pool.


Scale Up parfor-Loops to Cluster and Cloud

Develop parfor-loops on your desktop and scale up to a cluster without changing your code.

Use parfor-Loops for Reduction Assignments

You can use parfor-loops to calculate cumulative values, that are updated by each iteration.

Repeat Random Numbers in parfor-Loops

Control random number generation in parfor-loops by assigning a particular substream for each iteration.

Featured Examples

Was this topic helpful?