send - Send data between clients and workers using a data queue - MATLAB (original) (raw)

Send data between clients and workers using a data queue

Syntax

Description

send([queue](#bvl84az-queue),[data](#bvl84az-data)) sends a message or data with the value data to theDataQueue specified by queue. CallafterEach to pass each of the pending messages to the function specified by afterEach.

example

send([pollablequeue](#mw%5F5716d1f8-58e8-48f8-9424-bca561cb55e5),[data](#bvl84az-data)) sends a message or data with the value data to thePollableDataQueue specified bypollablequeue. Retrieve the result usingpoll, and return data as the answer.

Use the send and poll functions together with a pollable data queue to transfer and retrieve messages or data between the client and workers.

example

Examples

collapse all

Create a DataQueue, and useafterEach to set up a callback function that displays data from the queue on the client.

q = parallel.pool.DataQueue; afterEach(q,@disp);

Run a parfor-loop, and send a message to the queue. When the message arrives on the client, it is passed to theafterEach callback function,@disp.

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

For more details on listening for data using aDataQueue, see afterEach.

Create a PollableDataQueue object.

p = parallel.pool.PollableDataQueue;

Use parfeval to send a message, such as data with the value 1.

f = parfeval(@send,0,p,1); wait(f);

Poll for the result.

For more details on retrieving data using aPollableDataQueue, see poll.

This example shows a function that creates aparfor wait bar. Create a DataQueue, and use afterEach to specify the function to execute each time the queue receives data. This example calls a subfunction that updates the wait bar.

Create a parfor-loop to carry out a computationally demanding task in MATLABĀ®. Use send to send some dummy data on each iteration of the parfor-loop. When the queue receives the data, afterEach callsnUpdateWaitbar in the client MATLAB, and you can observe the wait bar progress.

function a = parforWaitbar

D = parallel.pool.DataQueue; h = waitbar(0,'Please wait ...'); afterEach(D,@nUpdateWaitbar);

N = 200; p = 1;

parfor i = 1:N a(i) = max(abs(eig(rand(400)))); send(D,i); end

function nUpdateWaitbar(~)
    waitbar(p/N,h);
    p = p + 1;
end

end

Status bar indicating roughly one third completion.

Input Arguments

collapse all

Data queue, specified as a parallel.pool.DataQueue object.

Example: q = parallel.pool.DataQueue;

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

Example: send(queue,data);

Pollable data queue, specified as a PollableDataQueue object.

If you close aPollableDataQueue using the close function, you can no longer send data to the queue. Any attempt to send data to the queue results in an error. (since R2025a)

Example: p = parallel.pool.PollableDataQueue;

Extended Capabilities

Version History

Introduced in R2017a