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 #if defined(Amesos_SHOW_DEPRECATED_WARNINGS)
5 #ifdef __GNUC__
6 #warning "The Amesos package is deprecated"
7 #endif
8 #endif
9 
10 #include "Epetra_RowMatrix.h"
11 #include "Epetra_MultiVector.h"
12 #include "Epetra_Vector.h"
13 #include "Epetra_Comm.h"
14 
26 {
27 public:
30 
33 
36  const Epetra_MultiVector& X,
37  const Epetra_MultiVector& B,
38  const bool UseTranspose,
39  const std::string prefix) const
40  {
41  double Norm;
42  Epetra_Vector Ax(B.Map());
43  int NumVectors = X.NumVectors();
44 
45  for (int i = 0 ; i < NumVectors ; ++i)
46  {
47  Matrix.Multiply(UseTranspose, *X(i), Ax);
48  Ax.Update(1.0, *B(i), -1.0);
49  Ax.Norm2(&Norm);
50 
51  if (Matrix.Comm().MyPID() == 0)
52  std::cout << prefix << " : vector " << i << ", ||Ax - b|| = "
53  << Norm << std::endl;
54  }
55  }
56 
59  const Epetra_MultiVector& B,
60  const std::string prefix) const
61  {
62  double NormLHS;
63  double NormRHS;
64  int NumVectors = X.NumVectors();
65 
66  for (int i = 0 ; i < NumVectors ; ++i)
67  {
68  X(i)->Norm2(&NormLHS);
69  B(i)->Norm2(&NormRHS);
70  if (X.Comm().MyPID() == 0)
71  std::cout << prefix << " : vector " << i << ", ||x|| = " << NormLHS
72  << ", ||b|| = " << NormRHS << std::endl;
73  }
74  }
75 
77  void PrintLine() const
78  {
79  std::cout << "--------------------------------------------";
80  std::cout << "--------------------------------" << std::endl;
81  }
82 
83  void SetMaxProcesses(int& MaxProcesses, const Epetra_RowMatrix& A)
84  {
85  int MaxProcs = A.Comm().NumProc();
86 
87  switch(MaxProcesses) {
88  case -3:
89  MaxProcesses = MaxProcs;
90  break;
91  case -2:
92  MaxProcesses = (int) sqrt(1.0 * MaxProcs);
93  break;
94  case -1:
95  MaxProcesses = 1 + static_cast<int>(EPETRA_MAX(A.NumGlobalRows64() / 10000,
96  A.NumGlobalNonzeros64() / 1000000));
97  break;
98  }
99 
100  if (MaxProcesses <= 0) MaxProcesses = 1;
101  if (MaxProcesses > MaxProcs) MaxProcesses = MaxProcs;
102 
103  return;
104  }
105 
106 };
107 #endif
void PrintLine() const
Prints line on std::cout.
Definition: Amesos_Utils.h:77
void SetMaxProcesses(int &MaxProcesses, const Epetra_RowMatrix &A)
Definition: Amesos_Utils.h:83
virtual int MyPID() const =0
Amesos_Utils()
Default constructor.
Definition: Amesos_Utils.h:29
~Amesos_Utils()
Default destructor.
Definition: Amesos_Utils.h:32
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:35
#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:58
Amesos_Utils: Collections of basic utilities.
Definition: Amesos_Utils.h:25