Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Amesos_Klu.h
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Amesos: Direct Sparse Solver Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
25 //
26 // ***********************************************************************
27 // @HEADER
28 
39 #ifndef AMESOS_KLU_H
40 #define AMESOS_KLU_H
41 
42 #include "Amesos_ConfigDefs.h"
43 #include "Amesos_BaseSolver.h"
44 #include "Amesos_NoCopiable.h"
45 #include "Amesos_Utils.h"
46 #include "Amesos_Time.h"
47 #include "Amesos_Status.h"
48 #include "Amesos_Control.h"
49 #include "Epetra_LinearProblem.h"
50 #include "Epetra_Time.h"
51 #include "Epetra_Import.h"
52 #ifdef EPETRA_MPI
53 #include "Epetra_MpiComm.h"
54 #else
55 #include "Epetra_Comm.h"
56 #endif
57 #include "Epetra_CrsGraph.h"
58 #include "Epetra_CrsMatrix.h"
59 
60 // class EpetraExt::MultiVector_Reindex ;
61 // class EpetraExt::CrsMatrix_Reindex ;
63 
101 // Amesos_Klu_Pimpl contains a pointer to two structures defined in
102 // klu.h: trilinos_klu_symbolic and trilinos_klu_numeric. This prevents Amesos_Klu.h
103 // from having to include klu.h.
104 //
105 // Doxygen does not handle forward class references well.
106 #ifndef DOXYGEN_SHOULD_SKIP_THIS
107 class Amesos_Klu_Pimpl ;
108 class Amesos_StandardIndex ;
109 #endif
110 
112  private Amesos_Time,
113  private Amesos_NoCopiable,
114  private Amesos_Utils,
115  private Amesos_Control,
116  private Amesos_Status {
117 
118 public:
119 
121 
129  Amesos_Klu(const Epetra_LinearProblem& LinearProblem );
130 
132  ~Amesos_Klu(void);
133 
135 
136 
137  int SymbolicFactorization() ;
138 
139  int NumericFactorization() ;
140 
141  int Solve();
142 
144 
145 
147  const Epetra_LinearProblem *GetProblem() const { return(Problem_); };
148 
150 
153  bool MatrixShapeOK() const ;
154 
156 
160  int SetUseTranspose(bool UseTranspose_in) {UseTranspose_ = UseTranspose_in; return(0);};
161 
162  bool UseTranspose() const {return(UseTranspose_);};
163 
164  const Epetra_Comm & Comm() const {return(GetProblem()->GetOperator()->Comm());};
165 
167 
170 
173 
175  int NumSolve() const { return( Amesos_Status::NumSolve_ ); }
176 
178  void PrintTiming() const;
179 
181  void PrintStatus() const;
182 
184  void GetTiming( Teuchos::ParameterList &TimingParameterList ) const { Amesos_Time::GetTiming( TimingParameterList ); }
185 
186 private:
187 
189 
190 
191  /*
192  CreateLocalMatrixAndExporters - Prepare to convert matrix and vectors to serial
193  Preconditions:
194  Problem_ must be set
195 
196  Postconditions:
197  UseDataInPlace_ is set to 1 if the input matrix can be used in place, i.e.
198  1) is entirely stored on process 0
199  2) range map and domain map are same as the row map
200  The following are only set if (! UseDataInPlace_ )"
201  SerialMap_
202  ImportToSerial_
203  SerialCrsMatrixA_
204 
205  SerialMatrix_
206  */
208  /*
209  ExportToSerial
210  Preconditions:
211  UseDataInPlace_ must be set
212  ImportToSerial and SerialCrsMatrixA_ must be set if UseDataInPlace_ != 1
213  Postconditions
214  SerialMatrix_ points to a serial version of the matrix
215  */
216  int ExportToSerial() ;
217  /*
218  ConvertToKluCRS - Convert matrix to form expected by Klu: Ai, Ap, Aval
219  Preconditions:
220  numentries_, RowMatrixA_, ImportToSerial_, StdIndexMatrix_, Reindex_
221  Postconditions:
222  SerialCrsMatrixA_
223  */
224  int ConvertToKluCRS(bool firsttime);
225 
226  /*
227  PerformSymbolicFactorization - Call Klu to perform symbolic factorization
228  Preconditions:
229  UseDataInPlace_ must be set to 1 if the input matrix is entirely stored on process 0
230  Ap, Ai and Aval point to a compressed row storage version of the input matrix A.
231  Postconditions:
232  Symbolic points to an KLU internal opaque object containing the
233  symbolic factorization and accompanying information.
234  SymbolicFactorizationOK_ = true;
235  Note: All action is performed on process 0
236 
237  Returns non-zero if the symbolic factorization failed
238  */
239 
241 
242  /*
243  PerformNumericFactorization - Call Klu to perform numeric factorization
244  Preconditions:
245  UseDataInPlace_ must be set
246  Ap, Ai and Aval point to a compressed row storage version of the input matrix A.
247  Symbolic must be set
248  Postconditions:
249  Numeric points to an KLU internal opaque object containing the
250  numeric factorization and accompanying information.
251  NumericFactorizationOK_ = true;
252  Note: All action is performed on process 0
253  */
255 
256  // @}
257 
259 
260 #ifdef Bug_8212
261  int *lose_this_;
262 #endif
263  //
264  // PrivateKluData_ contains pointers to data needed by klu whose
265  // data structures are defined by klu.h
266  //
271 
276  std::vector <int> Ap;
277  std::vector <int> VecAi;
278  std::vector <double> VecAval;
279  double* Aval;
280  int *Ai;
281 
285  long long numentries_;
288 
293 #if 0
299  Teuchos::RCP<Epetra_Map> ContiguousMap_;
300 #endif
309 
311  // serially, StorageOptimized, the LHS and RHS are assumed to be available
312  // when SymbolicFactorization is called and not to change (address or number
313  // of vectors) thereafter.
314  bool TrustMe_;
318  double *SerialXBvalues_ ;
319  double *SerialBvalues_ ;
326 
331 
333  std::vector<int> ColIndicesV_;
335  std::vector<double> RowValuesV_;
343 
344 }; // class Amesos_Klu
345 
346 #endif /* AMESOS_KLU_H */
Teuchos::RCP< Epetra_Import > ImportRangeToSerial_
Definition: Amesos_Klu.h:338
int NumSymbolicFact_
Number of symbolic factorization phases.
Definition: Amesos_Status.h:67
long long numentries_
Number of non-zero entries in Problem_-&gt;GetOperator()
Definition: Amesos_Klu.h:285
int PerformNumericFactorization()
Definition: Amesos_Klu.cpp:516
Amesos_Klu: A serial, unblocked code ideal for getting started and for very sparse matrices...
Definition: Amesos_Klu.h:111
Amesos_Control: Container for some control variables.
bool TrustMe_
If true, no checks are made and the matrix is assume to be distributed.
Definition: Amesos_Klu.h:314
std::vector< int > VecAi
Definition: Amesos_Klu.h:277
std::vector< int > Ap
Ap, Ai, Aval form the compressed row storage used by Klu Ai and Aval can point directly into a matrix...
Definition: Amesos_Klu.h:276
const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
Definition: Amesos_Klu.h:164
Teuchos::RCP< Amesos_StandardIndex > StdIndexRange_
Definition: Amesos_Klu.h:269
Epetra_RowMatrix * RowMatrixA_
Operator converted to a RowMatrix.
Definition: Amesos_Klu.h:290
long long NumGlobalElements_
Number of rows and columns in the Problem_-&gt;GetOperator()
Definition: Amesos_Klu.h:287
int SolveTime_
Definition: Amesos_Klu.h:342
int Solve()
Solves A X = B (or AT x = B)
Definition: Amesos_Klu.cpp:729
int * Ai
Definition: Amesos_Klu.h:280
const Epetra_LinearProblem * GetProblem() const
Get a pointer to the Problem.
Definition: Amesos_Klu.h:147
Teuchos::RCP< Epetra_Map > SerialMap_
Points to a Serial Map (unused if UseDataInPlace_ == 1 )
Definition: Amesos_Klu.h:302
bool MatrixShapeOK() const
Returns true if KLU can handle this matrix shape.
Definition: Amesos_Klu.cpp:603
int ExportToSerial()
Definition: Amesos_Klu.cpp:119
Teuchos::RCP< Epetra_CrsMatrix > SerialCrsMatrixA_
Points to a Serial Copy of A (unused if UseDataInPlace_==1)
Definition: Amesos_Klu.h:304
int SerialXlda_
Definition: Amesos_Klu.h:258
bool UseTranspose() const
Returns the current UseTranspose setting.
Definition: Amesos_Klu.h:162
Teuchos::RCP< Epetra_Import > ImportDomainToSerial_
Definition: Amesos_Klu.h:339
Epetra_CrsMatrix * CrsMatrixA_
Operator converted to a CrsMatrix.
Definition: Amesos_Klu.h:292
int MtxRedistTime_
Quick access ids for the individual timings.
Definition: Amesos_Klu.h:341
Teuchos::RCP< Epetra_MultiVector > SerialX_
Definition: Amesos_Klu.h:322
int NumSolve() const
Returns the number of solves performed by this object.
Definition: Amesos_Klu.h:175
Teuchos::RCP< Amesos_StandardIndex > StdIndexDomain_
Definition: Amesos_Klu.h:270
int OverheadTime_
Definition: Amesos_Klu.h:342
Epetra_RowMatrix * SerialMatrix_
Points to a Serial Copy of A.
Definition: Amesos_Klu.h:308
double * Aval
Definition: Amesos_Klu.h:279
int NumNumericFact_
Number of numeric factorization phases.
Definition: Amesos_Status.h:69
double * SerialXBvalues_
Pointer to the actual values in the serial version of X and B.
Definition: Amesos_Klu.h:318
std::vector< double > RowValuesV_
Only used for RowMatrices to extract copies.
Definition: Amesos_Klu.h:335
int CreateLocalMatrixAndExporters()
Definition: Amesos_Klu.cpp:196
int NumSolve_
Number of solves.
Definition: Amesos_Status.h:71
int NumSymbolicFact() const
Returns the number of symbolic factorizations performed by this object.
Definition: Amesos_Klu.h:169
int NumNumericFact() const
Returns the number of numeric factorizations performed by this object.
Definition: Amesos_Klu.h:172
std::vector< int > ColIndicesV_
Only used for RowMatrices to extract copies.
Definition: Amesos_Klu.h:333
Teuchos::RCP< Epetra_Import > ImportToSerial_
Importer to process 0.
Definition: Amesos_Klu.h:337
int SymFactTime_
Definition: Amesos_Klu.h:342
void GetTiming(Teuchos::ParameterList &list) const
Load up the current timing information into the parameter list.
Definition: Amesos_Time.h:124
int NumFactTime_
Definition: Amesos_Klu.h:342
int ConvertToKluCRS(bool firsttime)
Definition: Amesos_Klu.cpp:337
int PerformSymbolicFactorization()
Definition: Amesos_Klu.cpp:478
Epetra_RowMatrix * StdIndexMatrix_
Points to a Contiguous Copy of A.
Definition: Amesos_Klu.h:306
int NumericFactorization()
Performs NumericFactorization on the matrix A.
Definition: Amesos_Klu.cpp:681
bool UseTranspose_
If true, the transpose of A is used.
Definition: Amesos_Klu.h:328
~Amesos_Klu(void)
Amesos_Klu Destructor.
Definition: Amesos_Klu.cpp:111
Amesos_Status: Container for some status variables.
Definition: Amesos_Status.h:20
Amesos_Time: Container for timing information.
Definition: Amesos_Time.h:50
int NumVectors_
Number of vectors in RHS and LHS.
Definition: Amesos_Klu.h:316
int SetUseTranspose(bool UseTranspose_in)
SetUseTranpose(true) is more efficient in Amesos_Klu.
Definition: Amesos_Klu.h:160
Teuchos::RCP< Amesos_Klu_Pimpl > PrivateKluData_
Definition: Amesos_Klu.h:267
int SymbolicFactorization()
Performs SymbolicFactorization on the matrix A.
Definition: Amesos_Klu.cpp:617
void GetTiming(Teuchos::ParameterList &TimingParameterList) const
Extracts timing information and places in parameter list.
Definition: Amesos_Klu.h:184
const Epetra_LinearProblem * Problem_
Pointer to the linear system problem.
Definition: Amesos_Klu.h:330
int UseDataInPlace_
1 if Problem_-&gt;GetOperator() is stored entirely on process 0
Definition: Amesos_Klu.h:283
int MtxConvTime_
Definition: Amesos_Klu.h:341
Teuchos::RCP< Epetra_MultiVector > SerialBextract_
Definition: Amesos_Klu.h:325
void PrintStatus() const
Prints information about the factorization and solution phases.
Definition: Amesos_Klu.cpp:926
double * SerialBvalues_
Definition: Amesos_Klu.h:319
Teuchos::RCP< Epetra_MultiVector > SerialB_
Serial versions of the LHS and RHS (may point to the original vector if serial)
Definition: Amesos_Klu.h:321
Amesos_Klu(const Epetra_LinearProblem &LinearProblem)
Amesos_Klu Constructor.
Definition: Amesos_Klu.cpp:89
Amesos_BaseSolver: A pure virtual class for direct solution of real-valued double-precision operators...
std::vector< double > VecAval
Definition: Amesos_Klu.h:278
int VecRedistTime_
Definition: Amesos_Klu.h:341
Teuchos::RCP< Epetra_MultiVector > SerialXextract_
Serial versions of the LHS and RHS (if necessary)
Definition: Amesos_Klu.h:324
Teuchos::RCP< Amesos_StandardIndex > StdIndex_
Definition: Amesos_Klu.h:268
Amesos_NoCopiable: Simple class to prevent the usage of copy constructor and operator =...
int SetParameters(Teuchos::ParameterList &ParameterList)
Updates internal variables.
Definition: Amesos_Klu.cpp:449
void PrintTiming() const
Prints timing information.
Definition: Amesos_Klu.cpp:949
Amesos_Utils: Collections of basic utilities.
Definition: Amesos_Utils.h:19