43 #include "Ifpack_ConfigDefs.h" 44 #include "Ifpack_SILU.h" 45 #ifdef HAVE_IFPACK_SUPERLU 47 #include "Ifpack_CondestType.h" 48 #include "Epetra_ConfigDefs.h" 49 #include "Epetra_Comm.h" 50 #include "Epetra_Map.h" 51 #include "Epetra_RowMatrix.h" 52 #include "Epetra_Vector.h" 53 #include "Epetra_MultiVector.h" 54 #include "Epetra_CrsGraph.h" 55 #include "Epetra_CrsMatrix.h" 56 #include "Teuchos_ParameterList.hpp" 57 #include "Teuchos_RefCountPtr.hpp" 60 extern "C" {
int dfill_diag(
int n, NCformat *Astore);}
62 using Teuchos::RefCountPtr;
65 #ifdef IFPACK_TEUCHOS_TIME_MONITOR 66 # include "Teuchos_TimeMonitor.hpp" 71 A_(rcp(Matrix_in,false)),
72 Comm_(Matrix_in->Comm()),
80 IsInitialized_(false),
87 ApplyInverseTime_(0.0),
93 Teuchos::ParameterList List;
101 void Ifpack_SILU::Destroy()
107 Destroy_CompCol_Permuted(&SAc_);
108 Destroy_SuperNode_Matrix(&SL_);
109 Destroy_CompCol_Matrix(&SU_);
112 Destroy_SuperMatrix_Store(&SA_);
113 if(SY_.Store) Destroy_SuperMatrix_Store(&SY_);
117 delete [] etree_;etree_=0;
118 delete [] perm_r_;perm_r_=0;
119 delete [] perm_c_;perm_c_=0;
126 DropTol_=List.get(
"fact: drop tolerance",DropTol_);
127 FillTol_=List.get(
"fact: zero pivot threshold",FillTol_);
128 FillFactor_=List.get(
"fact: maximum fill factor",FillFactor_);
129 DropRule_=List.get(
"fact: silu drop rule",DropRule_);
132 sprintf(Label_,
"IFPACK SILU (drop=%d, zpv=%f, ffact=%f, rthr=%f)",
133 DropRule(),FillTol(),FillFactor(),DropTol());
141 #ifdef IFPACK_TEUCHOS_TIME_MONITOR 142 TEUCHOS_FUNC_TIME_MONITOR(
"Ifpack_SILU::Initialize");
145 Time_.ResetStartTime();
150 IsInitialized_ =
false;
152 Epetra_CrsMatrix* CrsMatrix;
153 CrsMatrix =
dynamic_cast<Epetra_CrsMatrix*
>(&*A_);
155 if(CrsMatrix && CrsMatrix->RowMap().SameAs(CrsMatrix->ColMap()) && CrsMatrix->IndicesAreContiguous()){
157 Aover_=rcp(CrsMatrix,
false);
159 else if(CrsMatrix && CrsMatrix->IndicesAreContiguous()){
161 int size = A_->MaxNumEntries();
162 int N=A_->NumMyRows();
163 Aover_ = rcp(
new Epetra_CrsMatrix(Copy,A_->RowMatrixRowMap(), size));
164 vector<int> Indices(size);
165 vector<double> Values(size);
167 int i,j,ct,*rowptr,*colind;
169 IFPACK_CHK_ERR(CrsMatrix->ExtractCrsDataPointers(rowptr,colind,values));
173 for(j=rowptr[i],ct=0;j<rowptr[i+1];j++){
175 Indices[ct]=CrsMatrix->GCID(colind[j]);
176 Values[ct]=values[j];
180 Aover_->InsertGlobalValues(CrsMatrix->GRID(i),ct,&Values[0],&Indices[0]);
182 IFPACK_CHK_ERR(Aover_->FillComplete(CrsMatrix->RowMap(),CrsMatrix->RowMap()));
186 int size = A_->MaxNumEntries();
187 Aover_ = rcp(
new Epetra_CrsMatrix(Copy,A_->RowMatrixRowMap(), size));
188 if (Aover_.get() == 0) IFPACK_CHK_ERR(-5);
190 vector<int> Indices1(size),Indices2(size);
191 vector<double> Values1(size),Values2(size);
195 int N=A_->NumMyRows();
196 for (
int i = 0 ; i < N ; ++i) {
198 int GlobalRow = A_->RowMatrixRowMap().GID(i);
199 IFPACK_CHK_ERR(A_->ExtractMyRowCopy(i, size, NumEntries,
200 &Values1[0], &Indices1[0]));
204 for (
int j=0; j < NumEntries ; ++j) {
206 Indices2[ct] = A_->RowMatrixColMap().GID(Indices1[j]);
207 Values2[ct]=Values1[j];
211 IFPACK_CHK_ERR(Aover_->InsertGlobalValues(GlobalRow,ct,
212 &Values2[0],&Indices2[0]));
214 IFPACK_CHK_ERR(Aover_->FillComplete(A_->RowMatrixRowMap(),A_->RowMatrixRowMap()));
218 Aover_->OptimizeStorage();
219 Graph_=rcp(const_cast<Epetra_CrsGraph*>(&Aover_->Graph()),
false);
221 IsInitialized_ =
true;
223 InitializeTime_ += Time_.ElapsedTime();
232 #ifdef IFPACK_TEUCHOS_TIME_MONITOR 233 TEUCHOS_FUNC_TIME_MONITOR(
"Ifpack_SILU::Compute");
239 Time_.ResetStartTime();
244 ilu_set_default_options(&options_);
245 options_.ILU_DropTol=DropTol_;
246 options_.ILU_FillTol=FillTol_;
247 options_.ILU_DropRule=DropRule_;
248 options_.ILU_FillFactor=FillFactor_;
253 IFPACK_CHK_ERR(Aover_->ExtractCrsDataPointers(rowptr,colind,values));
254 int N=Aover_->NumMyRows();
257 dCreate_CompCol_Matrix(&SA_,N,N,Aover_->NumMyNonzeros(),
258 values,colind,rowptr,SLU_NC,SLU_D,SLU_GE);
262 dfill_diag(N, (NCformat*)SA_.Store);
270 int permc_spec=options_.ColPerm;
271 if ( permc_spec != MY_PERMC && options_.Fact == DOFACT )
272 get_perm_c(permc_spec,&SA_,perm_c_);
275 sp_preorder(&options_, &SA_, perm_c_, etree_, &SAc_);
278 int panel_size = sp_ienv(1);
279 int relax = sp_ienv(2);
281 dgsitrf(&options_,&SAc_,relax,panel_size,etree_,NULL,0,perm_c_,perm_r_,&SL_,&SU_,&stat_,&info);
282 if(info<0) IFPACK_CHK_ERR(info);
286 ComputeTime_ += Time_.ElapsedTime();
292 int Ifpack_SILU::Solve(
bool Trans,
const Epetra_MultiVector& X,
293 Epetra_MultiVector& Y)
const 296 #ifdef IFPACK_TEUCHOS_TIME_MONITOR 297 TEUCHOS_FUNC_TIME_MONITOR(
"Ifpack_SILU::ApplyInverse - Solve");
302 int nrhs=X.NumVectors();
303 int N=A_->NumMyRows();
310 if(SY_.Store) Destroy_SuperMatrix_Store(&SY_);
312 dCreate_Dense_Matrix(&SY_,N,nrhs,Y[0],N,SLU_DN,SLU_D,SLU_GE);
315 dgstrs(TRANS,&SL_,&SU_,perm_c_,perm_r_,&SY_,&stat_,&info);
316 if(!info) IFPACK_CHK_ERR(info);
323 int Ifpack_SILU::Multiply(
bool Trans,
const Epetra_MultiVector& X,
324 Epetra_MultiVector& Y)
const 336 Epetra_MultiVector& Y)
const 339 #ifdef IFPACK_TEUCHOS_TIME_MONITOR 340 TEUCHOS_FUNC_TIME_MONITOR(
"Ifpack_SILU::ApplyInverse");
346 if (X.NumVectors() != Y.NumVectors())
349 Time_.ResetStartTime();
353 Teuchos::RefCountPtr< const Epetra_MultiVector > Xcopy;
354 if (X.Pointers()[0] == Y.Pointers()[0])
355 Xcopy = Teuchos::rcp(
new Epetra_MultiVector(X) );
357 Xcopy = Teuchos::rcp( &X,
false );
362 ApplyInverseTime_ += Time_.ElapsedTime();
370 const int MaxIters,
const double Tol,
371 Epetra_RowMatrix* Matrix_in)
374 #ifdef IFPACK_TEUCHOS_TIME_MONITOR 375 TEUCHOS_FUNC_TIME_MONITOR(
"Ifpack_SILU::Condest");
381 Condest_ = Ifpack_Condest(*
this, CT, MaxIters, Tol, Matrix_in);
390 if (!
Comm().MyPID()) {
392 os <<
"================================================================================" << endl;
393 os <<
"Ifpack_SILU: " <<
Label() << endl << endl;
394 os <<
"Dropping rule = "<< DropRule() << endl;
395 os <<
"Zero pivot thresh = "<< FillTol() << endl;
396 os <<
"Max fill factor = "<< FillFactor() << endl;
397 os <<
"Drop tolerance = "<< DropTol() << endl;
398 os <<
"Condition number estimate = " <<
Condest() << endl;
399 os <<
"Global number of rows = " << A_->NumGlobalRows() << endl;
403 if(SL_.Store) fnnz+=((SCformat*)SL_.Store)->nnz;
404 if(SU_.Store) fnnz+=((NCformat*)SU_.Store)->nnz;
405 int lufill=fnnz - A_->NumMyRows();
406 os <<
"No. of nonzeros in L+U = "<< lufill<<endl;
407 os <<
"Fill ratio: nnz(F)/nnz(A) = "<<(double)lufill / (
double)A_->NumMyNonzeros()<<endl;
410 os <<
"Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
411 os <<
"----- ------- -------------- ------------ --------" << endl;
414 <<
" 0.0 0.0" << endl;
415 os <<
"Compute() " << std::setw(5) <<
NumCompute()
421 os <<
" " << std::setw(15) << 0.0 << endl;
428 os <<
" " << std::setw(15) << 0.0 << endl;
429 os <<
"================================================================================" << endl;
virtual double ApplyInverseTime() const
Returns the time spent in ApplyInverse().
const char * Label() const
Returns a character string describing the operator.
Ifpack_SILU(Epetra_RowMatrix *A)
Constructor.
virtual int NumInitialize() const
Returns the number of calls to Initialize().
bool UseTranspose() const
Returns the current UseTranspose setting.
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
virtual ostream & Print(ostream &os) const
Prints on stream basic information about this object.
virtual double InitializeTime() const
Returns the time spent in Initialize().
bool IsInitialized() const
Returns true if the preconditioner has been successfully initialized.
int Compute()
Compute ILU factors L and U using the specified graph, diagonal perturbation thresholds and relaxatio...
int Initialize()
Initialize the preconditioner, does not touch matrix values.
int SetParameters(Teuchos::ParameterList ¶meterlist)
Set parameters using a Teuchos::ParameterList object.
bool IsComputed() const
If factor is completed, this query returns true, otherwise it returns false.
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.
virtual int NumCompute() const
Returns the number of calls to Compute().
const Epetra_Comm & Comm() const
Returns the Epetra_BlockMap object associated with the range of this matrix operator.
virtual int NumApplyInverse() const
Returns the number of calls to ApplyInverse().
virtual double ComputeFlops() const
Returns the number of flops in the computation phase.
double Condest() const
Returns the computed estimated condition number, or -1.0 if not computed.