Parallel Language Decision Tables - MATLAB & Simulink (original) (raw)
Main Content
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 |
---|---|---|---|---|
Perform Monte Carlo analysis. Perform parameter sweeps. Process millions of images in parallel. | parfor | A parallel for-loop in which each iteration is independent of all other iterations. | No | Synchronous |
Run multiple simulations.Test and optimize models. Design experiments. | parsim (Simulink) | Simulate a dynamic system multiple times in parallel or in series. | No | Synchronous |
Implement optimization procedures.Solve a "needle in a haystack" problem.Add more cases as you run your code.Fetch intermediate results. Evaluate functions in the background. | 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 |
Transfer data between workers during computations. Run code on workers that access different parts of a distributed array. Run a single program over multiple workers with message passing enabled. Process an image that is too large to fit in memory. | spmd | Execute a block of code in parallel on all the workers of the parallel pool. | Yes | Synchronous |
Train a deep learning network with a large data set.Read data from and write data to cloud storage.Solve linear algebra problems. | distributed | Analyze large, multidimensional data in parallel using distributed arrays and spmd code blocks. | Yes | Synchronous |
Process data that is too large to fit in memory and is large in one dimension.Perform machine learning tasks.Read data from and write data to cloud storage. | 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 anygpuArray
-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 |
Offload and run code containing parallel language such as parfor orspmd blocks in parallelUse a parallel pool on a cluster. | batch(__,Pool=...) | Offload and run a MATLAB script or function on a parallel pool of workers. | Yes | Asynchronous |
Finely control independent parallel tasks.Collate and offload tasks to independent workers on a cluster.Submit tasks and access results later. | createJob | Offload any number of tasks to independent workers on a cluster. A task can be a function or script. | No | Asynchronous |
Finely control communicating tasks on a parallel pool in a cluster. Execute a function simultaneously on distributed data sets. Submit tasks and access results later. | 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, usebatch(__,Pool=...)
or createCommunicatingJob.
See Also
parfor | parsim (Simulink) | parfeval | parfevalOnAll | gpuArray | spmd | distributed | tall | batch | batchsim (Simulink) | createJob | createCommunicatingJob