Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Tpetra_Power_Method_From_File.cpp
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Tpetra: Templated Linear Algebra Services Package
6 // Copyright (2008) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
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 #include <Teuchos_GlobalMPISession.hpp>
45 #include <Teuchos_oblackholestream.hpp>
46 #include <Teuchos_CommandLineProcessor.hpp>
47 #include <Teuchos_Array.hpp>
48 
49 // I/O for Harwell-Boeing files
50 #include <Tpetra_MatrixIO.hpp>
51 
52 #include "Tpetra_Power_Method.hpp"
53 
54 #include "Tpetra_DefaultPlatform.hpp"
55 #include "Tpetra_Version.hpp"
56 #include "Tpetra_Map.hpp"
57 #include "Tpetra_MultiVector.hpp"
58 #include "Tpetra_Vector.hpp"
59 #include "Tpetra_CrsMatrix.hpp"
60 
61 int main(int argc, char *argv[]) {
62  Teuchos::oblackholestream blackhole;
63  Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);
64 
65  //
66  // Specify types used in this example
67  //
68  typedef double Scalar;
69  typedef Teuchos::ScalarTraits<Scalar>::magnitudeType Magnitude;
70  typedef int Ordinal;
74  using Teuchos::RCP;
75  using Teuchos::tuple;
76 
77  //
78  // Get the default communicator and node
79  //
80  Platform &platform = Tpetra::DefaultPlatform::getDefaultPlatform();
81  RCP<const Teuchos::Comm<int> > comm = platform.getComm();
82  RCP<Node> node = platform.getNode();
83  const int myRank = comm->getRank();
84 
85  //
86  // Get example parameters from command-line processor
87  //
88  bool printMatrix = false;
89  bool verbose = (myRank==0);
90  int niters = 100;
91  Magnitude tolerance = 1.0e-2;
92  std::string filename("bcsstk14.hb");
93  Teuchos::CommandLineProcessor cmdp(false,true);
94  cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
95  cmdp.setOption("filename",&filename,"Filename for Harwell-Boeing test matrix.");
96  cmdp.setOption("tolerance",&tolerance,"Relative residual tolerance used for solver.");
97  cmdp.setOption("iterations",&niters,"Maximum number of iterations.");
98  cmdp.setOption("printMatrix","noPrintMatrix",&printMatrix,"Print the full matrix after reading it.");
99  if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
100  return -1;
101  }
102 
103  //
104  // Say hello, print some communicator info
105  //
106  if (verbose) {
107  std::cout << "\n" << Tpetra::version() << std::endl << std::endl;
108  }
109  std::cout << "Comm info: " << *comm;
110 
111  //
112  // Read Tpetra::CrsMatrix from file
113  //
114  RCP<CrsMatrix> A;
115  Tpetra::Utils::readHBMatrix(filename,comm,node,A);
116  if (printMatrix) {
117  RCP<Teuchos::FancyOStream> fos = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
118  A->describe(*fos, Teuchos::VERB_EXTREME);
119  }
120  else if (verbose) {
121  std::cout << std::endl << A->description() << std::endl << std::endl;
122  }
123 
124  //
125  // Iterate
126  //
127  TpetraExamples::powerMethod<Scalar,Ordinal>(A, niters, tolerance, verbose);
128 
129  if (verbose) {
130  std::cout << "\nEnd Result: TEST PASSED" << std::endl;
131  }
132  return 0;
133 }
Sparse matrix that presents a compressed sparse row interface.
Kokkos::DefaultNode::DefaultNodeType NodeType
Kokkos Node type; the template parameter of this class.
SerialPlatform specialization for Kokkos::DefaultNode::DefaultNodeType.
static DefaultPlatformType & getDefaultPlatform()
Return the default platform.