send
Send data to DataQueue
or
PollableDataQueue
Syntax
Description
Examples
Automatically Process Data Sent from the Background
This example shows how to automatically process data in your current MATLAB session that you send from the background.
Create a DataQueue
object. After each item of data is received on the DataQueue
in your current MATLAB session, automatically display that item using the disp
function.
q = parallel.pool.DataQueue; afterEach(q,@disp);
The helper function magicWithSend
defined at the end of this example sends the sum of a magic square to a DataQueue
or PollableDataQueue
object, then returns that magic square.
Use parfeval
and backgroundPool
to run the function magicWithSend
in the background.
f = parfeval(backgroundPool,@magicWithSend,1,q,3);
The sum is displayed before you fetch outputs from the future. To retrieve the output from the background, use fetchOutputs
. MATLAB returns the output once the execution of magicWithSend
is complete.
fetchOutputs(f)
ans = 3×3
8 1 6
3 5 7
4 9 2
Define Helper Function
Define the helper function magicWithSend
. The function creates a magic square, then sends the sum of the magic square to a DataQueue
or PollableDataQueue
object. After the sum is sent, the function returns the magic square.
function X = magicWithSend(q,n) X = magic(n); s = sum(X,'all'); send(q,s); end
Input Arguments
q
— Queue
parallel.pool.DataQueue
object | parallel.pool.PollableDataQueue
object
Queue, specified as a parallel.pool.DataQueue
or
parallel.pool.PollableDataQueue
object.
If
q
is aDataQueue
, useafterEach
to automatically process data when it is received in the current MATLAB session.If
q
is aPollableDataQueue
, usepoll
to manually retrieve data after it is received in the current MATLAB session.
Example: q = parallel.pool.DataQueue
Example: q = parallel.pool.PollableDataQueue
data
— Data to send
scalar | vector | matrix | multidimensional array
Data to send, specified as a scalar, vector, matrix, or multidimensional array.
Example: send(q,"A message");
Example: send(q,magic(3));
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced in R2017a
See Also
afterEach
| poll
| parfor
| parallel.pool.DataQueue
| parallel.pool.PollableDataQueue
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)