Parallel for-Loops (
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. Use
parfor to execute
for-loop iterations in parallel on workers in a parallel pool. When you have profiled your code and identified slow
parfor to increase your throughput. Develop
parfor-loops on your desktop and scale up to a cluster without changing your code.
Functions and Classes
for-loop iterations in parallel on workers
|Options set for
parfor (Since R2019a)
|Create parallel pool on cluster
|Run function on parallel pool worker
|Start counting bytes transferred within parallel pool
|Read how many bytes have been transferred since calling
|Send data from worker to client using a data queue
|Define a function to call when new data is received on a DataQueue
|Parallel pool of workers
|Send and listen for data between client and workers
Getting Started with
- Decide When to Use parfor
Discover basic concepts of a
parfor-loop, and decide when to use it.
- Convert for-Loops Into parfor-Loops
Diagnose and fix common
- Ensure That parfor-Loop Iterations are Independent
parfor-loop Iterations have no guaranteed order.
- Nested parfor and for-Loops and Other parfor Requirements
Learn how to deal with parallel nested loops.
- Troubleshoot Variables in parfor-Loops
Discover variable requirements and classification in
- Interactively Run Loops in Parallel Using parfor
for-loop into a scalable
- 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.
- Use Objects and Handles in parfor-Loops
Discover how to use objects, handles, and sliced variables in
- Ensure Transparency in parfor-Loops or spmd Statements
All references to variables in
parfor-loops must be visible in the body of the program.
- Scale Up parfor-Loops to Cluster and Cloud
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.
- Use parfor to Speed Up Monte-Carlo Code
This example shows how to speed up Monte-Carlo code by using
- Interactively Import and Process Data in Parallel
This example shows how to import and process data simultaneously in an interactive parallel pool. (Since R2023b)
- Use parfor to Train Multiple Deep Learning Networks (Deep Learning Toolbox)
This example shows how to use a
parforloop to perform a parameter sweep on a training option.