Documentation

parallel.pool.PollableDataQueue

Class that enables sending and polling for data between client and workers

Description

parallel.pool.PollableDataQueueenables sending and polling for data or messages between workers and client in a parallel pool while a computation is being carried out. You can get intermediate values and progress of the computation.

To send data from a parallel pool worker back to the client, first construct aPollableDataQueuein the client. Pass thisPollableDataQueueinto aparfor-loop or other parallel language construct, such asparfeval. From the workers, callsendto send data back to the client. At the client, usepollto retrieve the result of a message or data sent from a worker.

  • You can callsendfrom the process that calls the constructor, if required.

  • You can construct the queue on the workers and send it back to the client to enable communication in the reverse direction. However, you cannot send a queue from one worker to another. Usespmd,labSend, orlabReceiveinstead.

  • Unlike all other handle objects,PollableDataQueueinstances do remain connected when they are sent to workers.

Construction

p= parallel.pool.PollableDataQueue

The constructor for aPollableDataQueuetakes no arguments and returns an object that can be used to send and poll for messages (or data) from different workers. You call the constructor only in the process where you want to receive the data. In the usual workflow, the workers should not be calling the constructor, but should be handed an existingPollableDataQueueinstance instead.

Properties

collapse all

Read-only property that indicates how many items of data are waiting to be removed from the queue.

Example:

pollableQ = parallel.pool.PollableDataQueue;% No messages in queue because nothing has been sent yet.pollableQ.QueueLength
ans = 0
pollableQ.send('A message')% Now QueueLength = 1 because one message is sent and not yet polled.pollableQ.QueueLength
ans = 1
msg = pollableQ.poll(); disp(msg)
A message
pollableQ.QueueLength% Now QueueLength = 0 because there are no more pending messages.
ans = 0

Methods

A parallel.pool.PollableDataQueue object has the following methods.

poll Retrieve data sent from a worker
send Send data from worker to client using a data queue

Copy Semantics

Handle. To learn how handle classes affect copy operations, seeCopying Objects(MATLAB).

Examples

发送消息in aparfor-loop, and Poll for the Result

Construct aPollableDataQueue.

p = parallel.pool.PollableDataQueue;

Start aparfor-loop, and send a message, such as data with the value 1.

parfori = 1 send(p, i);end
Poll for the result.

poll(p)
1

For more details on polling for data using aPollableDataQueue, seepoll.

Introduced in R2017a

Was this topic helpful?