Amesos Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
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{
21public:
24
27
29 void ComputeTrueResidual(const Epetra_RowMatrix& Matrix,
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
52 void ComputeVectorNorms(const Epetra_MultiVector& X,
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
Amesos_Utils: Collections of basic utilities.
void SetMaxProcesses(int &MaxProcesses, const Epetra_RowMatrix &A)
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.
~Amesos_Utils()
Default destructor.
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.
void PrintLine() const
Prints line on std::cout.
Amesos_Utils()
Default constructor.