User`s guide
Partition a Datastore in Parallel
6-65
[total,count] = sumAndCountArrivalDelay(ds)
sumtime = toc
mean = total/count
total =
17211680
count =
2417320
sumtime =
10.8273
mean =
7.1201
The partition function allows you to partition the datastore into smaller parts,
each represented as a datastore itself. These smaller datastores work completely
independently of each other, so that you can work with them inside of parallel language
features such as parfor loops and spmd blocks.
The number of partitions in the following code is set by the numpartitions function,
based on the datastore itself (ds) and the parallel pool (gcp) size. This does not
necessarily equal the number of workers in the pool. In this case, the number of loop
iterations is then set to the number of partitions (N).
The following code starts a parallel pool on a local cluster, then partitions the datastore
among workers for iterating over the loop. Again, a separate function is called, which
includes the parfor loop to amass the count and sum totals. Copy and save this function
if you want to run the example.
function [total, count] = parforSumAndCountArrivalDelay(ds)
N = numpartitions(ds,gcp);