Documentation

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

Thelabindexof 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)指定的发送eddatato 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_datathat was sent from the worker whoselabindexissrcWkrIdx.

Iflabindexis notsrcWkrIdx, then you do not include thedataargument. 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 tolabBroadcastbefore others have started, uselabBarrierif you need to guarantee that all workers are at the same point in a program.

Examples

In this case, the broadcaster is the worker whoselabindexis1.

srcWkrIdx = 1;iflabindex == srcWkrIdx data = randn(10); shared_data = labBroadcast(srcWkrIdx,data);elseshared_data = labBroadcast(srcWkrIdx);end

Introduced before R2006a

Was this topic helpful?