%% ParallelPartition
% This example shows 
%% no pool to start

% Copyright 2015 The MathWorks, Inc.

delete(gcp('nocreate'));

%% serial function
% <include>sumAndCountArrivalDelay.m</include>

%% Serial partition
ds = datastore(repmat({'airlinesmall.csv'},20,1),'TreatAsMissing','NA');
ds.SelectedVariableNames = 'ArrDelay';

reset(ds);
tic
  [total,count] = sumAndCountArrivalDelay(ds)
sumtime = toc
mean = total/count

%% parfor function
% <include>parforSumAndCountArrivalDelay.m</include>

%% Automatic partitions
p = parpool('local',4);

reset(ds);
tic
  [total,count] = parforSumAndCountArrivalDelay(ds)
parfortime = toc
mean = total/count

%% spmd function
% <include>spmdSumAndCountArrivalDelay.m</include>

%% numlab partitions
reset(ds);
tic
  [total,count] = spmdSumAndCountArrivalDelay(ds)
spmdtime = toc
mean = total/count
%% shut down pool
delete(p);
