MyraMath
factor.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_MULTIFRONTAL_RLDLT_FACTOR_H
7 #define MYRAMATH_MULTIFRONTAL_RLDLT_FACTOR_H
8 
14 #include <myramath/multifrontal/detail/llt/factor.h>
15 
17 
18 #include <myramath/dense/Matrix.h>
22 #include <myramath/dense/trsm.h>
23 #include <myramath/dense/syrk.h>
24 #include <myramath/dense/gemm.h>
25 #include <myramath/dense/detail/nwork.h>
26 
27 namespace myra {
28 namespace multifrontal {
29 namespace rldlt {
30 namespace factor {
31 
32 template<class Precision> class JobGraphBase : public ::myra::multifrontal::detail::llt::factor::JobGraphBase2<RLDLTKernel<Precision> >
33  {
34  public:
35 
36  // Structural typedefs for base class.
37  typedef Precision Number;
39  typedef ::myra::multifrontal::detail::llt::factor::JobGraphBase2<Kernel> Base;
40 
41  // Typedefs related to numeric storage on LContainer
42  typedef ::myra::multifrontal::detail::llt::LContainer<Kernel> LContainer;
44 
45  // Constructor - requires reference to LContainer under construction.
46  JobGraphBase(LContainer* in_lcontainer)
47  : Base(in_lcontainer), lcontainer(in_lcontainer) { }
48 
49  // Virtual copy constructor.
50  virtual ::myra::JobGraphBase* clone() const
51  { return new JobGraphBase(*this); }
52 
53  protected:
54 
55  // Factors An(k,k) = Ln(k,k)*Ln(k,k)'
56  virtual uint64_t factor(int n, int k)
57  {
58  // Assign internode contributions if on first k-iteration.
59  if (k == 0) this->assign_contributions(n,k);
60  return lcontainer->factor(n,k);
61  }
62 
63  // Solves Ln(i,k)*Ln(k,k)' = An(i,k)
64  virtual uint64_t trsm(int n, int k, int i)
65  {
66  // Assign internode contributions if on first k-iteration.
67  if (k == 0) this->assign_contributions(n,i,k);
68  MatrixRange<Number> An_ik = this->a(n,i,k);
69  const Kernel& Ln_kk = this->l(n,k);
70  uint64_t w = Ln_kk.solveL(An_ik,'R','T');
71  Ln_kk.solveI(An_ik,'R');
72  return w;
73  }
74 
75  // Downdates An(ij,ij) -= Ln(ij,k)*Ln(ij,k)'
76  virtual uint64_t rankk(int n, int k, int ij)
77  {
78  // Useful constants.
79  Number one(1);
80  Number zero(0);
81  // Downdate An(ij,ij) -= Ln(ij,k)*Ln(ij,k)' [syrk]
82  LowerMatrixRange<Number> An_ij = this->a(n,ij);
83  CMatrixRange<Number> Ln_ijk = this->l(n,ij,k);
84  // Carefully choose beta and order of steps to avoid workspace initialization.
85  Number beta = k ? one : zero;
86  // Two syrk's required, with alpha = +/- one.
87  std::pair<int,int> inertia = this->l(n,k).inertia();
88  uint64_t w = 0;
89  w += syrk_nwork(An_ij, Ln_ijk. left(inertia.first) , 'N', -one, beta);
90  w += syrk_nwork(An_ij, Ln_ijk.right(inertia.second), 'N', one, one );
91  // Add internode contributions if on first k-iteration.
92  if (k == 0) this->add_contributions(n,ij);
93  return w;
94  }
95 
96  // Downdates An(i,j) -= Ln(i,k)*Ln(j,k)'
97  virtual uint64_t gemm(int n, int k, int i, int j)
98  {
99  // Useful constants.
100  Number one(1);
101  Number zero(0);
102  // Downdate An(i,j) -= Ln(i,k)*Ln(j,k)' [gemm]
103  MatrixRange<Number> An_ij = this->a(n,i,j);
104  CMatrixRange<Number> Ln_ik = this->l(n,i,k);
105  CMatrixRange<Number> Ln_jk = this->l(n,j,k);
106  // Carefully choose beta and order of steps to avoid workspace initialization.
107  Number beta = k ? one : zero;
108  // Two gemm's required, with alpha = +/- one.
109  std::pair<int,int> inertia = this->l(n,k).inertia();
110  uint64_t w = 0;
111  w += gemm_nwork(An_ij, Ln_ik. left(inertia.first ), 'N', Ln_jk. left(inertia.first ), 'T', -one, beta);
112  w += gemm_nwork(An_ij, Ln_ik.right(inertia.second), 'N', Ln_jk.right(inertia.second), 'T', one, one );
113  // Add internode contributions if on first k-iteration.
114  if (k == 0) this->add_contributions(n,i,j);
115  return w;
116  }
117 
118  private:
119 
120  // Reference to LContainer under construction.
121  LContainer* lcontainer;
122 
123  }; // class JobGraph
124 
125 } } } } // namespace
126 
127 #endif
Factors A into L*L&#39;, presents solve methods.
Definition: Kernel.h:38
Interface class for representing subranges of dense Matrix&#39;s.
Pivot factorization for SparseRLDLTSolver.
Represents a mutable LowerMatrixRange.
Definition: conjugate.h:28
uint64_t solveL(const MatrixRange< Precision > &B, char side, char op) const
Solves op(L)*X=B or X*op(L)=B, overwrites B with X.
Definition: Kernel.h:76
Range construct for a lower triangular matrix stored in rectangular packed format.
Definition: syntax.dox:1
Represents a const MatrixRange.
Definition: bothcat.h:22
void solveI(const MatrixRange< Precision > &B, char side) const
Solves I*X=B or X*I=B, overwrites B with X.
Definition: Kernel.h:134
Routines for backsolving by a triangular Matrix or LowerMatrix.
Specialized container for a lower triangular matrix, O(N^2/2) storage. Used by symmetry exploiting ma...
CMatrixRange< Number > right(int j) const
Returns the j rightmost columns, this(:,J-j:J)
Definition: MatrixRange.cpp:596
Represents a mutable MatrixRange.
Definition: conjugate.h:26
General purpose dense matrix container, O(i*j) storage.
Stores a lower triangular matrix in rectangular packed format.
Definition: conjugate.h:22
Routines for symmetric rank-k updates, a specialized form of Matrix*Matrix multiplication.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.