% Purpose: demonstrates MATLAB PCT commands with script
% Computes s = 1 + 2 + 3 + . . + n with nslots cores

% Compute with the Parallel Computing Toolbox

x2 = distributed.zeros(1,nslots);
spmd
  x2(labindex) = labindex;
end
% this is essential if mySCR invoked by MATLAB batch command
x2 = gather(x2);  

s2 = 0;    % initialize sum of arithmetic sequence
parfor i=1:n
    s2 = s2 + i;       % s = 1 + 2 + 3 + . . + n
end

txt2=sprintf(['Compute s = 1 + 2 + 3 + . . + n (n = %d)\n' ...
  'with Parallel Computing Toolbox parfor (%d cores)\n' ...
  'Computed s = %d; Expected s =  %d\n'], ... 
  n, nslots, s2, n*(n+1)/2);
