Parallel Language Decision Tables
MATLAB®, Parallel Computing Toolbox™, and MATLAB Parallel Server™ software provide parallel language features and functions with automatic parallel support that enable you to take advantage of more hardware resources.
Use parallel language features to help you parallelize your MATLAB code. For examples of common parallel features, see Choose Parallel Computing Language Feature.
After you choose a parallel language feature, decide where to run your parallel MATLAB code. For more information, see Choose Workflow.
Some functions come with automatic parallel support. You can enable the
UseParallel
option without choosing an external parallel language feature. For more information, see Run MATLAB Functions with Automatic Parallel Support.
Choose Parallel Computing Language Feature
Use this table to inform your choice of parallel language feature for your application. When you run a function asynchronously, MATLAB can run other code in the foreground at the same time.
Example Applications | Function | Description | Communication Between Workers | Synchronous or Asynchronous |
---|---|---|---|---|
| parfor | A parallel for -loop in which each
iteration is independent of all other iterations. | No | Synchronous |
| parsim (Simulink) | Simulate a dynamic system multiple times in parallel or in series. | No | Synchronous |
| parfeval | Run a function on a parallel pool worker. | No | Asynchronous |
Set up the environment of parallel workers in a parallel pool. | parfevalOnAll | Execute a function asynchronously on all workers in an interactive parallel pool. | No | Asynchronous |
Use MATLAB functions on a GPU. | gpuArray | Pass GPU arrays to supported functions to run your code on the GPU. | No | Synchronous |
| spmd | Execute a block of code in parallel on all the workers of the parallel pool. | Yes | Synchronous |
| distributed | Analyze large, multidimensional data in parallel using
distributed arrays and spmd code
blocks. | Yes | Synchronous |
| tall | Evaluate tall-array expressions in parallel using a parallel pool on your desktop, a cluster, or a Hadoop® cluster. | Yes | Synchronous |
Choose Workflow
Interactive Workflow
Use an interactive workflow to execute parallel code on a parallel pool of
workers using parpool
. In an interactive
workflow, you can view results as soon as they are ready. However, you cannot
retrieve data after you close the current MATLAB client session.
To use an interactive workflow, call parfor
, parfeval
, parfevalOnAll
, spmd
, distributed
, and tall
in your MATLAB code. These functions automatically start a parallel pool when you
call them. For more information, see Run Code on Parallel Pools.
Use gpuArray
to convert an array in
the MATLAB workspace to a gpuArray
object. You can use any
gpuArray
-enabled MATLAB function to work with the gpuArray
object. For
more information, see Run MATLAB Functions on a GPU.
Batch Workflow
Use a batch workflow to offload work to a compute cluster and carry out other tasks, or to submit long-running code for later execution. If you offload work to a remote compute cluster, you can close the MATLAB client session while the job is processing. MATLAB stores information about batch jobs, so you can retrieve results from a batch job later or in a new client session. To develop and test your code, you can offload work to a local cluster on your client machine. If you close your MATLAB session, any batch jobs using the local cluster also stop immediately.
Batch workflows support parfor
, parfeval
, gpuArray
, spmd
, distributed
, and tall
parallel language features
with any other MATLAB functions in a batch workflow. Submit your code as a script or
function with one of the batch parallel language features in this table. For
more information, see Run Batch Parallel Jobs.
Example Applications | Function | Description | Communication Between Workers | Synchronous or Asynchronous |
---|---|---|---|---|
Offload execution of a function or script to run in a cluster or in the desktop background. | batch | Offload and run a MATLAB script or function on a worker. | No | Asynchronous |
Offload parallel simulations in batch. | batchsim (Simulink) | Offload simulations to run on a compute cluster. | No | Asynchronous |
| batch (__,Pool=...) | Offload and run a MATLAB script or function on a parallel pool of workers. | Yes | Asynchronous |
| createJob | Offload any number of tasks to independent workers on a cluster. A task can be a function or script. | No | Asynchronous |
| createCommunicatingJob | Offload one task to communicating workers on a cluster. | Yes | Asynchronous |
Note
Batch functions are not available in interactive parallel pools. To submit
code that uses a pool of workers for batch execution, use
batch(__,Pool=...)
or createCommunicatingJob
.
See Also
parfor
| parsim
(Simulink) | parfeval
| parfevalOnAll
| gpuArray
| spmd
| distributed
| tall
| batch
| batchsim
(Simulink) | createJob
| createCommunicatingJob