Documentation

send

Send data from worker to client using a data queue

Syntax

send(queue, data)
send(pollablequeue, data)

Description

example

send(queue,data)sends a message or data with the valuedatato theparallel.pool.DataQueuespecified byqueue. CallafterEachto pass each of the pending messages to the function specified byafterEach.

example

send(pollablequeue,data)sends a message or data with the valuedatato theparallel.pool.PollableDataQueuespecified bypollablequeue. Retrieve the result usingpoll(pollablequeue), and returndataas the answer.

Use thesendandpollfunctions together using a pollable data queue to transfer and retrieve messages or data from different workers.

Examples

collapse all

Construct aDataQueue, and callafterEach.

q = parallel.pool.DataQueue; afterEach(q, @disp);
Start aparfor-loop, and send a message. The pending message is passed to theafterEachfunction, in this example@disp.

parfori = 1:3 send(q, i);end;
1 2 3

For more details on listening for data using aDataQueue, seeafterEach.

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 retrieving data using aPollableDataQueue, seepoll.

This example shows a function that creates aparforwait bar. Create aDataQueue, and useafterEachto specify the function to execute each time the queue receives data. This example calls a subfunction that updates the wait bar.

创建一个parfor-loop to carry out a computationally demanding task in MATLAB®. Usesendto send some dummy data on each iteration of theparfor-loop. When the queue receives the data,afterEachcallsnUpdateWaitbarin the client MATLAB, and you can observe the wait bar progress.

functiona = parforWaitbar D = parallel.pool.DataQueue; h = waitbar(0,'Please wait ...'); afterEach(D, @nUpdateWaitbar); N = 200; p = 1;parfori = 1:N a(i) = max(abs(eig(rand(400)))); send(D, i);endfunctionnUpdateWaitbar(~) waitbar(p/N, h); p = p + 1;endend

Input Arguments

collapse all

Data queue, specified as aparallel.pool.DataQueueobject.

Example:q = parallel.pool.DataQueue;

Message or data from workers to a data queue, specified as any data type that can be serialized.

Example:send(queue, data);

Pollable data queue, specified as aparallel.pool.PollableDataQueueobject.

Example:p = parallel.pool.PollableDataQueue;

Introduced in R2017a

Was this topic helpful?