Debian Codegraph @

packages/stratimikos/adapters/amesos/test/test_single_amesos_thyra_solver_driver.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Stratimikos: Thyra-based strategies for linear solvers
4 //
5 // Copyright 2006 NTESS and the Stratimikos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #include "test_single_amesos_thyra_solver.hpp"
11 #include "Teuchos_CommandLineProcessor.hpp"
12 #include "Teuchos_VerboseObject.hpp"
13 #include "Epetra_ConfigDefs.h"
14 #ifdef EPETRA_MPI
15 #include <mpi.h>
16 #endif
17
18 int main(int argc, char* argv[])
19 {
20
21 #ifdef EPETRA_MPI
22 MPI_Init(&argc, &argv);
23 #endif
24
25 using Teuchos::CommandLineProcessor;
26
27 bool success = true;
28 bool verbose = true;
29
30 Teuchos::RCP<Teuchos::FancyOStream>
31 out = Teuchos::VerboseObjectBase::getDefaultOStream();
32
33 try {
34
35 //
36 // Read options from command-line
37 //
38
39 std::string matrixFile = "";
40 Thyra::Amesos::ESolverType solverType
41 #ifdef HAVE_AMESOS_KLU
42 = Thyra::Amesos::KLU;
43 #else
44 = Thyra::Amesos::LAPACK;
45 #endif
46 Thyra::Amesos::ERefactorizationPolicy refactorizationPolicy = Thyra::Amesos::REPIVOT_ON_REFACTORIZATION;
47 bool testTranspose = true;
48 int numRandomVectors = 1;
49 double maxFwdError = 1e-14;
50 double maxError = 1e-10;
51 double maxResid = 1e-10;
52 bool showAllTests = false;
53 bool dumpAll = false;
54
55 CommandLineProcessor clp;
56 clp.throwExceptions(false);
57 clp.addOutputSetupOptions(true);
58 clp.setOption( "matrix-file", &matrixFile, "Matrix iput file [Required]." );
59 clp.setOption(
60 "solver-type", &solverType
61 ,Thyra::Amesos::numSolverTypes, Thyra::Amesos::solverTypeValues, Thyra::Amesos::solverTypeNames
62 ,"Type of direct solver."
63 );
64 clp.setOption(
65 "refactorization-policy", &refactorizationPolicy
66 ,Thyra::Amesos::numRefactorizationPolices, Thyra::Amesos::refactorizationPolicyValues, Thyra::Amesos::refactorizationPolicyNames
67 ,"Pivoting policy used on refactorizations."
68 );
69 clp.setOption( "test-transpose", "no-test-transpose", &testTranspose, "Test the transpose solve or not." );
70 clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
71 clp.setOption( "max-fwd-error", &maxFwdError, "The maximum relative error in the forward operator." );
72 clp.setOption( "max-error", &maxError, "The maximum relative error in the solution." );
73 clp.setOption( "max-resid", &maxResid, "The maximum relative error in the residual." );
74 clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
75 clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
76 clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
77 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
78 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
79
80 TEUCHOS_TEST_FOR_EXCEPT( matrixFile == "" );
81
82 Teuchos::ParameterList amesosLOWSFPL;
83 amesosLOWSFPL.set("Solver Type",toString(solverType));
84 amesosLOWSFPL.set("Refactorization Policy",toString(refactorizationPolicy));
85
86 success
87 = Thyra::test_single_amesos_thyra_solver(
88 matrixFile,&amesosLOWSFPL,testTranspose,numRandomVectors
89 ,maxFwdError,maxError,maxResid,showAllTests,dumpAll,verbose?&*out:0
90 );
91
92 }
93 catch( const std::exception &excpt ) {
94 std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
95 success = false;
96 }
97 catch( ... ) {
98 std::cerr << "*** Caught an unknown exception\n";
99 success = false;
100 }
101
102 if (verbose) {
103 if(success) *out << "\nCongratulations! All of the tests checked out!\n";
104 else *out << "\nOh no! At least one of the tests failed!\n";
105 }
106
107 #ifdef EPETRA_MPI
108 MPI_Finalize();
109 #endif
110
111 return ( success ? 0 : 1 );
112 }