SuperLU.hxx
1 // Copyright (C) 2003-2009 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 
20 #ifndef SELDON_FILE_SUPERLU_HXX
21 
22 #ifdef SUPERLU_INTSIZE64
23 #define _LONGINT
24 #endif
25 
26 #include "superlu_interface.h"
27 
28 // here superlu_int_t is introduced in order to use
29 // int64_t instead of long int which are different types
30 // In SparseDistributedSolver int64_t is used, hence
31 // this need of int64_t
32 #ifdef SUPERLU_INTSIZE64
33 #define superlu_int_t int64_t
34 #undef _LONGINT
35 #else
36 #define superlu_int_t int
37 #endif
38 
39 #if defined(SELDON_WITH_SUPERLU_DIST) || defined(SELDON_WITH_SUPERLU_MT)
40 #else
41 #define SELDON_WITH_SUPERLU_SEQ
42 #endif
43 
44 namespace Seldon
45 {
46 
47 #ifndef SELDON_WITH_SUPERLU_DIST
48  void SetComplexOne(superlu::doublecomplex& one);
49 #endif
50 
52  template<class T>
54  {
55  protected :
56 #ifndef SELDON_WITH_SUPERLU_DIST
57  superlu::SuperMatrix L, U, B;
59  superlu::GlobalLU_t Glu;
60 
61 #ifdef SELDON_WITH_SUPERLU_MT
62  superlu::superlumt_options_t options;
63  superlu::Gstat_t stat;
64  int_t nprocs;
65 
66  double diag_pivot_thresh, drop_tol;
67  superlu::yes_no_t usepr, refact;
68  superlu::fact_t fact;
69 
70  superlu::SCPformat *Lstore;
71  superlu::NCPformat *Ustore;
72 
73 #else
74  superlu::SCformat *Lstore;
75  superlu::NCformat *Ustore;
76  superlu::superlu_options_t options;
77  superlu::SuperLUStat_t stat;
78 #endif
79 
80 #else
81 
82  int nprow, npcol;
83  superlu::gridinfo_t grid;
84  superlu::superlu_dist_options_t options;
85  superlu::SuperLUStat_t stat;
86 
87  superlu::SuperMatrix A;
88 
89 #endif
90 
93 
94  colperm_t permc_spec;
95  int_t n;
96  int_t nloc;
97  bool display_info;
98  int info_facto;
100 
101  public :
104 
105  const Vector<int_t>& GetRowPermutation() const;
106  const Vector<int_t>& GetColPermutation() const;
107 
108  void Init(int size, int_t& panel_size, int_t& relax);
109  void SetNumberOfThreadPerNode(int p);
110 
111  void SelectOrdering(int type);
112  void SetPermutation(const IVect&);
113 
114  bool UseInteger8() const;
115  void Clear();
116  void HideMessages();
117  void ShowMessages();
118 
119  int GetInfoFactorization() const;
120  };
121 
122 
124  template<class T>
126  {
127  };
128 
129 
131  template<>
132  class MatrixSuperLU<double> : public MatrixSuperLU_Base<double>
133  {
134 #ifdef SELDON_WITH_SUPERLU_DIST
135  superlu::dScalePermstruct_t ScalePermstruct;
136  superlu::dLUstruct_t LUstruct;
137  superlu::dSOLVEstruct_t SOLVEstruct;
138 #endif
139 
140  public:
142 
143  size_t GetMemorySize() const;
144  void Clear();
145 
146 #ifndef SELDON_WITH_SUPERLU_DIST
147  template<class Prop, class Allocator>
150  bool permuted = true);
151 
152  template<class Prop, class Allocator>
155  bool permuted = true);
156 
157  void FactorizeCSC(Vector<superlu_int_t>& Ptr, Vector<superlu_int_t>& IndRow,
158  Vector<double>& Val, bool sym);
159 #endif
160 
161  template<class T0, class Prop, class Storage, class Allocator>
162  void FactorizeMatrix(Matrix<T0, Prop, Storage, Allocator> & mat,
163  bool keep_matrix = false);
164 
165  template<class Allocator2>
167 
168  template<class Allocator2>
169  void Solve(const SeldonTranspose& TransA,
171 
172  void Solve(const SeldonTranspose& Trans,
173  double* x_ptr, int nrhs_);
174 
175  template<class Allocator2>
177 
178  template<class Allocator2>
179  void Solve(const SeldonTranspose& TransA,
181 
182 #ifdef SELDON_WITH_SUPERLU_DIST
183  void FactorizeCSC(Vector<long>& Ptr, Vector<int>& IndRow,
184  Vector<double>& Val, bool sym);
185 
186  void FactorizeDistributedMatrix(MPI_Comm& comm_facto, Vector<long>& Ptr,
187  Vector<int>& IndRow, Vector<double>& Val,
188  const Vector<int>& glob_number,
189  bool sym, bool keep_matrix = false);
190 
191  void FactorizeDistributedMatrix(MPI_Comm& comm_facto, Vector<int64_t>& Ptr,
192  Vector<int64_t>& IndRow, Vector<double>& Val,
193  const Vector<int>& glob_number,
194  bool sym, bool keep_matrix = false);
195 
196  template<class Tint>
197  void FactorizeParallel(MPI_Comm& comm_facto,
200  const Vector<int>& glob_num,
201  bool sym, bool keep_matrix = false);
202 
203  void FactorizeParallel(MPI_Comm& comm_facto,
206  const Vector<int>& glob_num,
207  bool sym, bool keep_matrix = false);
208 
209  template<class Allocator2>
210  void SolveDistributed(MPI_Comm& comm_facto,
211  const SeldonTranspose& TransA,
213  const Vector<int>& glob_num);
214 
215  template<class Allocator2>
216  void SolveDistributed(MPI_Comm& comm_facto,
217  const SeldonTranspose& TransA,
219  const Vector<int>& glob_num);
220 
221  void SolveDistributed(MPI_Comm& comm_facto,
222  const SeldonTranspose& TransA,
223  double* x_ptr, int nrhs_,
224  const IVect& glob_num);
225 
226 #endif
227 
228  };
229 
230 
232  template<>
233  class MatrixSuperLU<complex<double> >
234  : public MatrixSuperLU_Base<complex<double> >
235  {
236 #ifdef SELDON_WITH_SUPERLU_DIST
237  superlu::zScalePermstruct_t ScalePermstruct;
238  superlu::zLUstruct_t LUstruct;
239  superlu::zSOLVEstruct_t SOLVEstruct;
240 #endif
241 
242  public:
244 
245  void Clear();
246  size_t GetMemorySize() const;
247 
248 #ifndef SELDON_WITH_SUPERLU_DIST
249  template<class Prop, class Allocator>
250  void GetLU(Matrix<complex<double>, Prop, ColSparse, Allocator>& Lmat,
251  Matrix<complex<double>, Prop, ColSparse, Allocator>& Umat,
252  bool permuted = true);
253 
254  template<class Prop, class Allocator>
255  void GetLU(Matrix<complex<double>, Prop, RowSparse, Allocator>& Lmat,
256  Matrix<complex<double>, Prop, RowSparse, Allocator>& Umat,
257  bool permuted = true);
258 
259  void FactorizeCSC(Vector<superlu_int_t>& Ptr, Vector<superlu_int_t>& IndRow,
260  Vector<complex<double> >& Val, bool sym);
261 
262 #endif
263 
264  template<class T0, class Prop, class Storage, class Allocator>
265  void FactorizeMatrix(Matrix<T0, Prop,
266  Storage, Allocator> & mat,
267  bool keep_matrix = false);
268 
269  template<class Allocator2>
270  void Solve(Vector<complex<double>, VectFull, Allocator2>& x);
271 
272  template<class Allocator2>
273  void Solve(const SeldonTranspose& TransA,
274  Vector<complex<double>, VectFull, Allocator2>& x);
275 
276  void Solve(const SeldonTranspose& Trans,
277  complex<double>* x_ptr, int nrhs_);
278 
279  template<class Allocator2>
280  void Solve(Matrix<complex<double>, General, ColMajor, Allocator2>& x);
281 
282  template<class Allocator2>
283  void Solve(const SeldonTranspose& TransA,
284  Matrix<complex<double>, General, ColMajor, Allocator2>& x);
285 
286 #ifdef SELDON_WITH_SUPERLU_DIST
287  void FactorizeCSC(Vector<long>& Ptr, Vector<int>& IndRow,
288  Vector<complex<double> >& Val, bool sym);
289 
290  void FactorizeDistributedMatrix(MPI_Comm& comm_facto, Vector<long>& Ptr,
291  Vector<int>& IndRow, Vector<complex<double> >& Val,
292  const Vector<int>& glob_number,
293  bool sym, bool keep_matrix = false);
294 
295  void FactorizeDistributedMatrix(MPI_Comm& comm_facto, Vector<int64_t>& Ptr,
296  Vector<int64_t>& IndRow, Vector<complex<double> >& Val,
297  const Vector<int>& glob_number,
298  bool sym, bool keep_matrix = false);
299 
300  template<class Tint>
301  void FactorizeParallel(MPI_Comm& comm_facto,
303  Vector<complex<double> >&,
304  const Vector<int>& glob_num,
305  bool sym, bool keep_matrix = false);
306 
307  void FactorizeParallel(MPI_Comm& comm_facto,
309  Vector<complex<double> >&,
310  const Vector<int>& glob_num,
311  bool sym, bool keep_matrix = false);
312 
313  template<class Allocator2>
314  void SolveDistributed(MPI_Comm& comm_facto,
315  const SeldonTranspose& TransA,
316  Vector<complex<double>, VectFull, Allocator2>& x,
317  const Vector<int>& glob_num);
318 
319  template<class Allocator2>
320  void SolveDistributed(MPI_Comm& comm_facto,
321  const SeldonTranspose& TransA,
322  Matrix<complex<double>, General, ColMajor, Allocator2>& x,
323  const Vector<int>& glob_num);
324 
325  void SolveDistributed(MPI_Comm& comm_facto,
326  const SeldonTranspose& TransA,
327  complex<double>* x_ptr, int nrhs_,
328  const IVect& glob_num);
329 #endif
330 
331  };
332 
333  template<class T0, class Prop, class Storage, class Allocator, class T>
335  bool keep_matrix = false);
336 
337  template<class T, class Allocator>
338  void SolveLU(MatrixSuperLU<T>& mat_lu, Vector<T, VectFull, Allocator>& x);
339 
340  template<class T, class Allocator>
341  void SolveLU(const SeldonTranspose& TransA,
343  template<class T, class Prop, class Allocator>
344  void SolveLU(MatrixSuperLU<T>& mat_lu,
346 
347  template<class T, class Prop, class Allocator>
348  void SolveLU(const SeldonTranspose& TransA,
350 
351  template<class Allocator>
352  void SolveLU(MatrixSuperLU<double>& mat_lu,
353  Vector<complex<double>, VectFull, Allocator>& x);
354 
355  template<class Allocator>
356  void SolveLU(const SeldonTranspose& TransA,
357  MatrixSuperLU<double>& mat_lu,
358  Vector<complex<double>, VectFull, Allocator>& x);
359 
360  template<class Allocator>
361  void SolveLU(MatrixSuperLU<complex<double> >& mat_lu,
363 
364  template<class Allocator>
365  void SolveLU(const SeldonTranspose& TransA,
366  MatrixSuperLU<complex<double> >& mat_lu,
368 
369 }
370 
371 #define SELDON_FILE_SUPERLU_HXX
372 #endif
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::MatrixSuperLU_Base::Glu
superlu::GlobalLU_t Glu
object of SuperLU
Definition: SuperLU.hxx:59
Seldon::ColSparse
Definition: Storage.hxx:79
Seldon::MatrixSuperLU_Base::~MatrixSuperLU_Base
~MatrixSuperLU_Base()
destructor
Definition: SuperLU.cxx:158
Seldon::MatrixSuperLU_Base::Init
void Init(int size, int_t &panel_size, int_t &relax)
inits SuperLU computation
Definition: SuperLU.cxx:199
Seldon::MatrixSuperLU_Base::SetNumberOfThreadPerNode
void SetNumberOfThreadPerNode(int p)
Sets the number of threads per mpi process.
Definition: SuperLU.cxx:228
Seldon::Vector< int_t >
Seldon::MatrixSuperLU_Base::perm_r
Vector< int_t > perm_r
permutation array
Definition: SuperLU.hxx:92
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::MatrixSuperLU_Base::HideMessages
void HideMessages()
no message from SuperLU
Definition: SuperLU.cxx:238
Seldon::MatrixSuperLU_Base::GetInfoFactorization
int GetInfoFactorization() const
returns status of factorisation
Definition: SuperLU.cxx:264
Seldon::MatrixSuperLU_Base::L
superlu::SuperMatrix L
objects of SuperLU
Definition: SuperLU.hxx:58
Seldon::MatrixSuperLU_Base::options
superlu::superlu_options_t options
options
Definition: SuperLU.hxx:76
Seldon::MatrixSuperLU_Base::MatrixSuperLU_Base
MatrixSuperLU_Base()
default constructor
Definition: SuperLU.cxx:119
Seldon::VectFull
Definition: StorageInline.cxx:74
Seldon::MatrixSuperLU_Base::GetColPermutation
const Vector< int_t > & GetColPermutation() const
Returns the permutation of columns.
Definition: SuperLU.cxx:292
Seldon::MatrixSuperLU_Base::stat
superlu::SuperLUStat_t stat
statistics
Definition: SuperLU.hxx:77
Seldon::MatrixSuperLU_Base::Ustore
superlu::NCformat * Ustore
object of SuperLU
Definition: SuperLU.hxx:75
Seldon::MatrixSuperLU_Base::Clear
void Clear()
same effect as a call to the destructor
Definition: SuperLU.cxx:166
Seldon::General
Definition: Properties.hxx:26
Seldon::MatrixSuperLU
empty matrix
Definition: SuperLU.hxx:125
Seldon::Vector< T, VectFull, Allocator >
Full vector class.
Definition: Vector.hxx:88
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::MatrixSuperLU_Base::ShowMessages
void ShowMessages()
allows messages from SuperLU
Definition: SuperLU.cxx:246
Seldon::MatrixSuperLU_Base::GetRowPermutation
const Vector< int_t > & GetRowPermutation() const
Returns the permutation of rows.
Definition: SuperLU.cxx:278
Seldon::MatrixSuperLU_Base::display_info
bool display_info
display information about factorization ? Error code returned by SuperLU.
Definition: SuperLU.hxx:97
Seldon::MatrixSuperLU_Base::SelectOrdering
void SelectOrdering(int type)
selects ordering to use in the interfaced solver
Definition: SuperLU.cxx:299
Seldon::MatrixSuperLU_Base::Lstore
superlu::SCformat * Lstore
object of SuperLU
Definition: SuperLU.hxx:74
Seldon::RowSparse
Definition: Storage.hxx:91
Seldon::MatrixSuperLU_Base::n
int_t n
number of rows
Definition: SuperLU.hxx:95
Seldon::MatrixSuperLU_Base::permc_spec
colperm_t permc_spec
ordering scheme
Definition: SuperLU.hxx:94
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::MatrixSuperLU_Base
class interfacing SuperLU functions
Definition: SuperLU.hxx:53
Seldon::MatrixSuperLU< double >
class interfacing SuperLU functions in double precision
Definition: SuperLU.hxx:132
Seldon::Matrix< T, Prop, ColMajor, Allocator >
Column-major full-matrix class.
Definition: Matrix_Pointers.hxx:176
Seldon::ColMajor
Definition: Storage.hxx:33