|
Tpetra Matrix/Vector Services Version of the Day
|
00001 #include <Teuchos_GlobalMPISession.hpp> 00002 #include <Teuchos_oblackholestream.hpp> 00003 #include <Teuchos_CommandLineProcessor.hpp> 00004 #include <Teuchos_Array.hpp> 00005 00006 // I/O for Harwell-Boeing files 00007 #include <Tpetra_MatrixIO.hpp> 00008 00009 #include "Tpetra_Power_Method.hpp" 00010 00011 #include "Tpetra_DefaultPlatform.hpp" 00012 #include "Tpetra_Version.hpp" 00013 #include "Tpetra_Map.hpp" 00014 #include "Tpetra_MultiVector.hpp" 00015 #include "Tpetra_Vector.hpp" 00016 #include "Tpetra_CrsMatrix.hpp" 00017 00018 int main(int argc, char *argv[]) { 00019 Teuchos::oblackholestream blackhole; 00020 Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole); 00021 00022 // 00023 // Specify types used in this example 00024 // 00025 typedef double Scalar; 00026 typedef Teuchos::ScalarTraits<Scalar>::magnitudeType Magnitude; 00027 typedef int Ordinal; 00028 typedef Tpetra::DefaultPlatform::DefaultPlatformType Platform; 00029 typedef Tpetra::DefaultPlatform::DefaultPlatformType::NodeType Node; 00030 00031 // 00032 // Get the default communicator and node 00033 // 00034 Platform &platform = Tpetra::DefaultPlatform::getDefaultPlatform(); 00035 Teuchos::RCP<const Teuchos::Comm<int> > comm = platform.getComm(); 00036 Teuchos::RCP<Node> node = platform.getNode(); 00037 const int myRank = comm->getRank(); 00038 00039 // 00040 // Get example parameters from command-line processor 00041 // 00042 bool printMatrix = false; 00043 bool verbose = (myRank==0); 00044 int niters = 100; 00045 Magnitude tolerance = 1.0e-2; 00046 std::string filename("bcsstk14.hb"); 00047 Teuchos::CommandLineProcessor cmdp(false,true); 00048 cmdp.setOption("verbose","quiet",&verbose,"Print messages and results."); 00049 cmdp.setOption("filename",&filename,"Filename for Harwell-Boeing test matrix."); 00050 cmdp.setOption("tolerance",&tolerance,"Relative residual tolerance used for solver."); 00051 cmdp.setOption("iterations",&niters,"Maximum number of iterations."); 00052 cmdp.setOption("printMatrix","noPrintMatrix",&printMatrix,"Print the full matrix after reading it."); 00053 if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) { 00054 return -1; 00055 } 00056 00057 // 00058 // Say hello, print some communicator info 00059 // 00060 if (verbose) { 00061 std::cout << "\n" << Tpetra::version() << std::endl << std::endl; 00062 } 00063 std::cout << "Comm info: " << *comm; 00064 00065 // 00066 // Read Tpetra::CrsMatrix from file 00067 // 00068 Teuchos::RCP< Tpetra::CrsMatrix<Scalar,Ordinal> > A; 00069 Tpetra::Utils::readHBMatrix(filename,comm,node,A); 00070 if (printMatrix) { 00071 Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); 00072 A->describe(*fos, Teuchos::VERB_EXTREME); 00073 } 00074 else if (verbose) { 00075 std::cout << std::endl << A->description() << std::endl << std::endl; 00076 } 00077 00078 // 00079 // Iterate 00080 // 00081 Scalar lambda; 00082 lambda = TpetraExamples::powerMethod<Scalar,Ordinal>(A, niters, tolerance, verbose); 00083 00084 if (verbose) { 00085 std::cout << "\nEnd Result: TEST PASSED" << std::endl; 00086 } 00087 return 0; 00088 }
1.7.4