Skip to content

BLAS 1::dot

Jennifer Loe edited this page May 12, 2020 · 4 revisions

KokkosBlas::dot()

Header File: KokkosBlas1_dot.hpp

Usage: result = KokkosBlas::dot(x,y); KokkosBlas::dot(r,x,y);

Multiplies each value of x(i) [x(i,j)] with y(i) or [y(i,j)] and computes the sum. (If x and y have scalar type Kokkos::complex, the complex conjugate of x(i) or x(i,j) will be used.)

Interface Single Vector only

template<class VectorX, class VectorY>
InnerProductSpaceTraits<VectorX::non_const_value_type>::dot_type
dot (const VectorX& X, const VectorY& Y);

Parameters:

  • VectorX: A rank-1 Kokkos::View
  • VectorY: A rank-1 Kokkos::View

Requirements:

  • Y.rank == 1 or X.rank == 1
  • Y.extent(0) == X.extent(0)

Interface Single and MultiVector

template<class ReturnVector, class VectorX, class VectorY>
void dot (const ReturnVector& R, const VectorX& X, const VectorY& Y);

Parameters:

  • ReturnVector: A rank-0 or rank-1 Kokkos::View
  • VectorX: A rank-1 or rank-2 Kokkos::View
  • VectorY: A rank-1 or rank-2 Kokkos::View

Requirements:

  • X.rank == Y.rank
  • X.rank == R.rank + 1
  • Y.extent(0) == X.extent(0)
  • Y.extent(1) == X.extent(1)
  • R.extent(0) == X.extent(1)
  • ReturnVector::non_const_value_type == ReturnVector::value_type

Example

#include<Kokkos_Core.hpp>
#include<KokkosBlas1_dot.hpp>

int main(int argc, char* argv[]) {
   Kokkos::initialize();

   int N = atoi(argv[1]);

   Kokkos::View<double*> x("X",N);
   Kokkos::View<double*> y("Y",N);
   Kokkos::deep_copy(x,3.0);
   Kokkos::deep_copy(y,2.0);

   double x_y = KokkosBlas::dot(x,y);

   printf("X_dot_Y: %lf Expected: %lf Diff: %e\n",x_y,1.0*N*(3.0 * 2.0),x_y-1.0*N(3.0 * 2.0));

   Kokkos::finalize();
}
Clone this wiki locally