Parallel for-Loops (parfor
)
parfor
on workers in a parallel poolParallel Computing Toolbox™ supports interactive parallel computing and enables you to accelerate your workflow by running on multiple workers in a parallel pool. Useparfor
to executefor
-loop iterations in parallel on workers in a parallel pool. When you have profiled your code and identified slowfor
-loops, tryparfor
to increase your throughput. Developparfor
-loops on your desktop and scale up to a cluster without changing your code.
Functions
Topics
Getting Started withparfor
Discover basic concepts of aparfor
-loop, and decide when to use it.
Convert for-Loops Into parfor-Loops
Diagnose and fix commonparfor
problems.
Ensure That parfor-Loop Iterations are Independent
Unlike afor
-loop,parfor
循环迭代have no guaranteed order.
Nested parfor-Loops and for-Loops
Learn how to deal with parallel nested loops.
Troubleshoot Variables in parfor-Loops
Discover variable requirements and classification inparfor
-loops.
Runningparfor
-Loops
Interactively Run a Loop in Parallel Using parfor
Convert a slowfor
-loop into a fasterparfor
-loop.
Create arrays inside or outsideparfor
-loops to speed up code.
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.
Use Objects and Handles in parfor-Loops
Discover how to use objects, handles, and sliced variables inparfor
-loops.
Ensure Transparency in parfor-Loops
All references to variables inparfor
-loops must be visible in the body of the program.
Examples
Scale Up parfor-Loops to Cluster and Cloud
Developparfor
-loops on your desktop, and scale up to a cluster without changing your code.
You can useparfor
-loops to calculate cumulative values that are updated by each iteration.
Repeat Random Numbers in parfor-Loops
Control random number generation inparfor
-loops by assigning a particular substream for each iteration.