GrPPI
0.3.1
Generic and Reusable Parallel Pattern Interface
|
The map/reduce pattern combines a map and reduce operation in a single pattern. In a map/reduce operation, firstly one or more input data sets are mapped by applying a transformation operation. Then, the results are combined by means of a reduction operation.
The interface to the map/reduce pattern is provided by function grppi::map_reduce()
. As all functions in GrPPI, this function takes as its first argument an execution policy.
Note: A map/reduce could be also expressed by the composition of a map and a reduce. However, map/reduce may fuse both stages, allowing for extra optimizations.
There are several variants:
There are two central elements of a map/reduce: the Transformer used for the map stage, and the Combiner used for the reduce stage.
A Transformer may be a UnaryTransformer or a MultiTransformer.
A UnaryTransformer is any C++ callable entity that takes a data item and transforms it. The input type and the output type may differ. Thus, a unary transformer op
is any operation that, given an input x
of type T
and output type U
, makes valid the following:
A MultiTransformer is any C++ callable entity that takes data items, one of each input sequence, and transforms them into an output value. The input types and the output type may differ. Thus, a multi-transformer op
is any operation that, given the inputs x1, x2, ... , xN
of types T1, T2, ... , TN
and an output type U
, makes valid the following:
A Combiner is any C++ callable entity, that is able to combine two values into a single value. A Combiner cmb
is any operation taking two values x
and y
of types T
and U
and returning a combined value of type T
, making valid the following:
An unary map/reduce takes a single data set and performs consecutively the map and the reduce stages, returning the reduced value.
The only interface currently offered for this pattern is based on iterators (following the C++ standard library conventions):
A unary map/reduce also requires an identity value for the Combiner.
Example: Transforms a sequence of strings to its corresponding double values and computes the addition of those values.
A n-ary map/reduce takes multiple data sets and performs consecutively the map and reduce stages, returning the reduced value.
The only interface currently offered for this pattern is based on iterators (following the C++ standard library conventions):
A n-ary map/reduce also requires an identity value for the Combiner.
Example: Compute scalar vector between two vectors of doubles.
Example: Count word appearances in text lines.