Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Amesos_Utils.h
Go to the documentation of this file.
1 #ifndef AMESOS_UTILS_H
2 #define AMESOS_UTILS_H
3 
4 #include "Epetra_RowMatrix.h"
5 #include "Epetra_MultiVector.h"
6 #include "Epetra_Vector.h"
7 #include "Epetra_Comm.h"
8 
20 {
21 public:
24 
27 
30  const Epetra_MultiVector& X,
31  const Epetra_MultiVector& B,
32  const bool UseTranspose,
33  const std::string prefix) const
34  {
35  double Norm;
36  Epetra_Vector Ax(B.Map());
37  int NumVectors = X.NumVectors();
38 
39  for (int i = 0 ; i < NumVectors ; ++i)
40  {
41  Matrix.Multiply(UseTranspose, *X(i), Ax);
42  Ax.Update(1.0, *B(i), -1.0);
43  Ax.Norm2(&Norm);
44 
45  if (Matrix.Comm().MyPID() == 0)
46  std::cout << prefix << " : vector " << i << ", ||Ax - b|| = "
47  << Norm << std::endl;
48  }
49  }
50 
53  const Epetra_MultiVector& B,
54  const std::string prefix) const
55  {
56  double NormLHS;
57  double NormRHS;
58  int NumVectors = X.NumVectors();
59 
60  for (int i = 0 ; i < NumVectors ; ++i)
61  {
62  X(i)->Norm2(&NormLHS);
63  B(i)->Norm2(&NormRHS);
64  if (X.Comm().MyPID() == 0)
65  std::cout << prefix << " : vector " << i << ", ||x|| = " << NormLHS
66  << ", ||b|| = " << NormRHS << std::endl;
67  }
68  }
69 
71  void PrintLine() const
72  {
73  std::cout << "--------------------------------------------";
74  std::cout << "--------------------------------" << std::endl;
75  }
76 
77  void SetMaxProcesses(int& MaxProcesses, const Epetra_RowMatrix& A)
78  {
79  int MaxProcs = A.Comm().NumProc();
80 
81  switch(MaxProcesses) {
82  case -3:
83  MaxProcesses = MaxProcs;
84  break;
85  case -2:
86  MaxProcesses = (int) sqrt(1.0 * MaxProcs);
87  break;
88  case -1:
89  MaxProcesses = 1 + static_cast<int>(EPETRA_MAX(A.NumGlobalRows64() / 10000,
90  A.NumGlobalNonzeros64() / 1000000));
91  break;
92  }
93 
94  if (MaxProcesses <= 0) MaxProcesses = 1;
95  if (MaxProcesses > MaxProcs) MaxProcesses = MaxProcs;
96 
97  return;
98  }
99 
100 };
101 #endif
void PrintLine() const
Prints line on std::cout.
Definition: Amesos_Utils.h:71
void SetMaxProcesses(int &MaxProcesses, const Epetra_RowMatrix &A)
Definition: Amesos_Utils.h:77
virtual int MyPID() const =0
Amesos_Utils()
Default constructor.
Definition: Amesos_Utils.h:23
~Amesos_Utils()
Default destructor.
Definition: Amesos_Utils.h:26
virtual const Epetra_Comm & Comm() const =0
virtual const Epetra_BlockMap & Map() const =0
virtual long long NumGlobalNonzeros64() const =0
virtual int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
virtual int NumProc() const =0
void ComputeTrueResidual(const Epetra_RowMatrix &Matrix, const Epetra_MultiVector &X, const Epetra_MultiVector &B, const bool UseTranspose, const std::string prefix) const
Computes the true residual, B - Matrix * X, and prints the results.
Definition: Amesos_Utils.h:29
#define EPETRA_MAX(x, y)
virtual long long NumGlobalRows64() const =0
void ComputeVectorNorms(const Epetra_MultiVector &X, const Epetra_MultiVector &B, const std::string prefix) const
Computes the norms of X and B and print the results.
Definition: Amesos_Utils.h:52
Amesos_Utils: Collections of basic utilities.
Definition: Amesos_Utils.h:19