Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 parallel.Future array complete. This array can contain futures returned by parfeval, parfevalOnAll, afterEach or afterAll.

Topics

Evaluate Functions in the Background Using parfeval

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

Functions

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
parallel.FutureRequest function execution on parallel pool workers or MATLAB client
parallel.PoolAccess parallel pool
parallel.pool.DataQueueClass that enables sending and listening for data between client and workers
parallel.pool.PollableDataQueue Class that enables sending and polling for data between client and workers

Featured Examples

Was this topic helpful?