Given two global vectors x and y in objects x and y, we wish to compute their inner product
Notice that if both x and y are of object type vector and they are aligned identically to the template, then the result equals
Thus, in this situation it suffices
to call the local inner product routine on the local data,
and reduce the results into the global result ,
stored in alpha.
If x and y are not distributed as vectors,
one approach is to create two temporary vectors
that are aligned, copy x and y into the
temporary vectors, execute the above described procedure
for aligned vectors, and compute the result.
We illustrate code for this solution in
Figure .
In the implementation of the routine pdot,
we are given objects x, y and alpha
as parameters to the subroutine.
The first two we assume are of object type
vector, possibly projected
and/or duplicated. The last is a
multiscalar,
possibly duplicated in rows and/or columns.
We start by creating temporary objects,
temp_x and temp_y, of object
type vector, identically aligned to the template.
We also create temp_alpha, a
multiscalar duplicated
on all nodes, so that all nodes have a place to put local
results.
The contents of x and y are copied to the temporary vectors
using PLA_Copy.
Local results are computed by calling PLA_Local_dot,
leaving the result in the local buffer of temp_alpha.
Finally, the local contributions are
reduced into the output multiscalar alpha.
PLACE BEGIN HR HERE
PLACE END HR HERE