43 #include "Ifpack_ConfigDefs.h" 46 #include "Epetra_Operator.h" 47 #include "Epetra_CrsMatrix.h" 48 #include "Epetra_Comm.h" 49 #include "Epetra_Map.h" 50 #include "Epetra_MultiVector.h" 51 #include "Ifpack_Preconditioner.h" 52 #include "Ifpack_PointRelaxation.h" 54 #include "Ifpack_Condest.h" 56 static const int IFPACK_JACOBI = 0;
57 static const int IFPACK_GS = 1;
58 static const int IFPACK_SGS = 2;
63 IsInitialized_(false),
70 ApplyInverseTime_(0.0),
72 ApplyInverseFlops_(0.0),
77 ComputeCondest_(false),
78 PrecType_(IFPACK_JACOBI),
79 MinDiagonalValue_(0.0),
83 NumGlobalNonzeros_(0),
84 Matrix_(
Teuchos::rcp(Matrix_in,false)),
86 ZeroStartingSolution_(true),
98 if (PrecType_ == IFPACK_JACOBI)
100 else if (PrecType_ == IFPACK_GS)
102 else if (PrecType_ == IFPACK_SGS)
103 PT =
"symmetric Gauss-Seidel";
105 PT = List.get(
"relaxation: type", PT);
108 PrecType_ = IFPACK_JACOBI;
109 else if (PT ==
"Gauss-Seidel")
110 PrecType_ = IFPACK_GS;
111 else if (PT ==
"symmetric Gauss-Seidel")
112 PrecType_ = IFPACK_SGS;
117 NumSweeps_ = List.get(
"relaxation: sweeps",NumSweeps_);
118 DampingFactor_ = List.get(
"relaxation: damping factor",
120 MinDiagonalValue_ = List.get(
"relaxation: min diagonal value",
122 ZeroStartingSolution_ = List.get(
"relaxation: zero starting solution",
123 ZeroStartingSolution_);
125 DoBackwardGS_ = List.get(
"relaxation: backward mode",DoBackwardGS_);
127 DoL1Method_ = List.get(
"relaxation: use l1",DoL1Method_);
129 L1Eta_ = List.get(
"relaxation: l1 eta",L1Eta_);
139 return(Matrix_->Comm());
145 return(Matrix_->OperatorDomainMap());
151 return(Matrix_->OperatorRangeMap());
157 IsInitialized_ =
false;
159 if (Matrix_ == Teuchos::null)
162 if (Time_ == Teuchos::null)
163 Time_ = Teuchos::rcp(
new Epetra_Time(
Comm()) );
165 if (
Matrix().NumGlobalRows() !=
Matrix().NumGlobalCols())
168 NumMyRows_ = Matrix_->NumMyRows();
169 NumMyNonzeros_ = Matrix_->NumMyNonzeros();
170 NumGlobalRows_ = Matrix_->NumGlobalRows();
171 NumGlobalNonzeros_ = Matrix_->NumGlobalNonzeros();
173 if (
Comm().NumProc() != 1)
179 InitializeTime_ += Time_->ElapsedTime();
180 IsInitialized_ =
true;
191 Time_->ResetStartTime();
197 if (NumSweeps_ == 0) ierr = 1;
201 Diagonal_ = Teuchos::rcp(
new Epetra_Vector(
Matrix().RowMatrixRowMap()) );
203 if (Diagonal_ == Teuchos::null)
206 IFPACK_CHK_ERR(
Matrix().ExtractDiagonalCopy(*Diagonal_));
217 if(DoL1Method_ && IsParallel_) {
218 int maxLength =
Matrix().MaxNumEntries();
219 std::vector<int> Indices(maxLength);
220 std::vector<double> Values(maxLength);
223 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
224 IFPACK_CHK_ERR(Matrix_->ExtractMyRowCopy(i, maxLength,NumEntries,
225 &Values[0], &Indices[0]));
226 double diagonal_boost=0.0;
227 for (
int k = 0 ; k < NumEntries ; ++k)
228 if(Indices[k] > NumMyRows_)
229 diagonal_boost+=std::abs(Values[k]/2.0);
230 if ((*Diagonal_)[i] < L1Eta_*diagonal_boost)
231 (*Diagonal_)[i]+=diagonal_boost;
238 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
239 double& diag = (*Diagonal_)[i];
240 if (IFPACK_ABS(diag) < MinDiagonalValue_)
241 diag = MinDiagonalValue_;
245 #ifdef IFPACK_FLOPCOUNTERS 246 ComputeFlops_ += NumMyRows_;
252 if ((PrecType_ == IFPACK_JACOBI) || (PrecType_ == IFPACK_GS)) {
253 Diagonal_->Reciprocal(*Diagonal_);
255 ComputeFlops_ += NumMyRows_;
265 if (IsParallel_ && ((PrecType_ == IFPACK_GS) || (PrecType_ == IFPACK_SGS))) {
266 Importer_ = Teuchos::rcp(
new Epetra_Import(
Matrix().RowMatrixColMap(),
267 Matrix().RowMatrixRowMap()) );
268 if (Importer_ == Teuchos::null) IFPACK_CHK_ERR(-5);
272 ComputeTime_ += Time_->ElapsedTime();
275 IFPACK_CHK_ERR(ierr);
283 double MyMinVal, MyMaxVal;
284 double MinVal, MaxVal;
287 Diagonal_->MinValue(&MyMinVal);
288 Diagonal_->MaxValue(&MyMaxVal);
289 Comm().MinAll(&MyMinVal,&MinVal,1);
290 Comm().MinAll(&MyMaxVal,&MaxVal,1);
293 if (!
Comm().MyPID()) {
295 os <<
"================================================================================" << endl;
296 os <<
"Ifpack_PointRelaxation" << endl;
297 os <<
"Sweeps = " << NumSweeps_ << endl;
298 os <<
"damping factor = " << DampingFactor_ << endl;
299 if (PrecType_ == IFPACK_JACOBI)
300 os <<
"Type = Jacobi" << endl;
301 else if (PrecType_ == IFPACK_GS)
302 os <<
"Type = Gauss-Seidel" << endl;
303 else if (PrecType_ == IFPACK_SGS)
304 os <<
"Type = symmetric Gauss-Seidel" << endl;
306 os <<
"Using backward mode (GS only)" << endl;
307 if (ZeroStartingSolution_)
308 os <<
"Using zero starting solution" << endl;
310 os <<
"Using input starting solution" << endl;
311 os <<
"Condition number estimate = " <<
Condest() << endl;
312 os <<
"Global number of rows = " << Matrix_->NumGlobalRows() << endl;
314 os <<
"Minimum value on stored diagonal = " << MinVal << endl;
315 os <<
"Maximum value on stored diagonal = " << MaxVal << endl;
318 os <<
"Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
319 os <<
"----- ------- -------------- ------------ --------" << endl;
320 os <<
"Initialize() " << std::setw(5) << NumInitialize_
321 <<
" " << std::setw(15) << InitializeTime_
322 <<
" 0.0 0.0" << endl;
323 os <<
"Compute() " << std::setw(5) << NumCompute_
324 <<
" " << std::setw(15) << ComputeTime_
325 <<
" " << std::setw(15) << 1.0e-6 * ComputeFlops_;
326 if (ComputeTime_ != 0.0)
327 os <<
" " << std::setw(15) << 1.0e-6 * ComputeFlops_ / ComputeTime_ << endl;
329 os <<
" " << std::setw(15) << 0.0 << endl;
330 os <<
"ApplyInverse() " << std::setw(5) << NumApplyInverse_
331 <<
" " << std::setw(15) << ApplyInverseTime_
332 <<
" " << std::setw(15) << 1.0e-6 * ApplyInverseFlops_;
333 if (ApplyInverseTime_ != 0.0)
334 os <<
" " << std::setw(15) << 1.0e-6 * ApplyInverseFlops_ / ApplyInverseTime_ << endl;
336 os <<
" " << std::setw(15) << 0.0 << endl;
337 os <<
"================================================================================" << endl;
347 const int MaxIters,
const double Tol,
348 Epetra_RowMatrix* Matrix_in)
355 Condest_ = Ifpack_Condest(*
this, CT, MaxIters, Tol, Matrix_in);
361 void Ifpack_PointRelaxation::SetLabel()
364 if (PrecType_ == IFPACK_JACOBI)
366 else if (PrecType_ == IFPACK_GS){
369 PT =
"Backward " + PT;
371 else if (PrecType_ == IFPACK_SGS)
393 if (X.NumVectors() != Y.NumVectors())
396 Time_->ResetStartTime();
400 Teuchos::RefCountPtr< const Epetra_MultiVector > Xcopy;
401 if (X.Pointers()[0] == Y.Pointers()[0])
402 Xcopy = Teuchos::rcp(
new Epetra_MultiVector(X) );
404 Xcopy = Teuchos::rcp( &X,
false );
406 if (ZeroStartingSolution_)
412 IFPACK_CHK_ERR(ApplyInverseJacobi(*Xcopy,Y));
415 IFPACK_CHK_ERR(ApplyInverseGS(*Xcopy,Y));
418 IFPACK_CHK_ERR(ApplyInverseSGS(*Xcopy,Y));
425 ApplyInverseTime_ += Time_->ElapsedTime();
433 int Ifpack_PointRelaxation::
434 ApplyInverseJacobi(
const Epetra_MultiVector& RHS, Epetra_MultiVector& LHS)
const 437 int NumVectors = LHS.NumVectors();
438 Epetra_MultiVector A_times_LHS( LHS.Map(),NumVectors );
440 for (
int j = 0; j < NumSweeps_ ; j++) {
442 IFPACK_CHK_ERR(
Apply(LHS,A_times_LHS));
443 IFPACK_CHK_ERR(A_times_LHS.Update(1.0,RHS,-1.0));
444 for (
int v = 0 ; v < NumVectors ; ++v)
445 IFPACK_CHK_ERR(LHS(v)->Multiply(DampingFactor_, *(A_times_LHS(v)),
458 #ifdef IFPACK_FLOPCOUNTERS 459 ApplyInverseFlops_ += NumVectors * (6 * NumGlobalRows_ + 2 * NumGlobalNonzeros_);
466 int Ifpack_PointRelaxation::
467 ApplyInverseGS(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const 469 const Epetra_CrsMatrix* CrsMatrix =
dynamic_cast<const Epetra_CrsMatrix*
>(&*Matrix_);
474 if (CrsMatrix->StorageOptimized())
475 return(ApplyInverseGS_FastCrsMatrix(CrsMatrix, X, Y));
477 return(ApplyInverseGS_CrsMatrix(CrsMatrix, X, Y));
480 return(ApplyInverseGS_RowMatrix(X, Y));
484 int Ifpack_PointRelaxation::
485 ApplyInverseGS_RowMatrix(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const 487 int NumVectors = X.NumVectors();
489 int Length =
Matrix().MaxNumEntries();
490 vector<int> Indices(Length);
491 vector<double> Values(Length);
493 Teuchos::RefCountPtr< Epetra_MultiVector > Y2;
495 Y2 = Teuchos::rcp(
new Epetra_MultiVector(Importer_->TargetMap(), NumVectors) );
497 Y2 = Teuchos::rcp( &Y,
false );
500 double** y_ptr, ** y2_ptr, ** x_ptr, *d_ptr;
501 X.ExtractView(&x_ptr);
502 Y.ExtractView(&y_ptr);
503 Y2->ExtractView(&y2_ptr);
504 Diagonal_->ExtractView(&d_ptr);
506 for (
int j = 0; j < NumSweeps_ ; j++) {
510 IFPACK_CHK_ERR(Y2->Import(Y,*Importer_,Insert));
513 if (NumVectors == 1) {
515 double* y0_ptr = y_ptr[0];
516 double* y20_ptr = y2_ptr[0];
517 double* x0_ptr = x_ptr[0];
521 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
525 IFPACK_CHK_ERR(Matrix_->ExtractMyRowCopy(i, Length,NumEntries,
526 &Values[0], &Indices[0]));
529 for (
int k = 0 ; k < NumEntries ; ++k) {
532 dtemp += Values[k] * y20_ptr[col];
535 y20_ptr[i] += DampingFactor_ * d_ptr[i] * (x0_ptr[i] - dtemp);
540 for (
int i = NumMyRows_ - 1 ; i > -1 ; --i) {
545 IFPACK_CHK_ERR(Matrix_->ExtractMyRowCopy(i, Length,NumEntries,
546 &Values[0], &Indices[0]));
548 for (
int k = 0 ; k < NumEntries ; ++k) {
551 dtemp += Values[k] * y20_ptr[i];
554 y20_ptr[i] += DampingFactor_ * d_ptr[i] * (x0_ptr[i] - dtemp);
560 for (
int i = 0 ; i < NumMyRows_ ; ++i)
561 y0_ptr[i] = y20_ptr[i];
567 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
571 IFPACK_CHK_ERR(Matrix_->ExtractMyRowCopy(i, Length,NumEntries,
572 &Values[0], &Indices[0]));
574 for (
int m = 0 ; m < NumVectors ; ++m) {
577 for (
int k = 0 ; k < NumEntries ; ++k) {
580 dtemp += Values[k] * y2_ptr[m][col];
583 y2_ptr[m][i] += DampingFactor_ * d_ptr[i] * (x_ptr[m][i] - dtemp);
589 for (
int i = NumMyRows_ - 1 ; i > -1 ; --i) {
592 IFPACK_CHK_ERR(Matrix_->ExtractMyRowCopy(i, Length,NumEntries,
593 &Values[0], &Indices[0]));
595 for (
int m = 0 ; m < NumVectors ; ++m) {
598 for (
int k = 0 ; k < NumEntries ; ++k) {
601 dtemp += Values[k] * y2_ptr[m][col];
604 y2_ptr[m][i] += DampingFactor_ * d_ptr[i] * (x_ptr[m][i] - dtemp);
612 for (
int m = 0 ; m < NumVectors ; ++m)
613 for (
int i = 0 ; i < NumMyRows_ ; ++i)
614 y_ptr[m][i] = y2_ptr[m][i];
619 #ifdef IFPACK_FLOPCOUNTERS 620 ApplyInverseFlops_ += NumVectors * (4 * NumGlobalRows_ + 2 * NumGlobalNonzeros_);
627 int Ifpack_PointRelaxation::
628 ApplyInverseGS_CrsMatrix(
const Epetra_CrsMatrix* A,
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const 630 int NumVectors = X.NumVectors();
635 Teuchos::RefCountPtr< Epetra_MultiVector > Y2;
637 Y2 = Teuchos::rcp(
new Epetra_MultiVector(Importer_->TargetMap(), NumVectors) );
640 Y2 = Teuchos::rcp( &Y,
false );
642 double** y_ptr, ** y2_ptr, ** x_ptr, *d_ptr;
643 X.ExtractView(&x_ptr);
644 Y.ExtractView(&y_ptr);
645 Y2->ExtractView(&y2_ptr);
646 Diagonal_->ExtractView(&d_ptr);
648 for (
int iter = 0 ; iter < NumSweeps_ ; ++iter) {
652 IFPACK_CHK_ERR(Y2->Import(Y,*Importer_,Insert));
656 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
660 double diag = d_ptr[i];
662 IFPACK_CHK_ERR(A->ExtractMyRowView(i, NumEntries, Values, Indices));
664 for (
int m = 0 ; m < NumVectors ; ++m) {
668 for (
int k = 0; k < NumEntries; ++k) {
671 dtemp += Values[k] * y2_ptr[m][col];
674 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
680 for (
int i = NumMyRows_ - 1 ; i > -1 ; --i) {
684 double diag = d_ptr[i];
686 IFPACK_CHK_ERR(A->ExtractMyRowView(i, NumEntries, Values, Indices));
688 for (
int m = 0 ; m < NumVectors ; ++m) {
691 for (
int k = 0; k < NumEntries; ++k) {
694 dtemp += Values[k] * y2_ptr[m][col];
697 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
704 for (
int m = 0 ; m < NumVectors ; ++m)
705 for (
int i = 0 ; i < NumMyRows_ ; ++i)
706 y_ptr[m][i] = y2_ptr[m][i];
709 #ifdef IFPACK_FLOPCOUNTERS 710 ApplyInverseFlops_ += NumVectors * (8 * NumGlobalRows_ + 4 * NumGlobalNonzeros_);
719 int Ifpack_PointRelaxation::
720 ApplyInverseGS_FastCrsMatrix(
const Epetra_CrsMatrix* A,
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const 725 IFPACK_CHK_ERR(A->ExtractCrsDataPointers(IndexOffset, Indices, Values));
727 int NumVectors = X.NumVectors();
729 Teuchos::RefCountPtr< Epetra_MultiVector > Y2;
731 Y2 = Teuchos::rcp(
new Epetra_MultiVector(Importer_->TargetMap(), NumVectors) );
734 Y2 = Teuchos::rcp( &Y,
false );
736 double** y_ptr, ** y2_ptr, ** x_ptr, *d_ptr;
737 X.ExtractView(&x_ptr);
738 Y.ExtractView(&y_ptr);
739 Y2->ExtractView(&y2_ptr);
740 Diagonal_->ExtractView(&d_ptr);
742 for (
int iter = 0 ; iter < NumSweeps_ ; ++iter) {
746 IFPACK_CHK_ERR(Y2->Import(Y,*Importer_,Insert));
750 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
753 double diag = d_ptr[i];
755 for (
int m = 0 ; m < NumVectors ; ++m) {
759 for (
int k = IndexOffset[i] ; k < IndexOffset[i + 1] ; ++k) {
762 dtemp += Values[k] * y2_ptr[m][col];
765 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
771 for (
int i = NumMyRows_ - 1 ; i > -1 ; --i) {
774 double diag = d_ptr[i];
776 for (
int m = 0 ; m < NumVectors ; ++m) {
779 for (
int k = IndexOffset[i] ; k < IndexOffset[i + 1] ; ++k) {
782 dtemp += Values[k] * y2_ptr[m][col];
785 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
793 for (
int m = 0 ; m < NumVectors ; ++m)
794 for (
int i = 0 ; i < NumMyRows_ ; ++i)
795 y_ptr[m][i] = y2_ptr[m][i];
798 #ifdef IFPACK_FLOPCOUNTERS 799 ApplyInverseFlops_ += NumVectors * (8 * NumGlobalRows_ + 4 * NumGlobalNonzeros_);
805 int Ifpack_PointRelaxation::
806 ApplyInverseSGS(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const 808 const Epetra_CrsMatrix* CrsMatrix =
dynamic_cast<const Epetra_CrsMatrix*
>(&*Matrix_);
813 if (CrsMatrix->StorageOptimized())
814 return(ApplyInverseSGS_FastCrsMatrix(CrsMatrix, X, Y));
816 return(ApplyInverseSGS_CrsMatrix(CrsMatrix, X, Y));
819 return(ApplyInverseSGS_RowMatrix(X, Y));
823 int Ifpack_PointRelaxation::
824 ApplyInverseSGS_RowMatrix(
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const 826 int NumVectors = X.NumVectors();
827 int Length =
Matrix().MaxNumEntries();
828 vector<int> Indices(Length);
829 vector<double> Values(Length);
831 Teuchos::RefCountPtr< Epetra_MultiVector > Y2;
833 Y2 = Teuchos::rcp(
new Epetra_MultiVector(Importer_->TargetMap(), NumVectors) );
836 Y2 = Teuchos::rcp( &Y,
false );
838 double** y_ptr, ** y2_ptr, ** x_ptr, *d_ptr;
839 X.ExtractView(&x_ptr);
840 Y.ExtractView(&y_ptr);
841 Y2->ExtractView(&y2_ptr);
842 Diagonal_->ExtractView(&d_ptr);
844 for (
int iter = 0 ; iter < NumSweeps_ ; ++iter) {
848 IFPACK_CHK_ERR(Y2->Import(Y,*Importer_,Insert));
850 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
854 double diag = d_ptr[i];
856 IFPACK_CHK_ERR(Matrix_->ExtractMyRowCopy(i, Length,NumEntries,
857 &Values[0], &Indices[0]));
859 for (
int m = 0 ; m < NumVectors ; ++m) {
863 for (
int k = 0 ; k < NumEntries ; ++k) {
866 dtemp += Values[k] * y2_ptr[m][col];
869 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
873 for (
int i = NumMyRows_ - 1 ; i > -1 ; --i) {
877 double diag = d_ptr[i];
879 IFPACK_CHK_ERR(Matrix_->ExtractMyRowCopy(i, Length,NumEntries,
880 &Values[0], &Indices[0]));
882 for (
int m = 0 ; m < NumVectors ; ++m) {
885 for (
int k = 0 ; k < NumEntries ; ++k) {
888 dtemp += Values[k] * y2_ptr[m][col];
891 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
897 for (
int m = 0 ; m < NumVectors ; ++m)
898 for (
int i = 0 ; i < NumMyRows_ ; ++i)
899 y_ptr[m][i] = y2_ptr[m][i];
902 #ifdef IFPACK_FLOPCOUNTERS 903 ApplyInverseFlops_ += NumVectors * (8 * NumGlobalRows_ + 4 * NumGlobalNonzeros_);
909 int Ifpack_PointRelaxation::
910 ApplyInverseSGS_CrsMatrix(
const Epetra_CrsMatrix* A,
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const 912 int NumVectors = X.NumVectors();
917 Teuchos::RefCountPtr< Epetra_MultiVector > Y2;
919 Y2 = Teuchos::rcp(
new Epetra_MultiVector(Importer_->TargetMap(), NumVectors) );
922 Y2 = Teuchos::rcp( &Y,
false );
924 double** y_ptr, ** y2_ptr, ** x_ptr, *d_ptr;
925 X.ExtractView(&x_ptr);
926 Y.ExtractView(&y_ptr);
927 Y2->ExtractView(&y2_ptr);
928 Diagonal_->ExtractView(&d_ptr);
930 for (
int iter = 0 ; iter < NumSweeps_ ; ++iter) {
934 IFPACK_CHK_ERR(Y2->Import(Y,*Importer_,Insert));
936 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
940 double diag = d_ptr[i];
942 IFPACK_CHK_ERR(A->ExtractMyRowView(i, NumEntries, Values, Indices));
944 for (
int m = 0 ; m < NumVectors ; ++m) {
948 for (
int k = 0; k < NumEntries; ++k) {
951 dtemp += Values[k] * y2_ptr[m][col];
954 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
958 for (
int i = NumMyRows_ - 1 ; i > -1 ; --i) {
962 double diag = d_ptr[i];
964 IFPACK_CHK_ERR(A->ExtractMyRowView(i, NumEntries, Values, Indices));
966 for (
int m = 0 ; m < NumVectors ; ++m) {
969 for (
int k = 0; k < NumEntries; ++k) {
972 dtemp += Values[k] * y2_ptr[m][col];
975 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
981 for (
int m = 0 ; m < NumVectors ; ++m)
982 for (
int i = 0 ; i < NumMyRows_ ; ++i)
983 y_ptr[m][i] = y2_ptr[m][i];
986 #ifdef IFPACK_FLOPCOUNTERS 987 ApplyInverseFlops_ += NumVectors * (8 * NumGlobalRows_ + 4 * NumGlobalNonzeros_);
994 int Ifpack_PointRelaxation::
995 ApplyInverseSGS_FastCrsMatrix(
const Epetra_CrsMatrix* A,
const Epetra_MultiVector& X, Epetra_MultiVector& Y)
const 1000 IFPACK_CHK_ERR(A->ExtractCrsDataPointers(IndexOffset, Indices, Values));
1002 int NumVectors = X.NumVectors();
1004 Teuchos::RefCountPtr< Epetra_MultiVector > Y2;
1006 Y2 = Teuchos::rcp(
new Epetra_MultiVector(Importer_->TargetMap(), NumVectors) );
1009 Y2 = Teuchos::rcp( &Y,
false );
1011 double** y_ptr, ** y2_ptr, ** x_ptr, *d_ptr;
1012 X.ExtractView(&x_ptr);
1013 Y.ExtractView(&y_ptr);
1014 Y2->ExtractView(&y2_ptr);
1015 Diagonal_->ExtractView(&d_ptr);
1017 for (
int iter = 0 ; iter < NumSweeps_ ; ++iter) {
1021 IFPACK_CHK_ERR(Y2->Import(Y,*Importer_,Insert));
1023 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
1026 double diag = d_ptr[i];
1031 for (
int m = 0 ; m < NumVectors ; ++m) {
1035 for (
int k = IndexOffset[i] ; k < IndexOffset[i + 1] ; ++k) {
1038 dtemp += Values[k] * y2_ptr[m][col];
1041 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
1045 for (
int i = NumMyRows_ - 1 ; i > -1 ; --i) {
1048 double diag = d_ptr[i];
1053 for (
int m = 0 ; m < NumVectors ; ++m) {
1056 for (
int k = IndexOffset[i] ; k < IndexOffset[i + 1] ; ++k) {
1059 dtemp += Values[k] * y2_ptr[m][col];
1062 y2_ptr[m][i] += DampingFactor_ * (x_ptr[m][i] - dtemp) * diag;
1068 for (
int m = 0 ; m < NumVectors ; ++m)
1069 for (
int i = 0 ; i < NumMyRows_ ; ++i)
1070 y_ptr[m][i] = y2_ptr[m][i];
1073 #ifdef IFPACK_FLOPCOUNTERS 1074 ApplyInverseFlops_ += NumVectors * (8 * NumGlobalRows_ + 4 * NumGlobalNonzeros_);
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the matrix to an Epetra_MultiVector.
virtual const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
string Ifpack_toString(const int &x)
Convertes an integer to string.
Ifpack_PointRelaxation(const Epetra_RowMatrix *Matrix)
Ifpack_PointRelaxation constructor with given Epetra_RowMatrix.
virtual double Condest() const
Returns the condition number estimate, or -1.0 if not computed.
virtual int SetParameters(Teuchos::ParameterList &List)
Sets all the parameters for the preconditioner.
virtual bool IsInitialized() const
Returns true if the preconditioner has been successfully initialized, false otherwise.
virtual int Compute()
Computes the preconditioners.
virtual int Initialize()
Computes all it is necessary to initialize the preconditioner.
virtual const Epetra_RowMatrix & Matrix() const
Returns a pointer to the matrix to be preconditioned.
virtual bool IsComputed() const
Returns true if the preconditioner has been successfully computed.
virtual ostream & Print(ostream &os) const
Prints object to an output stream.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the preconditioner to X, returns the result in Y.