IFPACK  Development
Ifpack_ILU.cpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) 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 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #include "Ifpack_ConfigDefs.h"
44 #include "Ifpack_CondestType.h"
45 #include "Ifpack_ILU.h"
46 #include "Epetra_ConfigDefs.h"
47 #include "Epetra_Comm.h"
48 #include "Epetra_Map.h"
49 #include "Epetra_RowMatrix.h"
50 #include "Epetra_Vector.h"
51 #include "Epetra_MultiVector.h"
52 #include "Epetra_CrsGraph.h"
53 #include "Epetra_CrsMatrix.h"
54 #include "Teuchos_ParameterList.hpp"
55 #include "Teuchos_RefCountPtr.hpp"
56 
57 using Teuchos::RefCountPtr;
58 using Teuchos::rcp;
59 
60 #ifdef IFPACK_TEUCHOS_TIME_MONITOR
61 # include "Teuchos_TimeMonitor.hpp"
62 #endif
63 
64 //==============================================================================
65 Ifpack_ILU::Ifpack_ILU(Epetra_RowMatrix* Matrix_in) :
66  A_(rcp(Matrix_in,false)),
67  Comm_(Matrix_in->Comm()),
68  UseTranspose_(false),
69  NumMyDiagonals_(0),
70  RelaxValue_(0.0),
71  Athresh_(0.0),
72  Rthresh_(1.0),
73  Condest_(-1.0),
74  LevelOfFill_(0),
75  IsInitialized_(false),
76  IsComputed_(false),
77  NumInitialize_(0),
78  NumCompute_(0),
79  NumApplyInverse_(0),
80  InitializeTime_(0.0),
81  ComputeTime_(0.0),
82  ApplyInverseTime_(0.0),
83  ComputeFlops_(0.0),
84  ApplyInverseFlops_(0.0),
85  Time_(Comm())
86 {
87  Teuchos::ParameterList List;
88  SetParameters(List);
89 }
90 
91 //==============================================================================
92 void Ifpack_ILU::Destroy()
93 {
94  // reset pointers to already allocated stuff
95  U_DomainMap_ = 0;
96  L_RangeMap_ = 0;
97 }
98 
99 //==========================================================================
100 int Ifpack_ILU::SetParameters(Teuchos::ParameterList& List)
101 {
102  RelaxValue_ = List.get("fact: relax value", RelaxValue_);
103  Athresh_ = List.get("fact: absolute threshold", Athresh_);
104  Rthresh_ = List.get("fact: relative threshold", Rthresh_);
105  LevelOfFill_ = List.get("fact: level-of-fill", LevelOfFill_);
106 
107  // set label
108  sprintf(Label_, "IFPACK ILU (fill=%d, relax=%f, athr=%f, rthr=%f)",
109  LevelOfFill(), RelaxValue(), AbsoluteThreshold(),
110  RelativeThreshold());
111  return(0);
112 }
113 
114 //==========================================================================
115 int Ifpack_ILU::ComputeSetup()
116 {
117 
118 #ifdef IFPACK_TEUCHOS_TIME_MONITOR
119  TEUCHOS_FUNC_TIME_MONITOR("Ifpack_ILU::ComputeSetup");
120 #endif
121 
122  L_ = rcp(new Epetra_CrsMatrix(Copy, Graph().L_Graph()));
123  U_ = rcp(new Epetra_CrsMatrix(Copy, Graph().U_Graph()));
124  D_ = rcp(new Epetra_Vector(Graph().L_Graph().RowMap()));
125  if ((L_.get() == 0) || (U_.get() == 0) || (D_.get() == 0))
126  IFPACK_CHK_ERR(-5);
127 
128  // Get Maximun Row length
129  int MaxNumEntries = Matrix().MaxNumEntries();
130 
131  // Set L range map and U domain map
132  U_DomainMap_ = &(Matrix().OperatorDomainMap());
133  L_RangeMap_ = &(Matrix().OperatorRangeMap());
134 
135  // this is the old InitAllValues()
136  int ierr = 0;
137  int i, j;
138  int NumIn, NumL, NumU;
139  bool DiagFound;
140  int NumNonzeroDiags = 0;
141 
142  vector<int> InI(MaxNumEntries); // Allocate temp space
143  vector<int> LI(MaxNumEntries);
144  vector<int> UI(MaxNumEntries);
145  vector<double> InV(MaxNumEntries);
146  vector<double> LV(MaxNumEntries);
147  vector<double> UV(MaxNumEntries);
148 
149  bool ReplaceValues = (L_->StaticGraph() || L_->IndicesAreLocal()); // Check if values should be inserted or replaced
150 
151  if (ReplaceValues) {
152  L_->PutScalar(0.0); // Zero out L and U matrices
153  U_->PutScalar(0.0);
154  }
155 
156  D_->PutScalar(0.0); // Set diagonal values to zero
157  double *DV;
158  IFPACK_CHK_ERR(D_->ExtractView(&DV)); // Get view of diagonal
159 
160  // First we copy the user's matrix into L and U, regardless of fill level
161 
162  for (i=0; i< NumMyRows(); i++) {
163 
164  IFPACK_CHK_ERR(Matrix().ExtractMyRowCopy(i, MaxNumEntries, NumIn, &InV[0], &InI[0])); // Get Values and Indices
165 
166  // Split into L and U (we don't assume that indices are ordered).
167 
168  NumL = 0;
169  NumU = 0;
170  DiagFound = false;
171 
172  for (j=0; j< NumIn; j++) {
173  int k = InI[j];
174 
175  if (k==i) {
176  DiagFound = true;
177  DV[i] += Rthresh_ * InV[j] + EPETRA_SGN(InV[j]) * Athresh_; // Store perturbed diagonal in Epetra_Vector D_
178  }
179 
180  else if (k < 0) {IFPACK_CHK_ERR(-4);} // Out of range
181 
182  else if (k < i) {
183  LI[NumL] = k;
184  LV[NumL] = InV[j];
185  NumL++;
186  }
187  else if (k<NumMyRows()) {
188  UI[NumU] = k;
189  UV[NumU] = InV[j];
190  NumU++;
191  }
192  }
193 
194  // Check in things for this row of L and U
195 
196  if (DiagFound) NumNonzeroDiags++;
197  else DV[i] = Athresh_;
198 
199  if (NumL) {
200  if (ReplaceValues) {
201  (L_->ReplaceMyValues(i, NumL, &LV[0], &LI[0]));
202  }
203  else {
204  IFPACK_CHK_ERR(L_->InsertMyValues(i, NumL, &LV[0], &LI[0]));
205  }
206  }
207 
208  if (NumU) {
209  if (ReplaceValues) {
210  (U_->ReplaceMyValues(i, NumU, &UV[0], &UI[0]));
211  }
212  else {
213  IFPACK_CHK_ERR(U_->InsertMyValues(i, NumU, &UV[0], &UI[0]));
214  }
215  }
216 
217  }
218 
219  if (!ReplaceValues) {
220  // The domain of L and the range of U are exactly their own row maps (there is no communication).
221  // The domain of U and the range of L must be the same as those of the original matrix,
222  // However if the original matrix is a VbrMatrix, these two latter maps are translation from
223  // a block map to a point map.
224  IFPACK_CHK_ERR(L_->FillComplete((L_->RowMatrixColMap()), *L_RangeMap_));
225  IFPACK_CHK_ERR(U_->FillComplete(*U_DomainMap_, U_->RowMatrixRowMap()));
226  }
227 
228  // At this point L and U have the values of A in the structure of L and U, and diagonal vector D
229  int TotalNonzeroDiags = 0;
230  IFPACK_CHK_ERR(Graph().L_Graph().RowMap().Comm().SumAll(&NumNonzeroDiags, &TotalNonzeroDiags, 1));
231  NumMyDiagonals_ = NumNonzeroDiags;
232  if (NumNonzeroDiags != NumMyRows()) ierr = 1; // Diagonals are not right, warn user
233 
234  IFPACK_CHK_ERR(ierr);
235  return(ierr);
236 }
237 
238 //==========================================================================
240 {
241 
242 #ifdef IFPACK_TEUCHOS_TIME_MONITOR
243  TEUCHOS_FUNC_TIME_MONITOR("Ifpack_ILU::Initialize");
244 #endif
245 
246  Time_.ResetStartTime();
247  IsInitialized_ = false;
248 
249  // reset this object
250  Destroy();
251 
252  Epetra_CrsMatrix* CrsMatrix;
253  CrsMatrix = dynamic_cast<Epetra_CrsMatrix*>(&*A_);
254  if (CrsMatrix == 0) {
255  // this means that we have to create
256  // the graph from a given Epetra_RowMatrix. Note
257  // that at this point we are ignoring any possible
258  // graph coming from VBR matrices.
259  int size = A_->MaxNumEntries();
260  CrsGraph_ = rcp(new Epetra_CrsGraph(Copy,A_->RowMatrixRowMap(), size));
261  if (CrsGraph_.get() == 0)
262  IFPACK_CHK_ERR(-5); // memory allocation error
263 
264  vector<int> Indices(size);
265  vector<double> Values(size);
266 
267  // extract each row at-a-time, and insert it into
268  // the graph, ignore all off-process entries
269  for (int i = 0 ; i < A_->NumMyRows() ; ++i) {
270  int NumEntries;
271  int GlobalRow = A_->RowMatrixRowMap().GID(i);
272  IFPACK_CHK_ERR(A_->ExtractMyRowCopy(i, size, NumEntries,
273  &Values[0], &Indices[0]));
274  // convert to global indices
275  for (int j = 0 ; j < NumEntries ; ++j) {
276  Indices[j] = A_->RowMatrixColMap().GID(Indices[j]);
277  }
278  IFPACK_CHK_ERR(CrsGraph_->InsertGlobalIndices(GlobalRow,NumEntries,
279  &Indices[0]));
280  }
281 
282  IFPACK_CHK_ERR(CrsGraph_->FillComplete(A_->RowMatrixRowMap(),
283  A_->RowMatrixRowMap()));
284 
285  // always overlap zero, wider overlap will be handled
286  // by the AdditiveSchwarz preconditioner.
287  Graph_ = rcp(new Ifpack_IlukGraph(*CrsGraph_, LevelOfFill_, 0));
288 
289  }
290  else {
291  // see comment above for the overlap.
292  Graph_ = rcp(new Ifpack_IlukGraph(CrsMatrix->Graph(), LevelOfFill_, 0));
293  }
294 
295  if (Graph_.get() == 0)
296  IFPACK_CHK_ERR(-5); // memory allocation error
297  IFPACK_CHK_ERR(Graph_->ConstructFilledGraph());
298 
299  IsInitialized_ = true;
300  NumInitialize_++;
301  InitializeTime_ += Time_.ElapsedTime();
302 
303  return(0);
304 }
305 
306 //==========================================================================
308 {
309 
310 #ifdef IFPACK_TEUCHOS_TIME_MONITOR
311  TEUCHOS_FUNC_TIME_MONITOR("Ifpack_ILU::Compute");
312 #endif
313 
314  if (!IsInitialized())
315  IFPACK_CHK_ERR(Initialize());
316 
317  Time_.ResetStartTime();
318  IsComputed_ = false;
319 
320  // convert Matrix() into L and U factors.
321  IFPACK_CHK_ERR(ComputeSetup());
322 
323  // MinMachNum should be officially defined, for now pick something a little
324  // bigger than IEEE underflow value
325 
326  double MinDiagonalValue = Epetra_MinDouble;
327  double MaxDiagonalValue = 1.0/MinDiagonalValue;
328 
329  int ierr = 0;
330  int i, j, k;
331  int *LI, *UI;
332  double *LV, *UV;
333  int NumIn, NumL, NumU;
334 
335  // Get Maximun Row length
336  int MaxNumEntries = L_->MaxNumEntries() + U_->MaxNumEntries() + 1;
337 
338  vector<int> InI(MaxNumEntries+1); // Allocate temp space, pad by one to
339  vector<double> InV(MaxNumEntries+1); // to avoid debugger complaints for pathological cases
340  vector<int> colflag(NumMyCols());
341 
342  double *DV;
343  ierr = D_->ExtractView(&DV); // Get view of diagonal
344 
345 #ifdef IFPACK_FLOPCOUNTERS
346  int current_madds = 0; // We will count multiply-add as they happen
347 #endif
348 
349  // =========================== //
350  // Now start the factorization //
351  // =========================== //
352 
353  // Need some integer workspace and pointers
354  int NumUU;
355  int * UUI;
356  double * UUV;
357  for (j = 0; j < NumMyCols(); ++j) colflag[j] = - 1;
358 
359  for (i = 0; i < NumMyRows(); ++i) {
360 
361  // Fill InV, InI with current row of L, D and U combined
362 
363  NumIn = MaxNumEntries;
364  IFPACK_CHK_ERR(L_->ExtractMyRowCopy(i, NumIn, NumL, &InV[0], &InI[0]));
365  LV = &InV[0];
366  LI = &InI[0];
367 
368  InV[NumL] = DV[i]; // Put in diagonal
369  InI[NumL] = i;
370 
371  IFPACK_CHK_ERR(U_->ExtractMyRowCopy(i, NumIn-NumL-1, NumU, &InV[NumL+1], &InI[NumL+1]));
372  NumIn = NumL+NumU+1;
373  UV = &InV[NumL+1];
374  UI = &InI[NumL+1];
375 
376  // Set column flags
377  for (j=0; j<NumIn; j++) colflag[InI[j]] = j;
378 
379  double diagmod = 0.0; // Off-diagonal accumulator
380 
381  for (int jj=0; jj<NumL; jj++) {
382  j = InI[jj];
383  double multiplier = InV[jj]; // current_mults++;
384 
385  InV[jj] *= DV[j];
386 
387  IFPACK_CHK_ERR(U_->ExtractMyRowView(j, NumUU, UUV, UUI)); // View of row above
388 
389  if (RelaxValue_==0.0) {
390  for (k=0; k<NumUU; k++) {
391  int kk = colflag[UUI[k]];
392  if (kk>-1) {
393  InV[kk] -= multiplier*UUV[k];
394 #ifdef IFPACK_FLOPCOUNTERS
395  current_madds++;
396 #endif
397  }
398  }
399  }
400  else {
401  for (k=0; k<NumUU; k++) {
402  int kk = colflag[UUI[k]];
403  if (kk>-1) InV[kk] -= multiplier*UUV[k];
404  else diagmod -= multiplier*UUV[k];
405 #ifdef IFPACK_FLOPCOUNTERS
406  current_madds++;
407 #endif
408  }
409  }
410  }
411  if (NumL) {
412  IFPACK_CHK_ERR(L_->ReplaceMyValues(i, NumL, LV, LI)); // Replace current row of L
413  }
414 
415  DV[i] = InV[NumL]; // Extract Diagonal value
416 
417  if (RelaxValue_!=0.0) {
418  DV[i] += RelaxValue_*diagmod; // Add off diagonal modifications
419  // current_madds++;
420  }
421 
422  if (fabs(DV[i]) > MaxDiagonalValue) {
423  if (DV[i] < 0) DV[i] = - MinDiagonalValue;
424  else DV[i] = MinDiagonalValue;
425  }
426  else
427  DV[i] = 1.0/DV[i]; // Invert diagonal value
428 
429  for (j=0; j<NumU; j++) UV[j] *= DV[i]; // Scale U by inverse of diagonal
430 
431  if (NumU) {
432  IFPACK_CHK_ERR(U_->ReplaceMyValues(i, NumU, UV, UI)); // Replace current row of L and U
433  }
434 
435  // Reset column flags
436  for (j=0; j<NumIn; j++) colflag[InI[j]] = -1;
437  }
438 
439  // Validate that the L and U factors are actually lower and upper triangular
440 
441  if (!L_->LowerTriangular())
442  IFPACK_CHK_ERR(-4);
443  if (!U_->UpperTriangular())
444  IFPACK_CHK_ERR(-4);
445 
446 #ifdef IFPACK_FLOPCOUNTERS
447  // Add up flops
448 
449  double current_flops = 2 * current_madds;
450  double total_flops = 0;
451 
452  IFPACK_CHK_ERR(Graph().L_Graph().RowMap().Comm().SumAll(&current_flops, &total_flops, 1)); // Get total madds across all PEs
453 
454  // Now count the rest
455  total_flops += (double) L_->NumGlobalNonzeros(); // Accounts for multiplier above
456  total_flops += (double) D_->GlobalLength(); // Accounts for reciprocal of diagonal
457  if (RelaxValue_!=0.0) total_flops += 2 * (double)D_->GlobalLength(); // Accounts for relax update of diag
458 
459  // add to this object's counter
460  ComputeFlops_ += total_flops;
461 #endif
462 
463  IsComputed_ = true;
464  NumCompute_++;
465  ComputeTime_ += Time_.ElapsedTime();
466 
467  return(ierr);
468 
469 }
470 
471 //=============================================================================
472 // This function finds Y such that LDU Y = X or U(trans) D L(trans) Y = X for multiple RHS
473 int Ifpack_ILU::Solve(bool Trans, const Epetra_MultiVector& X,
474  Epetra_MultiVector& Y) const
475 {
476 
477 #ifdef IFPACK_TEUCHOS_TIME_MONITOR
478  TEUCHOS_FUNC_TIME_MONITOR("Ifpack_ILU::ApplyInverse - Solve");
479 #endif
480 
481  // in this function the overlap is always zero
482  bool Upper = true;
483  bool Lower = false;
484  bool UnitDiagonal = true;
485 
486  if (!Trans) {
487 
488  IFPACK_CHK_ERR(L_->Solve(Lower, Trans, UnitDiagonal, X, Y));
489  // y = D*y (D_ has inverse of diagonal)
490  IFPACK_CHK_ERR(Y.Multiply(1.0, *D_, Y, 0.0));
491  // Solve Uy = y
492  IFPACK_CHK_ERR(U_->Solve(Upper, Trans, UnitDiagonal, Y, Y));
493  }
494  else {
495  // Solve Uy = y
496  IFPACK_CHK_ERR(U_->Solve(Upper, Trans, UnitDiagonal, X, Y));
497  // y = D*y (D_ has inverse of diagonal)
498  IFPACK_CHK_ERR(Y.Multiply(1.0, *D_, Y, 0.0));
499  IFPACK_CHK_ERR(L_->Solve(Lower, Trans, UnitDiagonal, Y, Y));
500  }
501 
502 
503  return(0);
504 }
505 
506 //=============================================================================
507 // This function finds X such that LDU Y = X or U(trans) D L(trans) Y = X for multiple RHS
508 int Ifpack_ILU::Multiply(bool Trans, const Epetra_MultiVector& X,
509  Epetra_MultiVector& Y) const
510 {
511 
512 #ifdef IFPACK_TEUCHOS_TIME_MONITOR
513  TEUCHOS_FUNC_TIME_MONITOR("Ifpack_ILU::Multiply");
514 #endif
515 
516  if (!IsComputed())
517  IFPACK_CHK_ERR(-3);
518 
519  if (!Trans) {
520  IFPACK_CHK_ERR(U_->Multiply(Trans, X, Y));
521  // Y1 = Y1 + X1 (account for implicit unit diagonal)
522  IFPACK_CHK_ERR(Y.Update(1.0, X, 1.0));
523  // y = D*y (D_ has inverse of diagonal)
524  IFPACK_CHK_ERR(Y.ReciprocalMultiply(1.0, *D_, Y, 0.0));
525  Epetra_MultiVector Y1temp(Y); // Need a temp copy of Y1
526  IFPACK_CHK_ERR(L_->Multiply(Trans, Y1temp, Y));
527  // (account for implicit unit diagonal)
528  IFPACK_CHK_ERR(Y.Update(1.0, Y1temp, 1.0));
529  }
530  else {
531 
532  IFPACK_CHK_ERR(L_->Multiply(Trans, X, Y));
533  // Y1 = Y1 + X1 (account for implicit unit diagonal)
534  IFPACK_CHK_ERR(Y.Update(1.0, X, 1.0));
535  // y = D*y (D_ has inverse of diagonal)
536  IFPACK_CHK_ERR(Y.ReciprocalMultiply(1.0, *D_, Y, 0.0));
537  Epetra_MultiVector Y1temp(Y); // Need a temp copy of Y1
538  IFPACK_CHK_ERR(U_->Multiply(Trans, Y1temp, Y));
539  // (account for implicit unit diagonal)
540  IFPACK_CHK_ERR(Y.Update(1.0, Y1temp, 1.0));
541  }
542 
543  return(0);
544 }
545 
546 //=============================================================================
547 // This function finds X such that LDU Y = X or U(trans) D L(trans) Y = X for multiple RHS
548 int Ifpack_ILU::ApplyInverse(const Epetra_MultiVector& X,
549  Epetra_MultiVector& Y) const
550 {
551 
552 #ifdef IFPACK_TEUCHOS_TIME_MONITOR
553  TEUCHOS_FUNC_TIME_MONITOR("Ifpack_ILU::ApplyInverse");
554 #endif
555 
556  if (!IsComputed())
557  IFPACK_CHK_ERR(-3);
558 
559  if (X.NumVectors() != Y.NumVectors())
560  IFPACK_CHK_ERR(-2);
561 
562  Time_.ResetStartTime();
563 
564  // AztecOO gives X and Y pointing to the same memory location,
565  // need to create an auxiliary vector, Xcopy
566  Teuchos::RefCountPtr< const Epetra_MultiVector > Xcopy;
567  if (X.Pointers()[0] == Y.Pointers()[0])
568  Xcopy = Teuchos::rcp( new Epetra_MultiVector(X) );
569  else
570  Xcopy = Teuchos::rcp( &X, false );
571 
572  IFPACK_CHK_ERR(Solve(Ifpack_ILU::UseTranspose(), *Xcopy, Y));
573 
574  // approx is the number of nonzeros in L and U
575 #ifdef IFPACK_FLOPCOUNTERS
576  ApplyInverseFlops_ += X.NumVectors() * 4 *
577  (L_->NumGlobalNonzeros() + U_->NumGlobalNonzeros());
578 #endif
579 
580  ++NumApplyInverse_;
581  ApplyInverseTime_ += Time_.ElapsedTime();
582 
583  return(0);
584 
585 }
586 
587 //=============================================================================
588 double Ifpack_ILU::Condest(const Ifpack_CondestType CT,
589  const int MaxIters, const double Tol,
590  Epetra_RowMatrix* Matrix_in)
591 {
592 
593 #ifdef IFPACK_TEUCHOS_TIME_MONITOR
594  TEUCHOS_FUNC_TIME_MONITOR("Ifpack_ILU::Condest");
595 #endif
596 
597  if (!IsComputed()) // cannot compute right now
598  return(-1.0);
599 
600  Condest_ = Ifpack_Condest(*this, CT, MaxIters, Tol, Matrix_in);
601 
602  return(Condest_);
603 }
604 
605 //=============================================================================
606 std::ostream&
607 Ifpack_ILU::Print(std::ostream& os) const
608 {
609  if (!Comm().MyPID()) {
610  os << endl;
611  os << "================================================================================" << endl;
612  os << "Ifpack_ILU: " << Label() << endl << endl;
613  os << "Level-of-fill = " << LevelOfFill() << endl;
614  os << "Absolute threshold = " << AbsoluteThreshold() << endl;
615  os << "Relative threshold = " << RelativeThreshold() << endl;
616  os << "Relax value = " << RelaxValue() << endl;
617  os << "Condition number estimate = " << Condest() << endl;
618  os << "Global number of rows = " << A_->NumGlobalRows() << endl;
619  if (IsComputed_) {
620  os << "Number of rows of L, D, U = " << L_->NumGlobalRows() << endl;
621  os << "Number of nonzeros of L + U = " << NumGlobalNonzeros() << endl;
622  os << "nonzeros / rows = "
623  << 1.0 * NumGlobalNonzeros() / U_->NumGlobalRows() << endl;
624  }
625  os << endl;
626  os << "Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
627  os << "----- ------- -------------- ------------ --------" << endl;
628  os << "Initialize() " << std::setw(5) << NumInitialize()
629  << " " << std::setw(15) << InitializeTime()
630  << " 0.0 0.0" << endl;
631  os << "Compute() " << std::setw(5) << NumCompute()
632  << " " << std::setw(15) << ComputeTime()
633  << " " << std::setw(15) << 1.0e-6 * ComputeFlops();
634  if (ComputeTime() != 0.0)
635  os << " " << std::setw(15) << 1.0e-6 * ComputeFlops() / ComputeTime() << endl;
636  else
637  os << " " << std::setw(15) << 0.0 << endl;
638  os << "ApplyInverse() " << std::setw(5) << NumApplyInverse()
639  << " " << std::setw(15) << ApplyInverseTime()
640  << " " << std::setw(15) << 1.0e-6 * ApplyInverseFlops();
641  if (ApplyInverseTime() != 0.0)
642  os << " " << std::setw(15) << 1.0e-6 * ApplyInverseFlops() / ApplyInverseTime() << endl;
643  else
644  os << " " << std::setw(15) << 0.0 << endl;
645  os << "================================================================================" << endl;
646  os << endl;
647  }
648 
649  return(os);
650 }
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...
Definition: Ifpack_ILU.cpp:548
virtual int NumCompute() const
Returns the number of calls to Compute().
Definition: Ifpack_ILU.h:242
virtual ostream & Print(ostream &os) const
Prints on stream basic information about this object.
Definition: Ifpack_ILU.cpp:607
virtual double ComputeFlops() const
Returns the number of flops in the computation phase.
Definition: Ifpack_ILU.h:277
bool UseTranspose() const
Returns the current UseTranspose setting.
Definition: Ifpack_ILU.h:215
Ifpack_IlukGraph: A class for constructing level filled graphs for use with ILU(k) class precondition...
const Epetra_RowMatrix & Matrix() const
Returns a reference to the matrix to be preconditioned.
Definition: Ifpack_ILU.h:227
const Epetra_Comm & Comm() const
Returns the Epetra_BlockMap object associated with the range of this matrix operator.
Definition: Ifpack_ILU.h:224
virtual double ComputeTime() const
Returns the time spent in Compute().
Definition: Ifpack_ILU.h:260
bool IsComputed() const
If factor is completed, this query returns true, otherwise it returns false.
Definition: Ifpack_ILU.h:119
int Compute()
Compute ILU factors L and U using the specified graph, diagonal perturbation thresholds and relaxatio...
Definition: Ifpack_ILU.cpp:307
virtual double ApplyInverseTime() const
Returns the time spent in ApplyInverse().
Definition: Ifpack_ILU.h:266
int SetParameters(Teuchos::ParameterList &parameterlist)
Set parameters using a Teuchos::ParameterList object.
Definition: Ifpack_ILU.cpp:100
int Initialize()
Initialize the preconditioner, does not touch matrix values.
Definition: Ifpack_ILU.cpp:239
virtual double InitializeTime() const
Returns the time spent in Initialize().
Definition: Ifpack_ILU.h:254
virtual double ApplyInverseFlops() const
Returns the number of flops in the application of the preconditioner.
Definition: Ifpack_ILU.h:282
bool IsInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack_ILU.h:102
double Condest() const
Returns the computed estimated condition number, or -1.0 if not computed.
Definition: Ifpack_ILU.h:181
Ifpack_ILU(Epetra_RowMatrix *A)
Constructor.
Definition: Ifpack_ILU.cpp:65
const char * Label() const
Returns a character string describing the operator.
Definition: Ifpack_ILU.h:199
virtual int NumApplyInverse() const
Returns the number of calls to ApplyInverse().
Definition: Ifpack_ILU.h:248
virtual int NumInitialize() const
Returns the number of calls to Initialize().
Definition: Ifpack_ILU.h:236