parallel ‐ A parallelization operator.
Synopsis
Declared in <folly/gen/Parallel.h>
template<
class Ops,
class Parallel = /* implementation-defined */>
Parallel
parallel(
Ops ops,
size_t threads = 0);
Description
'parallel(ops)' can be used with any generator to process a segment of the pipeline in parallel. Multiple threads are used to apply the operations ('ops') to the input sequence, with the resulting sequence interleaved to be processed on the client thread.
auto scoredResults = from(ids) | parallel(map(fetchObj) | filter(isValid) | map(scoreObj)) | as<vector>();
Operators specified for parallel execution must yield sequences, not just individual values. If a sink function such as 'count' is desired, it must be wrapped in 'sub' to produce a subcount, since any such aggregation must be re‐aggregated.
auto matches = from(docs) | parallel(filter(expensiveTest) | sub(count)) | sum;
Here, each thread counts its portion of the result, then the sub‐counts are summed up to produce the total count.
Return Value
An operator that applies ops across threads.
Parameters
Name |
Description |
ops |
The pipeline of operations to run in parallel. |
threads |
The number of worker threads to use; 0 selects a default. |
Created with MrDocs