Amesos Package Browser (Single Doxygen Collection)  Development
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 */
Amesos_Klu::SerialXBvalues_
double * SerialXBvalues_
Pointer to the actual values in the serial version of X and B.
Definition: Amesos_Klu.h:318
Amesos_Klu::NumNumericFact
int NumNumericFact() const
Returns the number of numeric factorizations performed by this object.
Definition: Amesos_Klu.h:172
Amesos_Status::NumSolve_
int NumSolve_
Number of solves.
Definition: Amesos_Status.h:71
Amesos_Klu::CreateLocalMatrixAndExporters
int CreateLocalMatrixAndExporters()
Definition: Amesos_Klu.cpp:196
Amesos_Klu::Ap
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
Amesos_NoCopiable.h
Amesos_NoCopiable
Amesos_NoCopiable: Simple class to prevent the usage of copy constructor and operator =.
Definition: Amesos_NoCopiable.h:44
Amesos_Klu::UseTranspose_
bool UseTranspose_
If true, the transpose of A is used.
Definition: Amesos_Klu.h:328
Amesos_Klu::StdIndexDomain_
Teuchos::RCP< Amesos_StandardIndex > StdIndexDomain_
Definition: Amesos_Klu.h:270
Amesos_Klu
Amesos_Klu: A serial, unblocked code ideal for getting started and for very sparse matrices,...
Definition: Amesos_Klu.h:111
Amesos_Klu::NumSymbolicFact
int NumSymbolicFact() const
Returns the number of symbolic factorizations performed by this object.
Definition: Amesos_Klu.h:169
Amesos_Klu::Solve
int Solve()
Solves A X = B (or AT x = B)
Definition: Amesos_Klu.cpp:729
Amesos_BaseSolver
Amesos_BaseSolver: A pure virtual class for direct solution of real-valued double-precision operators...
Definition: Amesos_BaseSolver.h:223
Amesos_Klu::SerialBextract_
Teuchos::RCP< Epetra_MultiVector > SerialBextract_
Definition: Amesos_Klu.h:325
Amesos_Klu::NumFactTime_
int NumFactTime_
Definition: Amesos_Klu.h:342
Amesos_Klu::StdIndex_
Teuchos::RCP< Amesos_StandardIndex > StdIndex_
Definition: Amesos_Klu.h:268
Amesos_Klu::PrintTiming
void PrintTiming() const
Prints timing information.
Definition: Amesos_Klu.cpp:949
Amesos_Klu::~Amesos_Klu
~Amesos_Klu(void)
Amesos_Klu Destructor.
Definition: Amesos_Klu.cpp:111
Amesos_Status::NumSymbolicFact_
int NumSymbolicFact_
Number of symbolic factorization phases.
Definition: Amesos_Status.h:67
Amesos_Klu::GetProblem
const Epetra_LinearProblem * GetProblem() const
Get a pointer to the Problem.
Definition: Amesos_Klu.h:147
Amesos_Klu::PrivateKluData_
Teuchos::RCP< Amesos_Klu_Pimpl > PrivateKluData_
Definition: Amesos_Klu.h:267
Epetra_CrsMatrix.h
Amesos_Klu::SerialBvalues_
double * SerialBvalues_
Definition: Amesos_Klu.h:319
Amesos_Klu::RowMatrixA_
Epetra_RowMatrix * RowMatrixA_
Operator converted to a RowMatrix.
Definition: Amesos_Klu.h:290
Amesos_Klu::VecRedistTime_
int VecRedistTime_
Definition: Amesos_Klu.h:341
Amesos_Klu::Ai
int * Ai
Definition: Amesos_Klu.h:280
Amesos_Klu::MtxRedistTime_
int MtxRedistTime_
Quick access ids for the individual timings.
Definition: Amesos_Klu.h:341
Amesos_Klu::MatrixShapeOK
bool MatrixShapeOK() const
Returns true if KLU can handle this matrix shape.
Definition: Amesos_Klu.cpp:603
Amesos_Time.h
Epetra_Comm
Amesos_Klu::UseDataInPlace_
int UseDataInPlace_
1 if Problem_->GetOperator() is stored entirely on process 0
Definition: Amesos_Klu.h:283
Amesos_Klu::PerformSymbolicFactorization
int PerformSymbolicFactorization()
Definition: Amesos_Klu.cpp:478
Epetra_LinearProblem.h
Teuchos::RCP< Amesos_Klu_Pimpl >
Epetra_CrsMatrix
Epetra_MpiComm.h
Amesos_Klu::SetParameters
int SetParameters(Teuchos::ParameterList &ParameterList)
Updates internal variables.
Definition: Amesos_Klu.cpp:449
Amesos_Klu::CrsMatrixA_
Epetra_CrsMatrix * CrsMatrixA_
Operator converted to a CrsMatrix.
Definition: Amesos_Klu.h:292
Amesos_Klu::RowValuesV_
std::vector< double > RowValuesV_
Only used for RowMatrices to extract copies.
Definition: Amesos_Klu.h:335
Amesos_Klu::ColIndicesV_
std::vector< int > ColIndicesV_
Only used for RowMatrices to extract copies.
Definition: Amesos_Klu.h:333
Amesos_Klu::SerialCrsMatrixA_
Teuchos::RCP< Epetra_CrsMatrix > SerialCrsMatrixA_
Points to a Serial Copy of A (unused if UseDataInPlace_==1)
Definition: Amesos_Klu.h:304
Amesos_Status::NumNumericFact_
int NumNumericFact_
Number of numeric factorization phases.
Definition: Amesos_Status.h:69
Amesos_Klu::PerformNumericFactorization
int PerformNumericFactorization()
Definition: Amesos_Klu.cpp:516
Amesos_Klu::SerialXlda_
int SerialXlda_
Definition: Amesos_Klu.h:258
Amesos_Klu::numentries_
long long numentries_
Number of non-zero entries in Problem_->GetOperator()
Definition: Amesos_Klu.h:285
Amesos_Utils
Amesos_Utils: Collections of basic utilities.
Definition: Amesos_Utils.h:19
Epetra_RowMatrix
Amesos_BaseSolver.h
Amesos_Klu::VecAval
std::vector< double > VecAval
Definition: Amesos_Klu.h:278
Amesos_Klu::PrintStatus
void PrintStatus() const
Prints information about the factorization and solution phases.
Definition: Amesos_Klu.cpp:926
Amesos_Klu::TrustMe_
bool TrustMe_
If true, no checks are made and the matrix is assume to be distributed.
Definition: Amesos_Klu.h:314
Amesos_Klu::SerialMap_
Teuchos::RCP< Epetra_Map > SerialMap_
Points to a Serial Map (unused if UseDataInPlace_ == 1 )
Definition: Amesos_Klu.h:302
Amesos_Klu::NumSolve
int NumSolve() const
Returns the number of solves performed by this object.
Definition: Amesos_Klu.h:175
Epetra_LinearProblem
Amesos_Klu::UseTranspose
bool UseTranspose() const
Returns the current UseTranspose setting.
Definition: Amesos_Klu.h:162
Amesos_Klu::SerialXextract_
Teuchos::RCP< Epetra_MultiVector > SerialXextract_
Serial versions of the LHS and RHS (if necessary)
Definition: Amesos_Klu.h:324
Amesos_Klu::SymbolicFactorization
int SymbolicFactorization()
Performs SymbolicFactorization on the matrix A.
Definition: Amesos_Klu.cpp:617
Amesos_Klu_Pimpl
Definition: Amesos_Klu.cpp:80
Amesos_Klu::ExportToSerial
int ExportToSerial()
Definition: Amesos_Klu.cpp:119
Epetra_Import.h
Amesos_Klu::SymFactTime_
int SymFactTime_
Definition: Amesos_Klu.h:342
Amesos_Control
Amesos_Control: Container for some control variables.
Definition: Amesos_Control.h:16
Amesos_Klu::Amesos_Klu
Amesos_Klu(const Epetra_LinearProblem &LinearProblem)
Amesos_Klu Constructor.
Definition: Amesos_Klu.cpp:89
Epetra_Comm.h
Amesos_ConfigDefs.h
Amesos_Klu::SerialX_
Teuchos::RCP< Epetra_MultiVector > SerialX_
Definition: Amesos_Klu.h:322
Amesos_Klu::NumGlobalElements_
long long NumGlobalElements_
Number of rows and columns in the Problem_->GetOperator()
Definition: Amesos_Klu.h:287
Amesos_Klu::NumVectors_
int NumVectors_
Number of vectors in RHS and LHS.
Definition: Amesos_Klu.h:316
Amesos_Klu::Problem_
const Epetra_LinearProblem * Problem_
Pointer to the linear system problem.
Definition: Amesos_Klu.h:330
Amesos_Utils.h
Amesos_Control.h
Amesos_StandardIndex
Definition: Amesos_Support.h:40
Amesos_Time::GetTiming
void GetTiming(Teuchos::ParameterList &list) const
Load up the current timing information into the parameter list.
Definition: Amesos_Time.h:124
Amesos_Klu::ImportRangeToSerial_
Teuchos::RCP< Epetra_Import > ImportRangeToSerial_
Definition: Amesos_Klu.h:338
Epetra_CrsGraph.h
Amesos_Klu::MtxConvTime_
int MtxConvTime_
Definition: Amesos_Klu.h:341
Teuchos::ParameterList
Amesos_Klu::GetTiming
void GetTiming(Teuchos::ParameterList &TimingParameterList) const
Extracts timing information and places in parameter list.
Definition: Amesos_Klu.h:184
Amesos_Klu::OverheadTime_
int OverheadTime_
Definition: Amesos_Klu.h:342
Amesos_Klu::SolveTime_
int SolveTime_
Definition: Amesos_Klu.h:342
Amesos_Klu::NumericFactorization
int NumericFactorization()
Performs NumericFactorization on the matrix A.
Definition: Amesos_Klu.cpp:681
Amesos_Time
Amesos_Time: Container for timing information.
Definition: Amesos_Time.h:50
Amesos_Klu::StdIndexRange_
Teuchos::RCP< Amesos_StandardIndex > StdIndexRange_
Definition: Amesos_Klu.h:269
Amesos_Klu::SetUseTranspose
int SetUseTranspose(bool UseTranspose_in)
SetUseTranpose(true) is more efficient in Amesos_Klu.
Definition: Amesos_Klu.h:160
Amesos_Klu::SerialMatrix_
Epetra_RowMatrix * SerialMatrix_
Points to a Serial Copy of A.
Definition: Amesos_Klu.h:308
Amesos_Klu::VecAi
std::vector< int > VecAi
Definition: Amesos_Klu.h:277
Amesos_Klu::ConvertToKluCRS
int ConvertToKluCRS(bool firsttime)
Definition: Amesos_Klu.cpp:337
Amesos_Klu::StdIndexMatrix_
Epetra_RowMatrix * StdIndexMatrix_
Points to a Contiguous Copy of A.
Definition: Amesos_Klu.h:306
Amesos_Klu::Comm
const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
Definition: Amesos_Klu.h:164
Epetra_Time.h
Amesos_Klu::ImportToSerial_
Teuchos::RCP< Epetra_Import > ImportToSerial_
Importer to process 0.
Definition: Amesos_Klu.h:337
Amesos_Klu::ImportDomainToSerial_
Teuchos::RCP< Epetra_Import > ImportDomainToSerial_
Definition: Amesos_Klu.h:339
Amesos_Status
Amesos_Status: Container for some status variables.
Definition: Amesos_Status.h:20
Amesos_Klu::SerialB_
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_Status.h
Amesos_Klu::Aval
double * Aval
Definition: Amesos_Klu.h:279