43 #include "Ifpack_ConfigDefs.h" 44 #include "Ifpack_Preconditioner.h" 45 #include "Ifpack_IKLU.h" 46 #include "Ifpack_Condest.h" 48 #include "Ifpack_HashTable.h" 49 #include "Epetra_SerialComm.h" 50 #include "Epetra_Comm.h" 51 #include "Epetra_Map.h" 52 #include "Epetra_RowMatrix.h" 53 #include "Epetra_CrsMatrix.h" 54 #include "Epetra_Vector.h" 55 #include "Epetra_MultiVector.h" 56 #include "Epetra_Util.h" 57 #include "Teuchos_ParameterList.hpp" 58 #include "Teuchos_RefCountPtr.hpp" 73 DropTolerance_(1e-12),
74 IsInitialized_(false),
83 ApplyInverseTime_(0.0),
85 ApplyInverseFlops_(0.0),
102 void Ifpack_IKLU::Destroy()
104 IsInitialized_ =
false;
119 LevelOfFill_ = List.get<
double>(
"fact: ilut level-of-fill", LevelOfFill());
120 if (LevelOfFill_ <= 0.0)
123 Athresh_ = List.get<
double>(
"fact: absolute threshold", Athresh_);
124 Rthresh_ = List.get<
double>(
"fact: relative threshold", Rthresh_);
125 Relax_ = List.get<
double>(
"fact: relax value", Relax_);
126 DropTolerance_ = List.get<
double>(
"fact: drop tolerance", DropTolerance_);
138 cerr <<
"Caught an exception while parsing the parameter list" << endl;
139 cerr <<
"This typically means that a parameter was set with the" << endl;
140 cerr <<
"wrong type (for example, int instead of double). " << endl;
141 cerr <<
"please check the documentation for the type required by each parameer." << endl;
154 Time_.ResetStartTime();
156 if (A_.Comm().NumProc() != 1) {
157 cout <<
" There are too many processors !!! " << endl;
158 cerr <<
"Ifpack_IKLU can be used with Comm().NumProc() == 1" << endl;
159 cerr <<
"only. This class is a subdomain solver for Ifpack_AdditiveSchwarz," << endl;
160 cerr <<
"and it is currently not meant to be used otherwise." << endl;
168 NumMyRows_ =
Matrix().NumMyRows();
169 NumMyNonzeros_ =
Matrix().NumMyNonzeros();
171 int RowNnz, Length =
Matrix().MaxNumEntries();
172 vector<int> RowIndices(Length);
173 vector<double> RowValues(Length);
177 csrA_ = csr_spalloc( NumMyRows_, NumMyRows_, NumMyNonzeros_, 1, 0 );
182 for (
int i = 0; i < NumMyRows_; ++i ) {
184 IFPACK_CHK_ERR(A_.ExtractMyRowCopy(i,Length,RowNnz,
185 &RowValues[0],&RowIndices[0]));
186 for (
int j = 0 ; j < RowNnz ; ++j) {
187 csrA_->j[count++] = RowIndices[j];
190 csrA_->p[i+1] = csrA_->p[i] + RowNnz;
195 cssS_ = csr_sqr( order, csrA_ );
196 for (
int i = 0; i < NumMyRows_; ++i ) {
197 cout <<
"AMD Perm (from inside KLU) [" << i <<
"] = " << cssS_->q[i] << endl;
201 IsInitialized_ =
true;
203 InitializeTime_ += Time_.ElapsedTime();
212 inline bool operator()(
const double& x,
const double& y)
214 return(IFPACK_ABS(x) > IFPACK_ABS(y));
225 Time_.ResetStartTime();
228 NumMyRows_ = A_.NumMyRows();
229 int Length = A_.MaxNumEntries();
231 bool distributed = (
Comm().NumProc() > 1)?
true:
false;
234 SerialComm_ = rcp(
new Epetra_SerialComm);
235 SerialMap_ = rcp(
new Epetra_Map(NumMyRows_, 0, *SerialComm_));
236 assert (SerialComm_.get() != 0);
237 assert (SerialMap_.get() != 0);
240 SerialMap_ = rcp(const_cast<Epetra_Map*>(&A_.RowMatrixRowMap()),
false);
243 vector<int> RowIndices(Length);
244 vector<double> RowValues(Length);
248 for (
int i = 0; i < NumMyRows_; ++i ) {
250 IFPACK_CHK_ERR(A_.ExtractMyRowCopy(i,Length,RowNnz,
251 &RowValues[0],&RowIndices[0]));
253 if (RowNnz != (csrA_->p[i+1]-csrA_->p[i])) {
254 cout <<
"The number of nonzeros for this row does not math the expected number of nonzeros!!!" << endl;
256 for (
int j = 0 ; j < RowNnz ; ++j) {
258 csrA_->x[count++] = RowValues[j];
265 csrnN_ = csr_lu( &*csrA_, &*cssS_, tol );
268 csr* L_tmp = csrnN_->L;
269 csr* U_tmp = csrnN_->U;
270 vector<int> numEntriesL( NumMyRows_ ), numEntriesU( NumMyRows_ );
271 for (
int i=0; i < NumMyRows_; ++i) {
272 numEntriesL[i] = ( L_tmp->p[i+1] - L_tmp->p[i] );
273 numEntriesU[i] = ( U_tmp->p[i+1] - U_tmp->p[i] );
275 L_ = rcp(
new Epetra_CrsMatrix(View, *SerialMap_, &numEntriesL[0]));
276 U_ = rcp(
new Epetra_CrsMatrix(View, *SerialMap_, &numEntriesU[0]));
279 for (
int i=0; i < NumMyRows_; ++i) {
280 L_->InsertGlobalValues( i, numEntriesL[i], &(L_tmp->x[L_tmp->p[i]]), &(L_tmp->j[L_tmp->p[i]]) );
281 U_->InsertGlobalValues( i, numEntriesU[i], &(U_tmp->x[U_tmp->p[i]]), &(U_tmp->j[U_tmp->p[i]]) );
284 IFPACK_CHK_ERR(L_->FillComplete());
285 IFPACK_CHK_ERR(U_->FillComplete());
287 int MyNonzeros = L_->NumGlobalNonzeros() + U_->NumGlobalNonzeros();
288 Comm().SumAll(&MyNonzeros, &GlobalNonzeros_, 1);
293 ComputeTime_ += Time_.ElapsedTime();
301 Epetra_MultiVector& Y)
const 306 if (X.NumVectors() != Y.NumVectors())
309 Time_.ResetStartTime();
317 vector<int> invq( NumMyRows_ );
319 for (
int i=0; i<NumMyRows_; ++i ) {
320 csrnN_->perm[ csrnN_->pinv[i] ] = i;
321 invq[ cssS_->q[i] ] = i;
324 Teuchos::RefCountPtr<Epetra_MultiVector> Xcopy = Teuchos::rcp(
new Epetra_MultiVector(X.Map(),X.NumVectors()),
false );
325 Teuchos::RefCountPtr<Epetra_MultiVector> Ytemp = Teuchos::rcp(
new Epetra_MultiVector(Y.Map(),Y.NumVectors()) );
327 for (
int i=0; i<NumMyRows_; ++i) {
328 for (
int j=0; j<X.NumVectors(); ++j) {
329 Xcopy->ReplaceMyValue( invq[i], j, (*X(j))[i] );
336 IFPACK_CHK_ERR(L_->Solve(
false,
false,
false,*Xcopy,*Ytemp));
337 IFPACK_CHK_ERR(U_->Solve(
true,
false,
false,*Ytemp,*Ytemp));
342 IFPACK_CHK_ERR(U_->Solve(
true,
true,
false,*Xcopy,*Ytemp));
343 IFPACK_CHK_ERR(L_->Solve(
false,
true,
false,*Ytemp,*Ytemp));
347 for (
int i=0; i<NumMyRows_; ++i) {
348 for (
int j=0; j<Y.NumVectors(); ++j) {
349 Y.ReplaceMyValue( csrnN_->perm[i], j, (*(*Ytemp)(j))[i] );
354 #ifdef IFPACK_FLOPCOUNTERS 355 ApplyInverseFlops_ += X.NumVectors() * 2 * GlobalNonzeros_;
357 ApplyInverseTime_ += Time_.ElapsedTime();
364 int Ifpack_IKLU::Apply(
const Epetra_MultiVector& X,
365 Epetra_MultiVector& Y)
const 373 const int MaxIters,
const double Tol,
374 Epetra_RowMatrix* Matrix_in)
380 if (Condest_ == -1.0)
381 Condest_ = Ifpack_Condest(*
this, CT, MaxIters, Tol, Matrix_in);
390 if (!
Comm().MyPID()) {
392 os <<
"================================================================================" << endl;
393 os <<
"Ifpack_IKLU: " <<
Label() << endl << endl;
394 os <<
"Level-of-fill = " << LevelOfFill() << endl;
397 os <<
"Relax value = " <<
RelaxValue() << endl;
398 os <<
"Condition number estimate = " <<
Condest() << endl;
399 os <<
"Global number of rows = " << A_.NumGlobalRows() << endl;
401 os <<
"Number of nonzeros in A = " << A_.NumGlobalNonzeros() << endl;
404 <<
" % of A)" << endl;
405 os <<
"nonzeros / rows = " 409 os <<
"Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
410 os <<
"----- ------- -------------- ------------ --------" << endl;
413 <<
" 0.0 0.0" << endl;
414 os <<
"Compute() " << std::setw(5) <<
NumCompute()
420 os <<
" " << std::setw(15) << 0.0 << endl;
427 os <<
" " << std::setw(15) << 0.0 << endl;
428 os <<
"================================================================================" << endl;
Ifpack_IKLU(const Epetra_RowMatrix *A)
Ifpack_IKLU constuctor with variable number of indices per row.
const Epetra_RowMatrix & Matrix() const
Returns a reference to the matrix to be preconditioned.
virtual ostream & Print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
int SetParameters(Teuchos::ParameterList ¶meterlis)
Set parameters using a Teuchos::ParameterList object.
virtual int NumApplyInverse() const
Returns the number of calls to ApplyInverse().
string Ifpack_toString(const int &x)
Convertes an integer to string.
virtual double InitializeTime() const
Returns the time spent in Initialize().
int NumGlobalNonzeros() const
Returns the number of nonzero entries in the global graph.
virtual double ComputeTime() const
Returns the time spent in Compute().
virtual double ApplyInverseFlops() const
Returns the number of flops in the application of the preconditioner.
const char * Label() const
Returns the label of this object.
bool IsInitialized() const
Returns true if the preconditioner has been successfully initialized.
virtual double ApplyInverseTime() const
Returns the time spent in ApplyInverse().
bool IsComputed() const
If factor is completed, this query returns true, otherwise it returns false.
virtual int NumCompute() const
Returns the number of calls to Compute().
virtual ~Ifpack_IKLU()
Ifpack_IKLU Destructor.
double DropTolerance() const
Gets the dropping tolerance.
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Ifpack_IKLU forward/back solve on a Epetra_MultiVector X in Y...
double RelativeThreshold() const
Get relative threshold value.
double RelaxValue() const
Set relative threshold value.
const Epetra_Comm & Comm() const
Returns the Epetra_BlockMap object associated with the range of this matrix operator.
virtual int NumInitialize() const
Returns the number of calls to Initialize().
double AbsoluteThreshold() const
Get absolute threshold value.
int Initialize()
Initialize L and U with values from user matrix A.
double Condest() const
Returns the computed estimated condition number, or -1.0 if no computed.
int Compute()
Compute IC factor U using the specified graph, diagonal perturbation thresholds and relaxation parame...
virtual double ComputeFlops() const
Returns the number of flops in the computation phase.