Asynchronous Parallel Programming - MATLAB & Simulink (original) (raw)

Main Content

Evaluate functions in the background using parfeval

You can evaluate a function in the background without waiting for it to complete, usingparfeval. 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. Using parfeval or parfevalOnAll 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.

Functions

expand all

parfeval Run function on parallel pool worker
parfevalOnAll Run function asynchronously on all workers in parallel pool
Future Function scheduled to run
afterEach Run function after each function finishes running in the background
afterAll Run function after all functions finish running in the background
fetchOutputs Retrieve results from function running in the background
fetchNext Retrieve next unread outputs from Future array
cancel Stop function running in the background
cancelAll Cancel all jobs or tasks (Since R2022a)
wait Wait for futures to complete
parallel.Pool Parallel pool of workers
ticBytes Start counting bytes transferred within parallel pool
tocBytes Read how many bytes have been transferred since callingticBytes

Topics

Get Started with Asynchronous Parallel Programming

Applications