Next: Communication Between Elements Up: A Brief Introduction Previous: ProcessorsThreads, and

Collections and Templates

The C++ language provides the templates mechanism to build parameterized classes. Collections are very similar to templates defined over TEClasses. In fact, it is almost sufficient to describe a collection class as


template <class ElementType>
TEClass MyCollection: Kernel<ElementType> {
  MyCollection(Distribution &D,Align &A)::
    Kernel(D,A) { ...}
      ...
};
where Kernel is a super-template class that defines the concurrent aggregate structure of the collection. Indeed, as will be shown in the following sections of this paper, it is the structure of Kernel and its basic constructors and member functions that is at the core of the runtime system for pC++.

While the construction above is nearly sufficient to define collections, it does not give us everything we want. In particular, collections define a generalization of data parallelism as follows. Let C be a collection type and E an element type. Assume E has the form


class E {
  int a;
  void f();
  E & operator +(E&);
};
and let x and y be declared to be of type C<E>. Because + is defined on the elements, one can write x+y and this means the ``pointwise'' addition of the elements and the result is a new collection of type C<E>. In a similar manner the expression x.a + y.a is a new collection of type C<int>. In addition, the expression x.f() means the parallel application of the element member function f to each element of the collection. These operations, together with collection specific reductions form the main parallel control in pC++.

To accomplish this we provide a special form of the C++ template construct with a distinguished class parameter, called ElementType, which defines the type of the element in the collection. The exact syntax is shown below:


Collection<class ElementType>
TEClass CollName: ParentCollection {
  public:
   CollName(Distribution &D, Align &A);
  private:
  protected:
   // TEClass member functions and fields.
   // Methods declared here are executed in
   // parallel by the associated PO thread.
  MethodOfElement:
   // Fields declared here are added to each
   // element, Methods to the element class.
}
Data fields defined in the public, private and protected areas are components of the underlying TEClass object. The size and shape of the collection and the way in which the elements of the collection are distributed to the processor object threads is defined by the Distribution and Alignment objects supplied to the constructor for the collection. The set of elements that are mapped to a single PO thread object is called the ``local collection'' for that thread. The data structure that contains and manages these elements is part of the Kernel class which is a required ancestor of any collection.



Next: Communication Between Elements Up: A Brief Introduction Previous: ProcessorsThreads, and


mohr@cs.uoregon.edu
Thu Feb 24 15:47:41 PST 1994