SparseDirectSolverInline.cxx
1 // Copyright (C) 2015 Marc DuruflĂ©
2 //
3 // This file is part of the linear-algebra library Seldon,
4 // http://seldon.sourceforge.net/.
5 //
6 // Seldon is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your option)
9 // any later version.
10 //
11 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 // more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with Seldon. If not, see http://www.gnu.org/licenses/.
18 
19 #ifndef SELDON_FILE_COMPUTATION_SPARSE_DIRECT_SOLVER_INLINE_CXX
20 
21 namespace Seldon
22 {
23 
25  template<class T>
26  inline int SparseDirectSolver<T>::GetM() const
27  {
28  return n;
29  }
30 
31 
33  template<class T>
34  inline int SparseDirectSolver<T>::GetN() const
35  {
36  return n;
37  }
38 
39 
41  template<class T>
43  {
44  return type_ordering;
45  }
46 
47 
49  template<class T>
51  {
52  type_ordering = SparseMatrixOrdering::USER;
53  permut = num;
54  }
55 
56 
58  template<class T>
60  {
61  type_ordering = type;
62  }
63 
64 
66  template<class T>
68  {
69  print_level = 0;
70  solver->HideMessages();
71  }
72 
73 
75  template<class T>
77  {
78  print_level = 1;
79  solver->ShowMessages();
80  }
81 
82 
84  template<class T>
86  {
87  print_level = 2;
88  solver->ShowMessages();
89  }
90 
91 
93  template<class T>
95  {
96  pivot_threshold = eps;
97  solver->SetPivotThreshold(eps);
98  }
99 
100 
102  template<class T>
104  {
105  nb_threads_per_node = p;
106  solver->SetNumberOfThreadPerNode(nb_threads_per_node);
107  }
108 
109 
111  template<class T>
113  {
114  return nb_threads_per_node;
115  }
116 
117 
119  template<class T>
121  {
122  type_solver = type;
123  type_ordering = SparseMatrixOrdering::AUTO;
124  InitSolver();
125  }
126 
127 
129  template<class T>
131  {
132  enforce_unsym_ilut = true;
133  }
134 
135 
137  template<class T>
139  {
140  return type_solver;
141  }
142 
143 
144  template<class T>
146  {
147  refine_solution = true;
148  solver->RefineSolution();
149  }
150 
151 
152  template<class T>
153  inline void SparseDirectSolver<T>::DoNotRefineSolution()
154  {
155  refine_solution = false;
156  solver->DoNotRefineSolution();
157  }
158 
159 
160  template<class T>
161  inline void SparseDirectSolver<T>::
162  SetCoefficientEstimationNeededMemory(double coef)
163  {
164  solver->SetCoefficientEstimationNeededMemory(coef);
165  }
166 
167 
168  template<class T>
169  inline void SparseDirectSolver<T>::
170  SetMaximumCoefficientEstimationNeededMemory(double coef)
171  {
172  solver->SetMaximumCoefficientEstimationNeededMemory(coef);
173  }
174 
175 
176  template<class T>
177  inline void SparseDirectSolver<T>::
178  SetIncreaseCoefficientEstimationNeededMemory(double coef)
179  {
180  solver->SetIncreaseCoefficientEstimationNeededMemory(coef);
181  }
182 
183 
185  template<class T>
187  {
188  return threshold_matrix;
189  }
190 
191 
193  template<class T0, class Prop, class Storage, class Allocator, class T>
195  SparseDirectSolver<T>& mat_lu, bool keep_matrix)
196  {
197  mat_lu.Factorize(mat_lu, keep_matrix);
198  }
199 
200 
201 
202  /*************************
203  * Solve and SparseSolve *
204  *************************/
205 
206 
208 
215  template <class T0, class Prop0, class Storage0, class Allocator0,
216  class T1, class Storage1, class Allocator1>
219  {
220 #ifdef SELDON_CHECK_DIMENSIONS
221  CheckDim(M, Y, "SolveLU(M, Y)");
222 #endif
223 
225  SparseDirectSolver<Tmat> matrix_lu;
226 
227  matrix_lu.Factorize(M);
228  matrix_lu.Solve(Y);
229  }
230 
231 
234  template <class T, class Prop0, class Allocator0, class Allocator1>
237  {
238  SparseSolve(M, Y);
239  }
240 
241 
244  template <class T, class Prop0, class Allocator0, class Allocator1>
247  {
248  SparseSolve(M, Y);
249  }
250 
251 
254  template <class T, class Prop0, class Allocator0, class Allocator1>
257  {
258  SparseSolve(M, Y);
259  }
260 
261 
264  template <class T, class Prop0, class Allocator0, class Allocator1>
267  {
268  SparseSolve(M, Y);
269  }
270 
271 
274  template <class T, class Prop0, class Allocator0, class Allocator1>
277  {
278  SparseSolve(M, Y);
279  }
280 
281 
284  template <class T, class Prop0, class Allocator0, class Allocator1>
287  {
288  SparseSolve(M, Y);
289  }
290 
291 }
292 
293 #define SELDON_FILE_COMPUTATION_SPARSE_DIRECT_SOLVER_INLINE_CXX
294 #endif
295 
Seldon::SparseDirectSolver::Factorize
void Factorize(Matrix< T, Prop, Storage, Allocator > &A, bool keep_matrix=false)
factorisation of matrix A
Definition: SparseDirectSolver.cxx:503
Seldon::SparseDirectSolver::SetPermutation
void SetPermutation(const IVect &)
sets directly the new ordering (by giving a permutation vector)
Definition: SparseDirectSolverInline.cxx:50
Seldon::SparseDirectSolver::Solve
void Solve(Vector< T > &x)
x_solution is overwritten by solution of A x = b
Definition: SparseDirectSolver.cxx:783
Seldon::SparseDirectSolver::GetM
int GetM() const
returns the number of rows of the factorised matrix
Definition: SparseDirectSolverInline.cxx:26
Seldon::Vector< int, VectFull >
Seldon::SparseDirectSolver::SelectOrdering
void SelectOrdering(int)
modifies the ordering algorithm to use
Definition: SparseDirectSolverInline.cxx:59
Seldon::SparseDirectSolver::SelectDirectSolver
void SelectDirectSolver(int)
modifies the direct solver to use
Definition: SparseDirectSolverInline.cxx:120
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::GetAndSolveLU
void GetAndSolveLU(Matrix< T0, Prop0, Storage0, Allocator0 > &M, Vector< T1, Storage1, Allocator1 > &Y)
Solves a linear system using LU factorization.
Definition: Functions_MatVect.cxx:1841
Seldon::SparseDirectSolver
Class grouping different direct solvers.
Definition: SparseDirectSolver.hxx:26
Seldon::SparseDirectSolver::HideMessages
void HideMessages()
hiding all messages
Definition: SparseDirectSolverInline.cxx:67
Seldon::SparseSolve
void SparseSolve(Matrix< T0, Prop0, Storage0, Allocator0 > &M, Vector< T1, Storage1, Allocator1 > &Y)
Solves a sparse linear system using LU factorization.
Definition: SparseDirectSolverInline.cxx:217
Seldon::SparseDirectSolver::GetNumberOfThreadPerNode
int GetNumberOfThreadPerNode() const
modifies the number of threads per node (for Pastix only)
Definition: SparseDirectSolverInline.cxx:112
Seldon::SparseDirectSolver::SetNonSymmetricIlut
void SetNonSymmetricIlut()
enforces the use of unsymmetric algorithm for ilut solver
Definition: SparseDirectSolverInline.cxx:130
Seldon::SparseDirectSolver::SetNumberOfThreadPerNode
void SetNumberOfThreadPerNode(int m)
modifies the number of threads per node (for Pastix only)
Definition: SparseDirectSolverInline.cxx:103
Seldon::GetLU
void GetLU(Matrix< T0, Prop0, Storage0, Allocator0 > &A)
Returns the LU factorization of a matrix.
Definition: Functions_Matrix.cxx:2073
Seldon::CheckDim
void CheckDim(const Matrix< T0, Prop0, Storage0, Allocator0 > &A, const Matrix< T1, Prop1, Storage1, Allocator1 > &B, const Matrix< T2, Prop2, Storage2, Allocator2 > &C, string function)
Checks the compatibility of the dimensions.
Definition: Functions_Matrix.cxx:2132
Seldon::SparseDirectSolver::ShowMessages
void ShowMessages()
displaying basic messages
Definition: SparseDirectSolverInline.cxx:76
Seldon::SparseDirectSolver::GetThresholdMatrix
double GetThresholdMatrix() const
returns threshold used for ilut (if this solver is selected)
Definition: SparseDirectSolverInline.cxx:186
Seldon::SparseDirectSolver::SetPivotThreshold
void SetPivotThreshold(const double &)
sets the threshold used for pivoting
Definition: SparseDirectSolverInline.cxx:94
Seldon::SparseDirectSolver::GetDirectSolver
int GetDirectSolver()
returns the direct solver to use
Definition: SparseDirectSolverInline.cxx:138
Seldon::SparseDirectSolver::ShowFullHistory
void ShowFullHistory()
displaying all the messages
Definition: SparseDirectSolverInline.cxx:85
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::SparseDirectSolver::GetTypeOrdering
int GetTypeOrdering() const
returns the ordering algorithm to use
Definition: SparseDirectSolverInline.cxx:42
Seldon::SparseDirectSolver::GetN
int GetN() const
returns the number of rows of the factorised matrix
Definition: SparseDirectSolverInline.cxx:34