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),
76 Problem_ = Teuchos::rcp(
new Epetra_LinearProblem );
84 IsInitialized_(false),
97 Problem_ = Teuchos::rcp(
new Epetra_LinearProblem );
100 Teuchos::ParameterList RHSList(rhs.List());
107 IsInitialized_ =
true;
121 Label_ = List_in.get(
"amesos: solver type", Label_);
130 IsInitialized_ =
false;
133 if (Matrix_ == Teuchos::null)
139 if (
Comm().NumProc() != 1) {
140 cout <<
"Class Ifpack_Amesos must be used for serial runs;" << endl;
141 cout <<
"for parallel runs you should declare objects as:" << endl;
142 cout <<
"Ifpack_AdditiveSchwarz<Ifpack_Amesos> APrec(Matrix)" << endl;
148 if (Matrix_->NumGlobalRows() != Matrix_->NumGlobalCols())
152 if (Matrix_->NumGlobalRows() == 0) {
154 IsInitialized_ =
true;
159 Problem_->SetOperator(const_cast<Epetra_RowMatrix*>(Matrix_.get()));
162 if (Time_ == Teuchos::null)
163 Time_ = Teuchos::rcp(
new Epetra_Time(
Comm()) );
166 Solver_ = Teuchos::rcp( Factory.Create((
char*)Label_.c_str(),*Problem_) );
168 if (Solver_ == Teuchos::null)
171 Solver_ = Teuchos::rcp( Factory.Create(
"Amesos_Klu",*Problem_) );
173 if (Solver_ == Teuchos::null)
180 cerr <<
"IFPACK WARNING: In class Ifpack_Amesos:" << endl;
181 cerr <<
"IFPACK WARNING: Using LAPACK because other Amesos" << endl;
182 cerr <<
"IFPACK WARNING: solvers are not available. LAPACK" << endl;
183 cerr <<
"IFPACK WARNING: allocates memory to store the matrix as" << endl;
184 cerr <<
"IFPACK WARNING: dense, I hope you have enough memory..." << endl;
185 cerr <<
"IFPACK WARNING: (file " << __FILE__ <<
", line " << __LINE__
189 Solver_ = Teuchos::rcp( Factory.Create(
"Amesos_Lapack",*Problem_) );
192 if (Solver_ == Teuchos::null)
195 IFPACK_CHK_ERR(Solver_->SetUseTranspose(UseTranspose_));
196 Solver_->SetParameters(List_);
197 IFPACK_CHK_ERR(Solver_->SymbolicFactorization());
199 IsInitialized_ =
true;
201 InitializeTime_ += Time_->ElapsedTime();
219 Time_->ResetStartTime();
221 if (Matrix_ == Teuchos::null)
224 IFPACK_CHK_ERR(Solver_->NumericFactorization());
228 ComputeTime_ += Time_->ElapsedTime();
237 UseTranspose_ = UseTranspose_in;
238 if (Solver_ != Teuchos::null)
239 IFPACK_CHK_ERR(Solver_->SetUseTranspose(UseTranspose_in));
246 Apply(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const 249 IFPACK_CHK_ERR(Matrix_->Apply(X,Y));
265 if (X.NumVectors() != Y.NumVectors())
268 Time_->ResetStartTime();
272 Teuchos::RefCountPtr<const Epetra_MultiVector> Xcopy;
273 if (X.Pointers()[0] == Y.Pointers()[0])
274 Xcopy = Teuchos::rcp(
new Epetra_MultiVector(X) );
276 Xcopy = Teuchos::rcp( &X,
false );
278 Problem_->SetLHS(&Y);
279 Problem_->SetRHS((Epetra_MultiVector*)Xcopy.get());
280 IFPACK_CHK_ERR(Solver_->Solve());
283 ApplyInverseTime_ += Time_->ElapsedTime();
297 return((
char*)Label_.c_str());
303 return(UseTranspose_);
315 return(Matrix_->Comm());
321 return(Matrix_->OperatorDomainMap());
327 return(Matrix_->OperatorRangeMap());
332 const int MaxIters,
const double Tol,
333 Epetra_RowMatrix* Matrix_in)
339 if (Condest_ == -1.0)
340 Condest_ = Ifpack_Condest(*
this, CT, MaxIters, Tol, Matrix_in);
348 if (!
Comm().MyPID()) {
350 os <<
"================================================================================" << endl;
351 os <<
"Ifpack_Amesos: " <<
Label () << endl << endl;
352 os <<
"Condition number estimate = " <<
Condest() << endl;
353 os <<
"Global number of rows = " << Matrix_->NumGlobalRows() << endl;
355 os <<
"Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
356 os <<
"----- ------- -------------- ------------ --------" << endl;
357 os <<
"Initialize() " << std::setw(5) << NumInitialize_
358 <<
" " << std::setw(15) << InitializeTime_
359 <<
" 0.0 0.0" << endl;
360 os <<
"Compute() " << std::setw(5) << NumCompute_
361 <<
" " << std::setw(15) << ComputeTime_
362 <<
" " << std::setw(15) << 1.0e-6 * ComputeFlops_;
363 if (ComputeTime_ != 0.0)
364 os <<
" " << std::setw(15) << 1.0e-6 * ComputeFlops_ / ComputeTime_ << endl;
366 os <<
" " << std::setw(15) << 0.0 << endl;
367 os <<
"ApplyInverse() " << std::setw(5) << NumApplyInverse_
368 <<
" " << std::setw(15) << ApplyInverseTime_
369 <<
" " << std::setw(15) << 1.0e-6 * ApplyInverseFlops_;
370 if (ApplyInverseTime_ != 0.0)
371 os <<
" " << std::setw(15) << 1.0e-6 * ApplyInverseFlops_ / ApplyInverseTime_ << endl;
373 os <<
" " << std::setw(15) << 0.0 << endl;
374 os <<
"================================================================================" << endl;
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
virtual double ComputeTime() const
Returns the total time spent in Compute().
virtual int NumInitialize() const
Returns the number of calls to Initialize().
virtual double ApplyInverseTime() const
Returns the total time spent in ApplyInverse().
virtual int SetParameters(Teuchos::ParameterList &List)
Sets all the parameters for the preconditioner.
virtual double ComputeFlops() const
Returns the total number of flops to computate the preconditioner.
virtual int NumCompute() const
Returns the number of calls to Compute().
Ifpack_Amesos(Epetra_RowMatrix *Matrix)
Constructor.
virtual double ApplyInverseFlops() const
Returns the total number of flops to apply the preconditioner.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the matrix to an Epetra_MultiVector.
virtual const Epetra_RowMatrix & Matrix() const
Returns a const reference to the internally stored matrix.
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 double InitializeTime() const
Returns the total time spent in Initialize().
virtual int NumApplyInverse() const
Returns the number of calls to ApplyInverse().
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.