Main Content

codistributor2dbc.defaultWorkerGrid

Default computational grid for 2-D block-cyclic distributed arrays

    Description

    grid = codistributor2dbc.defaultWorkerGrid returns a vector defining a computational grid of nrow-by-ncol workers such that the product is the number of workers running in the current spmd block or communicating job. To get the number of workers running in the current spmd block, use the spmdSize function. The grid defined by codistributor2dbc.defaultWorkerGrid is as close to a square as possible. The following rules define the nrow and ncol of the grid:

    • If the number of workers running in the current spmd block is a perfect square, nrow = ncol = sqrt(spmdSize).

    • If the number of workers running in the current spmd block is an odd power of 2, then nrow = ncol/2 = sqrt(spmdSize/2).

    • nrow <= ncol.

    • If the number of workers running in the current spmd block is a prime number, nrow = 1, ncol = spmdSize.

    • nrow is the greatest integer less than or equal to sqrt(spmdSize) for which ncol = spmdSize/nrow is also an integer.

    example

    Examples

    collapse all

    Use codistributor2dbc.defaultWorkerGrid to get the layout of the default computational grid for 2-D block-cyclic distributed arrays in an spmd block.

    Create a parallel pool with four workers.

    parpool(4);

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

    View the computational grid layout of the default distribution scheme for the current spmd block.

    spmd
        grid = codistributor2dbc.defaultWorkerGrid
    end
    Worker 3: 
      
      grid =
      
           2     2
      
    Worker 4: 
      
      grid =
      
           2     2
      
    Worker 1: 
      
      grid =
      
           2     2
      
    Worker 2: 
      
      grid =
      
           2     2
      

    Output Arguments

    collapse all

    Default computational grid for 2-D block-cyclic distributed arrays in an spmd block, returned as a vector of nrow-by-ncol workers. The product of nrow*nrow is the number of workers running the current spmd block or communicating job.

    Version History

    Introduced in R2009b

    expand all