function dgrid = defaultWorkerGrid()
%codistributor2dbc.defaultWorkerGrid    MATLAB's choice for computational grid
%   dgrid = codistributor2dbc.defaultWorkerGrid()
%            = [nprow, npcol]
%   Express spmdSize as nprow*npcol with integers nprow <= npcol.
%   nprow is the greatest integer <= sqrt(spmdSize) for which
%   npcol = spmdSize/nprow is also an integer.
%   If spmdSize is a perfect square, then nprow = npcol = sqrt(spmdSize).
%   If spmdSize is a prime, then nprow = 1, npcol = spmdSize.
%   If spmdSize is an even power of 2, then nprow = npcol = sqrt(spmdSize).
%   If spmdSize is an odd power of 2, then nprow = npcol/2 = sqrt(spmdSize/2).
%
%   Example:
%     spmd
%         codistr = codistributor2dbc()
%     end
%   returns a distribution scheme with codistr.WorkerGrid set to
%   codistributor2dbc.defaultWorkerGrid 
%
%   See also codistributor2dbc, codistributor2dbc/defaultBlockSize,
%   codistributor2dbc/defaultOrientation

%   Copyright 2006-2022 The MathWorks, Inc.

nprow = floor(sqrt(spmdSize));
npcol = spmdSize/nprow;
while npcol ~= round(npcol)
   nprow = nprow - 1;
   npcol = spmdSize/nprow;
end
dgrid = [nprow npcol];

end % End of defaultWorkerGrid.
