Next: Working with the Up: Communication between Collection Previous: Vector Subsets of

More on ThisCollection. Ver. 2.0

A standard member of the MethodOfElement fields that are added to each element is the ThisCollection pointer which allows an element to refer the the collection (TEClass) object for which it is a local collection member. In this section we will illustrate how it can be used to access local collection data members.

The third way to write the summation program is to have each element add its value into a local collection variable. In this case we create an ElementType Object local_total (which we assume is initialized to a ``zero'' value) as a member field in the Collection TEClass object.

Collection D: SuperKernel{
      ElementType local_total;
      D(Distribution *d, Align *A);
      ElementType reduce2();
      virtual ElementType &operator +=(ElementType &);
      void accumulate();

The accumulation function adds each element value directly to local_total.

void D::accumulate(){
   D<ElementType> * ptr;
   ptr = (D<ElementType> *) ThisCollection;
   ptr->local_total += *this;
Note that because ThisCollection is inherited from the SuperKernel, we must cast it to the type of our collection before we can access the local_total field.

The reduction function which runs in each TEClass processors/object thread will invoke the accumulate function on each element. It is important to understand that, within a processors object thread, this action is completely serial, so there is no ``race condition'' involved with the update to local_total. We use a simple TEClass reduction function to compute the total between threads as shown below.

ElementType D::reduce2(){
     return pCxx_sum(&local_total);
NOTE: for Version 1.0, the pCxx_sum() function is not yet part of the standard library. However, everything else described in this subsection will work in version 1.0.
Mon Nov 21 09:49:54 EST 1994