function varargout = flip(varargin)
%FLIP  Flip a distributed array in one direction.
%   FLIP(X) returns X flipped in the first non-singleton dimension.
%   FLIP(X,DIM) returns X with dimension DIM flipped.
%   
%   Example:
%       V1 = distributed.rand(1,20);
%       V2 = flip(V1)
%       D1 = distributed.rand(10,20,30);
%       D2 = flip(D1,2)
%   
%   See also FLIP, DISTRIBUTED, DISTRIBUTED/FLIPLR, DISTRIBUTED/FLIPUD, DISTRIBUTED/RAND.
%   


%   Copyright 2013-2019 The MathWorks, Inc.

% Gather all but first input
if nargin>1
    [varargin{2:end}] = gather(varargin{2:end});
end

% If first input is distributed, call remote version
if isdistributed(varargin{1})
    [varargout{1:max(nargout, 1)}] = distributedutil.distributedSpmdWrapper( @flip, varargin{:} );
else % Otherwise, call client version
    [varargout{1:max(nargout, 1)}] = flip(varargin{:});
end
