KokkosLapack::getrs¶
Defined in header: KokkosLapack_getrs.hpp
template <class ExecutionSpace, class AMatrix, class IpivView, class BMatrix, class InfoView>
void getrs(const ExecutionSpace& space, const char trans[], const AMatrix& A, const IpivView& Ipiv, const BMatrix& B,
const InfoView& Info);
template <class AMatrix, class IpivView, class BMatrix, class InfoView>
void getrs(const char trans[], const AMatrix& A, const IpivView& Ipiv, const BMatrix& B, const InfoView& Info);
where \(A\) is a square matrix that store \(L\) and \(U\) factors obtained from KokkosLapack::getrf, \(B\) is the right handside of the problem and \(X\) is the left hand side solution that we are seeking.
Swap entries of \(B\) using \(Ipiv\) and apply two triangular solves for the lower and upper factors stored in \(A\) to overwrite \(B\) with the solution of to the system of equations. If a transpose or conjugate transpose mode is requested, the order of operations is reversed.
Same as 1. but uses the resources of the default execution space from
AMatrix::execution_space.
Parameters¶
- space:
execution space instance.
- trans:
a transpose mode to apply to matrix A: “N” for no transpose, “T” for transpose and “C” for conjugate transpose.
- A:
The input matrix that contains the \(L\) and \(U\) factors from a call to getrf.
- Ipiv:
Pivots to apply to \(B\)
- B:
On input the right hand side vectors that gets overwritten on output by the solution vectors.
- Info:
A scalar (stored in a device view) that holds the return code indicating if a zero pivot was detected.
Type Requirements¶
ExecutionSpace must be a Kokkos execution space
AMatrix must be a Kokkos View of rank 2 that satisfies
Kokkos::SpaceAccessibility<ExecutionSpace, typename AMatrix::memory_space>::accessible
IpivView must be a Kokkos View of rank 1 that satisfies
Kokkos::SpaceAccessibility<ExecutionSpace, typename IpivView::memory_space>::accessiblestd::is_integral_v<typename IpivView::non_const_value_type>
BMatrix must be a Kokkos View of rank 2 that satisfies
Kokkos::SpaceAccessibility<ExecutionSpace, typename AMatrix::memory_space>::accessible!std::is_const_v<typename BMatrix::value_type>
InfoView must be a Kokkos View of rank 1 that satisfies
Kokkos::SpaceAccessibility<ExecutionSpace, typename Info::memory_space>::accessiblestd::is_same_v<typename InfoView::value_type, int>
Example¶
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright Contributors to the Kokkos project
#include <Kokkos_Core.hpp>
#include <KokkosLapack_getrs.hpp>
#include <iostream>
int main(void) {
bool correct = true;
Kokkos::initialize();
{
using execution_space = Kokkos::DefaultExecutionSpace;
using KAT = KokkosKernels::ArithTraits<double>;
Kokkos::View<double**, Kokkos::LayoutLeft> A("A", 3, 3);
Kokkos::View<double**, Kokkos::LayoutLeft> B("B", 3, 2);
Kokkos::View<int*, Kokkos::LayoutLeft> Ipiv("Ipiv", 3);
Kokkos::View<int*, Kokkos::LayoutLeft> Info("Info", 1);
{
auto h_A = Kokkos::create_mirror_view(A);
h_A(0, 0) = -1;
h_A(0, 1) = 2;
h_A(0, 2) = -1;
h_A(1, 0) = 2;
h_A(1, 1) = -1;
h_A(1, 2) = 0;
h_A(2, 0) = 0;
h_A(2, 1) = -1;
h_A(2, 2) = 2;
Kokkos::deep_copy(A, h_A);
}
auto h_B = Kokkos::create_mirror_view(B);
h_B(0, 0) = 0;
h_B(0, 1) = 0;
h_B(1, 0) = 4;
h_B(1, 1) = -2;
h_B(2, 0) = 4;
h_B(2, 1) = 4;
execution_space space{};
KokkosLapack::getrs(space, "N", A, Ipiv, B, Info);
Kokkos::fence();
Kokkos::deep_copy(h_B, B);
auto h_Ipiv = Kokkos::create_mirror_view(Ipiv);
Kokkos::deep_copy(h_Ipiv, Ipiv);
if (KAT::abs(h_B(0, 0) - 1) > 10 * KAT::epsilon()) {
correct = false;
}
if (KAT::abs(h_B(1, 0) - 2) / 2 > 10 * KAT::epsilon()) {
correct = false;
}
if (KAT::abs(h_B(2, 0) - 3) / 3 > 10 * KAT::epsilon()) {
correct = false;
}
if (KAT::abs(h_B(0, 1) - 3) / 3 > 10 * KAT::epsilon()) {
correct = false;
}
if (KAT::abs(h_B(1, 1) - 2) / 2 > 10 * KAT::epsilon()) {
correct = false;
}
if (KAT::abs(h_B(2, 1) - 3) / 3 > 10 * KAT::epsilon()) {
correct = false;
}
if (correct) std::cout << "KokkosLapack::getrs() returned correct results!" << std::endl;
}
Kokkos::finalize();
}
output: