16 #include "Galeri_Maps.h"
17 #include "Galeri_CrsMatrices.h"
19 #ifdef HAVE_VALGRIND_H
20 #include <valgrind/valgrind.h>
23 #ifdef HAVE_VALGRIND_VALGRIND_H
24 #include <valgrind/valgrind.h>
29 using namespace Teuchos;
30 using namespace Galeri;
41 bool testPassed =
true;
54 TimingsList.
get(
"Total symbolic factorization time", 0.0 );
59 Teuchos::getParameter<double>( TimingsList,
"Total numeric factorization time" );
64 Teuchos::getParameter<double>( TimingsList,
"Total solve time" );
69 Teuchos::getParameter<double>( TimingsList,
"Total solve time" );
73 TimingsList.get(
"Total matrix redistribution time", 0.0 );
77 TimingsList.get(
"Total vector redistribution time", 0.0 );
80 catch( std::exception& e ) {
81 if (Comm.
MyPID() == 0)
82 std::cout << std::endl <<
"Exception caught in TestTiming() : " << e.what() << std::endl;
92 const std::string Descriptor,
99 std::cout << std::endl <<
"*** " << SolverType <<
" : "
100 << Descriptor <<
" ***" << std::endl;
101 std::vector<double> Norm;
102 int NumVectors = x.NumVectors();
103 Norm.resize(NumVectors);
106 Ax.Update(1.0,b,-1.0);
108 bool TestPassed =
false;
109 double TotalNorm = 0.0;
110 for (
int i = 0 ; i < NumVectors ; ++i) {
111 TotalNorm += Norm[i];
114 std::cout <<
"||Ax - b|| = " << TotalNorm << std::endl;
115 if (TotalNorm < 1e-5 )
120 Ax.Update (1.0,x,-1.0,x_exact,0.0);
122 for (
int i = 0 ; i < NumVectors ; ++i) {
123 TotalNorm += Norm[i];
126 std::cout <<
"||x - x_exact|| = " << TotalNorm << std::endl;
127 if (TotalNorm < 1e-5 )
144 bool TestPassed =
true;
161 Solver = Factory.
Create(SolverType,ProblemA);
167 std::string ST = SolverType ;
168 if (! ( ST ==
"Amesos_Superludist" ) ) {
171 TestPassed = TestPassed &&
172 CheckError(SolverType,
"Solve() only", A,x_A,b_A,x_exactA) &&
191 Solver = Factory.
Create(SolverType,ProblemA);
199 TestPassed = TestPassed &&
200 CheckError(SolverType,
"NumFact() + Solve()", A,x_A,b_A,x_exactA) &&
223 Solver = Factory.
Create(SolverType,ProblemA);
243 TestPassed = TestPassed &&
244 CheckError(SolverType,
"SymFact() + NumFact() + Solve()",
245 A,x_A,b_A,x_exactA) &&
267 Solver = Factory.
Create(SolverType,ProblemA);
278 TestPassed = TestPassed &&
279 CheckError(SolverType,
"Set A, solve B", B,x_B,b_B,x_exactB) &&
296 Solver = Factory.
Create(SolverType,ProblemA);
300 std::string ST = SolverType ;
301 if (! ( ST ==
"Amesos_Superludist" ) ) {
310 TestPassed = TestPassed &&
311 CheckError(SolverType,
"Set A, Solve C", C,x_C,b_C,x_exactC) &&
328 Solver = Factory.
Create(SolverType,ProblemA);
330 std::string ST = SolverType ;
331 if (! ( ST ==
"Amesos_Superludist" ) ) {
342 TestPassed = TestPassed &&
343 CheckError(SolverType,
"Solve A + Solve C", C,x_C,b_C,x_exactC) &&
363 int NumVectors_AB = 7;
364 int NumVectors_C = 13;
367 if ( RUNNING_ON_VALGRIND ) {
377 GaleriList.
set(
"n", Size_AB * Size_AB);
378 GaleriList.
set(
"nx", Size_AB);
379 GaleriList.
set(
"ny", Size_AB);
380 Epetra_Map* Map_A = CreateMap(
"Interlaced", Comm, GaleriList);
384 GaleriList.
set(
"n", Size_C);
385 Epetra_Map* Map_C = CreateMap(
"Interlaced", Comm, GaleriList);
410 std::vector<std::string> SolverType;
411 SolverType.push_back(
"Amesos_Klu");
412 SolverType.push_back(
"Amesos_Lapack");
413 SolverType.push_back(
"Amesos_Umfpack");
414 SolverType.push_back(
"Amesos_Superlu");
415 SolverType.push_back(
"Amesos_Superludist");
416 SolverType.push_back(
"Amesos_Mumps");
420 bool TestPassed =
true;
422 for (
unsigned int i = 0 ; i < SolverType.size() ; ++i) {
423 std::string
Solver = SolverType[i];
424 if (Factory.
Query((
char*)Solver.c_str())) {
425 bool ok =
Test((
char*)Solver.c_str(),
426 A, x_A, b_A, x_exactA,
427 B, x_B, b_B, x_exactB,
428 C, x_C, b_C, x_exactC);
429 TestPassed = TestPassed && ok;
433 if (Comm.
MyPID() == 0)
434 std::cout <<
"Solver " << Solver <<
" not available" << std::endl;
445 if (Comm.
MyPID() == 0)
446 std::cout << std::endl <<
"TEST PASSED" << std::endl << std::endl;
447 return(EXIT_SUCCESS);
450 if (Comm.
MyPID() == 0)
451 std::cout << std::endl <<
"TEST FAILED" << std::endl << std::endl;
458 int main(
int argc,
char *argv[]) {
461 MPI_Init(&argc, &argv);
468 if ( Comm.
MyPID() == 0 ) {
469 std::cout <<
"Enter a char to continue" ;
void SetLHS(Epetra_MultiVector *X)
void SetOperator(Epetra_RowMatrix *A)
int SubMain(Epetra_Comm &Comm)
virtual int Solve()=0
Solves A X = B (or AT x = B)
T & get(ParameterList &l, const std::string &name)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
virtual int NumericFactorization()=0
Performs NumericFactorization on the matrix A.
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
virtual int SymbolicFactorization()=0
Performs SymbolicFactorization on the matrix A.
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
Amesos_TestRowMatrix: a class to test Epetra_RowMatrix based codes.
virtual int MyPID() const =0
virtual int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_RowMatrix multiplied by a Epetra_MultiVector X in Y.
virtual const Epetra_Comm & Comm() const =0
#define AMESOS_CHK_ERR(a)
bool TestTiming(const Amesos_BaseSolver *Solver, const Epetra_Comm &Comm)
int main(int argc, char *argv[])
Factory for binding a third party direct solver to an Epetra_LinearProblem.
int CreateCrsMatrix(const char *in_filename, const Epetra_Comm &Comm, Epetra_Map *&readMap, const bool transpose, const bool distribute, bool &symmetric, Epetra_CrsMatrix *&Matrix)
virtual int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
virtual void GetTiming(Teuchos::ParameterList &TimingParameterList) const
Extracts timing information from the current solver and places it in the parameter list...
void SetRHS(Epetra_MultiVector *B)
Amesos_BaseSolver * Create(const char *ClassType, const Epetra_LinearProblem &LinearProblem)
Amesos Create method.
bool CheckError(const std::string SolverType, const std::string Descriptor, const Epetra_RowMatrix &A, const Epetra_MultiVector &x, const Epetra_MultiVector &b, const Epetra_MultiVector &x_exact)
Amesos_BaseSolver: A pure virtual class for direct solution of real-valued double-precision operators...
bool Test(char *SolverType, Epetra_RowMatrix &A, Epetra_MultiVector &x_A, Epetra_MultiVector &b_A, Epetra_MultiVector &x_exactA, Epetra_RowMatrix &B, Epetra_MultiVector &x_B, Epetra_MultiVector &b_B, Epetra_MultiVector &x_exactB, Epetra_RowMatrix &C, Epetra_MultiVector &x_C, Epetra_MultiVector &b_C, Epetra_MultiVector &x_exactC)
bool Query(const char *ClassType)
Queries whether a given interface is available or not.