Main Content

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.

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 ApplicationsFunctionDescriptionCommunication Between WorkersSynchronous or Asynchronous

  • Perform Monte Carlo analysis.

  • Perform parameter sweeps.

  • Process millions of images in parallel.

parforA parallel for-loop in which each iteration is independent of all other iterations. NoSynchronous

  • Run multiple simulations.

  • Test and optimize models.

  • Design experiments.

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

  • 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.

parfevalRun a function on a parallel pool worker. NoAsynchronous

Set up the environment of parallel workers in a parallel pool.

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.NoSynchronous

  • 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.

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

  • Train a deep learning network with a large data set.

  • Read data from and write data to cloud storage.

  • Solve linear algebra problems.

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

  • 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.

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

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 ApplicationsFunctionDescriptionCommunication Between WorkersSynchronous 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.NoAsynchronous
Offload parallel simulations in batch.batchsim (Simulink)Offload simulations to run on a compute cluster.NoAsynchronous

  • Offload and run code containing parallel language such as parfor or spmd blocks in parallel

  • Use a parallel pool on a cluster.

batch(__,Pool=...)Offload and run a MATLAB script or function on a parallel pool of workers.YesAsynchronous

  • Finely control 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

  • 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.

createCommunicatingJobOffload one task to communicating workers on a cluster. YesAsynchronous

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

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

Related Topics