pcxx_ug (1158314), страница 14
Текст из файла (страница 14)
It is assumedthat the total number of elements in the collection is a power of two.BroadcastDim1() broadcasts elements parallel to the rst dimension. Elements in therst row are broadcast to elements in other rows. It is assumed that the number of rows isa power of two.BroadcastDim2() broadcasts elements parallel to the second dimension. Elements in therst column are broadcast to elements in other columns. It is assumed that the number ofcolumns 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 denefunction 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 distributedacross 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 thecorresponding elements of \arg1." The results of the local dot-product are added togetherby a global tree reduction to form the sum of the dot-product.
The result of the sum is thenbroadcast to each element and stored in \dotprodtemp."WhereAmI() prints out indexes of an element and the ID of the processor on which theelement resides.Virtual function Dot(ElementType &arg1) is called by function DotProd and needs tobe dened by the user. Its implementation depends on the data structure of the element.As an example, element class myElement can be dened as follows:class myElement {public:int i, j;double a[10];double Dot(myElement &arg1);};double myElement::Dot(myElement &arg1){64int i;double dot_sum;for(i = 0; i < 10; i++)dot_sum += this->a[i]*arg1.a[i];return dot_sum;}The function computes the dot-product between array \a" of two collection elements.
Auser needs to dene a dummy Dot(myElement &arg1) if function DotProd is to be invoked.Virtual function &operator +=(ElementType &rhs) is called by the reduction functionsand needs to be dened by the user. Its implementation depends on the data structure ofthe element. As an example, class myElement can be dened asclass 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;}Here the overloaded operator sums the corresponding elements of array \a" together.65AcknowledgmentsThis research is supported by DARPA under contract AF 30602-92-C-0135 from Rome Labs,National Science Foundation Oce of Advanced Scientic Computing under grant ASC9111616.Special thanks to Bernd Mohr at University of Oregon for proofreading the manuscriptand pointing out several errors in an earlier draft.66.