-
Notifications
You must be signed in to change notification settings - Fork 97
BLAS 1::scal
Jennifer Loe edited this page May 8, 2020
·
2 revisions
Header File: KokkosBlas1_scal.hpp
Usage: KokkosBlas::scal(y,alpha,x);
Multiply each value of x(i)
or x(i,j)
with a scalar alpha
(or alpha(j)
), and assigns it to y(i)
or y(i,j)
respectively.
template<class OutputVector, class ScalarType, class InputVector>
void scal (const OutputVector& Y, const ScalarType& alpha, const InputVector& X);
- OutputVector: A rank-1 or rank-2
Kokkos::View
with non-const data type. - ScalarType: A scalar type or rank-1
Kokkos::View
. - InputVector: A rank-1 or rank-2
Kokkos::View
OutputVector::value_type == OutputVector::non_const_value_type
Y.rank == X.rank
-
Y.rank == 1
orY.rank == 2
Y.extent(0) == X.extent(0)
Y.extent(1) == X.extent(1)
- If
Y.rank == 1
thenScalarType
is a scalar type. - If
Y.rank == 2
thenScalarType
is aKokkos::View
andalpha.rank == 1
#include<Kokkos_Core.hpp>
#include<KokkosBlas1_scal.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);
KokkosBlas::scal(y,1.5,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*4.5,sum-1.0*N*4.5);
Kokkos::finalize();
}