SparseSolver.hxx
1 // Copyright (C) 2010 Vivien Mallet
2 // Copyright (C) 2010 Marc Durufle
3 //
4 // This file is part of the linear-algebra library Seldon,
5 // http://seldon.sourceforge.net/.
6 //
7 // Seldon is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 2.1 of the License, or (at your option)
10 // any later version.
11 //
12 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with Seldon. If not, see http://www.gnu.org/licenses/.
19 
20 
21 #ifndef SELDON_FILE_COMPUTATION_SPARSESOLVER_HXX
22 
23 #include "Ordering.hxx"
24 
25 namespace Seldon
26 {
27 
29  template<class T>
31  {
32  public:
34 
35  virtual void SetPivotThreshold(double);
36  virtual void RefineSolution();
37  virtual void DoNotRefineSolution();
38 
39  virtual void SetCoefficientEstimationNeededMemory(double coef);
40  virtual void SetMaximumCoefficientEstimationNeededMemory(double coef);
41  virtual void SetIncreaseCoefficientEstimationNeededMemory(double coef);
42 
43  virtual void SelectOrdering(int);
44  virtual void SelectParallelOrdering(int);
45  virtual void SetPermutation(const Vector<int>&);
46  virtual void SetNumberOfThreadPerNode(int n);
47 
48 #ifdef SELDON_WITH_MPI
49  virtual void
50  FactorizeDistributedMatrix(MPI_Comm& comm_facto, Vector<long>& Ptr,
51  Vector<int>& IndRow, Vector<T>& Val,
52  const Vector<int>& glob_number,
53  bool sym, bool keep_matrix = false);
54 
55  virtual void
56  FactorizeDistributedMatrix(MPI_Comm& comm_facto, Vector<int64_t>& Ptr,
57  Vector<int64_t>& IndRow, Vector<T>& Val,
58  const Vector<int>& glob_number,
59  bool sym, bool keep_matrix = false);
60 
61  virtual void
62  PerformAnalysisDistributed(MPI_Comm& comm_facto, Vector<long>& Ptr,
63  Vector<int>& IndRow, Vector<T>& Val,
64  const Vector<int>& glob_number,
65  bool sym, bool keep_matrix = false);
66 
67  virtual void
68  PerformAnalysisDistributed(MPI_Comm& comm_facto, Vector<int64_t>& Ptr,
69  Vector<int64_t>& IndRow, Vector<T>& Val,
70  const Vector<int>& glob_number,
71  bool sym, bool keep_matrix = false);
72 
73  virtual void
74  PerformFactorizationDistributed(MPI_Comm& comm_facto, Vector<long>& Ptr,
75  Vector<int>& IndRow, Vector<T>& Val,
76  const Vector<int>& glob_number,
77  bool sym, bool keep_matrix = false);
78 
79  virtual void
80  PerformFactorizationDistributed(MPI_Comm& comm_facto, Vector<int64_t>& Ptr,
81  Vector<int64_t>& IndRow, Vector<T>& Val,
82  const Vector<int>& glob_number,
83  bool sym, bool keep_matrix = false);
84 
85  virtual void SolveDistributed(MPI_Comm& comm_facto,
86  const SeldonTranspose& TransA,
87  T* x_ptr, int nrhs,
88  const IVect& glob_num);
89 #endif
90 
91 
92  // pure virtual methods (must be overloaded)
93 
94  // (returns true if using 64-bit integers)
95  virtual bool UseInteger8() const = 0;
96  virtual size_t GetMemorySize() const = 0;
97  virtual int GetInfoFactorization() const = 0;
98 
99  virtual void Clear() = 0;
100  virtual void HideMessages() = 0;
101  virtual void ShowMessages() = 0;
102 
103  virtual void Solve(const SeldonTranspose&, T* x_ptr, int nrhs) = 0;
104 
105  };
106 
107 
109  template<class T, class Allocator
110  = typename SeldonDefaultAllocator<ArrayRowSparse, T>::allocator>
112  {
113  protected :
117  double permtol;
123  IVect permutation_row, permutation_col;
126 
127  public :
128 
130 
131  bool UseInteger8() const;
132  void Clear();
133 
134  void HideMessages();
135  void ShowMessages();
136  int GetPrintLevel() const;
137 
138  size_t GetMemorySize() const;
139  int GetInfoFactorization() const;
140 
141  double GetPivotThreshold() const;
142  void SetPivotThreshold(double);
143 
144  template<class T0, class Storage0, class Allocator0>
145  void FactorizeMatrix(const IVect& perm,
147  bool keep_matrix = false);
148 
149  template<class T0, class Storage0, class Allocator0>
150  void FactorizeMatrix(const IVect& perm,
152  bool keep_matrix = false);
153 
154  template<class T1>
155  void Solve(Vector<T1>& z);
156 
157  template<class T1>
158  void Solve(const SeldonTranspose& TransA, Vector<T1>& z);
159 
160  void Solve(const SeldonTranspose&, T* x_ptr, int nrhs);
161 
162  };
163 
164  template<class T, class Allocator>
166  IVect& iperm, IVect& rperm,
167  const double& permtol, int print_level);
168 
169  template<class T1, class Allocator1,
170  class T2, class Storage2, class Allocator2>
173 
174  template<class T1, class Allocator1,
175  class T2, class Storage2, class Allocator2>
176  void SolveLuVector(const SeldonTranspose& transA,
179 
180  template<class T, class Allocator>
182 
183  template<class T1, class Allocator1,
184  class T2, class Storage2, class Allocator2>
187 
188  template<class T1, class Allocator1,
189  class T2, class Storage2, class Allocator2>
190  void SolveLuVector(const SeldonTranspose& transA,
193 
194  template<class T0, class Prop, class Storage, class Allocator,
195  class T, class Alloc2>
198  bool keep_matrix = false);
199 
200  template<class T0, class Prop, class Storage, class Allocator,
201  class T, class Alloc2>
204  IVect& permut, bool keep_matrix = false);
205 
206  template<class T, class Alloc2, class T1, class Allocator>
207  void SolveLU(SparseSeldonSolver<T, Alloc2>& mat_lu,
209 
210  template<class T, class Alloc2, class T1, class Allocator>
211  void SolveLU(const SeldonTranspose& TransA,
214 
215 } // namespace Seldon.
216 
217 
218 #define SELDON_FILE_COMPUTATION_SPARSESOLVER_HXX
219 #endif
Seldon::SparseSeldonSolver::SetPivotThreshold
void SetPivotThreshold(double)
Sets the threshold for pivot.
Definition: SparseSolverInline.cxx:86
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::Vector< int >
Seldon::SparseSeldonSolver::permtol
double permtol
Threshold for pivoting.
Definition: SparseSolver.hxx:117
Seldon::VirtualSparseDirectSolver::SelectParallelOrdering
virtual void SelectParallelOrdering(int)
selects ordering to use in parallel for the interfaced solver
Definition: SparseSolver.cxx:94
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::VirtualSparseDirectSolver::SetPivotThreshold
virtual void SetPivotThreshold(double)
Sets the threshold for pivot.
Definition: SparseSolver.cxx:42
Seldon::VirtualSparseDirectSolver::~VirtualSparseDirectSolver
virtual ~VirtualSparseDirectSolver()
Destructor.
Definition: SparseSolver.cxx:35
Seldon::SparseSeldonSolver::permutation_row
IVect permutation_row
Permutation arrays.
Definition: SparseSolver.hxx:123
Seldon::VirtualSparseDirectSolver::SetIncreaseCoefficientEstimationNeededMemory
virtual void SetIncreaseCoefficientEstimationNeededMemory(double coef)
Method overloaded in Mumps solver.
Definition: SparseSolver.cxx:80
Seldon::SparseSeldonSolver::FactorizeMatrix
void FactorizeMatrix(const IVect &perm, Matrix< T0, General, Storage0, Allocator0 > &mat, bool keep_matrix=false)
performs LU factorisation of matrix mat
Definition: SparseSolver.cxx:247
Seldon::VirtualSparseDirectSolver::SelectOrdering
virtual void SelectOrdering(int)
selects ordering to use in the interfaced solver
Definition: SparseSolver.cxx:87
Seldon::GetLU
void GetLU(Matrix< T0, Prop0, Storage0, Allocator0 > &A)
Returns the LU factorization of a matrix.
Definition: Functions_Matrix.cxx:2073
Seldon::VirtualSparseDirectSolver
Base class for an interface with a direct solver.
Definition: SparseSolver.hxx:30
Seldon::SolveLuVector
void SolveLuVector(const Matrix< T0, Prop0, Storage0, Allocator0 > &M, Vector< T1, Storage1, Allocator1 > &Y)
Solves a linear system whose matrix has been LU-factorized.
Definition: Functions_MatVect.cxx:1782
Seldon::SparseSeldonSolver
Default solver in Seldon.
Definition: SparseSolver.hxx:111
Seldon::SparseSeldonSolver::GetMemorySize
size_t GetMemorySize() const
returns memory used by the object in bytes
Definition: SparseSolver.cxx:230
Seldon::SparseSeldonSolver::mat_sym
Matrix< T, Symmetric, ArrayRowSymSparse, Allocator > mat_sym
Symmetric matrix.
Definition: SparseSolver.hxx:119
Seldon::VirtualSparseDirectSolver::RefineSolution
virtual void RefineSolution()
Tells to the direct solver that refinement is required.
Definition: SparseSolver.cxx:50
Seldon::VirtualSparseDirectSolver::SetPermutation
virtual void SetPermutation(const Vector< int > &)
gives the ordering array to the interface solver
Definition: SparseSolver.cxx:101
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::SparseSeldonSolver::symmetric_matrix
bool symmetric_matrix
if true the factorisation is contained in mat_sym
Definition: SparseSolver.hxx:125
Seldon::SparseSeldonSolver::mat_unsym
Matrix< T, General, ArrayRowSparse, Allocator > mat_unsym
Unsymmetric matrix.
Definition: SparseSolver.hxx:121
Seldon::VirtualSparseDirectSolver::SetCoefficientEstimationNeededMemory
virtual void SetCoefficientEstimationNeededMemory(double coef)
Method overloaded in Mumps solver.
Definition: SparseSolver.cxx:64
Seldon::SparseSeldonSolver::print_level
int print_level
Verbosity level.
Definition: SparseSolver.hxx:115
Seldon::VirtualSparseDirectSolver::SetMaximumCoefficientEstimationNeededMemory
virtual void SetMaximumCoefficientEstimationNeededMemory(double coef)
Method overloaded in Mumps solver.
Definition: SparseSolver.cxx:72
Seldon::VirtualSparseDirectSolver::SetNumberOfThreadPerNode
virtual void SetNumberOfThreadPerNode(int n)
Sets the number of threads per mpi process.
Definition: SparseSolver.cxx:108
Seldon::VirtualSparseDirectSolver::DoNotRefineSolution
virtual void DoNotRefineSolution()
Tells to the direct solver that no refinement is required.
Definition: SparseSolver.cxx:57