function p = defaultPartition(n)
%codistributor1d.defaultPartition Default partition across the workers
%   codistributor1d.defaultPartition is the basis for DRANGE loops (Distributed
%   RANGE for-loops) and the default distribution of codistributed arrays.
%
%   P = codistributor1d.defaultPartition(N) is a vector of length spmdSize
%   with SUM(P) = N. Most of the elements of P are equal to
%   FLOOR(N/spmdSize) but the first REM(N,spmdSize) elements of P are equal
%   to CEIL(N/spmdSize). 
%
%   Example:
%   With spmdSize = 4
%
%     spmd
%         p = codistributor1d.defaultPartition(10)
%     end
%
%   returns p = [3 3 2 2] a vector of length 4 with sum(p) = 10.
%
%   This same p is used implicitly in a parallel for loop over 10 iterates:
%
%     spmd
%         x = [];
%         for i = drange(1 : 10)
%            x = [x i];
%         end
%         x
%     end
%
%   returns length p(spmdIndex) vectors x on each worker.
%
%   The same p is also the default partition for a codistributed matrix with
%   10 columns:
%
%     spmd
%         D = eye(10,codistributor('1d'))
%         dist = getCodistributor(D);
%         p = dist.Partition;
%     end
%
%   See also spmdSize, spmdIndex, CODISTRIBUTED, CODISTRIBUTED/COLON
%   CODISTRIBUTOR1D/EYE.

%   Copyright 2006-2023 The MathWorks, Inc.

narginchk(1, 1);

% Note that in the degenerate case where n equals 0, we return
% codistributor1d.unsetPartition.
p = distributedutil.getCodistributor1dDefaultPartition(n, spmdSize);
end
