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.


expand all

parfevalRun function on parallel pool worker
parfevalOnAllRun 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
afterEachRun function after each function finishes running in the background
afterAllRun function after all functions finish running in the background
fetchOutputsRetrieve results from function running in the background
fetchNextRetrieve next unread outputs from Future array
cancelStop function running in the background
cancelAllCancel all jobs or tasks (Since R2022a)
waitWait for futures to complete
FutureFunction scheduled to run
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