labBroadcast - Send data to all labs or receive data sent to all labs

Syntax

shared_data = labBroadcast(senderlab, data)
shared_data = labBroadcast(senderlab)

Arguments

senderlab

The labindex of the lab sending the broadcast.

data

The data being broadcast. This argument is required only for the lab that is broadcasting. The absence of this argument indicates that a lab is receiving.

shared_data

The broadcast data as it is received on all other labs.

Description

shared_data = labBroadcast(senderlab, data) sends the specified data to all executing labs. The data is broadcast from the lab with labindex == senderlab, and received by all other labs.

shared_data = labBroadcast(senderlab) receives on each executing lab the specified shared_data that was sent from the lab whose labindex is senderlab.

If labindex is not senderlab, then you do not include the data argument. This indicates that the function is to receive data, not broadcast it. The received data, shared_data, is identical on all labs.

This function blocks execution until the lab's involvement in the collective broadcast operation is complete. Because some labs may complete their call to labBroadcast before others have started, use labBarrier to guarantee that all labs are at the same point in a program.

Examples

In this case, the broadcaster is the lab whose labindex is 1.

broadcast_id = 1;
if labindex == broadcast_id
  data = randn(10);
  shared_data = labBroadcast(broadcast_id, data);
else
  shared_data = labBroadcast(broadcast_id);
end

See Also

labBarrier, labindex

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS