Ifpack Package Browser (Single Doxygen Collection) Development
build_problem.cpp
Go to the documentation of this file.
00001 
00002 #include <string>
00003 #include <sstream>
00004 #include <iostream>
00005 
00006 #include "Teuchos_ParameterList.hpp"
00007 #include "Teuchos_RefCountPtr.hpp"
00008 #include "Teuchos_Time.hpp"
00009 #include "Teuchos_Comm.hpp"
00010 
00011 #include "Epetra_Comm.h"
00012 #include "Epetra_Map.h"
00013 #include "Epetra_MultiVector.h"
00014 #include "Epetra_RowMatrix.h"
00015 #include "Epetra_CrsMatrix.h"
00016 #include "Epetra_LinearProblem.h"
00017 
00018 #include "ParameterHelper.hpp"
00019 #include "read_matrix.hpp"
00020 
00021 Teuchos::RCP<Epetra_LinearProblem> build_problem_mm(Teuchos::ParameterList& test_params, Epetra_CrsMatrix* A, Epetra_MultiVector* b)
00022 {
00023   const Epetra_Map& rowmap = A->RowMap();
00024 
00025   Epetra_MultiVector* x = new Epetra_MultiVector(rowmap, 1);
00026   if (b == NULL) {
00027 std::cout << "creating b = A*random" << std::endl;
00028     b = new Epetra_MultiVector(rowmap, 1);
00029     x->Random();
00030 
00031     A->Apply(*x, *b);
00032   }
00033   x->PutScalar(0);
00034 
00035   Teuchos::RCP<Epetra_LinearProblem> problem = Teuchos::rcp(new Epetra_LinearProblem(A,x,b));
00036 
00037   return problem;
00038 }
00039 
00040 Teuchos::RCP< Epetra_LinearProblem >
00041 build_problem(Teuchos::ParameterList& test_params,
00042               const Epetra_Comm& comm)
00043 {
00044   Teuchos::Time timer("build_problem");
00045   timer.start();
00046 
00047   Epetra_CrsMatrix* A;
00048   Epetra_Vector* b = NULL;
00049 
00050   std::string mm_file("not specified");
00051   std::string rhs_mm_file("not specified");
00052   helper::GetParameter(test_params, "mm_file", mm_file);
00053   helper::GetParameter(test_params, "rhs_mm_file", rhs_mm_file);
00054   std::string hb_file("not specified");
00055   helper::GetParameter(test_params, "hb_file", hb_file);
00056 
00057   if (mm_file != "not specified") {
00058     if (comm.MyPID() == 0) {
00059       std::cout << "Matrix-Market file: " << mm_file << std::endl;
00060     }
00061     A = read_matrix_mm(mm_file, comm);
00062     if (rhs_mm_file != "not specified") {
00063       if (comm.MyPID() == 0) {
00064         std::cout << "Matrix-Market file: " << rhs_mm_file << std::endl;
00065       }
00066       b = read_vector_mm(rhs_mm_file, comm);
00067     }
00068   }
00069   else if (hb_file != "not specified") {
00070     read_matrix_hb(hb_file, comm, A, b);
00071   }
00072   else {
00073     throw std::runtime_error("No matrix file specified.");
00074   }
00075 
00076   Teuchos::RCP<Epetra_LinearProblem> problem = build_problem_mm(test_params, A, b);
00077   timer.stop();
00078   if (comm.MyPID() == 0) {
00079     std::cout << "proc 0 time to read matrix & create problem: " << timer.totalElapsedTime()
00080       << std::endl;
00081   }
00082 
00083   return problem;
00084 }
00085 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines