1 #ifndef VIEW_ARITHMETIC_HPP
2 #define VIEW_ARITHMETIC_HPP
18 template<
typename V1,
typename V2,
typename T>
20 if (dest_view.size() != added_view.size())
exit_XGC(
"\nWARNING: dest_view and added_view are not the same size");
24 Kokkos::parallel_for(
"host_add_ay_to_x", Kokkos::RangePolicy<HostExSpace>( 0, dest_view.size()), KOKKOS_LAMBDA(
const int idx){
25 ptrs.x[idx] += coeff*ptrs.y[idx];
30 template<
typename V1,
typename V2>
32 if (dest_view.size() != multiplier_view.size())
exit_XGC(
"\nWARNING: dest_view and multiplier_view are not the same size");
36 Kokkos::parallel_for(
"host_multiply_x_by_y", Kokkos::RangePolicy<HostExSpace>( 0, dest_view.size()), KOKKOS_LAMBDA(
const int idx){
37 ptrs.x[idx] *= ptrs.y[idx];
42 template<
typename V1,
typename V2>
44 if (dest_view.size() != divisor_view.size())
exit_XGC(
"\nWARNING: dest_view and divisor_view are not the same size");
48 Kokkos::parallel_for(
"host_divide_x_by_y", Kokkos::RangePolicy<HostExSpace>( 0, dest_view.size()), KOKKOS_LAMBDA(
const int idx){
49 ptrs.x[idx] /= ptrs.y[idx];
54 template<
typename V1,
typename T>
56 double coeff_inv = 1.0/coeff;
59 View<typename V1::value_type*,CLayout, typename V1::device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged>> view_1D(dest_view.data(), dest_view.size());
62 Kokkos::parallel_for(
"divide_x_by_a", Kokkos::RangePolicy<typename V1::execution_space>( 0, view_1D.size()), KOKKOS_LAMBDA(
const int idx){
63 view_1D(idx) *= coeff_inv;
69 template<
typename V1,
typename V2>
71 if (dest_view.size() != device_view.size())
exit_XGC(
"\nWARNING: dest_view and device_view are not the same size");
74 View<double*,CLayout,HostType> view_tmp_h(
NoInit(
"view_tmp_h"), device_view.size());
75 View<double*,CLayout,typename V2::device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged>> view_tmp_d(device_view.data(),device_view.size());
76 Kokkos::deep_copy(view_tmp_h, view_tmp_d);
80 Kokkos::parallel_for(
"host_view_sum", Kokkos::RangePolicy<HostExSpace>( 0, dest_view.size()), KOKKOS_LAMBDA(
const int idx){
81 ptrs.x[idx] += ptrs.y[idx];
87 inline typename T::value_type
sum_view(
const T& view){
89 View<typename T::value_type*,CLayout, typename T::device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged>> view_1D(view.data(), view.size());
91 typename T::value_type sum = 0;
92 Kokkos::parallel_reduce(
"sum", Kokkos::RangePolicy<typename T::execution_space>( 0,view.size() ), KOKKOS_LAMBDA(
const int i,
typename T::value_type& sum_l){
102 inline typename T::value_type
max_view(
const T& view){
104 View<typename T::value_type*,CLayout, typename T::device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged>> view_1D(view.data(), view.size());
106 typename T::value_type maxval = 0;
107 Kokkos::parallel_reduce(
"maxval", Kokkos::RangePolicy<typename T::execution_space>( 0,view.size() ), KOKKOS_LAMBDA(
const int i,
typename T::value_type& maxval_l){
108 maxval_l = max(maxval_l, view_1D(i));
109 }, Kokkos::Max<typename T::value_type,HostType>(maxval));
void host_divide_x_by_y(V1 &dest_view, const V2 &divisor_view)
Definition: view_arithmetic.hpp:43
void host_multiply_x_by_y(V1 &dest_view, const V2 &multiplier_view)
Definition: view_arithmetic.hpp:31
T::value_type max_view(const T &view)
Definition: view_arithmetic.hpp:102
void add_device_view_to_host_view(V1 &dest_view, const V2 &device_view)
Definition: view_arithmetic.hpp:70
void host_add_ay_to_x(V1 &dest_view, const V2 &added_view, T coeff)
Definition: view_arithmetic.hpp:19
T * y
Definition: view_arithmetic.hpp:12
ViewArithmeticPointers(T *x, T *y)
Definition: view_arithmetic.hpp:14
T::value_type sum_view(const T &view)
Definition: view_arithmetic.hpp:87
void exit_XGC(std::string msg)
Definition: globals.hpp:37
void parallel_for(const std::string name, int n_ptl, Function func, Option option, HostAoSoA aosoa_h, DeviceAoSoA aosoa_d)
Definition: streamed_parallel_for.hpp:252
Definition: view_arithmetic.hpp:10
T * x
Definition: view_arithmetic.hpp:11
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68
void divide_x_by_a(const V1 &dest_view, T coeff)
Definition: view_arithmetic.hpp:55