%% Run parfor on a Cluster Without a Parallel Pool
% Create a cluster object using the parcluster function, and create a set of parfor options with it. By default, parcluster uses your default cluster profile. Check your default profile on the MATLAB Home tab, in Parallel > Select a Default Cluster.

cluster = parcluster;

% To run parfor computations directly in the cluster, pass the cluster object as the second input argument to parfor.
% When you use this approach, parfor can use all the available workers in the cluster, and workers become available as soon as the loop completes. This approach is also useful if your cluster does not support parallel pools. If you want to control other options, including partitioning of iterations, use parforOptions.

values = [3 3 3 7 3 3 3];
parfor (i=1:numel(values),cluster)
    out(i) = norm(pinv(rand(values(i)*1e3)));
end

% Use this syntax to run parfor on a large cluster without consuming workers for longer than necessary.
% Copyright 2018 The MathWorks, Inc.