43 #include "Ifpack_ConfigDefs.h"
44 #include "Ifpack_Preconditioner.h"
45 #include "Ifpack_Amesos.h"
46 #include "Ifpack_Condest.h"
47 #include "Epetra_MultiVector.h"
48 #include "Epetra_Map.h"
49 #include "Epetra_Comm.h"
51 #include "Epetra_LinearProblem.h"
52 #include "Epetra_RowMatrix.h"
53 #include "Epetra_Time.h"
54 #include "Teuchos_ParameterList.hpp"
56 static bool FirstTime =
true;
60 Matrix_(Teuchos::rcp( Matrix_in, false )),
63 IsInitialized_(false),
71 ApplyInverseTime_(0.0),
73 ApplyInverseFlops_(0),
81 Matrix_(Teuchos::rcp( &rhs.Matrix(), false )),
84 IsInitialized_(false),
86 NumInitialize_(rhs.NumInitialize()),
87 NumCompute_(rhs.NumCompute()),
88 NumApplyInverse_(rhs.NumApplyInverse()),
89 InitializeTime_(rhs.InitializeTime()),
90 ComputeTime_(rhs.ComputeTime()),
91 ApplyInverseTime_(rhs.ApplyInverseTime()),
92 ComputeFlops_(rhs.ComputeFlops()),
93 ApplyInverseFlops_(rhs.ApplyInverseFlops()),
94 Condest_(rhs.Condest())
100 Teuchos::ParameterList RHSList(rhs.List());
107 IsInitialized_ =
true;
121 Label_ = List_in.get(
"amesos: solver type", Label_);
132 IsInitialized_ =
false;
135 if (Matrix_ == Teuchos::null)
143 if (
Comm().NumProc() != 1) {
144 cout <<
"Class Ifpack_Amesos must be used for serial runs;" << endl;
145 cout <<
"for parallel runs you should declare objects as:" << endl;
146 cout <<
"Ifpack_AdditiveSchwarz<Ifpack_Amesos> APrec(Matrix)" << endl;
152 if (Matrix_->NumGlobalRows64() != Matrix_->NumGlobalCols64())
156 if (Matrix_->NumGlobalRows64() == 0) {
158 IsInitialized_ =
true;
163 Problem_->SetOperator(const_cast<Epetra_RowMatrix*>(Matrix_.get()));
166 if (Time_ == Teuchos::null)
170 Solver_ = Teuchos::rcp( Factory.Create((
char*)Label_.c_str(),*Problem_) );
172 if (Solver_ == Teuchos::null)
175 Label_ =
"Amesos_Klu";
176 Solver_ = Teuchos::rcp( Factory.Create(
"Amesos_Klu",*Problem_) );
178 if (Solver_ == Teuchos::null)
185 cerr <<
"IFPACK WARNING: In class Ifpack_Amesos:" << endl;
186 cerr <<
"IFPACK WARNING: Using LAPACK because other Amesos" << endl;
187 cerr <<
"IFPACK WARNING: solvers are not available. LAPACK" << endl;
188 cerr <<
"IFPACK WARNING: allocates memory to store the matrix as" << endl;
189 cerr <<
"IFPACK WARNING: dense, I hope you have enough memory..." << endl;
190 cerr <<
"IFPACK WARNING: (file " << __FILE__ <<
", line " << __LINE__
194 Label_ =
"Amesos_Lapack";
195 Solver_ = Teuchos::rcp( Factory.Create(
"Amesos_Lapack",*Problem_) );
198 if (Solver_ == Teuchos::null)
201 IFPACK_CHK_ERR(Solver_->SetUseTranspose(UseTranspose_));
202 Solver_->SetParameters(List_);
203 IFPACK_CHK_ERR(Solver_->SymbolicFactorization());
205 IsInitialized_ =
true;
207 InitializeTime_ += Time_->ElapsedTime();
225 Time_->ResetStartTime();
227 if (Matrix_ == Teuchos::null)
230 IFPACK_CHK_ERR(Solver_->NumericFactorization());
234 ComputeTime_ += Time_->ElapsedTime();
243 UseTranspose_ = UseTranspose_in;
244 if (Solver_ != Teuchos::null)
245 IFPACK_CHK_ERR(Solver_->SetUseTranspose(UseTranspose_in));
255 IFPACK_CHK_ERR(Matrix_->Apply(X,Y));
271 if (X.NumVectors() != Y.NumVectors())
274 Time_->ResetStartTime();
278 Teuchos::RefCountPtr<const Epetra_MultiVector> Xcopy;
279 if (X.Pointers()[0] == Y.Pointers()[0])
282 Xcopy = Teuchos::rcp( &X,
false );
284 Problem_->SetLHS(&Y);
286 IFPACK_CHK_ERR(Solver_->Solve());
289 ApplyInverseTime_ += Time_->ElapsedTime();
303 return((
char*)Label_.c_str());
309 return(UseTranspose_);
321 return(Matrix_->Comm());
327 return(Matrix_->OperatorDomainMap());
333 return(Matrix_->OperatorRangeMap());
338 const int MaxIters,
const double Tol,
345 if (Condest_ == -1.0)
346 Condest_ = Ifpack_Condest(*
this, CT, MaxIters, Tol, Matrix_in);
356 if (!
Comm().MyPID()) {
358 os <<
"================================================================================" << endl;
359 os <<
"Ifpack_Amesos: " <<
Label () << endl << endl;
360 os <<
"Condition number estimate = " <<
Condest() << endl;
361 os <<
"Global number of rows = " << Matrix_->NumGlobalRows64() << endl;
363 os <<
"Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
364 os <<
"----- ------- -------------- ------------ --------" << endl;
365 os <<
"Initialize() " << std::setw(5) << NumInitialize_
366 <<
" " << std::setw(15) << InitializeTime_
367 <<
" 0.0 0.0" << endl;
368 os <<
"Compute() " << std::setw(5) << NumCompute_
369 <<
" " << std::setw(15) << ComputeTime_
370 <<
" " << std::setw(15) << 1.0e-6 * ComputeFlops_;
371 if (ComputeTime_ != 0.0)
372 os <<
" " << std::setw(15) << 1.0e-6 * ComputeFlops_ / ComputeTime_ << endl;
374 os <<
" " << std::setw(15) << 0.0 << endl;
375 os <<
"ApplyInverse() " << std::setw(5) << NumApplyInverse_
376 <<
" " << std::setw(15) << ApplyInverseTime_
377 <<
" " << std::setw(15) << 1.0e-6 * ApplyInverseFlops_;
378 if (ApplyInverseTime_ != 0.0)
379 os <<
" " << std::setw(15) << 1.0e-6 * ApplyInverseFlops_ / ApplyInverseTime_ << endl;
381 os <<
" " << std::setw(15) << 0.0 << endl;
382 os <<
"================================================================================" << endl;
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
virtual int SetParameters(Teuchos::ParameterList &List)
Sets all the parameters for the preconditioner.
Ifpack_Amesos(Epetra_RowMatrix *Matrix)
Constructor.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the matrix to an Epetra_MultiVector.
virtual bool IsComputed() const
Returns true if the preconditioner has been successfully computed.
Ifpack_Amesos: a class to use Amesos' factorizations as preconditioners.
virtual int Compute()
Computes the preconditioners.
virtual int Initialize()
Initializes the preconditioners.
virtual int SetUseTranspose(bool UseTranspose_in)
If set true, transpose of this operator will be applied (not implemented).
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
virtual const char * Label() const
Returns a character string describing the operator.
virtual double Condest() const
Returns the estimated condition number, never computes it.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the preconditioner to X, returns the result in Y.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual bool IsInitialized() const
Returns true is the preconditioner has been successfully initialized.
virtual double NormInf() const
Returns the infinity norm of the global matrix (not implemented)
virtual const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
virtual std::ostream & Print(std::ostream &os) const
Prints on ostream basic information about this object.