Main Content

Asynchronous Parallel Programming

Evaluate functions in the background using parfeval

You can evaluate a function in the background without waiting for it to complete, using parfeval. In many cases, it can be convenient to break out of a for loop early. For example, in an optimization procedure, you can stop the loop early when the result is good enough. You can do this on one or all parallel pool workers, using parfeval or parfevalOnAll. This can be useful if you want to be able to plot intermediate results. Note that this is different from using parfor, where you have to wait for the loop to complete.

Use send and poll together to send and poll for messages or data from different workers using a data queue. You can use afterEach to add a function to call when new data is received from a data queue.

Use afterEach and afterAll to automatically invoke functions after each or after all elements of a Future array complete. This array can contain futures returned by parfeval, parfevalOnAll, afterEach or afterAll.


Evaluate Functions in the Background Using parfeval

Break out of a loop early and collect results as they become available.

Query and Cancel parfeval Futures

This example shows how to query the state of parfeval futures and cancel them.

Plot During Parameter Sweep with parfeval

This example shows how to perform a parallel parameter sweep with parfeval and send results back during computations with a DataQueue object.

Update User Interface Asynchronously Using afterEach and afterAll

This example shows how to update a user interface as computations complete.

Perform Webcam Image Acquisition in Parallel with Postprocessing

This example shows how to perform frame acquisition from a webcam in parallel with data postprocessing.

Perform Image Acquisition and Parallel Image Processing

This example shows how to perform image acquisition from a webcam and postprocess data in parallel.

Train Deep Learning Networks in Parallel

This example shows how to run multiple deep learning experiments on your local machine.

Use parfeval to Train Multiple Deep Learning Networks

This example shows how to use parfeval to perform a parameter sweep on the depth of the network architecture for a deep learning network and retrieve data during training.

Choose Between spmd, parfor, and parfeval

Compare and contrast spmd against other parallel computing functionality such as parfor and parfeval.


expand all

parfevalExecute function asynchronously on parallel pool worker
parfevalOnAllExecute function asynchronously on all workers in parallel pool
ticBytesStart counting bytes transferred within parallel pool
tocBytesRead how many bytes have been transferred since calling ticBytes
sendSend data from worker to client using a data queue
poll Retrieve data sent from a worker
afterEachDefine a function to call when new data is received on a DataQueue
afterEachSpecify a function to invoke after each parallel.Future completes
afterAllSpecify a function to invoke after all parallel.Futures complete
fetchOutputsRetrieve all output arguments from Future
fetchNextRetrieve next available unread FevalFuture outputs
cancelCancel queued or running future
isequalTrue if futures have same ID
waitWait for futures to complete
FutureRequest function execution on parallel pool workers or MATLAB client
parallel.PoolParallel pool of workers
parallel.pool.DataQueueSend and listen for data between client and workers
parallel.pool.PollableDataQueue Send and poll data between client and workers

Featured Examples