Belos Package Browser (Single Doxygen Collection) Development
test_belos_projected_least_squares_solver.cpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 //
00004 //                 Belos: Block Linear Solvers Package
00005 //                  Copyright 2004 Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ************************************************************************
00040 //@HEADER
00041 
00042 #include <BelosProjectedLeastSquaresSolver.hpp>
00043 #include <Teuchos_DefaultComm.hpp>
00044 #include <Teuchos_CommandLineProcessor.hpp>
00045 #include <Teuchos_GlobalMPISession.hpp>
00046 #include <Teuchos_oblackholestream.hpp>
00047 #include <Teuchos_ParameterList.hpp>
00048 
00049 int 
00050 main (int argc, char *argv[]) 
00051 {
00052   using Belos::details::ERobustness;
00053   using Belos::details::ProjectedLeastSquaresSolver;
00054   using Belos::details::robustnessEnumToString;
00055   using Belos::details::robustnessStringToEnum;
00056   using Teuchos::CommandLineProcessor;
00057   using Teuchos::RCP;
00058   using Teuchos::rcp;
00059   using std::endl;
00060 
00061   typedef double scalar_type;
00062   typedef Teuchos::ScalarTraits<scalar_type> STS;
00063   typedef Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00064   typedef Teuchos::ScalarTraits<magnitude_type> STM;
00065 
00066   Teuchos::oblackholestream blackHole;
00067   // Initialize MPI using Teuchos wrappers, if Trilinos was built with
00068   // MPI support.  Otherwise, initialize a communicator with one
00069   // process.
00070   Teuchos::GlobalMPISession mpiSession (&argc, &argv, &blackHole);
00071   const int myRank = mpiSession.getRank();
00072   // Output stream only prints on MPI Proc 0.
00073   std::ostream& out = (myRank == 0) ? std::cout : blackHole;
00074   
00075   // Command-line arguments
00076   std::string robustnessLevel ("None");
00077   bool testBlockGivens = false;
00078   bool testGivensRotations = false;
00079   bool verbose = false;
00080   bool debug = false;
00081   int testProblemSize = 10;
00082 
00083   // Parse command-line arguments
00084   CommandLineProcessor cmdp (false,true);
00085   cmdp.setOption ("robustness", &robustnessLevel,
00086       "Robustness level: \"None\", \"Some\", or \"Lots\".");
00087   cmdp.setOption ("testGivensRotations", "dontTestGivensRotations", 
00088       &testGivensRotations, 
00089       "Test the implementation of Givens rotations.");
00090   cmdp.setOption ("testBlockGivens", "dontTestBlockGivens", &testBlockGivens,
00091       "Test the panel version of the Givens rotations - based "
00092       "update.");
00093   cmdp.setOption ("verbose", "quiet", &verbose, "Print messages and results.");
00094   cmdp.setOption ("debug", "release", &debug, "Print copious debug output.");
00095   cmdp.setOption ("testProblemSize", &testProblemSize, 
00096       "Number of columns in the projected least-squares test "
00097       "problem.");
00098   if (cmdp.parse (argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
00099     out << "End Result: TEST FAILED" << endl;
00100     return EXIT_FAILURE;
00101   }
00102   // Verbose output stream only prints on MPI Proc 0, and only in
00103   // verbose mode.
00104   std::ostream& verboseOut = verbose ? out : blackHole;
00105 
00106   // Robustness level for triangular solves.
00107   const ERobustness robustness = robustnessStringToEnum (robustnessLevel);
00108   verboseOut << "-- Robustness level: " << robustnessLevel << endl;
00109 
00110   bool success = true; // Innocent until proven guilty.
00111 
00112   // Seed the pseudorandom number generator with the same seed each
00113   // time, to ensure repeatable results.
00114   STS::seedrandom (0);
00115   ProjectedLeastSquaresSolver<scalar_type> solver (out, robustness);
00116 
00117   if (testGivensRotations) {
00118     solver.testGivensRotations (verboseOut);
00119   }
00120   if (testProblemSize > 0) {
00121     const bool extraVerbose = debug;
00122     success = success && 
00123       solver.testUpdateColumn (verboseOut, testProblemSize, 
00124              testBlockGivens, extraVerbose);
00125     success = success &&
00126       solver.testTriangularSolves (verboseOut, testProblemSize, 
00127            robustness, extraVerbose);
00128   }
00129 
00130   if (success) {
00131     out << "End Result: TEST PASSED" << endl;  
00132     return EXIT_SUCCESS;
00133   } else {
00134     out << "End Result: TEST FAILED" << endl;
00135     return EXIT_FAILURE;
00136   }
00137 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines