SparseLU_kernel_bmod.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
5 // Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef SPARSELU_KERNEL_BMOD_H
12 #define SPARSELU_KERNEL_BMOD_H
13 
14 // IWYU pragma: private
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 namespace internal {
19 
20 template <int SegSizeAtCompileTime>
35  template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
36  static EIGEN_DONT_INLINE void run(const Index segsize, BlockScalarVector& dense, ScalarVector& tempv,
37  ScalarVector& lusup, Index& luptr, const Index lda, const Index nrow,
38  IndexVector& lsub, const Index lptr, const Index no_zeros);
39 };
40 
41 template <int SegSizeAtCompileTime>
42 template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
43 EIGEN_DONT_INLINE void LU_kernel_bmod<SegSizeAtCompileTime>::run(const Index segsize, BlockScalarVector& dense,
44  ScalarVector& tempv, ScalarVector& lusup, Index& luptr,
45  const Index lda, const Index nrow, IndexVector& lsub,
46  const Index lptr, const Index no_zeros) {
47  typedef typename ScalarVector::Scalar Scalar;
48  // First, copy U[*,j] segment from dense(*) to tempv(*)
49  // The result of triangular solve is in tempv[*];
50  // The result of matric-vector update is in dense[*]
51  Index isub = lptr + no_zeros;
52  Index i;
53  Index irow;
54  for (i = 0; i < ((SegSizeAtCompileTime == Dynamic) ? segsize : SegSizeAtCompileTime); i++) {
55  irow = lsub(isub);
56  tempv(i) = dense(irow);
57  ++isub;
58  }
59  // Dense triangular solve -- start effective triangle
60  luptr += lda * no_zeros + no_zeros;
61  // Form Eigen matrix and vector
63  &(lusup.data()[luptr]), segsize, segsize, OuterStride<>(lda));
64  Map<Matrix<Scalar, SegSizeAtCompileTime, 1> > u(tempv.data(), segsize);
65 
66  u = A.template triangularView<UnitLower>().solve(u);
67 
68  // Dense matrix-vector product y <-- B*x
69  luptr += segsize;
71  Index ldl = internal::first_multiple(nrow, PacketSize);
73  segsize, OuterStride<>(lda));
74  Index aligned_offset = internal::first_default_aligned(tempv.data() + segsize, PacketSize);
75  Index aligned_with_B_offset = (PacketSize - internal::first_default_aligned(B.data(), PacketSize)) % PacketSize;
76  Map<Matrix<Scalar, Dynamic, 1>, 0, OuterStride<> > l(tempv.data() + segsize + aligned_offset + aligned_with_B_offset,
77  nrow, OuterStride<>(ldl));
78 
79  l.noalias() = B * u;
80 
81  // Scatter tempv[] into SPA dense[] as a temporary storage
82  isub = lptr + no_zeros;
83  for (i = 0; i < ((SegSizeAtCompileTime == Dynamic) ? segsize : SegSizeAtCompileTime); i++) {
84  irow = lsub(isub++);
85  dense(irow) = tempv(i);
86  }
87 
88  // Scatter l into SPA dense[]
89  for (i = 0; i < nrow; i++) {
90  irow = lsub(isub++);
91  dense(irow) -= l(i);
92  }
93 }
94 
95 template <>
96 struct LU_kernel_bmod<1> {
97  template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
98  static EIGEN_DONT_INLINE void run(const Index /*segsize*/, BlockScalarVector& dense, ScalarVector& /*tempv*/,
99  ScalarVector& lusup, Index& luptr, const Index lda, const Index nrow,
100  IndexVector& lsub, const Index lptr, const Index no_zeros);
101 };
102 
103 template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
104 EIGEN_DONT_INLINE void LU_kernel_bmod<1>::run(const Index /*segsize*/, BlockScalarVector& dense,
105  ScalarVector& /*tempv*/, ScalarVector& lusup, Index& luptr,
106  const Index lda, const Index nrow, IndexVector& lsub, const Index lptr,
107  const Index no_zeros) {
108  typedef typename ScalarVector::Scalar Scalar;
109  typedef typename IndexVector::Scalar StorageIndex;
110  Scalar f = dense(lsub(lptr + no_zeros));
111  luptr += lda * no_zeros + no_zeros + 1;
112  const Scalar* a(lusup.data() + luptr);
113  const StorageIndex* irow(lsub.data() + lptr + no_zeros + 1);
114  Index i = 0;
115  for (; i + 1 < nrow; i += 2) {
116  Index i0 = *(irow++);
117  Index i1 = *(irow++);
118  Scalar a0 = *(a++);
119  Scalar a1 = *(a++);
120  Scalar d0 = dense.coeff(i0);
121  Scalar d1 = dense.coeff(i1);
122  d0 -= f * a0;
123  d1 -= f * a1;
124  dense.coeffRef(i0) = d0;
125  dense.coeffRef(i1) = d1;
126  }
127  if (i < nrow) dense.coeffRef(*(irow++)) -= f * *(a++);
128 }
129 
130 } // end namespace internal
131 
132 } // end namespace Eigen
133 #endif // SPARSELU_KERNEL_BMOD_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_DONT_INLINE
Definition: Macros.h:853
SCALAR Scalar
Definition: bench_gemm.cpp:45
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:48
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Convenience specialization of Stride to specify only an outer stride See class Map for some examples.
Definition: Stride.h:104
Definition: matrices.h:74
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
const Scalar * a
Definition: level2_cplx_impl.h:32
const char const int const RealScalar const RealScalar const int * lda
Definition: level2_cplx_impl.h:20
Index first_multiple(Index size, Index base)
Definition: Memory.h:559
static Index first_default_aligned(const DenseBase< Derived > &m)
Definition: DenseCoeffsBase.h:539
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
const int Dynamic
Definition: Constants.h:25
Definition: Eigen_Colamd.h:49
Definition: SparseLU_kernel_bmod.h:21
static EIGEN_DONT_INLINE void run(const Index segsize, BlockScalarVector &dense, ScalarVector &tempv, ScalarVector &lusup, Index &luptr, const Index lda, const Index nrow, IndexVector &lsub, const Index lptr, const Index no_zeros)
Performs numeric block updates from a given supernode to a single column.
Definition: SparseLU_kernel_bmod.h:43
Definition: GenericPacketMath.h:108