KokkosBlas::fill¶
Defined in header: KokkosBlas1_fill.hpp
template <class execution_space, class XMV>
void fill(const execution_space& space, const XMV& X, const typename XMV::non_const_value_type& val);
template <class XMV>
void fill(const XMV& X, const typename XMV::non_const_value_type& val);
Fills X with the value of val.
Overwrites the entries of X with val using
spaceinstance.Overwrites the entries of X with val using the default instance of
typename XMV::execution_space.
The function will throw a runtime exception if R.extent(0) != X.extent(0) || R.extent(1) != X.extent(1)
Parameters¶
- space:
execution space instance
- X:
input vector(s)
- val:
the value used to overwrite the entries of X
Type Requirements¶
execution_space must be a Kokkos execution space
XMV must be a Kokkos View that satisfies
Kokkos::SpaceAccessibility<execution_space, typename XMV::memory_space>::accessible
Example¶
1#include <iostream>
2#include <Kokkos_Core.hpp>
3#include <KokkosBlas1_fill.hpp>
4
5int main(void) {
6 Kokkos::initialize();
7 {
8 Kokkos::View<double*> x("x", 5);
9 auto h_x = Kokkos::create_mirror_view(x);
10 h_x(0) = 0.0;
11 h_x(1) = -1.0;
12 h_x(2) = -2.0;
13 h_x(3) = 3.0;
14 h_x(4) = -4.0;
15
16 std::cout << "orignal values:\n"
17 << " x: {" << h_x(0) << ", " << h_x(1) << ", " << h_x(2) << ", " << h_x(3) << ", " << h_x(4) << "}"
18 << std::endl;
19 Kokkos::deep_copy(x, h_x);
20
21 KokkosBlas::fill(x, 7);
22
23 Kokkos::deep_copy(h_x, x);
24 std::cout << "final values:\n"
25 << " x: {" << h_x(0) << ", " << h_x(1) << ", " << h_x(2) << ", " << h_x(3) << ", " << h_x(4) << "}"
26 << std::endl;
27 }
28 Kokkos::finalize();
29}
output:
orignal values:
x: {0, -1, -2, 3, -4}
final values:
x: {7, 7, 7, 7, 7}