Skip to content

BLAS 1::abs

Christian Trott edited this page Jan 3, 2018 · 4 revisions

KokkosBlas::abs()

Header File: KokkosBlas1_abs.hpp

Usage: KokkosBlas::abs(y,x);

Computes for each value of x(i) or x(i,j) the absolute value, and assigns it to y(i) or y(i,j) respectively.

Interface

template<class OutputVector, class InputVector>
void abs (const OutputVector& R, const InputVector& X);

Parameters:

  • OutputVector: A rank-1 or rank-2 Kokkos::View with non-const data type.
  • InputVector: A rank-1 or rank-2 Kokkos::View

Requirements:

  • OutputVector::non_const_value_type == InputVector::non_const_value_type
  • R.rank == X.rank
  • R.extent(0) == X.extent(0)
  • R.extent(1) == X.extent(1)

Example

#include<Kokkos_Core.hpp>
#include<KokkosBlas1_abs.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,-1.0);

   KokkosBlas::abs(y,x);

   double sum = 0.0;
   Kokkos::parallel_reduce("CheckValue", N, KOKKOS_LAMBDA (const int& i, double& lsum) {
     lsum += y(i);
   },sum);

   printf("Sum: %lf Expected: %lf Diff: %e\n",sum,1.0*N,sum-1.0*N);

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