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"
72 template<
class ViewType1,
74 const int rank1 = ViewType1::rank>
76 static KOKKOS_INLINE_FUNCTION
void
77 run (
const ViewType2& Y,
const ViewType1& X);
84 template<
class ViewType1,
86 struct AbsMax<ViewType1, ViewType2, 2> {
89 static KOKKOS_INLINE_FUNCTION
void
90 run (
const ViewType2& Y,
const ViewType1& X)
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);
103 const int numRows = Y.extent (0);
104 for (
int j = 0; j < numCols; ++j) {
105 for (
int i = 0; i < numRows; ++i) {
107 const STX X_ij = X(i,j);
110 const auto Y_ij_abs = KAT::abs (Y_ij);
111 const auto X_ij_abs = KAT::abs (X_ij);
112 Y_ij = (Y_ij_abs >= X_ij_abs) ?
113 static_cast<STY> (Y_ij_abs) :
114 static_cast<STY
> (X_ij_abs);
124 template<
class ViewType1,
129 static KOKKOS_INLINE_FUNCTION
void
130 run (
const ViewType2& Y,
const ViewType1& X)
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;
143 const int numRows = Y.extent (0);
144 for (
int i = 0; i < numRows; ++i) {
146 const STX X_i = X(i);
149 const auto Y_i_abs = KAT::abs (Y_i);
150 const auto X_i_abs = KAT::abs (X_i);
151 Y_i = (Y_i_abs >= X_i_abs) ?
152 static_cast<STY> (Y_i_abs) :
153 static_cast<STY
> (X_i_abs);
164 template<
class ViewType1,
class ViewType2, const
int rank = ViewType1::rank>
165 KOKKOS_INLINE_FUNCTION
void
166 absMax (
const ViewType2& Y,
const ViewType1& X)
168 static_assert (static_cast<int> (ViewType1::rank) == static_cast<int> (ViewType2::rank),
169 "absMax: ViewType1 and ViewType2 must have the same rank.");
177 template<
class ViewType,
178 class CoefficientType,
179 class LayoutType =
typename ViewType::array_layout,
180 class IndexType = int,
181 const int rank = ViewType::rank>
183 static KOKKOS_INLINE_FUNCTION
void
184 run (
const CoefficientType& alpha,
const ViewType& x);
189 template<
class ViewType,
190 class CoefficientType,
193 struct SCAL<ViewType, CoefficientType, LayoutType, IndexType, 1> {
195 static KOKKOS_INLINE_FUNCTION
void
196 run (
const CoefficientType& alpha,
const ViewType& x)
198 const IndexType numRows =
static_cast<IndexType
> (x.extent (0));
200 for (IndexType i = 0; i < numRows; ++i) {
208 template<
class ViewType,
209 class CoefficientType,
212 struct SCAL<ViewType, CoefficientType, LayoutType, IndexType, 2> {
214 static KOKKOS_INLINE_FUNCTION
void
215 run (
const CoefficientType& alpha,
const ViewType& A)
217 const IndexType numRows =
static_cast<IndexType
> (A.extent (0));
218 const IndexType numCols =
static_cast<IndexType
> (A.extent (1));
221 for (IndexType i = 0; i < numRows; ++i) {
222 for (IndexType j = 0; j < numCols; ++j) {
223 A(i,j) = alpha * A(i,j);
234 template<
class ViewType,
235 class CoefficientType,
237 struct SCAL<ViewType, CoefficientType, Kokkos::LayoutRight, IndexType, 2> {
239 static KOKKOS_INLINE_FUNCTION
void
240 run (
const CoefficientType& alpha,
const ViewType& A)
242 const IndexType N = A.size ();
243 typedef typename std::decay<decltype (A(0,0)) >::type scalar_type;
244 scalar_type*
const A_raw = A.data ();
246 for (IndexType i = 0; i < N; ++i) {
247 A_raw[i] = alpha * A_raw[i];
257 template<
class ViewType,
259 class LayoutType =
typename ViewType::array_layout,
260 class IndexType = int,
261 const int rank = ViewType::rank>
263 static KOKKOS_INLINE_FUNCTION
void
264 run (
const ViewType& x,
const InputType& val);
269 template<
class ViewType,
273 struct FILL<ViewType, InputType, LayoutType, IndexType, 1> {
274 static KOKKOS_INLINE_FUNCTION
void
275 run (
const ViewType& x,
const InputType& val)
277 const IndexType numRows =
static_cast<IndexType
> (x.extent (0));
278 for (IndexType i = 0; i < numRows; ++i) {
286 template<
class ViewType,
290 struct FILL<ViewType, InputType, LayoutType, IndexType, 2> {
291 static KOKKOS_INLINE_FUNCTION
void
292 run (
const ViewType& X,
const InputType& val)
294 const IndexType numRows =
static_cast<IndexType
> (X.extent (0));
295 const IndexType numCols =
static_cast<IndexType
> (X.extent (1));
296 for (IndexType j = 0; j < numCols; ++j) {
297 for (IndexType i = 0; i < numRows; ++i) {
308 template<
class CoefficientType,
311 class LayoutType1 =
typename ViewType1::array_layout,
312 class LayoutType2 =
typename ViewType2::array_layout,
313 class IndexType = int,
314 const int rank = ViewType1::rank>
316 static KOKKOS_INLINE_FUNCTION
void
317 run (
const CoefficientType& alpha,
324 template<
class CoefficientType,
330 struct AXPY<CoefficientType, ViewType1, ViewType2, LayoutType1, LayoutType2, IndexType, 1> {
332 static KOKKOS_INLINE_FUNCTION
void
333 run (
const CoefficientType& alpha,
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.");
341 const IndexType numRows =
static_cast<IndexType
> (y.extent (0));
342 if (alpha != ArithTraits<CoefficientType>::zero ()) {
343 for (IndexType i = 0; i < numRows; ++i) {
344 y(i) += alpha * x(i);
352 template<
class CoefficientType,
358 struct AXPY<CoefficientType, ViewType1, ViewType2, LayoutType1, LayoutType2, IndexType, 2> {
360 static KOKKOS_INLINE_FUNCTION
void
361 run (
const CoefficientType& alpha,
365 using Kokkos::Details::ArithTraits;
366 static_assert (ViewType1::rank == ViewType2::rank,
367 "AXPY: X and Y must have the same rank.");
368 const IndexType numRows =
static_cast<IndexType
> (Y.extent (0));
369 const IndexType numCols =
static_cast<IndexType
> (Y.extent (1));
371 if (alpha != ArithTraits<CoefficientType>::zero ()) {
372 for (IndexType i = 0; i < numRows; ++i) {
373 for (IndexType j = 0; j < numCols; ++j) {
374 Y(i,j) += alpha * X(i,j);
384 template<
class CoefficientType,
388 struct AXPY<CoefficientType, ViewType1, ViewType2, Kokkos::LayoutRight, Kokkos::LayoutRight, IndexType, 2> {
390 static KOKKOS_INLINE_FUNCTION
void
391 run (
const CoefficientType& alpha,
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;
402 const IndexType N =
static_cast<IndexType
> (Y.size ());
403 const SX*
const X_raw = X.data ();
404 SY*
const Y_raw = Y.data ();
406 if (alpha != ArithTraits<CoefficientType>::zero ()) {
407 for (IndexType i = 0; i < N; ++i) {
408 Y_raw[i] += alpha * X_raw[i];
417 template<
class CoefficientType,
421 struct AXPY<CoefficientType, ViewType1, ViewType2, Kokkos::LayoutLeft, Kokkos::LayoutLeft, IndexType, 2> {
423 static KOKKOS_INLINE_FUNCTION
void
424 run (
const CoefficientType& alpha,
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;
434 const IndexType N =
static_cast<IndexType
> (Y.size ());
435 const SX*
const X_raw = X.data ();
436 SY*
const Y_raw = Y.data ();
438 if (alpha != ArithTraits<CoefficientType>::zero ()) {
439 for (IndexType i = 0; i < N; ++i) {
440 Y_raw[i] += alpha * X_raw[i];
450 template<
class ViewType1,
452 class LayoutType1 =
typename ViewType1::array_layout,
453 class LayoutType2 =
typename ViewType2::array_layout,
454 class IndexType = int,
455 const int rank = ViewType1::rank>
457 static KOKKOS_INLINE_FUNCTION
void
458 run (
const ViewType1& x,
const ViewType2& y);
463 template<
class ViewType1,
468 struct COPY<ViewType1, ViewType2, LayoutType1, LayoutType2, IndexType, 1> {
470 static KOKKOS_INLINE_FUNCTION
void
471 run (
const ViewType1& x,
const ViewType2& y)
473 const IndexType numRows =
static_cast<IndexType
> (x.extent (0));
474 for (IndexType i = 0; i < numRows; ++i) {
482 template<
class ViewType1,
487 struct COPY<ViewType1, ViewType2, LayoutType1, LayoutType2, IndexType, 2> {
489 static KOKKOS_INLINE_FUNCTION
void
490 run (
const ViewType1& X,
const ViewType2& Y)
492 const IndexType numRows =
static_cast<IndexType
> (Y.extent (0));
493 const IndexType numCols =
static_cast<IndexType
> (Y.extent (1));
496 for (IndexType i = 0; i < numRows; ++i) {
497 for (IndexType j = 0; j < numCols; ++j) {
507 template<
class ViewType1,
510 struct COPY<ViewType1, ViewType2, Kokkos::LayoutRight, Kokkos::LayoutRight, IndexType, 2> {
512 static KOKKOS_INLINE_FUNCTION
void
513 run (
const ViewType1& X,
const ViewType2& Y)
515 typedef typename std::decay<decltype (X(0,0)) >::type SX;
516 typedef typename std::decay<decltype (Y(0,0)) >::type SY;
518 const IndexType N =
static_cast<IndexType
> (Y.size ());
519 const SX*
const X_raw = X.data ();
520 SY*
const Y_raw = Y.data ();
523 for (IndexType i = 0; i < N; ++i) {
532 template<
class ViewType1,
535 struct COPY<ViewType1, ViewType2, Kokkos::LayoutLeft, Kokkos::LayoutLeft, IndexType, 2> {
537 static KOKKOS_INLINE_FUNCTION
void
538 run (
const ViewType1& X,
const ViewType2& Y)
540 typedef typename std::decay<decltype (X(0,0)) >::type SX;
541 typedef typename std::decay<decltype (Y(0,0)) >::type SY;
543 const IndexType N =
static_cast<IndexType
> (Y.size ());
544 const SX*
const X_raw = X.data ();
545 SY*
const Y_raw = Y.data ();
548 for (IndexType i = 0; i < N; ++i) {
555 template<
class VecType1,
559 class IndexType = int,
560 class VecLayoutType1 =
typename VecType1::array_layout,
561 class BlkLayoutType =
typename BlkType::array_layout,
562 class VecLayoutType2 =
typename VecType2::array_layout>
564 static KOKKOS_INLINE_FUNCTION
void
565 run (
const CoeffType& alpha,
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;
575 const IndexType numRows =
static_cast<IndexType
> (A.extent (0));
576 const IndexType numCols =
static_cast<IndexType
> (A.extent (1));
578 for (IndexType i = 0; i < numRows; ++i) {
579 y_elt_type y_i = y(i);
580 for (IndexType j = 0; j < numCols; ++j) {
581 y_i += alpha * A(i,j) * x(j);
588 template<
class VecType1,
593 struct 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);
623 template<
class VecType1,
628 struct 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);
658 template<
class ViewType,
659 class CoefficientType,
660 class LayoutType =
typename ViewType::array_layout,
661 class IndexType = int,
662 const int rank = ViewType::rank>
663 KOKKOS_INLINE_FUNCTION
void
664 SCAL (
const CoefficientType& alpha,
const ViewType& x)
670 template<
class ViewType,
672 class LayoutType =
typename ViewType::array_layout,
673 class IndexType = int,
674 const int rank = ViewType::rank>
675 KOKKOS_INLINE_FUNCTION
void
676 FILL (
const ViewType& x,
const InputType& val)
686 template<
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>
693 KOKKOS_INLINE_FUNCTION
void
694 AXPY (
const CoefficientType& alpha,
698 static_assert (static_cast<int> (ViewType1::rank) ==
699 static_cast<int> (ViewType2::rank),
700 "AXPY: x and y must have the same rank.");
701 Impl::AXPY<CoefficientType, ViewType1, ViewType2, LayoutType1, LayoutType2,
702 IndexType, rank>::run (alpha, x, y);
713 template<
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>
719 KOKKOS_INLINE_FUNCTION
void
720 COPY (
const ViewType1& x,
const ViewType2& y)
722 static_assert (static_cast<int> (ViewType1::rank) ==
723 static_cast<int> (ViewType2::rank),
724 "COPY: x and y must have the same rank.");
725 Impl::COPY<ViewType1, ViewType2, LayoutType1, LayoutType2, IndexType,
740 template<
class VecType1,
744 class IndexType =
int>
745 KOKKOS_INLINE_FUNCTION
void
751 Impl::GEMV<VecType1, BlkType, VecType2, CoeffType,
752 IndexType>::run (alpha, A, x, y);
762 template<
class ViewType1,
765 class CoefficientType,
766 class IndexType =
int>
767 KOKKOS_INLINE_FUNCTION
void
770 const CoefficientType& alpha,
773 const CoefficientType& beta,
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;
783 const Scalar
ZERO = STS::zero();
784 const Scalar ONE = STS::one();
788 if(transA[0] ==
'N' || transA[0] ==
'n') {
789 m =
static_cast<IndexType
> (A.extent (0));
790 n =
static_cast<IndexType
> (A.extent (1));
793 m =
static_cast<IndexType
> (A.extent (1));
794 n =
static_cast<IndexType
> (A.extent (0));
796 k =
static_cast<IndexType
> (C.extent (1));
799 if(alpha == ZERO && beta == ONE)
805 for(IndexType i=0; i<m; i++) {
806 for(IndexType j=0; j<k; j++) {
812 for(IndexType i=0; i<m; i++) {
813 for(IndexType j=0; j<k; j++) {
814 C(i,j) = beta*C(i,j);
821 if(transB[0] ==
'n' || transB[0] ==
'N') {
822 if(transA[0] ==
'n' || transA[0] ==
'N') {
824 for(IndexType j=0; j<n; j++) {
826 for(IndexType i=0; i<m; i++) {
830 else if(beta != ONE) {
831 for(IndexType i=0; i<m; i++) {
832 C(i,j) = beta*C(i,j);
835 for(IndexType l=0; l<k; l++) {
836 Scalar temp = alpha*B(l,j);
837 for(IndexType i=0; i<m; i++) {
838 C(i,j) = C(i,j) + temp*A(i,l);
845 for(IndexType j=0; j<n; j++) {
846 for(IndexType i=0; i<m; i++) {
848 for(IndexType l=0; l<k; l++) {
849 temp = temp + A(l,i)*B(l,j);
855 C(i,j) = alpha*temp + beta*C(i,j);
862 if(transA[0] ==
'n' || transA[0] ==
'N') {
864 for(IndexType j=0; j<n; j++) {
866 for(IndexType i=0; i<m; i++) {
870 else if(beta != ONE) {
871 for(IndexType i=0; i<m; i++) {
872 C(i,j) = beta*C(i,j);
875 for(IndexType l=0; l<k; l++) {
876 Scalar temp = alpha*B(j,l);
877 for(IndexType i=0; i<m; i++) {
878 C(i,j) = C(i,j) + temp*A(i,l);
885 for(IndexType j=0; j<n; j++) {
886 for(IndexType i=0; i<m; i++) {
888 for(IndexType l=0; l<k; l++) {
889 temp = temp + A(l,i)*B(j,l);
895 C(i,j) = alpha*temp + beta*C(i,j);
904 template<
class LittleBlockType,
905 class LittleVectorType>
906 KOKKOS_INLINE_FUNCTION
void
907 GETF2 (
const LittleBlockType& A,
const LittleVectorType& ipiv,
int& info)
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;
920 const Scalar
ZERO = STS::zero();
922 const IndexType numRows =
static_cast<IndexType
> (A.extent (0));
923 const IndexType numCols =
static_cast<IndexType
> (A.extent (1));
924 const IndexType pivDim =
static_cast<IndexType
> (ipiv.extent (0));
927 const IndexType minPivDim = (numRows < numCols) ? numRows : numCols;
928 if (pivDim < minPivDim) {
936 for(IndexType j=0; j < pivDim; j++)
940 for(IndexType i=j+1; i<numRows; i++)
942 if(STS::abs(A(i,j)) > STS::abs(A(jp,j))) {
953 for(IndexType i=0; i < numCols; i++)
955 Scalar temp = A(jp,i);
962 for(IndexType i=j+1; i<numRows; i++) {
963 A(i,j) = A(i,j) / A(j,j);
971 for(IndexType r=j+1; r < numRows; r++)
973 for(IndexType c=j+1; c < numCols; c++) {
974 A(r,c) = A(r,c) - A(r,j) * A(j,c);
985 template<
class LittleBlockType,
986 class LittleIntVectorType,
987 class LittleScalarVectorType,
988 const int rank = LittleScalarVectorType::rank>
990 static KOKKOS_INLINE_FUNCTION
void
991 run (
const char mode[],
992 const LittleBlockType& A,
993 const LittleIntVectorType& ipiv,
994 const LittleScalarVectorType& B,
999 template<
class LittleBlockType,
1000 class LittleIntVectorType,
1001 class LittleScalarVectorType>
1002 struct GETRS<LittleBlockType, LittleIntVectorType, LittleScalarVectorType, 1> {
1003 static KOKKOS_INLINE_FUNCTION
void
1004 run (
const char mode[],
1005 const LittleBlockType& A,
1006 const LittleIntVectorType& ipiv,
1007 const LittleScalarVectorType& B,
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;
1025 const Scalar
ZERO = STS::zero();
1026 const IndexType numRows =
static_cast<IndexType
> (A.extent (0));
1027 const IndexType numCols =
static_cast<IndexType
> (A.extent (1));
1028 const IndexType pivDim =
static_cast<IndexType
> (ipiv.extent (0));
1033 if (numRows != numCols) {
1039 if (pivDim < numRows) {
1045 if(mode[0] ==
'n' || mode[0] ==
'N') {
1047 for(IndexType i=0; i<numRows; i++) {
1048 if(ipiv(i) != i+1) {
1050 B(i) = B(ipiv(i)-1);
1051 B(ipiv(i)-1) = temp;
1056 for(IndexType r=1; r < numRows; r++) {
1057 for(IndexType c=0; c < r; c++) {
1058 B(r) = B(r) - A(r,c)*B(c);
1063 for(IndexType r=numRows-1; r >= 0; r--) {
1065 if(A(r,r) == ZERO) {
1070 for(IndexType c=r+1; c < numCols; c++) {
1071 B(r) = B(r) - A(r,c)*B(c);
1073 B(r) = B(r) / A(r,r);
1077 else if(mode[0] ==
't' || mode[0] ==
'T') {
1082 else if (mode[0] ==
'c' || mode[0] ==
'C') {
1095 template<
class LittleBlockType,
1096 class LittleIntVectorType,
1097 class LittleScalarVectorType>
1098 struct GETRS<LittleBlockType, LittleIntVectorType, LittleScalarVectorType, 2> {
1099 static KOKKOS_INLINE_FUNCTION
void
1100 run (
const char mode[],
1101 const LittleBlockType& A,
1102 const LittleIntVectorType& ipiv,
1103 const LittleScalarVectorType& B,
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.");
1119 const IndexType numRhs = B.extent (1);
1122 for (IndexType rhs = 0; rhs < numRhs; ++rhs) {
1123 auto B_cur = Kokkos::subview (B, Kokkos::ALL (), rhs);
1137 template<
class LittleBlockType,
1138 class LittleIntVectorType,
1139 class LittleScalarVectorType>
1140 KOKKOS_INLINE_FUNCTION
void
1142 const LittleBlockType& A,
1143 const LittleIntVectorType& ipiv,
1144 const LittleScalarVectorType& B,
1147 Impl::GETRS<LittleBlockType, LittleIntVectorType, LittleScalarVectorType,
1148 LittleScalarVectorType::rank>::run (mode, A, ipiv, B, info);
1166 template<
class LittleBlockType,
1167 class LittleIntVectorType,
1168 class LittleScalarVectorType>
1169 KOKKOS_INLINE_FUNCTION
void
1171 const LittleIntVectorType& ipiv,
1172 const LittleScalarVectorType& work,
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;
1189 const Scalar
ZERO = STS::zero();
1190 const Scalar ONE = STS::one();
1192 const IndexType numRows =
static_cast<IndexType
> (A.extent (0));
1193 const IndexType numCols =
static_cast<IndexType
> (A.extent (1));
1194 const IndexType pivDim =
static_cast<IndexType
> (ipiv.extent (0));
1195 const IndexType workDim =
static_cast<IndexType
> (work.extent (0));
1200 if (numRows != numCols) {
1206 if (pivDim < numRows) {
1212 if (workDim < numRows) {
1218 for(IndexType j=0; j < numRows; j++) {
1219 if(A(j,j) ==
ZERO) {
1224 A(j,j) = ONE / A(j,j);
1227 for(IndexType r=0; r < j; r++) {
1228 A(r,j) = A(r,r)*A(r,j);
1229 for(IndexType c=r+1; c < j; c++) {
1230 A(r,j) = A(r,j) + A(r,c)*A(c,j);
1233 for(IndexType r=0; r < j; r++) {
1234 A(r,j) = -A(j,j)*A(r,j);
1239 for(IndexType j = numCols-2; j >= 0; j--) {
1241 for(IndexType r=j+1; r < numRows; r++) {
1246 for(IndexType r=0; r < numRows; r++) {
1247 for(IndexType i=j+1; i < numRows; i++) {
1248 A(r,j) = A(r,j) - work(i)*A(r,i);
1254 for(IndexType j=numRows-1; j >= 0; j--) {
1255 IndexType jp = ipiv(j)-1;
1257 for(IndexType r=0; r < numRows; r++) {
1258 Scalar temp = A(r,j);
1271 template<
class LittleBlockType,
1272 class LittleVectorTypeX,
1273 class LittleVectorTypeY,
1274 class CoefficientType,
1275 class IndexType =
int>
1276 KOKKOS_INLINE_FUNCTION
void
1277 GEMV (
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);
1337 #endif // TPETRA_BLOCKVIEW_HPP
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 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 ViewType1 &x, const ViewType2 &y)
y := x (rank-1 x and y, i.e., vectors)
Implementation of Tpetra::SCAL function.
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.
static KOKKOS_INLINE_FUNCTION void run(const ViewType1 &X, const ViewType2 &Y)
Y := X (rank-2 X and Y, i.e., matrices)
KOKKOS_INLINE_FUNCTION void FILL(const ViewType &x, const InputType &val)
Set every entry of x to val.
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)
KOKKOS_INLINE_FUNCTION void absMax(const ViewType2 &Y, const ViewType1 &X)
Implementation of Tpetra's ABSMAX CombineMode for the small dense blocks in BlockCrsMatrix, and the small dense vectors in BlockMultiVector and BlockVector.
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 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
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 ViewType &A)
A := alpha*A (rank-2 A, i.e., a matrix)
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's ABSMAX CombineMode for the small dense blocks in BlockCrsMatrix, or the small dense vectors in BlockMultiVector and BlockVector.
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...
Replace old values with zero.
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.
Implementation of Tpetra::COPY function.
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)
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)
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::AXPY function.
static KOKKOS_INLINE_FUNCTION void run(const ViewType1 &X, const ViewType2 &Y)
Y := X (rank-2 X and Y, i.e., matrices)
Computes the solution to Ax=b.
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 GETF2(const LittleBlockType &A, const LittleVectorType &ipiv, int &info)
Computes A = P*L*U.
Implementation of Tpetra::FILL 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.