43 #include "Teuchos_GlobalMPISession.hpp" 44 #include "Teuchos_CommandLineProcessor.hpp" 45 #include "Teuchos_ParameterList.hpp" 46 #include "Teuchos_ParameterXMLFileReader.hpp" 47 #include "Teuchos_RefCountPtr.hpp" 48 #include "Teuchos_Time.hpp" 49 #include "Teuchos_Comm.hpp" 52 #include "Epetra_MpiComm.h" 54 #include "Epetra_SerialComm.h" 57 #include "Epetra_LinearProblem.h" 68 int main(
int argc,
char*argv[])
70 Teuchos::GlobalMPISession mpisess(&argc,&argv,&std::cout);
72 Teuchos::Time timer(
"total");
76 Epetra_MpiComm Comm(MPI_COMM_WORLD);
78 Epetra_SerialComm Comm;
84 std::string xml_file(
"xml_params.xml");
93 std::cout <<
"Every proc reading parameters from xml_file: " 94 << xml_file << std::endl;
95 Teuchos::ParameterList test_params =
96 Teuchos::ParameterXMLFileReader(xml_file).getParameters();
102 Teuchos::RCP<Epetra_LinearProblem> problem =
build_problem(test_params, Comm);
106 Teuchos::RCP<AztecOO> solver =
build_solver(test_params, problem);
108 int max_iters = solver->GetAllAztecOptions()[AZ_max_iter];
109 double tol = solver->GetAllAztecParams()[AZ_tol];
111 Teuchos::Time prec_time(
"precond");
115 if (solver->GetAllAztecOptions()[AZ_precond] != AZ_user_precond) {
116 err_code = solver->ConstructPreconditioner(cond_est);
119 if (Comm.MyPID() == 0 && err_code == 0) {
120 std::cout <<
"Time to compute preconditioner: " << prec_time.totalElapsedTime() <<
"s"<<std::endl;
123 int ret = solver->Iterate(max_iters,
tol);
126 solver->DestroyPreconditioner();
129 int actual_iters = (int)solver->GetAztecStatus()[AZ_its];
131 if (Comm.MyPID() == 0) {
132 std::cout <<
"Converged in " << actual_iters <<
" iterations." << std::endl;
135 if (problem->GetLHS()->NumVectors() > 1) {
136 throw std::runtime_error(
"ERROR: MultiVector->NumVectors()>1.");
139 Epetra_MultiVector* x = problem->GetLHS();
140 Epetra_MultiVector* b = problem->GetRHS();
141 Epetra_Operator* A = problem->GetOperator();
142 Teuchos::RCP<Epetra_MultiVector> r = Teuchos::rcp(
new Epetra_MultiVector(*b));
144 r->Update(1.0, *b, -1.0);
148 if (Comm.MyPID() == 0) {
149 std::cout <<
"2-Norm of residual vec: " << norm << std::endl;
157 Epetra_Operator* prec = solver->GetPrecOperator();
163 if (test_params.isParameter(
"expectNumIters")) {
164 int expected_iters = 0;
167 if (ret == 0 && actual_iters <= expected_iters && norm < eps) {
168 if (Comm.MyPID() == 0) {
169 std::cout <<
"End Result: TEST PASSED" << std::endl;
173 if (Comm.MyPID() == 0) {
174 std::cout <<
"Actual iters("<<actual_iters
175 <<
") > expected number of iterations (" 176 <<expected_iters<<
"), or resid-norm(" << norm <<
") >= "<<eps <<std::endl;
182 if (Comm.MyPID() == 0) {
183 std::cout <<
"proc 0 total program time: " << timer.totalElapsedTime() << std::endl;
191 Teuchos::CommandLineProcessor cmdp(
false,
true);
192 cmdp.setOption(
"xml_file", &xml_file,
"XML Parameters file");
193 if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
194 throw std::runtime_error(
"Error parsing command-line.");
void process_command_line(int argc, char *argv[], std::string &xml_file)
int main(int argc, char *argv[])
void GetParameter(const Teuchos::ParameterList ¶ms, const std::string &name, T &value)
Set a value from a ParameterList if a parameter with the specified name exists.
Teuchos::RCP< Epetra_LinearProblem > build_problem(Teuchos::ParameterList &test_params, const Epetra_Comm &comm)
Teuchos::RCP< AztecOO > build_solver(Teuchos::ParameterList &test_params, Teuchos::RCP< Epetra_LinearProblem > problem)