Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
build_problem.cpp
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ***********************************************************************
4 //
5 // Ifpack: Object-Oriented Algebraic Preconditioner Package
6 // Copyright (2002) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //@HEADER
42 */
43 
44 
45 #include <string>
46 #include <sstream>
47 #include <iostream>
48 
49 #include "Teuchos_ParameterList.hpp"
50 #include "Teuchos_RefCountPtr.hpp"
51 #include "Teuchos_Time.hpp"
52 #include "Teuchos_Comm.hpp"
53 
54 #include "Epetra_Comm.h"
55 #include "Epetra_Map.h"
56 #include "Epetra_MultiVector.h"
57 #include "Epetra_RowMatrix.h"
58 #include "Epetra_CrsMatrix.h"
59 #include "Epetra_LinearProblem.h"
60 
61 #include "ParameterHelper.hpp"
62 #include "read_matrix.hpp"
63 
65 {
66  const Epetra_Map& rowmap = A->RowMap();
67 
68  Epetra_MultiVector* x = new Epetra_MultiVector(rowmap, 1);
69  if (b == NULL) {
70 std::cout << "creating b = A*random" << std::endl;
71  b = new Epetra_MultiVector(rowmap, 1);
72  x->Random();
73 
74  A->Apply(*x, *b);
75  }
76  x->PutScalar(0);
77 
79 
80  return problem;
81 }
82 
85  const Epetra_Comm& comm)
86 {
87  Teuchos::Time timer("build_problem");
88  timer.start();
89 
91  Epetra_Vector* b = NULL;
92 
93  std::string mm_file("not specified");
94  std::string rhs_mm_file("not specified");
95  helper::GetParameter(test_params, "mm_file", mm_file);
96  helper::GetParameter(test_params, "rhs_mm_file", rhs_mm_file);
97  std::string hb_file("not specified");
98  helper::GetParameter(test_params, "hb_file", hb_file);
99 
100  if (mm_file != "not specified") {
101  if (comm.MyPID() == 0) {
102  std::cout << "Matrix-Market file: " << mm_file << std::endl;
103  }
104  A = read_matrix_mm(mm_file, comm);
105  if (rhs_mm_file != "not specified") {
106  if (comm.MyPID() == 0) {
107  std::cout << "Matrix-Market file: " << rhs_mm_file << std::endl;
108  }
109  b = read_vector_mm(rhs_mm_file, comm);
110  }
111  }
112  else if (hb_file != "not specified") {
113  read_matrix_hb(hb_file, comm, A, b);
114  }
115  else {
116  throw std::runtime_error("No matrix file specified.");
117  }
118 
119  Teuchos::RCP<Epetra_LinearProblem> problem = build_problem_mm(test_params, A, b);
120  timer.stop();
121  if (comm.MyPID() == 0) {
122  std::cout << "proc 0 time to read matrix & create problem: " << timer.totalElapsedTime()
123  << std::endl;
124  }
125 
126  return problem;
127 }
128 
void read_matrix_hb(const std::string &hb_file, const Epetra_Comm &Comm, Epetra_CrsMatrix *&A, Epetra_Vector *&b)
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
virtual int MyPID() const =0
const Epetra_Map & RowMap() const
void start(bool reset=false)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
double stop()
void GetParameter(const Teuchos::ParameterList &params, const std::string &name, T &value)
Set a value from a ParameterList if a parameter with the specified name exists.
double totalElapsedTime(bool readCurrentTime=false) const
Teuchos::RCP< Epetra_LinearProblem > build_problem(Teuchos::ParameterList &test_params, const Epetra_Comm &comm)
Epetra_Vector * read_vector_mm(const std::string &mm_file, const Epetra_Comm &comm)
Epetra_CrsMatrix * read_matrix_mm(const std::string &mm_file, const Epetra_Comm &comm)
Definition: read_matrix.cpp:54
Teuchos::RCP< Epetra_LinearProblem > build_problem_mm(Teuchos::ParameterList &test_params, Epetra_CrsMatrix *A, Epetra_MultiVector *b)