31 #include "Stratimikos_Config.h"
35 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
36 #include "Thyra_EpetraLinearOp.hpp"
41 namespace Teuchos {
class ParameterList; }
60 using Teuchos::getParameter;
61 bool result, success =
true;
68 paramList =
rcp(paramList_inout,
false);
72 *out <<
"\nEchoing input parameters ...\n";
73 paramList->print(*out,1,
true,
false);
79 validParamList.
set(
"Matrix File",
"fileName");
80 validParamList.
sublist(
"Linear Solver Builder");
86 this fails because validParamList has only been set one level deep - see 5-10 lines above
88 if(out) *out <<
"\nValidating top-level input parameters ...\n";
93 paramList->validateParameters(validParamList,0);
95 if(out) *out <<
"\nValidating top-level input parameters ...\n";
96 paramList->validateParameters(StratimikosList,0);
100 &matrixFile = getParameter<std::string>(*paramList,
"Matrix File");
102 if(out) *out <<
"\nReading in an epetra matrix A from the file \'"<<matrixFile<<
"\' ...\n";
112 const int num_vecs = 1 ;
120 assert( status==0 ) ;
125 epetra_A->
Apply( X, Residual );
126 Residual.Update( 1.0, B, -1.0 );
129 Residual.Norm2( &ResidualNorm );
134 std::string SolverType = Amesos_PL.
get<std::string>(
"Solver Type");
135 assert( SolverType ==
"Lapack" ) ;
138 double AddToDiag = -13.0;
139 if ( SolverType ==
"Lapack" ) {
140 AddToDiag = SolverType_PL.
get<
double>(
"AddToDiag");
142 assert( AddToDiag >= 0.0 ) ;
143 double MaxError = 1e-15*BNorm + 10.0 * AddToDiag ;
144 double MinError = 0.02 * ( 1e-15*BNorm + AddToDiag );
145 success = ResidualNorm < nrows * MaxError &&
146 ResidualNorm > MinError ;
149 std::cout << __FILE__ <<
"::" << __LINE__
150 <<
" ResidualNorm = " << ResidualNorm
151 <<
" MinError = " << MinError
152 <<
" MaxError = " << MaxError << std::endl ;
153 std::cout <<
" B = " ;
154 B.
Print( std::cout ) ;
155 std::cout <<
" X = " ;
156 X.
Print( std::cout ) ;
157 std::cout <<
" epetra_A = " ;
158 epetra_A->
Print( std::cout ) ;
159 std::cout <<
" success = " << success <<
" ResidualNorm = " << ResidualNorm << std::endl ;
163 *out <<
"\nPrinting the parameter list (showing what was used) ...\n";
164 paramList->print(*out,1,
true,
true);
168 catch(
const std::exception &excpt ) {
169 std::cerr <<
"*** Caught standard exception : " << excpt.what() << std::endl;
183 int main(
int argc,
char* argv[])
194 out = Teuchos::VerboseObjectBase::getDefaultOStream();
202 std::string inputFile =
"stratimikos_amesos_lapack.xml";
203 std::string extraParams =
"";
204 bool dumpAll =
false;
206 CommandLineProcessor clp(
false);
207 std::string default_inputFile ;
208 sprintf( &default_inputFile[0],
"Input file [%s]", &inputFile[0] );
209 clp.setOption(
"input-file", &inputFile, &default_inputFile[0],
false );
210 clp.setOption(
"extra-params", &extraParams,
"Extra parameters overriding the parameters read in from --input-file");
212 "Testing program for Trilinos (and non-Trilinos) linear solvers access through Thyra."
215 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
216 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
return parse_return;
219 if(verbose) *out <<
"\nReading parameters from XML file \""<<inputFile<<
"\" ...\n";
220 Teuchos::updateParametersFromXmlFile(inputFile,¶mList);
221 if(extraParams.length()) {
222 if(verbose) *out <<
"\nAppending extra parameters from the XML string \""<<extraParams<<
"\" ...\n";
223 Teuchos::updateParametersFromXmlString(extraParams,¶mList);
228 ¶mList,dumpAll,verbose?&*out:0
235 if(success) *out <<
"\nCongratulations! All of the tests checked out!\n";
236 else *out <<
"\nOh no! At least one of the tests failed!\n";
239 return ( success ? 0 : 1 );
const Epetra_Map & RangeMap() const
bool TestSingleStratimikosSolver(Teuchos::ParameterList *paramList_inout, const bool dumpAll, Teuchos::FancyOStream *out)
T & get(ParameterList &l, const std::string &name)
virtual void Print(std::ostream &os) const
int NumGlobalRows() const
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
basic_OSTab< char > OSTab
bool Residual(int N, int NRHS, double *A, int LDA, bool Transpose, double *X, int LDX, double *B, int LDB, double *resid)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
int main(int argc, char *argv[])
void readEpetraLinearSystem(const std::string &fileName, const Epetra_Comm &comm, Teuchos::RCP< Epetra_CrsMatrix > *A=NULL, Teuchos::RCP< Epetra_Map > *map=NULL, Teuchos::RCP< Epetra_Vector > *x=NULL, Teuchos::RCP< Epetra_Vector > *b=NULL, Teuchos::RCP< Epetra_Vector > *xExact=NULL)
virtual void Print(std::ostream &os) const
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
const Epetra_Map & DomainMap() const
int simpleStratimikosSolve(Epetra_CrsMatrix const &epetra_A, Epetra_MultiVector const &epetra_B, Epetra_MultiVector *epetra_X, Teuchos::ParameterList *paramList)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)