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
Functions and Classes
parfor |
Execute for-loop iterations in parallel on workers in parallel pool |
parpool |
Create parallel pool on cluster |
parfeval |
Execute function asynchronously on parallel pool worker |
ticBytes |
Start counting bytes transferred within parallel pool |
tocBytes |
Read how many bytes have been transferred since calling ticBytes |
send |
Send data from worker to client using a data queue |
afterEach |
Define a function to call when new data is received |
parallel.Pool |
Access parallel pool |
parallel.pool.DataQueue |
Class that enables sending and listening for data between client and workers |
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
-loop Iterations 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.