KokkosBlas::scal

Defined in header: KokkosBlas1_scal.hpp

template <class execution_space, class RMV, class AV, class XMV>
void scal(const execution_space& space, const RMV& R, const AV& a, const XMV& X);

template <class RMV, class AV, class XMV>
void scal(const RMV& R, const AV& a, const XMV& X);

Scales the vector(s) in X by a and stores the result(s) in R.

  1. store X scaled by a in R and fences the space instance

  2. store X scaled by a in R and fences the default instance of typename RMV::execution_space

The function will throw a runtime exception if X.extent(0) != R.extent(0) || X.extent(1) != R.extent(1)

Parameters

space:

execution space instance

R:

scaled version of the vector(s) of X

a:

scaling factor(s) for the vector(s) of X

X:

vector(s) to scale

Type Requirements

  • execution_space must be a Kokkos execution space

  • XMV must be a Kokkos View of rank 1 or 2 that satisfies

    • Kokkos::SpaceAccessibility<execution_space, typename XMV::memory_space>::accessible == true

    • RMV::rank == XMV::rank

  • RMV must be a Kokkos View of rank 1 or 2 that satisfies

    • Kokkos::SpaceAccessibility<execution_space, typename RMV::memory_space>::accessible == true

    • RMV::rank == XMV::rank

Example

#include <iostream>
#include <Kokkos_Core.hpp>
#include <KokkosBlas1_scal.hpp>

int main(void) {
  Kokkos::initialize();
  {
    Kokkos::View<double*> x("X", 5);
    auto h_x = Kokkos::create_mirror_view(x);
    Kokkos::deep_copy(h_x, -3.0);
    std::cout << "orignal values:\n"
              << "   {" << h_x(0) << ", " << h_x(1) << ", " << h_x(2) << ", " << h_x(3) << ", " << h_x(4) << "}"
              << std::endl;
    Kokkos::deep_copy(x, h_x);

    KokkosBlas::scal(x, -2.0, x);
    Kokkos::deep_copy(h_x, x);

    std::cout << "final values:\n"
              << "   {" << h_x(0) << ", " << h_x(1) << ", " << h_x(2) << ", " << h_x(3) << ", " << h_x(4) << "}"
              << std::endl;
  }
  Kokkos::finalize();
}

output:

orignal values:
   {-3, -3, -3, -3, -3}
final values:
   {6, 6, 6, 6, 6}