-
Notifications
You must be signed in to change notification settings - Fork 99
BLAS 1::sum
Nathan Ellingwood edited this page Jun 24, 2020
·
1 revision
Header File: KokkosBlas1_sum.hpp
Usage: sum = KokkosBlas::sum(x);
KokkosBlas::sum(r,x);
Return the sum of elements of x
, or replace entry of r
with sum of corresponding multi-vector entries of x
.
template<class XVector>
typename XVector::size_type sum (const XVector& x);
- XVector: a rank-1
Kokkos::View
x.rank == 1
template<class ReturnVector, class XVector>
void sum (const ReturnVector& r, const XVector& x);
- ReturnVector: a rank-0 or rank-1
Kokkos::View
- XVector: a rank-1 or rank-2
Kokkos::View
x.rank == r.rank + 1
r.extent(0) == x.extent(1)
ReturnVector::non_const_value_type == ReturnVector::value_type
ReturnVector::value_type == XVector::size_type
#include<Kokkos_Core.hpp>
#include<Kokkos_Random.hpp>
#include<KokkosBlas1_sum.hpp>
int main(int argc, char* argv[]) {
Kokkos::initialize();
{
int N = atoi(argv[1]);
using ViewType = Kokkos::View<double*>;
using Scalar = typename ViewType::non_const_value_type;
using AT = Kokkos::Details::ArithTraits<Scalar>;
using mag_type = typename AT::mag_type;
using size_type= typename ViewType::size_type;
ViewType x("X",N);
Kokkos::Random_XorShift64_Pool<typename ViewType::device_type::execution_space> rand_pool(13718);
Kokkos::fill_random(x,rand_pool,Scalar(10));
typename ViewType::HostMirror h_x = Kokkos::create_mirror_view(x);
Kokkos::deep_copy(h_x,x);
Scalar sum = KokkosBlas::sum(x);
Scalar expected_result = 0;
for(int i=0; i<N; i++) {
expected_result += h_x(i);
}
printf("Sum of X: %lf, Expected: %lf\n",sum, expected_result);
}
Kokkos::finalize();
}