%% Number of Partitions for Parallel Datastore Access
% Partition a datastore to facilitate parallel access over the available parallel pool of workers.
% Specify the file path to the audio samples included with Audio Toolbox™. Create an audio datastore that points to the specified folder.

folder = fullfile(matlabroot,'toolbox','audio','samples');
ADS = audioDatastore(folder);

%
% Return an estimate for a reasonable number of partitions for parallel processing, given the current parallel pool.

pool = gcp;
n = numpartitions(ADS,pool);

%
% Partition the audio datastore and read the data in each part.

parfor ii = 1:n
    subds = partition(ADS,n,ii);
    while hasdata(subds)
        data = read(subds);
    end
end

%
% Copyright 2018 The MathWorks, Inc.