Run MATLAB Functions with Automatic Parallel Support - MATLAB & Simulink (original) (raw)

Main Content

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.

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 isProcesses. 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. TheUseParallel name-value argument accepts"off", "auto" or "on" values. You can choose the appropriate value for theUseParallel 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. UseParallel="off" (default) 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. UseParallel="auto" 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. UseParallel="on" 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

If a function you are interested in does not include automatic parallel support, here are some alternatives:

See Also

Topics