Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

labBroadcast

Send data to all workers or receive data sent to all workers

Syntax

shared_data = labBroadcast(srcWkrIdx,data)
shared_data = labBroadcast(srcWkrIdx)

Arguments

srcWkrIdx

The labindex of the worker sending the broadcast.

data

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.

shared_data

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

Description

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

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

If labindex is not srcWkrIdx, 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 workers.

This function blocks execution until the worker's involvement in the collective broadcast operation is complete. Because some workers may complete their call to labBroadcast before others have started, use labBarrier 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 whose labindex is 1.

srcWkrIdx = 1;
if labindex == srcWkrIdx
  data = randn(10);
  shared_data = labBroadcast(srcWkrIdx,data);
else
  shared_data = labBroadcast(srcWkrIdx);
end
Was this topic helpful?