31 #include "Stratimikos_Config.h" 32 #include "Teuchos_ConfigDefs.hpp" 33 #include "Teuchos_FancyOStream.hpp" 35 #include "Stratimikos_DefaultLinearSolverBuilder.hpp" 36 #include "Thyra_EpetraLinearOp.hpp" 38 #include "EpetraExt_readEpetraLinearSystem.h" 39 #include "Teuchos_ParameterList.hpp" 41 namespace Teuchos {
class ParameterList; }
44 # include "Epetra_MpiComm.h" 46 # include "Epetra_SerialComm.h" 50 Teuchos::ParameterList *paramList_inout
52 ,Teuchos::FancyOStream *out
59 using Teuchos::ParameterList;
60 using Teuchos::getParameter;
61 bool result, success =
true;
65 TEUCHOS_TEST_FOR_EXCEPT(!paramList_inout);
68 paramList = rcp(paramList_inout,
false);
72 *out <<
"\nEchoing input parameters ...\n";
73 paramList->print(*out,1,
true,
false);
78 Teuchos::ParameterList validParamList(
"TestSingleStratimikosSolver");
79 validParamList.set(
"Matrix File",
"fileName");
80 validParamList.sublist(
"Linear Solver Builder");
82 Teuchos::ParameterList &StratimikosList = paramList_inout->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";
89 StratimikosList.validateParameters(validParamList.sublist(
"Linear Solver Builder"),0);
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";
105 Epetra_MpiComm comm(MPI_COMM_WORLD);
107 Epetra_SerialComm comm;
109 Teuchos::RCP<Epetra_CrsMatrix> epetra_A;
110 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );
112 const int num_vecs = 1 ;
113 const Epetra_Map& A_domainmap = epetra_A->DomainMap() ;
114 Epetra_MultiVector X( A_domainmap, num_vecs ) ;
115 const Epetra_Map& A_rangemap = epetra_A->RangeMap() ;
116 Epetra_MultiVector B( A_rangemap, num_vecs ) ;
120 assert( status==0 ) ;
123 int nrows =epetra_A->NumGlobalRows();
124 Epetra_MultiVector Residual( B ) ;
125 epetra_A->Apply( X, Residual );
126 Residual.Update( 1.0, B, -1.0 );
129 Residual.Norm2( &ResidualNorm );
132 const Teuchos::ParameterList& LST_PL = StratimikosList.sublist(
"Linear Solver Types");
133 const Teuchos::ParameterList& Amesos_PL = LST_PL.sublist(
"Amesos");
134 std::string SolverType = Amesos_PL.get<std::string>(
"Solver Type");
135 assert( SolverType ==
"Lapack" ) ;
136 const Teuchos::ParameterList& AmesosSettings_PL = Amesos_PL.sublist(
"Amesos Settings");
137 const Teuchos::ParameterList& SolverType_PL = AmesosSettings_PL.sublist(SolverType);
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;
177 #include "Teuchos_GlobalMPISession.hpp" 178 #include "Teuchos_VerboseObject.hpp" 179 #include "Teuchos_CommandLineProcessor.hpp" 180 #include "Teuchos_XMLParameterListHelpers.hpp" 181 #include "Teuchos_StandardCatchMacros.hpp" 183 int main(
int argc,
char* argv[])
186 Teuchos::GlobalMPISession mpiSession(&argc,&argv);
188 using Teuchos::CommandLineProcessor;
193 Teuchos::RCP<Teuchos::FancyOStream>
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;
218 Teuchos::ParameterList paramList;
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
232 TEUCHOS_STANDARD_CATCH_STATEMENTS(
verbose,std::cerr,success)
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 );
bool TestSingleStratimikosSolver(Teuchos::ParameterList *paramList_inout, const bool dumpAll, Teuchos::FancyOStream *out)
int main(int argc, char *argv[])
int simpleStratimikosSolve(Epetra_CrsMatrix const &epetra_A, Epetra_MultiVector const &epetra_B, Epetra_MultiVector *epetra_X, Teuchos::ParameterList *paramList)