DistributedArray provides the a number of functions for the user-interface. The definition of the collection and some useful functions are given below. Functions and variables internal to the collection are omitted.

Collection DistributedArray : public SuperKernel { public: DistributedArray(Distribution *T, Align *A); void Assign(int i, ElementType &e); void Assign(int i, int j, ElementType &e); DistributedArray<ElementType> &operator = (DistributedArray<ElementType> &rhs); void Shift(int dim, int distance); void Reduce(); void ReduceDim1(); void ReduceDim2(); void Broadcast(); void BroadcastDim1(); void BroadcastDim2(); double DotProd(DistributedArray<ElementType> &arg1); MethodOfElement: void WhereAmI(); virtual double Dot(ElementType &arg1); virtual ElementType &operator +=(ElementType &rhs); double dotprodtemp; };

DistributedArray(Distribution *T, Align *A) is the constructor of the collection. It has class objects Distribution and Align as its arguments.

Assign(int i, ElementType &e) copies an element of DistributedArray element type, argument ``e,'' to an element of an index ``i'' of the invoking DistributedArray object.

Assign(int i, int j, ElementType &e)

is its two-dimensional counterpart.

Operator ``='' is overloaded. It copies a DistributedArray object to another DistributedArray object.

Shift(int dim, int distance) performs a circular shift of collection elements parallel to a given dimension of the collection by a given distance. Elements shifted out at one end are shifted in at the other end. For example, Shift(1, 2) will shift elements parallel to the first dimension by a distance of 2.

Reduce() applies a global reduction to collection elements. Elements are summed together, the result is stored in element ``0,'' the very first element in the collection. It is assumed that the total number of elements in the collection is a power of two. The user needs to define function &operator +=(ElementType &rhs) before invoking this function.

ReduceDim1() applies a reduction parallel to the first dimension of the collection. Elements are summed together along columns, if the first index is defined as the row index and the second as the column index. The results are stored in elements in the first row. It is assumed that the number of rows is a power of two. The user needs to define function &operator +=(ElementType &rhs) before invoking this function.

ReduceDim2() applies a reduction parallel to the second dimension of the collection. Elements are summed together along rows. The results are stored in elements in the first column. It is assumed that the number of columns is a power of two. The user needs to define function &operator +=(ElementType &rhs) before invoking this function.

Broadcast() broadcasts element zero to all others elements in a collection. After the broadcast, each element gets an exact copy of the first element in the collection. It is assumed that the total number of elements in the collection is a power of two.

BroadcastDim1() broadcasts elements parallel to the first dimension. Elements in the first row are broadcast to elements in other rows. It is assumed that the number of rows is a power of two.

BroadcastDim2() broadcasts elements parallel to the second dimension. Elements in the first column are broadcast to elements in other columns. It is assumed that the number of columns is a power of two.

DotProd(DistributedArray<ElementType> &arg1) performs dot-product between elements of ``arg1'' and that of the invoking DistributedArray object. A user needs to define function Dot(ElementType &arg1) before invoking this function. This function can be used, for example, if each DistributedArray element is a segment of a vector that is distributed across the DistributedArray elements. A ``local dot-product'' is performed by the Dot function, which computes the dot-product between elements of the invoking object and the corresponding elements of ``arg1.'' The results of the local dot-product are added together by a global tree reduction to form the sum of the dot-product. The result of the sum is then broadcast to each element and stored in ``dotprodtemp.''

WhereAmI() prints out indexes of an element and the ID of the processor on which the element resides.

Virtual function Dot(ElementType &arg1) is called by function DotProd and needs to be defined by the user. Its implementation depends on the data structure of the element. As an example, element class myElement can be defined as follows:

The function computes the dot-product between array ``a'' of two collection elements. A user needs to define a dummy Dot(myElement &arg1) if function DotProd is to be invoked.class myElement { public: int i, j; double a[10]; double Dot(myElement &arg1); }; double myElement::Dot(myElement &arg1) { int i; double dot_sum; for(i = 0; i < 10; i++) dot_sum += this->a[i]*arg1.a[i]; return dot_sum; }

Virtual function &operator +=(ElementType &rhs) is called by the reduction functions and needs to be defined by the user. Its implementation depends on the data structure of the element. As an example, class myElement can be defined as

Here the overloaded operator sums the corresponding elements of array ``a'' together.class myElement { public: int i, j; double a[10]; myElement &operator +=(myElement &rhs); }; myElement& myElement::operator +=(myElement &rhs) { int i; for(i = 0; i < 10; i++) { this->a[i] += rhs.a[i]; } return *this; }

Mon Nov 21 09:49:54 EST 1994