Amesos Package Browser (Single Doxygen Collection) Development
Amesos_Utils.h
Go to the documentation of this file.
00001 #ifndef AMESOS_UTILS_H
00002 #define AMESOS_UTILS_H
00003 
00004 #include "Epetra_RowMatrix.h"
00005 #include "Epetra_MultiVector.h"
00006 #include "Epetra_Vector.h"
00007 #include "Epetra_Comm.h"
00008 
00019 class Amesos_Utils
00020 {
00021 public:
00023   Amesos_Utils() {}
00024   
00026   ~Amesos_Utils() {}
00027 
00029   void ComputeTrueResidual(const Epetra_RowMatrix& Matrix,
00030                            const Epetra_MultiVector& X,
00031                            const Epetra_MultiVector& B,
00032                            const bool UseTranspose,
00033                            const std::string prefix) const
00034   {
00035     double Norm;
00036     Epetra_Vector Ax(B.Map());
00037     int NumVectors = X.NumVectors();
00038 
00039     for (int i = 0 ; i < NumVectors ; ++i) 
00040     {
00041       Matrix.Multiply(UseTranspose, *X(i), Ax);
00042       Ax.Update(1.0, *B(i), -1.0);
00043       Ax.Norm2(&Norm);
00044 
00045       if (Matrix.Comm().MyPID() == 0) 
00046         std::cout << prefix << " : vector " << i << ", ||Ax - b|| = " 
00047           << Norm << std::endl;
00048     }
00049   }
00050 
00052   void ComputeVectorNorms(const Epetra_MultiVector& X,
00053                           const Epetra_MultiVector& B,
00054                           const std::string prefix) const
00055   {
00056     double NormLHS;
00057     double NormRHS;
00058     int NumVectors = X.NumVectors();
00059 
00060     for (int i = 0 ; i < NumVectors ; ++i) 
00061     {
00062       X(i)->Norm2(&NormLHS);
00063       B(i)->Norm2(&NormRHS);
00064       if (X.Comm().MyPID() == 0) 
00065         std::cout << prefix << " : vector " << i << ", ||x|| = " << NormLHS
00066           << ", ||b|| = " << NormRHS << std::endl;
00067     }
00068   }
00069 
00071   void PrintLine() const
00072   {
00073     std::cout << "--------------------------------------------";
00074     std::cout << "--------------------------------" << std::endl;
00075   }
00076 
00077   void SetMaxProcesses(int& MaxProcesses, const Epetra_RowMatrix& A)
00078   {
00079     int MaxProcs = A.Comm().NumProc();
00080 
00081     switch(MaxProcesses) {
00082     case -3:
00083       MaxProcesses = MaxProcs;
00084       break;
00085     case -2:
00086       MaxProcesses = (int) sqrt(1.0 * MaxProcs);
00087       break;
00088     case -1:
00089       MaxProcesses = 1 + EPETRA_MAX(A.NumGlobalRows() / 10000, 
00090                                     A.NumGlobalNonzeros() / 1000000);
00091       break;
00092     }
00093 
00094     if (MaxProcesses <= 0) MaxProcesses = 1;
00095     if (MaxProcesses > MaxProcs) MaxProcesses = MaxProcs;
00096 
00097     return;
00098   }
00099 
00100 };
00101 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines