Skip to content

BLAS 1::fill

Christian Trott edited this page Jan 22, 2018 · 1 revision

KokkosBlas::fill()

Header File: KokkosBlas1_fill.hpp

Usage: KokkosBlas::fill(x,alpha);

Set each value of x(i) or x(i,j) to alpha.

Interface

template<class Vector>
void fill (const Vector& X, Vector::const_value_type& alpha);

Parameters:

  • X: A rank-1 or rank-2 Kokkos::View with non-const data type.
  • alpha: A scalar.

Requirements:

  • Vector::value_type == Vector::non_const_value_type
  • X.rank == 1 or X.rank == 2

Example

#include<Kokkos_Core.hpp>
#include<KokkosBlas1_fill.hpp>

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

   int N = atoi(argv[1]);

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

   double alpha = 1.5;

   KokkosBlas::fill(x,alpha);

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

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

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