Main Content

labProbe

(Not recommended) Determine if data is available for the current worker in an spmd to receive

    labProbe is not recommended. Use spmdProbe instead. For more information, see Version History.

    Description

    example

    tf = labProbe tests if data is available for the current worker in an spmd block or communicating job to receive using labReceive.

    Tip

    When you offload computations using parfor and parfeval, each computation is run by only one worker at a time. These workers are independent and do not communicate with each other. If you use labProbe on these workers, the function has no effect.

    If data is available, labProbe returns logical 1 (true); otherwise, it returns logical 0 (false).

    To use labProbe, numlabs must be greater than 1.

    tf = labProbe(source) tests if data is available for the current worker to receive from the worker with labindex equal to source.

    tf = labProbe('any') tests if the sent data is available for the current worker to receive from any worker.

    tf = labProbe('any',tag) tests if data sent with the tag tag is available for the current worker to receive from any worker.

    tf = labProbe(source,tag) tests if data sent with the tag tag is available for the current worker to receive from the worker with labindex equal to source.

    [tf,sources,tags] = labProbe(___) tests if data is available for the current worker to receive, returns the labindex of the workers that are sending data as source, and returns the tags of data available to receive as tag.

    Examples

    collapse all

    This example shows how to determine if data is available to be received on workers in an spmd block or communicating job.

    Create a parallel pool with 4 workers.

    parpool(4);

    When you execute an spmd block after creating a parallel pool, by default all available workers in the pool will run the code inside the spmd block.

    Create an spmd block. On the worker with labindex equal to 1, create an array. Use labSend to send the array to the worker with labindex equal to 2.

    Use labBarrier to guarantee that labProbe is called on workers after data has been sent from the worker with labindex equal to 1. Then, use labProbe to test if data is available for each worker to receive. Use labReceive to collect the data.

    spmd
        switch labindex
            case 1
                A = magic(3);
                labSend(A,2);
        end
        
        labBarrier;
    
        tf = labProbe
        
        if tf
            labReceive;
        end
    end
    Worker 1: 
      
      tf =
      
        logical
      
         0
      
    Worker 2: 
      
      tf =
      
        logical
      
         1
      
    Worker 3: 
      
      tf =
      
        logical
      
         0
      
    Worker 4: 
      
      tf =
      
        logical
      
         0
      

    Input Arguments

    collapse all

    Index of the source worker, specified as a positive integer scalar or the character vector 'any'. The value must be less than or equal to the value given by numlabs, the number of workers running the current spmd block or communicating job. When specified as a positive integer scalar, labProbe returns logical 1 (true) if data is available to be received by the current worker from the worker with labindex equal to source. When not specified, labProbe returns logical 1 (true) if data is available to be received by the current worker from any worker.

    Example: 1

    Tag attached to data, specified as 0 or a positive integer scalar. When specified, labProbe returns logical 1 (true) if data sent using labSend with tag equal to tag is available to be received by the current worker.

    Example: 314159

    Output Arguments

    collapse all

    Index of workers that has sent data not yet received by the current worker, specified as a positive integer scalar or empty. The values are equal to labindex on each of the workers that sent data. If no data is available to be received, sources is [].

    Tag attached to data sent from workers that has not yet received by the current worker, specified as a positive integer scalar or empty. If no data is available to be received, tags is [].

    Version History

    Introduced before R2006a

    expand all

    See Also