Belos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_belos_projected_least_squares_solver.cpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
43 #include <Teuchos_DefaultComm.hpp>
48 
49 int
50 main (int argc, char *argv[])
51 {
57  using Teuchos::RCP;
58  using Teuchos::rcp;
59  using std::endl;
60 
61  typedef double scalar_type;
65 
66  Teuchos::oblackholestream blackHole;
67  // Initialize MPI using Teuchos wrappers, if Trilinos was built with
68  // MPI support. Otherwise, initialize a communicator with one
69  // process.
70  Teuchos::GlobalMPISession mpiSession (&argc, &argv, &blackHole);
71  const int myRank = mpiSession.getRank();
72  // Output stream only prints on MPI Proc 0.
73  std::ostream& out = (myRank == 0) ? std::cout : blackHole;
74 
75  // Command-line arguments
76  std::string robustnessLevel ("None");
77  bool testBlockGivens = false;
78  bool testGivensRotations = false;
79  bool verbose = false;
80  bool debug = false;
81  int testProblemSize = 10;
82 
83  // Parse command-line arguments
84  CommandLineProcessor cmdp (false,true);
85  cmdp.setOption ("robustness", &robustnessLevel,
86  "Robustness level: \"None\", \"Some\", or \"Lots\".");
87  cmdp.setOption ("testGivensRotations", "dontTestGivensRotations",
88  &testGivensRotations,
89  "Test the implementation of Givens rotations.");
90  cmdp.setOption ("testBlockGivens", "dontTestBlockGivens", &testBlockGivens,
91  "Test the panel version of the Givens rotations - based "
92  "update.");
93  cmdp.setOption ("verbose", "quiet", &verbose, "Print messages and results.");
94  cmdp.setOption ("debug", "release", &debug, "Print copious debug output.");
95  cmdp.setOption ("testProblemSize", &testProblemSize,
96  "Number of columns in the projected least-squares test "
97  "problem.");
98  if (cmdp.parse (argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
99  out << "End Result: TEST FAILED" << endl;
100  return EXIT_FAILURE;
101  }
102  // Verbose output stream only prints on MPI Proc 0, and only in
103  // verbose mode.
104  std::ostream& verboseOut = verbose ? out : blackHole;
105 
106  // Robustness level for triangular solves.
107  const ERobustness robustness = robustnessStringToEnum (robustnessLevel);
108  verboseOut << "-- Robustness level: " << robustnessLevel << endl;
109 
110  bool success = true; // Innocent until proven guilty.
111 
112  // Seed the pseudorandom number generator with the same seed each
113  // time, to ensure repeatable results.
114  STS::seedrandom (0);
115  ProjectedLeastSquaresSolver<scalar_type> solver (out, robustness);
116 
117  if (testGivensRotations) {
118  solver.testGivensRotations (verboseOut);
119  }
120  if (testProblemSize > 0) {
121  const bool extraVerbose = debug;
122  success = success &&
123  solver.testUpdateColumn (verboseOut, testProblemSize,
124  testBlockGivens, extraVerbose);
125  success = success &&
126  solver.testTriangularSolves (verboseOut, testProblemSize,
127  robustness, extraVerbose);
128  }
129 
130  if (success) {
131  out << "End Result: TEST PASSED" << endl;
132  return EXIT_SUCCESS;
133  } else {
134  out << "End Result: TEST FAILED" << endl;
135  return EXIT_FAILURE;
136  }
137 }
int main(int argc, char *argv[])
std::string robustnessEnumToString(const ERobustness x)
Convert the given ERobustness enum value to a string.
ERobustness robustnessStringToEnum(const std::string &x)
Convert the given robustness string value to an ERobustness enum.
Methods for solving GMRES&#39; projected least-squares problem.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
ERobustness
Robustness level of projected least-squares solver operations.
Methods for solving GMRES&#39; projected least-squares problem.