42#ifndef TPETRA_BLOCKVIEW_HPP
43#define TPETRA_BLOCKVIEW_HPP
53#include "TpetraCore_config.h"
54#include "Kokkos_ArithTraits.hpp"
55#include "Kokkos_Complex.hpp"
72template<
class ViewType1,
74 const int rank1 = ViewType1::rank>
92 static_assert (
static_cast<int> (ViewType1::rank) ==
static_cast<int> (ViewType2::rank),
93 "AbsMax: ViewType1 and ViewType2 must have the same rank.");
94 typedef typename std::remove_reference<
decltype (
Y(0,0)) >::type
STY;
95 static_assert(! std::is_const<STY>::value,
96 "AbsMax: The type of each entry of Y must be nonconst.");
97 typedef typename std::decay<
decltype (
X(0,0)) >::type
STX;
98 static_assert( std::is_same<STX, STY>::value,
99 "AbsMax: The type of each entry of X and Y must be the same.");
100 typedef Kokkos::Details::ArithTraits<STY>
KAT;
102 const int numCols =
Y.extent (1);
104 for (
int j = 0;
j < numCols; ++
j) {
132 static_assert (
static_cast<int> (ViewType1::rank) ==
static_cast<int> (ViewType2::rank),
133 "AbsMax: ViewType1 and ViewType2 must have the same rank.");
135 typedef typename std::remove_reference<
decltype (
Y(0)) >::type
STY;
136 static_assert(! std::is_const<STY>::value,
137 "AbsMax: The type of each entry of Y must be nonconst.");
138 typedef typename std::remove_const<
typename std::remove_reference<
decltype (
X(0)) >::type>::type
STX;
139 static_assert( std::is_same<STX, STY>::value,
140 "AbsMax: The type of each entry of X and Y must be the same.");
141 typedef Kokkos::Details::ArithTraits<STY>
KAT;
164template<
class ViewType1,
class ViewType2, const
int rank = ViewType1::rank>
168 static_assert (
static_cast<int> (ViewType1::rank) ==
static_cast<int> (ViewType2::rank),
169 "absMax: ViewType1 and ViewType2 must have the same rank.");
179 class LayoutType =
typename ViewType::array_layout,
181 const int rank = ViewType::rank>
243 typedef typename std::decay<
decltype (
A(0,0)) >::type scalar_type;
244 scalar_type*
const A_raw =
A.data ();
259 class LayoutType =
typename ViewType::array_layout,
261 const int rank = ViewType::rank>
311 class LayoutType1 =
typename ViewType1::array_layout,
312 class LayoutType2 =
typename ViewType2::array_layout,
314 const int rank = ViewType1::rank>
337 using Kokkos::Details::ArithTraits;
338 static_assert (
static_cast<int> (ViewType1::rank) ==
static_cast<int> (ViewType2::rank),
339 "AXPY: x and y must have the same rank.");
365 using Kokkos::Details::ArithTraits;
366 static_assert (ViewType1::rank == ViewType2::rank,
367 "AXPY: X and Y must have the same rank.");
395 using Kokkos::Details::ArithTraits;
396 static_assert (
static_cast<int> (ViewType1::rank) ==
397 static_cast<int> (ViewType2::rank),
398 "AXPY: X and Y must have the same rank.");
399 typedef typename std::decay<
decltype (
X(0,0)) >::type
SX;
400 typedef typename std::decay<
decltype (
Y(0,0)) >::type
SY;
428 using Kokkos::Details::ArithTraits;
429 static_assert (ViewType1::rank == ViewType2::rank,
430 "AXPY: X and Y must have the same rank.");
431 typedef typename std::decay<
decltype (
X(0,0)) >::type
SX;
432 typedef typename std::decay<
decltype (
Y(0,0)) >::type
SY;
452 class LayoutType1 =
typename ViewType1::array_layout,
453 class LayoutType2 =
typename ViewType2::array_layout,
455 const int rank = ViewType1::rank>
515 typedef typename std::decay<
decltype (
X(0,0)) >::type
SX;
516 typedef typename std::decay<
decltype (
Y(0,0)) >::type
SY;
540 typedef typename std::decay<
decltype (
X(0,0)) >::type
SX;
541 typedef typename std::decay<
decltype (
Y(0,0)) >::type
SY;
570 static_assert (VecType1::rank == 1,
"GEMV: VecType1 must have rank 1.");
571 static_assert (BlkType::rank == 2,
"GEMV: BlkType must have rank 2.");
572 static_assert (VecType2::rank == 1,
"GEMV: VecType2 must have rank 1.");
573 typedef typename std::decay<
decltype (
y(0)) >::type
y_elt_type;
588template<
class VecType1,
593struct GEMV<VecType1, BlkType, VecType2, CoeffType, IndexType,
594 Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight>
596 static KOKKOS_INLINE_FUNCTION
void
597 run (
const CoeffType& alpha,
602 static_assert (VecType1::rank == 1,
"GEMV: VecType1 must have rank 1.");
603 static_assert (BlkType::rank == 2,
"GEMV: BlkType must have rank 2.");
604 static_assert (VecType2::rank == 1,
"GEMV: VecType2 must have rank 1.");
605 typedef typename std::decay<
decltype (y(0)) >::type y_elt_type;
606 typedef typename std::decay<
decltype (A(0,0)) >::type A_elt_type;
608 const IndexType numRows =
static_cast<IndexType
> (A.extent (0));
609 const IndexType numCols =
static_cast<IndexType
> (A.extent (1));
610 const A_elt_type*
const A_raw = A.data ();
612 for (IndexType i = 0; i < numRows; ++i) {
613 y_elt_type y_i = y(i);
614 const A_elt_type*
const A_i = A_raw + i*numCols;
615 for (IndexType j = 0; j < numCols; ++j) {
616 y_i += alpha * A_i[j] * x(j);
623template<
class VecType1,
628struct GEMV<VecType1, BlkType, VecType2, CoeffType, IndexType,
629 Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft>
631 static KOKKOS_INLINE_FUNCTION
void
632 run (
const CoeffType& alpha,
637 static_assert (VecType1::rank == 1,
"GEMV: VecType1 must have rank 1.");
638 static_assert (BlkType::rank == 2,
"GEMV: BlkType must have rank 2.");
639 static_assert (VecType2::rank == 1,
"GEMV: VecType2 must have rank 1.");
640 typedef typename std::decay<
decltype (A(0,0)) >::type A_elt_type;
642 const A_elt_type*
const A_raw = A.data ();
643 const IndexType numRows =
static_cast<IndexType
> (A.extent (0));
644 const IndexType numCols =
static_cast<IndexType
> (A.extent (1));
645 for (IndexType j = 0; j < numCols; ++j) {
646 const A_elt_type*
const A_j = A_raw + j*numRows;
647 for (IndexType i = 0; i < numRows; ++i) {
648 y(i) += alpha * A_j[i] * x(i);
658template<
class ViewType,
659 class CoefficientType,
660 class LayoutType =
typename ViewType::array_layout,
661 class IndexType = int,
662 const int rank = ViewType::rank>
663KOKKOS_INLINE_FUNCTION
void
670template<
class ViewType,
672 class LayoutType =
typename ViewType::array_layout,
673 class IndexType = int,
674 const int rank = ViewType::rank>
675KOKKOS_INLINE_FUNCTION
void
686template<
class CoefficientType,
689 class LayoutType1 =
typename ViewType1::array_layout,
690 class LayoutType2 =
typename ViewType2::array_layout,
691 class IndexType = int,
692 const int rank = ViewType1::rank>
693KOKKOS_INLINE_FUNCTION
void
698 static_assert (
static_cast<int> (ViewType1::rank) ==
699 static_cast<int> (ViewType2::rank),
700 "AXPY: x and y must have the same rank.");
713template<
class ViewType1,
715 class LayoutType1 =
typename ViewType1::array_layout,
716 class LayoutType2 =
typename ViewType2::array_layout,
717 class IndexType = int,
718 const int rank = ViewType1::rank>
719KOKKOS_INLINE_FUNCTION
void
722 static_assert (
static_cast<int> (ViewType1::rank) ==
723 static_cast<int> (ViewType2::rank),
724 "COPY: x and y must have the same rank.");
740template<
class VecType1,
744 class IndexType =
int>
745KOKKOS_INLINE_FUNCTION
void
762template<
class ViewType1,
765 class CoefficientType,
766 class IndexType =
int>
767KOKKOS_INLINE_FUNCTION
void
777 static_assert (ViewType1::rank == 2,
"GEMM: A must have rank 2 (be a matrix).");
778 static_assert (ViewType2::rank == 2,
"GEMM: B must have rank 2 (be a matrix).");
779 static_assert (ViewType3::rank == 2,
"GEMM: C must have rank 2 (be a matrix).");
781 typedef typename std::remove_reference<
decltype (
A(0,0))>::type
Scalar;
782 typedef Kokkos::Details::ArithTraits<Scalar> STS;
904template<
class LittleBlockType,
905 class LittleVectorType>
906KOKKOS_INLINE_FUNCTION
void
910 typedef typename std::decay<
decltype (
ipiv(0)) >::type
IndexType;
911 static_assert (std::is_integral<IndexType>::value,
912 "GETF2: The type of each entry of ipiv must be an integer type.");
913 typedef typename std::remove_reference<
decltype (
A(0,0))>::type
Scalar;
914 static_assert (! std::is_const<Scalar>::value,
915 "GETF2: A must not be a const View (or LittleBlock).");
916 static_assert (! std::is_const<std::remove_reference<
decltype (
ipiv(0))>>::value,
917 "GETF2: ipiv must not be a const View (or LittleBlock).");
918 static_assert (LittleBlockType::rank == 2,
"GETF2: A must have rank 2 (be a matrix).");
919 typedef Kokkos::Details::ArithTraits<Scalar> STS;
942 if(STS::abs(
A(
i,
j)) > STS::abs(
A(
jp,
j))) {
985template<
class LittleBlockType,
986 class LittleIntVectorType,
987 class LittleScalarVectorType,
988 const int rank = LittleScalarVectorType::rank>
991 run (
const char mode[],
1004 run (
const char mode[],
1011 typedef typename std::decay<
decltype (
ipiv(0))>::type
IndexType;
1014 static_assert (std::is_integral<IndexType>::value &&
1015 std::is_signed<IndexType>::value,
1016 "GETRS: The type of each entry of ipiv must be a signed integer.");
1017 typedef typename std::decay<
decltype (
A(0,0))>::type
Scalar;
1018 static_assert (! std::is_const<std::remove_reference<
decltype (
B(0))>>::value,
1019 "GETRS: B must not be a const View (or LittleBlock).");
1020 static_assert (LittleBlockType::rank == 2,
"GETRS: A must have rank 2 (be a matrix).");
1021 static_assert (LittleIntVectorType::rank == 1,
"GETRS: ipiv must have rank 1.");
1022 static_assert (LittleScalarVectorType::rank == 1,
"GETRS: For this specialization, B must have rank 1.");
1024 typedef Kokkos::Details::ArithTraits<Scalar> STS;
1045 if(
mode[0] ==
'n' ||
mode[0] ==
'N') {
1077 else if(
mode[0] ==
't' ||
mode[0] ==
'T') {
1082 else if (
mode[0] ==
'c' ||
mode[0] ==
'C') {
1100 run (
const char mode[],
1107 typedef typename std::decay<
decltype (
ipiv(0)) >::type
IndexType;
1108 static_assert (std::is_integral<IndexType>::value,
1109 "GETRS: The type of each entry of ipiv must be an integer type.");
1110 static_assert (! std::is_const<std::remove_reference<
decltype (
B(0)) > >::value,
1111 "GETRS: B must not be a const View (or LittleBlock).");
1112 static_assert (LittleBlockType::rank == 2,
"GETRS: A must have rank 2 (be a matrix).");
1113 static_assert (LittleIntVectorType::rank == 1,
"GETRS: ipiv must have rank 1.");
1114 static_assert (LittleScalarVectorType::rank == 2,
"GETRS: For this specialization, B must have rank 2.");
1123 auto B_cur = Kokkos::subview (
B, Kokkos::ALL (),
rhs);
1166template<
class LittleBlockType,
1167 class LittleIntVectorType,
1168 class LittleScalarVectorType>
1169KOKKOS_INLINE_FUNCTION
void
1176 typedef typename std::decay<
decltype (
ipiv(0))>::type
IndexType;
1179 static_assert (std::is_integral<IndexType>::value &&
1180 std::is_signed<IndexType>::value,
1181 "GETRI: The type of each entry of ipiv must be a signed integer.");
1182 typedef typename std::remove_reference<
decltype (
A(0,0))>::type
Scalar;
1183 static_assert (! std::is_const<std::remove_reference<
decltype (
A(0,0))>>::value,
1184 "GETRI: A must not be a const View (or LittleBlock).");
1185 static_assert (! std::is_const<std::remove_reference<
decltype (
work(0))>>::value,
1186 "GETRI: work must not be a const View (or LittleBlock).");
1187 static_assert (LittleBlockType::rank == 2,
"GETRI: A must have rank 2 (be a matrix).");
1188 typedef Kokkos::Details::ArithTraits<Scalar> STS;
1271template<
class LittleBlockType,
1272 class LittleVectorTypeX,
1273 class LittleVectorTypeY,
1274 class CoefficientType,
1275 class IndexType =
int>
1276KOKKOS_INLINE_FUNCTION
void
1277GEMV (
const char trans,
1278 const CoefficientType& alpha,
1279 const LittleBlockType& A,
1280 const LittleVectorTypeX& x,
1281 const CoefficientType& beta,
1282 const LittleVectorTypeY& y)
1288 typedef typename std::remove_reference<
decltype (y(0)) >::type y_value_type;
1289 const IndexType numRows =
static_cast<IndexType
> (A.extent (0));
1290 const IndexType numCols =
static_cast<IndexType
> (A.extent (1));
1294 for (IndexType i = 0; i < numRows; ++i) {
1299 for (IndexType i = 0; i < numRows; ++i) {
1300 y_value_type y_i = 0.0;
1301 for (IndexType j = 0; j < numCols; ++j) {
1302 y_i += A(i,j) * x(j);
1311 for (IndexType i = 0; i < numRows; ++i) {
1316 for (IndexType i = 0; i < numRows; ++i) {
1322 for (IndexType i = 0; i < numRows; ++i) {
1323 y_value_type y_i = beta * y(i);
1324 for (IndexType j = 0; j < numCols; ++j) {
1325 y_i += alpha * A(i,j) * x(j);
Struct that holds views of the contents of a CrsMatrix.
KOKKOS_INLINE_FUNCTION void absMax(const ViewType2 &Y, const ViewType1 &X)
Implementation of Tpetra's ABSMAX CombineMode for the small dense blocks in BlockCrsMatrix,...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
KOKKOS_INLINE_FUNCTION void GEMV(const CoeffType &alpha, const BlkType &A, const VecType1 &x, const VecType2 &y)
y := y + alpha * A * x (dense matrix-vector multiply)
KOKKOS_INLINE_FUNCTION void GETF2(const LittleBlockType &A, const LittleVectorType &ipiv, int &info)
Computes A = P*L*U.
KOKKOS_INLINE_FUNCTION void SCAL(const CoefficientType &alpha, const ViewType &x)
x := alpha*x, where x is either rank 1 (a vector) or rank 2 (a matrix).
KOKKOS_INLINE_FUNCTION void GETRI(const LittleBlockType &A, const LittleIntVectorType &ipiv, const LittleScalarVectorType &work, int &info)
Compute inverse of A, using result of GETRF or GETF2.
KOKKOS_INLINE_FUNCTION void FILL(const ViewType &x, const InputType &val)
Set every entry of x to val.
KOKKOS_INLINE_FUNCTION void AXPY(const CoefficientType &alpha, const ViewType1 &x, const ViewType2 &y)
y := y + alpha * x (dense vector or matrix update)
KOKKOS_INLINE_FUNCTION void GETRS(const char mode[], const LittleBlockType &A, const LittleIntVectorType &ipiv, const LittleScalarVectorType &B, int &info)
Solve the linear system(s) AX=B, using the result of GETRF or GETF2.
KOKKOS_INLINE_FUNCTION void GEMM(const char transA[], const char transB[], const CoefficientType &alpha, const ViewType1 &A, const ViewType2 &B, const CoefficientType &beta, const ViewType3 &C)
Small dense matrix-matrix multiply: C := alpha*A*B + beta*C
@ ZERO
Replace old values with zero.
KOKKOS_INLINE_FUNCTION void COPY(const ViewType1 &x, const ViewType2 &y)
Deep copy x into y, where x and y are either rank 1 (vectors) or rank 2 (matrices) with the same dime...
static KOKKOS_INLINE_FUNCTION void run(const CoefficientType &alpha, const ViewType1 &X, const ViewType2 &Y)
Y := Y + alpha*X (rank-2 X and Y, i.e., matrices)
static KOKKOS_INLINE_FUNCTION void run(const CoefficientType &alpha, const ViewType1 &X, const ViewType2 &Y)
Y := Y + alpha*X (rank-2 X and Y, i.e., matrices)
static KOKKOS_INLINE_FUNCTION void run(const CoefficientType &alpha, const ViewType1 &X, const ViewType2 &Y)
Y := Y + alpha*X (rank-2 X and Y, i.e., matrices)
static KOKKOS_INLINE_FUNCTION void run(const CoefficientType &alpha, const ViewType1 &x, const ViewType2 &y)
y := y + alpha*x (rank-1 x and y, i.e., vectors)
Implementation of Tpetra::AXPY function.
static KOKKOS_INLINE_FUNCTION void run(const ViewType2 &Y, const ViewType1 &X)
(*this)(i) := max(abs((*this)(i)), abs(X(i))) for all i.
static KOKKOS_INLINE_FUNCTION void run(const ViewType2 &Y, const ViewType1 &X)
(*this)(i,j) := max(abs((*this)(i,j)), abs(X(i,j))) for all (i,j).
Implementation of Tpetra's ABSMAX CombineMode for the small dense blocks in BlockCrsMatrix,...
static KOKKOS_INLINE_FUNCTION void run(const ViewType1 &X, const ViewType2 &Y)
Y := X (rank-2 X and Y, i.e., matrices)
static KOKKOS_INLINE_FUNCTION void run(const ViewType1 &X, const ViewType2 &Y)
Y := X (rank-2 X and Y, i.e., matrices)
static KOKKOS_INLINE_FUNCTION void run(const ViewType1 &x, const ViewType2 &y)
y := x (rank-1 x and y, i.e., vectors)
static KOKKOS_INLINE_FUNCTION void run(const ViewType1 &X, const ViewType2 &Y)
Y := X (rank-2 X and Y, i.e., matrices)
Implementation of Tpetra::COPY function.
Implementation of Tpetra::FILL function.
Computes the solution to Ax=b.
static KOKKOS_INLINE_FUNCTION void run(const CoefficientType &alpha, const ViewType &A)
A := alpha*A (rank-2 A, i.e., a matrix)
static KOKKOS_INLINE_FUNCTION void run(const CoefficientType &alpha, const ViewType &x)
x := alpha*x (rank-1 x, i.e., a vector)
static KOKKOS_INLINE_FUNCTION void run(const CoefficientType &alpha, const ViewType &A)
A := alpha*A (rank-2 A, i.e., a matrix)
Implementation of Tpetra::SCAL function.