44 #ifndef IFPACK_BLOCKPRECONDITIONER_H
45 #define IFPACK_BLOCKPRECONDITIONER_H
47 #if defined(Ifpack_SHOW_DEPRECATED_WARNINGS)
49 #warning "The Ifpack package is deprecated"
65 #include "Teuchos_ParameterList.hpp"
66 #include "Teuchos_RefCountPtr.hpp"
68 #include "Epetra_Map.h"
69 #include "Epetra_RowMatrix.h"
70 #include "Epetra_MultiVector.h"
71 #include "Epetra_Vector.h"
72 #include "Epetra_Time.h"
73 #include "Epetra_Import.h"
205 virtual const char*
Label()
const;
274 std::ostream&
Print(std::ostream& os)
const;
315 #ifdef IFPACK_FLOPCOUNTERS
323 for (
unsigned int i = 0 ; i <
Containers_.size() ; ++i)
333 #ifdef IFPACK_FLOPCOUNTERS
338 for (
unsigned int i = 0 ; i <
Containers_.size() ; ++i)
348 #ifdef IFPACK_FLOPCOUNTERS
353 for (
unsigned int i = 0 ; i <
Containers_.size() ; ++i) {
434 Teuchos::RefCountPtr< const Epetra_RowMatrix >
Matrix_;
446 Teuchos::RefCountPtr<Ifpack_Graph>
Graph_;
448 Teuchos::RefCountPtr<Epetra_Vector>
W_;
462 IsInitialized_(
false),
467 InitializeTime_(0.0),
469 ApplyInverseTime_(0.0),
470 InitializeFlops_(0.0),
472 ApplyInverseFlops_(0.0),
476 Matrix_(Teuchos::
rcp(Matrix_in,
false)),
477 Diagonal_( Matrix_in->Map()),
478 PartitionerType_(
"greedy"),
480 ZeroStartingSolution_(
true),
499 return(Label_.c_str());
507 int ierr = Matrix().Apply(X,Y);
516 return(Matrix().Comm());
524 return(Matrix().OperatorDomainMap());
532 return(Matrix().OperatorRangeMap());
543 NumLocalBlocks_ = Partitioner_->NumLocalParts();
545 Containers_.resize(NumLocalBlocks());
548 Matrix_->ExtractDiagonalCopy(Diagonal_);
550 for (
int i = 0 ; i < NumLocalBlocks() ; ++i) {
552 int rows = Partitioner_->NumRowsInPart(i);
564 for (
int j = 0 ; j < rows ; ++j) {
565 int LRID = (*Partitioner_)(i,j);
566 Containers_[i]->ID(j) = LRID;
574 #ifdef SINGLETON_DEBUG
577 for (
int i = 0 ; i < NumLocalBlocks() ; ++i)
578 issing += (
int) ( Partitioner_->NumRowsInPart(i) == 1);
579 printf(
" %d of %d containers are singleton \n",issing,NumLocalBlocks());
590 if (!IsInitialized())
593 Time_.ResetStartTime();
597 if (Matrix().NumGlobalRows64() != Matrix().NumGlobalCols64())
605 Matrix().RowMatrixRowMap()) );
610 ComputeTime_ += Time_.ElapsedTime();
625 if (X.NumVectors() != Y.NumVectors())
628 Time_.ResetStartTime();
632 Teuchos::RefCountPtr< const Epetra_MultiVector > Xcopy;
633 if (X.Pointers()[0] == Y.Pointers()[0])
650 ApplyInverseTime_ += Time_.ElapsedTime();
666 if (ZeroStartingSolution_)
670 if (NumSweeps_ == 1 && ZeroStartingSolution_) {
671 int ierr = DoJacobi(X,Y);
677 for (
int j = 0; j < NumSweeps_ ; j++) {
679 ApplyInverseFlops_ += X.NumVectors() * 2 * Matrix_->NumGlobalNonzeros64();
681 ApplyInverseFlops_ += X.NumVectors() * 2 * Matrix_->NumGlobalRows64();
697 if (OverlapLevel_ == 0) {
699 for (
int i = 0 ; i < NumLocalBlocks() ; ++i) {
701 int rows = Partitioner_->NumRowsInPart(i);
710 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
711 LID = Containers_[i]->ID(j);
713 Containers_[i]->RHS(j,k) = X[k][LID];
724 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
725 LID = Containers_[i]->ID(j);
727 Y[k][LID] += DampingFactor_ * Containers_[i]->LHS(j,k);
733 int LRID = (*Partitioner_)(i,0);
734 double b = X[0][LRID];
735 double a = Diagonal_[LRID];
736 Y[0][LRID] += DampingFactor_* b/a;
740 #ifdef IFPACK_FLOPCOUNTERS
741 ApplyInverseFlops_ += NumVectors * 2 * Matrix_->NumGlobalRows();
748 for (
int i = 0 ; i < NumLocalBlocks() ; ++i) {
750 int rows = Partitioner_->NumRowsInPart(i);
759 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
760 LID = Containers_[i]->ID(j);
762 Containers_[i]->RHS(j,k) = (*W_)[LID] * X[k][LID];
771 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
772 LID = Containers_[i]->ID(j);
774 Y[k][LID] += DampingFactor_ * (*W_)[LID] * Containers_[i]->LHS(j,k);
779 int LRID = (*Partitioner_)(i,0);
780 double w = (*W_)[LRID];
781 double b = w * X[0][LRID];
782 double a = Diagonal_[LRID];
784 Y[0][LRID] += DampingFactor_ * w * b / a;
790 #ifdef IFPACK_FLOPCOUNTERS
791 ApplyInverseFlops_ += NumVectors * 4 * Matrix_->NumGlobalRows();
805 if (ZeroStartingSolution_)
809 for (
int j = 0; j < NumSweeps_ ; j++) {
811 if (j != NumSweeps_ - 1)
827 int Length = Matrix().MaxNumEntries();
828 std::vector<int> Indices(Length);
829 std::vector<double> Values(Length);
831 int NumMyRows = Matrix().NumMyRows();
837 Teuchos::RefCountPtr< Epetra_MultiVector > Y2;
845 Y.ExtractView(&y_ptr);
846 Y2->ExtractView(&y2_ptr);
852 for (
int i = 0 ; i < NumLocalBlocks() ; ++i) {
853 int rows = Partitioner_->NumRowsInPart(i);
856 if (rows!=1 && Containers_[i]->NumRows() == 0)
863 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
864 LID = (*Partitioner_)(i,j);
868 &Values[0], &Indices[0]));
870 for (
int k = 0 ; k < NumEntries ; ++k) {
871 int col = Indices[k];
874 X[kk][LID] -= Values[k] * y2_ptr[kk][col];
882 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
883 LID = Containers_[i]->ID(j);
885 Containers_[i]->RHS(j,k) = X[k][LID];
890 #ifdef IFPACK_FLOPCOUNTERS
891 ApplyInverseFlops_ += Containers_[i]->ApplyInverseFlops();
894 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
895 LID = Containers_[i]->ID(j);
897 double temp = DampingFactor_ * Containers_[i]->LHS(j,k);
898 y2_ptr[k][LID] += temp;
903 int LRID = (*Partitioner_)(i,0);
904 double b = X[0][LRID];
905 double a = Diagonal_[LRID];
906 y2_ptr[0][LRID]+= DampingFactor_* b/a;
912 #ifdef IFPACK_FLOPCOUNTERS
913 ApplyInverseFlops_ += NumVectors * 2 * Matrix_->NumGlobalNonzeros();
914 ApplyInverseFlops_ += NumVectors * 2 * Matrix_->NumGlobalRows();
921 for (
int i = 0 ; i < NumMyRows ; ++i)
922 y_ptr[m][i] = y2_ptr[m][i];
933 if (ZeroStartingSolution_)
937 for (
int j = 0; j < NumSweeps_ ; j++) {
939 if (j != NumSweeps_ - 1)
952 int NumMyRows = Matrix().NumMyRows();
955 int Length = Matrix().MaxNumEntries();
956 std::vector<int> Indices;
957 std::vector<double> Values;
958 Indices.resize(Length);
959 Values.resize(Length);
964 Teuchos::RefCountPtr< Epetra_MultiVector > Y2;
972 Y.ExtractView(&y_ptr);
973 Y2->ExtractView(&y2_ptr);
979 for (
int i = 0 ; i < NumLocalBlocks() ; ++i) {
980 int rows = Partitioner_->NumRowsInPart(i);
982 if (rows !=1 && Containers_[i]->NumRows() == 0)
989 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
990 LID = (*Partitioner_)(i,j);
993 &Values[0], &Indices[0]));
995 for (
int k = 0 ; k < NumEntries ; ++k) {
996 int col = Indices[k];
999 Xcopy[kk][LID] -= Values[k] * y2_ptr[kk][col];
1007 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
1008 LID = Containers_[i]->ID(j);
1010 Containers_[i]->RHS(j,k) = Xcopy[k][LID];
1015 #ifdef IFPACK_FLOPCOUNTERS
1016 ApplyInverseFlops_ += Containers_[i]->ApplyInverseFlops();
1019 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
1020 LID = Containers_[i]->ID(j);
1022 y2_ptr[k][LID] += DampingFactor_ * Containers_[i]->LHS(j,k);
1027 int LRID = (*Partitioner_)(i,0);
1028 double b = Xcopy[0][LRID];
1029 double a = Diagonal_[LRID];
1030 y2_ptr[0][LRID]+= DampingFactor_* b/a;
1034 #ifdef IFPACK_FLOPCOUNTERS
1036 ApplyInverseFlops_ += NumVectors * 2 * Matrix_->NumGlobalNonzeros();
1037 ApplyInverseFlops_ += NumVectors * 2 * Matrix_->NumGlobalRows();
1042 for (
int i = NumLocalBlocks() - 1; i >=0 ; --i) {
1043 int rows = Partitioner_->NumRowsInPart(i);
1044 if (rows != 1 &&Containers_[i]->NumRows() == 0)
1051 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
1052 LID = (*Partitioner_)(i,j);
1056 &Values[0], &Indices[0]));
1058 for (
int k = 0 ; k < NumEntries ; ++k) {
1059 int col = Indices[k];
1062 Xcopy[kk][LID] -= Values[k] * y2_ptr[kk][col];
1069 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
1070 LID = Containers_[i]->ID(j);
1072 Containers_[i]->RHS(j,k) = Xcopy[k][LID];
1077 #ifdef IFPACK_FLOPCOUNTERS
1078 ApplyInverseFlops_ += Containers_[i]->ApplyInverseFlops();
1081 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
1082 LID = Containers_[i]->ID(j);
1084 y2_ptr[k][LID] += DampingFactor_ * Containers_[i]->LHS(j,k);
1089 int LRID = (*Partitioner_)(i,0);
1090 double b = Xcopy[0][LRID];
1091 double a = Diagonal_[LRID];
1092 y2_ptr[0][LRID]+= DampingFactor_* b/a;
1096 #ifdef IFPACK_FLOPCOUNTERS
1098 ApplyInverseFlops_ += NumVectors * 2 * Matrix_->NumGlobalNonzeros();
1099 ApplyInverseFlops_ += NumVectors * 2 * Matrix_->NumGlobalRows();
1106 for (
int i = 0 ; i < NumMyRows ; ++i)
1107 y_ptr[m][i] = y2_ptr[m][i];
1113 template<
typename T>
1122 PT =
"Gauss-Seidel";
1124 PT =
"symmetric Gauss-Seidel";
1126 if (!Comm().MyPID()) {
1128 os <<
"================================================================================" << endl;
1129 os <<
"Ifpack_BlockRelaxation, " << PT << endl;
1130 os <<
"Sweeps = " << NumSweeps_ << endl;
1131 os <<
"Damping factor = " << DampingFactor_;
1132 if (ZeroStartingSolution_)
1133 os <<
", using zero starting solution" << endl;
1135 os <<
", using input starting solution" << endl;
1136 os <<
"Number of local blocks = " << Partitioner_->NumLocalParts() << endl;
1138 os <<
"Global number of rows = " << Matrix_->NumGlobalRows64() << endl;
1140 os <<
"Phase # calls Total Time (s) Total MFlops MFlops/s" << endl;
1141 os <<
"----- ------- -------------- ------------ --------" << endl;
1142 os <<
"Initialize() " << std::setw(5) << NumInitialize()
1143 <<
" " << std::setw(15) << InitializeTime()
1144 <<
" " << std::setw(15) << 1.0e-6 * InitializeFlops();
1145 if (InitializeTime() != 0.0)
1146 os <<
" " << std::setw(15) << 1.0e-6 * InitializeFlops() / InitializeTime() << endl;
1148 os <<
" " << std::setw(15) << 0.0 << endl;
1149 os <<
"Compute() " << std::setw(5) << NumCompute()
1150 <<
" " << std::setw(15) << ComputeTime()
1151 <<
" " << std::setw(15) << 1.0e-6 * ComputeFlops();
1152 if (ComputeTime() != 0.0)
1153 os <<
" " << std::setw(15) << 1.0e-6 * ComputeFlops() / ComputeTime() << endl;
1155 os <<
" " << std::setw(15) << 0.0 << endl;
1156 os <<
"ApplyInverse() " << std::setw(5) << NumApplyInverse()
1157 <<
" " << std::setw(15) << ApplyInverseTime()
1158 <<
" " << std::setw(15) << 1.0e-6 * ApplyInverseFlops();
1159 if (ApplyInverseTime() != 0.0)
1160 os <<
" " << std::setw(15) << 1.0e-6 * ApplyInverseFlops() / ApplyInverseTime() << endl;
1162 os <<
" " << std::setw(15) << 0.0 << endl;
1163 os <<
"================================================================================" << endl;
1171 template<
typename T>
1181 PT =
"Gauss-Seidel";
1183 PT =
"symmetric Gauss-Seidel";
1185 PT = List.
get(
"relaxation: type", PT);
1187 if (PT ==
"Jacobi") {
1190 else if (PT ==
"Gauss-Seidel") {
1193 else if (PT ==
"symmetric Gauss-Seidel") {
1196 cerr <<
"Option `relaxation: type' has an incorrect value ("
1197 << PT <<
")'" << endl;
1198 cerr <<
"(file " << __FILE__ <<
", line " << __LINE__ <<
")" << endl;
1202 NumSweeps_ = List.
get(
"relaxation: sweeps", NumSweeps_);
1203 DampingFactor_ = List.
get(
"relaxation: damping factor",
1205 ZeroStartingSolution_ = List.
get(
"relaxation: zero starting solution",
1206 ZeroStartingSolution_);
1207 PartitionerType_ = List.
get(
"partitioner: type",
1209 NumLocalBlocks_ = List.
get(
"partitioner: local parts",
1212 OverlapLevel_ = List.
get(
"partitioner: overlap",
1218 if (NumLocalBlocks_ < 0)
1219 NumLocalBlocks_ = Matrix().NumMyRows() / (-NumLocalBlocks_);
1234 Label_ =
"IFPACK (" + PT2 +
", sweeps="
1243 template<
typename T>
1246 IsInitialized_ =
false;
1247 Time_.ResetStartTime();
1252 if (PartitionerType_ ==
"linear")
1254 else if (PartitionerType_ ==
"greedy")
1256 else if (PartitionerType_ ==
"metis")
1258 else if (PartitionerType_ ==
"equation")
1260 else if (PartitionerType_ ==
"user")
1262 else if (PartitionerType_ ==
"line")
1274 NumLocalBlocks_ = Partitioner_->NumLocalParts();
1280 for (
int i = 0 ; i < NumLocalBlocks() ; ++i) {
1282 for (
int j = 0 ; j < Partitioner_->NumRowsInPart(i) ; ++j) {
1283 int LID = (*Partitioner_)(i,j);
1287 W_->Reciprocal(*W_);
1290 if (PartitionerType_ ==
"line") {
1299 Label_ =
"IFPACK (" + PT2 +
", auto-line, sweeps="
1305 InitializeTime_ += Time_.ElapsedTime();
1306 IsInitialized_ =
true;
1313 #endif // IFPACK_BLOCKPRECONDITIONER_H
Teuchos::RefCountPtr< Epetra_Import > Importer_
int NumSweeps_
Number of preconditioning sweeps.
virtual const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
Teuchos::RefCountPtr< const Epetra_RowMatrix > Matrix_
Containers_[i] contains all the necessary information to solve on each subblock.
double ApplyInverseFlops_
Contain sthe number of flops for ApplyInverse().
bool IsComputed_
If true, the preconditioner has been successfully computed.
Ifpack_BlockRelaxation: a class to define block relaxation preconditioners of Epetra_RowMatrix's.
double InitializeFlops_
Contains the number of flops for Initialize().
Teuchos::RefCountPtr< Ifpack_Graph > Graph_
Ifpack_UserPartitioner: A class to define linear partitions.
virtual const char * Label() const
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
virtual double ApplyInverseFlops() const
Returns the number of flops in the application of the preconditioner.
Ifpack_BlockRelaxation & operator=(const Ifpack_BlockRelaxation &rhs)
operator= (PRIVATE, should not be used).
T & get(ParameterList &l, const std::string &name)
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual int NumInitialize() const
Returns the number of calls to Initialize().
static const int IFPACK_SGS
virtual int ApplyInverseJacobi(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
virtual double ApplyInverseTime() const
Returns the time spent in ApplyInverse().
virtual int DoJacobi(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the block Jacobi preconditioner to X, returns the result in Y.
Teuchos::ParameterList List_
Parameters list to be used to solve on each subblock.
int NumApplyInverse_
Contains the number of successful call to ApplyInverse().
int NumLocalBlocks() const
Returns the number local blocks.
virtual bool IsComputed() const
Returns true if the preconditioner has been successfully computed.
virtual double ComputeTime() const
Returns the time spent in Compute().
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
std::string Label_
Label for this object.
virtual bool IsInitialized() const
Returns true if the preconditioner has been successfully computed.
Ifpack_EquationPartitioner: A class to decompose an Ifpack_Graph so that each block will contain all ...
virtual int SetUseTranspose(bool UseTranspose_in)
virtual double ComputeFlops() const
Returns the number of flops in the computation phase.
double ComputeFlops_
Contains the number of flops for Compute().
virtual const Epetra_RowMatrix & Matrix() const
Returns a pointer to the matrix to be preconditioned.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the matrix to an Epetra_MultiVector.
double ComputeTime_
Contains the time for all successful calls to Compute().
int NumInitialize_
Contains the number of successful calls to Initialize().
Ifpack_CondestType
Ifpack_CondestType: enum to define the type of condition number estimate.
double InitializeTime_
Contains the time for all successful calls to Initialize().
virtual ~Ifpack_BlockRelaxation()
virtual const Epetra_Comm & Comm() const =0
bool ZeroStartingSolution_
If true, starting solution is the zero vector.
virtual int Compute()
Computes the preconditioner.
std::string PartitionerType_
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
double ApplyInverseTime_
Contains the time for all successful calls to ApplyInverse().
Ifpack_METISPartitioner: A class to decompose Ifpack_Graph's using METIS.
static const int IFPACK_GS
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
Ifpack_BlockRelaxation(const Epetra_RowMatrix *Matrix)
Ifpack_BlockRelaxation constructor with given Epetra_RowMatrix.
Teuchos::RefCountPtr< Epetra_Vector > W_
Weights for overlapping Jacobi only.
virtual int SetParameters(Teuchos::ParameterList &List)
Sets all the parameters for the preconditioner.
std::string Ifpack_toString(const int &x)
Converts an integer to std::string.
Ifpack_Graph_Epetra_RowMatrix: a class to define Ifpack_Graph as a light-weight conversion of Epetra_...
std::ostream & Print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
virtual int DoSGS(const Epetra_MultiVector &X, Epetra_MultiVector &Xtmp, Epetra_MultiVector &Y) const
virtual int NumCompute() const
Returns the number of calls to Compute().
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
virtual int DoGaussSeidel(Epetra_MultiVector &X, Epetra_MultiVector &Y) const
#define IFPACK_RETURN(ifpack_err)
virtual double InitializeTime() const
Returns the time spent in Initialize().
std::vector< Teuchos::RefCountPtr< T > > Containers_
virtual int NumProc() const =0
virtual double Condest() const
Returns the computed condition number estimate, or -1.0 if not computed.
static const int IFPACK_JACOBI
virtual int Initialize()
Initializes the preconditioner.
int NumLocalBlocks_
Number of local blocks.
virtual int ApplyInverseGS(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Ifpack_LinearPartitioner: A class to define linear partitions.
virtual double InitializeFlops() const
Returns the number of flops in the initialization phase.
Teuchos::RefCountPtr< Ifpack_Partitioner > Partitioner_
Contains information about non-overlapping partitions.
virtual int NumApplyInverse() const
Returns the number of calls to ApplyInverse().
int NumCompute_
Contains the number of successful call to Compute().
virtual double Condest(const Ifpack_CondestType=Ifpack_Cheap, const int=1550, const double=1e-9, Epetra_RowMatrix *=0)
Computes the condition number estimate, returns its value.
virtual double NormInf() const
Returns the infinity norm of the global matrix (not implemented)
double DampingFactor_
Damping parameter.
#define IFPACK_CHK_ERR(ifpack_err)
Ifpack_GreedyPartitioner: A class to decompose Ifpack_Graph's using a simple greedy algorithm...
bool IsInitialized_
If true, the preconditioner has been successfully initialized.
virtual int ApplyInverseSGS(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const