Main Content

Parallel Language Decision Tables

MATLAB®, Parallel Computing Toolbox™ and MATLAB Parallel Server™ provide parallel language features and functions with automatic parallel support that enable you to take advantage of more hardware resources.

Parallel language features help you parallelize your MATLAB code. For example use cases of common parallel features to help you choose, see Choose Your Parallel Computing Language Feature.

After choosing a parallel language feature, decide where you want to run your parallel MATLAB code. For more information, see Choose Your Workflow.

Some MATLAB and other toolbox functions come with automatic parallel support. You can use the UseParallel option without choosing an external parallel language feature. For more information, see Run MATLAB Functions with Automatic Parallel Support.

Choose Your Parallel Computing Language Feature

This table is designed to help you choose a parallel language feature for your application.

Example Use CaseFunctionDescriptionCommunication Between WorkersSynchronous or Asynchronous

Monte Carlo analysis.

Parameter sweeps.

Process millions of images in parallel.

parforA parallel for loop where each iteration is independent of all other iterations. NoSynchronous

Multiple simulations.

Model testing and optimization.

Experiment design.

parsim (Simulink)Simulate dynamic system multiple times in parallel or serial.NoSynchronous

Optimization procedures.

Needle in a haystack problem.

Add more cases as you run.

Fetch intermediate results.

Evaluate functions in the background.

parfevalRun a function on a parallel pool worker. NoAsynchronous

Setting up the environment of parallel workers in a parpool.

parfevalOnAllExecute a function asynchronously on all workers in an interactive parallel pool.NoAsynchronous

Use MATLAB functions on a GPU.

gpuArrayPass GPU arrays to supported functions to run your code on the GPU.YesSynchronous

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.

Process an image too large to fit into memory.

spmdExecute a block of code in parallel on all the workers of the parallel pool.YesSynchronous

Train deep learning network with large data set.

Read and write data from cloud storage.

Solve linear algebra problems.

distributedAnalyze large multidimensional data in parallel using distributed arrays and spmd code blocks.YesSynchronous

Use when data is too large to fit in memory and is large in one dimension.

Machine learning.

Data analytics.

Read and write data from cloud storage.

tallEvaluate tall-array expressions in parallel using a parallel pool on your desktop, a cluster or Hadoop® cluster.YesSynchronous

Choose Your Workflow

Interactive Workflow

Use an interactive workflow to execute parallel code on a parallel pool of workers (parpool). In an interactive workflow, results can be viewed as soon as it is ready. However, data from the execution is lost after the current MATLAB client session is closed.

For an interactive workflow, use parfor, parfeval, parfevalOnAll, spmd, distributed, and tall from the table above 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 into a gpuArray object. Then use any gpuArray-enabled MATLAB function to operate with the gpuArray object.

Batch Workflow

Use a batch workflow to offload work to a compute cluster and carry out other tasks, or submit long running code for later execution. In a batch workflow, you can close the MATLAB client session while the job is processing. You can retrieve information from a batch job later or in a new client session.

You can use parfor, gpuArray, spmd, distributed, and tall parallel language features, along 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 below.

For more information, see Run Batch Parallel Jobs.

Example Use CaseFunctionDescriptionCommunication Between WorkersSynchronous or Asynchronous

Offload execution of a function or script to run in a cluster or desktop background.

batch Offload and run MATLAB script or function on worker.NoAsynchronous
Offload parallel simulations in batch.batchsim (Simulink)Offload simulations to run on a compute cluster.NoAsynchronous

Offload and run multiple spmd blocks in parallel.

Use a parallel pool on a cluster.

batch(_'Pool'...)Offload and run MATLAB script or function on parallel pool of workers.YesAsynchronous

Finer control of independent parallel tasks.

Collate and offload tasks to independent workers on a cluster.

Submit tasks and access results later.

createJobOffload any number of tasks to independent workers on a cluster. A task can be a function or script. NoAsynchronous

Finer control of communicating tasks on a parallel pool in a cluster.

Execute function simultaneously on distributed data sets.

Submit task and access results later.

createCommunicatingJobOffload one task to communicating workers on a cluster. YesAsynchronous

Note

Batch functions are not available in interactive parallel pools. To execute code that uses a pool of workers for batch execution, use batch(_'Pool'...) or createCommunicatingJob.

See Also

| (Simulink) | | | | | | | | (Simulink) | |

Related Topics