Next: The DistributedArray Collection Up: The pC++ Kernel Previous: The pC++ Kernel

The pC++ SuperKernel collection

The SuperKernel collection inherits Kernel class, therefore, all functionalities available to the Kernel class are available as ``methods of collection'' in Superkernel. SuperKernel is designed as a base collection so that new collections can be derived from it. It provides a few basic element access functions. The declaration of the SuperKernel is as follows:


Collection SuperKernel : public Kernel {
 public:
  int dim1size;
  int dim2size;
  SuperKernel(Distribution *T, Align *A);
  ElementType  *operator()(int i);           
  ElementType  *operator()(int i, int j);  
 MethodOfElement:
  int Ident;
  int index1;
  int index2;
  SuperKernel<ElementType> *ThisCollection;
  ElementType *Self(int i);        
  ElementType *Self(int i, int j); 
};
In the ``methods of collection'' part (part before the MethodOfElement statement), ``dim1size'' and ``dim2size'' denote the first and second dimension sizes of the collection. They are set by the alignment parameter, Align, in the collection constructor. Operators (int i) and (int i, int j) are overloaded. So instead of using Get_Element(), a user uses these operators to fetch elements. Suppose we construct a one-dimensional collection of myElement by calling SuperKernel constructor,

  SuperKernel<myElement> S(&D, &A);
S(10) then returns a pointer to the 11th element of the collection and S(10)->a will return a pointer to the array ``a.'' Meanwhile, S(10)->a[5] will return the 6th element in the array.

In the ``methods of elements'' part (part after the MethodOfElement statement), ``index1'' and ``index2'' denote the indexes assigned to a collection element. These indexes can be accessed by an element. For example, in a two-dimensional collection, function foo() can be defined as


void myElement::foo() {
  if(index1 == 1) printf("Hello from element (%d, %d)\n", index1, index2);
}
In this example, all elements with index1 = 1 print the message.

The pointer ``ThisCollection'' provides a way for the methods of element to access methods of collection. Without it methods of element cannot execute a method of collection. We can modify the above example to allow foo() access a collection element:


void myElement::foo() {
  a[5] = (*ThisCollection)(2,3)->a[5];
}
In this example the value of a[5] of collection element (2,3) is assigned to a[5] of the current element. Since every element executes this operation, the value of a[5] of element (2,3) is broadcast to other elements in the collection. Note that currently this is not an efficient way to broadcast, because (*ThisCollection)(2,3) simply invokes the overloaded operator which fetches the entire element (2,3) and returns a pointer to the copy. In our future release, the compiler will convert this to Get_ElementPartDouble so that only array element a[5] is fetched.

The ``Self'' functions in methods of element provide another convenient way for an element to address other elements in a collection. The integers ``i'' and ``j'' represent index offsets to the current element. As an example, Self(1,1) would return the element with indexes (index1+1, index2+1), where index1 and index2 are the indexes of the current element.



Next: The DistributedArray Collection Up: The pC++ Kernel Previous: The pC++ Kernel


beckman@cica.indiana.edu
Mon Nov 21 09:49:54 EST 1994