function tf = isreplicated( C )
%ISREPLICATED Check whether Composite data is replicated on workers
%   TF = ISREPLICATED( C ) returns true if the entries in Composite C have
%   defined values on all workers, and those values are identical.
%
%   Example:
%   spmd
%     c1 = spmdIndex + 1;
%     c2 = ones( 1, spmdSize );
%     if spmdIndex > 1
%       c3 = 1;
%     end
%   end
%   % providing the available parallel pool size is > 1
%   isreplicated( c1 ) % false - different values
%   isreplicated( c2 ) % true  - same value everywhere
%   isreplicated( c3 ) % false - not defined on all workers
%
%   See also COMPOSITE, ISREPLICATED

% Copyright 2009-2022 The MathWorks, Inc.

if all( exist( C ) ) %#ok<EXIST> Composite.exist()
    tf = spmd_feval_fcn( @iIsReplicated, {C} );
    tf = tf.Value;
else
    tf = false;
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function tfAuto = iIsReplicated( C )
tfAuto = distributedutil.AutoTransfer( isreplicated( C ) );
end
