Skip to content

BLAS 1::nrm2_squared

Christian Trott edited this page Jan 22, 2018 · 2 revisions

KokkosBlas::nrm2_squared()

Header File: KokkosBlas1_nrm2_squared.hpp

Usage: nrm = KokkosBlas::nrm2_squared(x); KokkosBlas::nrm2_squared(r,x);

Computes the sum of all squares of the absolute values of x.

Interface Single Vector Only

template<class VectorX, class VectorY>
InnerProductSpaceTraits<VectorX::non_const_value_type>::mag_type
nrm2_squared (const VectorX& X);

Parameters:

  • VectorX: A rank-1 Kokkos::View

Requirements:

  • X.rank == 1

Interface Single and MultiVector

template<class ReturnVector, class VectorX>
void nrm2_squared (const ReturnVector& R, const VectorX& X);

Parameters:

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

Requirements:

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

Example

#include<Kokkos_Core.hpp>
#include<KokkosBlas1_nrm2.hpp>

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

   int N = atoi(argv[1]);

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

   double x_nrm = KokkosBlas::nrm2_squared(x);

   printf("X_nrm: %lf Expected: %lf Diff: %e\n",x_nrm,1.0*(N*3.0*3.0),x_nrm-1.0*(N*3.0*3.0));

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