Run MATLAB Functions with Automatic Parallel Support
Several MATLAB and Simulink products have a growing number of functions and features that help you take advantage of parallel computing resources without requiring any extra coding. You can enable this support by simply setting a flag or preference.
To take advantage of this functionality on your desktop, you need Parallel Computing Toolbox. Run calculations in parallel using local workers to speed up large calculations. To scale the parallel computing to larger resources such as computer clusters, you also need a MATLAB Parallel Server cluster.
Many other functions run automatically in parallel if you set an option to use parallel.
When you run a function with parallel enabled, MATLAB® automatically opens a parallel pool of workers. MATLAB runs the computation across the available workers.
Automatic parallel support starts a parallel pool of workers using the default cluster
profile. If you have not touched your parallel settings, the default profile is
Processes
. Control parallel behavior with the parallel settings,
including scaling up to a cluster and automatic pool creation.
Choose How Functions Run in Parallel
For several MATLAB and Simulink® functions with automatic parallel support, you enable parallel
execution using the UseParallel
name-value argument. The
UseParallel
name-value argument accepts
"off"
, "auto"
or "on"
values. You can choose the appropriate value for the
UseParallel
argument based on your goal.
Goal | Value | Function Behavior |
---|---|---|
You want run your code in serial for debugging purposes or because the task does not benefit from parallelization. |
| Runs in serial on the MATLAB client. |
You want to write portable code that automatically uses a parallel pool if you have Parallel Computing Toolbox™, and that can still run if you do not have Parallel Computing Toolbox. |
| Automatically uses a parallel pool if one is open or if MATLAB can automatically create one. Otherwise it falls back to serial execution on the MATLAB client. |
You want to always run on a parallel pool. |
| Automatically uses a parallel pool if one is open or if MATLAB can automatically create one. Otherwise it throws an error. |
Find Automatic Parallel Support
On function pages, find information under Extended Capabilities.
You can browse supported functions from all MathWorks® products at the following link: All Functions List (Automatic Parallel Support). Alternatively, you can filter by product. On the Help bar, click the Functions tab, select a product, and select the check box Automatic Parallel Support. For example, for a filtered list of all Statistics and Machine Learning Toolbox™ functions with automatic parallel support, see Function List (Automatic Parallel Support) (Statistics and Machine Learning Toolbox). If you select a product that does not have functions with automatic parallel support, then the Automatic Parallel Support filter is not available.
If a function you are interested in does not include automatic parallel support, here are some alternatives:
If you have a GPU, many MATLAB functions run automatically on a GPU. See Run MATLAB Functions on a GPU.
Any MATLAB code inside a for-loop can be made into a parallel for loop, provided the iterations are independent. See
parfor
.If you are you looking for other ways to speed up your processing or to scale up your big data calculation, see Choose a Parallel Computing Solution.