Main Content

numpartitions

Return estimate for reasonable number of partitions for parallel processing

Description

example

n= numpartitions(sds)returns the default number of partitions for the signal datastoresds.

example

n= numpartitions(sds,pool)returns a reasonable number of partitions to parallelizesdsover the parallel pool.

  • Ifsds包含文件数据,分区数取决于池中工人的数量和文件总数。

  • Ifsdscontains in-memory data, the number of partitions depends on the number of workers in the pool and the total number of members.

要并行化数据存储访问,您必须安装并行计算工具箱™。

Examples

collapse all

Specify the file path to the example signals included with MATLAB®. Create a signal datastore that points to the specified folder.

folder = fullfile(matlabroot,'toolbox','matlab','audiovideo'); sds = signalDatastore(folder,'SampleRateVariableName','Fs');

Get the default number of partitions for the signal datastore.

n = numpartitions(sds)
n = 7

Partition the datastore into the default number of partitions and return the datastore corresponding to the fourth partition.

subsds = partition(sds,n,4);

Use theextractAfterfunction to display the name of the file contained in the datastore corresponding to the fourth partition.

fname = extractafter(subsds.files,'audiovideo\')
fname =1x1 cell array{0x0 char}

Read the data and information about the signal in the datastore corresponding to the fourth partition. Extract the sample rate frominfoand resample the signal to half the original sample rate. Plot the original and resampled signals.

whilehasdata(subsds)[data,info] = read(subsds);fs = info.samplater;f_res = 0.5*fs;ts =(0:长度(data)-1)/fs;data_res = respample(数据,1,2);t_res =(0:长度(data_res)-1)/f_res;图(TS,DATA,T_RES,DATA_RES,':')xlabel('Time (s)')ylabel('Signal') legend('Original','Resampled','地点','NorthWest')end

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Original, Resampled.

Specify the path to a directory containing example signals included with MATLAB®.

folder = fullfile(matlabroot,'toolbox','matlab','audiovideo');

Create a signal datastore that points to the specified folder.

sds = signalDatastore(folder);

给定当前的并行池,返回对并行处理的合理数量分区的估计值。

pool = gcp;
Starting parallel pool (parpool) using the 'local' profile ... Connected to the parallel pool (number of workers: 6).
n = numpartitions(sds,pool)
n = 7

Partition the signal datastore and read the signal data in each part.

parforII = 1:n subds =分区(SDS,N,II);whilehasdata(subds) data = read(subds);endend

Input Arguments

collapse all

信号数据存储,指定为signalDatastore目的。

Parallel pool, specified as a parallel pool object.

Output Arguments

collapse all

Number of partitions over which datastore access is parallelized. By default, the number of partitions ismin(N观察, 3Nworkers), where:

  • N观察is the number of files in the datastore (in case of file data) or number of members in the datastore (in case of in-memory data).

  • Nworkersis the number of workers in the pool.

版本历史

Introduced in R2020a