labBroadcast
Send data to all workers or receive data sent to all workers
Syntax
shared_data = labBroadcast(srcWkrIdx,data)
shared_data = labBroadcast(srcWkrIdx)
Arguments
|
The |
|
The data being broadcast. This argument is required only for the worker that is broadcasting. The absence of this argument indicates that a worker is receiving. |
|
The broadcast data as it is received on all other workers. |
Description
shared_data = labBroadcast(srcWkrIdx,data)
指定的发送eddata
to all executing workers. The data is broadcast from the worker withlabindex == srcWkrIdx
, and is received by all other workers.
shared_data = labBroadcast(srcWkrIdx)
receives on each executing worker the specifiedshared_data
that was sent from the worker whoselabindex
issrcWkrIdx
.
Iflabindex
is notsrcWkrIdx
, then you do not include thedata
argument. This indicates that the function is to receive data, not broadcast it. The received data,shared_data
, is identical on all workers.
This function blocks execution until the worker’s involvement in the collective broadcast operation is complete. Because some workers may complete their call tolabBroadcast
before others have started, uselabBarrier
if you need to guarantee that all workers are at the same point in a program.
Examples
In this case, the broadcaster is the worker whoselabindex
is1
.
srcWkrIdx = 1;iflabindex == srcWkrIdx data = randn(10); shared_data = labBroadcast(srcWkrIdx,data);elseshared_data = labBroadcast(srcWkrIdx);end