Check out the new USENIX Web site. next up previous contents
Next: Data Parallel Algorithms Up: Data Parallel Objects Previous: Type-specific Reduction

Using Reduction Objects

The user code uses the reduction facility as given below. Each thread does the following:

  1. Obtain the reduction tree skeleton object corresponding to this thread's rope.
  2. For each type T for which reduction operation is to be performed, create a type-specific per-thread reduction object.
  3. For each reducer (binary commutative and associative operator for type T), invoke the '()' operator of the ReductionT object.
The following piece of code shows a sum reduction followed by a product reduction on integer types. It is executed by each thread in the rope.
 // build the type specific reduction object

ReductionT<int, binary_function<int, int, int> >

red_obj(Rope::SelfRope().ReductionObj());

int my_contrib =

// sum reduction

int my_sum = red_obj(plus<int>, my_contrib);

// product reduction

int my_prod = red_obj(times<int>, my_contrib);

where ReducerType is a type of a binary function object which expects two arguments of type convertible to type T, and result type is a type convertible to type T. The constructor expects a Reduction object as an argument which is typically Rope::SelfRope().ReductionObj(). The class also exports a type called reducer_type which is the same as the actual argument for the template parameter ReducerType, and a type data_type which is basically type T. The () operator takes two arguments - reducer is a binary commutative and associative function object that is used in the reduction, and data is the contribution of the thread to the reduction operation. The () operator performs the actual reduction - each thread participating in the reduction operation invokes the () operator while in a data parallel computation. Note that all the threads should specify the same reducer_type argument. Making it a part of the () operator allows us to reuse the same reduction object for a different reduction operation easily.



Sundaresan Neelakantan
Thu May 15 16:11:49 PDT 1997