Main Content

numlabs

(Not recommended) Number of workers running current spmd block

    numlabs is not recommended. Use spmdSize instead. For more information, see Version History.

    Description

    n = numlabs returns the number of workers running the current spmd block or communicating job. This value is the maximum value that can be used with labSend and labReceive.

    example

    Examples

    collapse all

    This example shows how to run numlabs inside and outside an spmd block.

    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.

    Run numlabs inside and outside an spmd block. In the block, the returned value is equal to the number of workers. Outside the block, the returned value is 1.

    spmd
        disp(numlabs)
    end
    disp(numlabs)
    Worker 1: 
           4
      
    Worker 2: 
           4
      
    Worker 3: 
           4
      
    Worker 4: 
           4
      
         1

    Output Arguments

    collapse all

    Number of workers running the current spmd block or communicating job, specified as an integer. In an spmd block, numlabs returns the number of workers running the spmd block. Outside an spmd block, numlabs is 1.

    When you create a communicating job using createCommunicatingJob, you can run a function or script on N workers. When one of the workers runs numlabs, the returned value is N.

    Version History

    Introduced before R2006a

    collapse all

    R2022b: numlabs is not recommended

    To indicate their intended use within spmd blocks, numlabs is renamed to spmdSize. numlabs will continue to work but is no longer recommended. To update your code, replace any instance of numlabs with spmdSize. There are no plans to remove numlabs.

    See Also