function [allNames, defaultName] = listProfiles
%parallel.listProfiles Return the name of all valid parallel computing profiles
%   ALLPROFILES = parallel.listProfiles returns a cell array
%   containing the names of all available profiles.
%
%   [ALLPROFILES, DEFAULTPROFILE] = parallel.listProfiles returns a 
%   cell array containing the names of all available profiles, and 
%   separately the name of the default profile.
%
%   The cell array ALLPROFILES always contains a profile called 'local'
%   for the local cluster.  The default profile returned by
%   parallel.listProfiles is guaranteed to be found in ALLPROFILES.
%
%   If the default profile has been deleted, or if it has never been
%   set, parallel.clusterProfiles returns 'local' as the default
%   profile.
%
%   Profiles of cluster type can be created and changed using the saveProfile 
%   or saveAsProfile methods on a cluster object.  Profiles can be created, 
%   deleted, and changed using  the Cluster Profiles Manager.  On the Home
%   tab, in the Environment section, click Parallel > Create and Manager 
%   Clusters... to open the Cluster Profiles Manager.
%
%   Examples: 
%   Display the names of all the available profiles and set the first in the
%   list to be the default.
%      allNames = parallel.listProfiles()
%      parallel.defaultProfile(allNames{1});
%
%
%   See also PARPOOL, BATCH, PARCLUSTER, parallel.defaultProfile,
%   parallel.Cluster.saveProfile, parallel.Cluster.saveAsProfile.

%  Copyright 2011-2022 The MathWorks, Inc.

try
    parallel.internal.pool.errorIfPoolThreadWorker(mfilename);
    p = parallel.Settings;
    allNames = p.hGetAllProfileNames();
    allNames = allNames(parallel.internal.settings.isProfileVisible(allNames));
    
    defaultName = p.DefaultProfile;
catch err
    throw(err);
end
