45 #include <Teuchos_oblackholestream.hpp> 49 #include "Tpetra_Power_Method.hpp" 51 #include "Tpetra_DefaultPlatform.hpp" 52 #include "Tpetra_Version.hpp" 53 #include "Tpetra_Map.hpp" 54 #include "Tpetra_MultiVector.hpp" 55 #include "Tpetra_Vector.hpp" 56 #include "Tpetra_CrsMatrix.hpp" 61 int main(
int argc,
char *argv[]) {
68 typedef double Scalar;
78 using Teuchos::getFancyOStream;
80 using Teuchos::rcpFromRef;
90 RCP<const Teuchos::Comm<int> > comm = platform.getComm();
91 RCP<Node> node = platform.getNode();
92 const int myRank = comm->getRank();
97 bool printMatrix =
false;
98 bool verbose = (myRank==0);
100 int numGlobalElements = 100;
101 Magnitude tolerance = 1.0e-2;
103 cmdp.setOption (
"verbose",
"quiet", &verbose,
"Print messages and results.");
104 cmdp.setOption (
"numGlobalElements", &numGlobalElements,
105 "Global problem size.");
106 cmdp.setOption (
"tolerance", &tolerance,
107 "Relative residual tolerance used for solver.");
108 cmdp.setOption (
"iterations", &niters,
"Maximum number of iterations.");
109 cmdp.setOption (
"printMatrix",
"noPrintMatrix", &printMatrix,
110 "Print the full matrix after reading it.");
119 cout << endl << Tpetra::version() << endl << endl;
121 cout <<
"Comm info: " << *comm;
127 RCP<const Map> map = Tpetra::createUniformContigMap<Ordinal,Ordinal> (numGlobalElements, comm);
129 const size_type numMyElements = as<size_type> (map->getNodeNumElements ());
130 ArrayView<const Ordinal> myGlobalElements = map->getNodeElementList ();
132 RCP<CrsMatrix> A = Tpetra::createCrsMatrix<Scalar> (map, 3);
134 for (size_type i = 0; i < numMyElements; ++i) {
137 if (myGlobalElements[i] == 0) {
138 A->insertGlobalValues (myGlobalElements[i],
139 tuple<Ordinal> (myGlobalElements[i], myGlobalElements[i]+1),
140 tuple<Scalar> (2.0, -1.0));
142 else if (myGlobalElements[i] == numGlobalElements-1) {
143 A->insertGlobalValues (myGlobalElements[i],
144 tuple<Ordinal> (myGlobalElements[i]-1, myGlobalElements[i]),
145 tuple<Scalar> (-1.0, 2.0));
148 A->insertGlobalValues (myGlobalElements[i],
149 tuple<Ordinal> (myGlobalElements[i]-1,
151 myGlobalElements[i]+1),
152 tuple<Scalar> (-1.0, 2.0, -1.0));
160 RCP<Teuchos::FancyOStream> fos = fancyOStream (rcpFromRef (cout));
164 cout << endl << A->description() << endl << endl;
170 TpetraExamples::powerMethod<Scalar,Ordinal> (A, niters, tolerance, verbose);
174 cout << endl <<
"Increasing magnitude of first diagonal term, solving again" 183 if (A->getRowMap ()->isNodeGlobalElement (0)) {
188 size_t numVals = A->getNumEntriesInGlobalRow (0);
189 Array<Scalar> rowVals (as<size_type> (numVals));
190 Array<Ordinal> rowInds (as<size_type> (numVals));
197 A->getGlobalRowCopy (0, rowInds (), rowVals (), numVals);
199 for (size_type k = 0; k < as<size_type> (numVals); ++k) {
200 if (rowInds[k] == 0) {
201 rowVals[k] = as<Scalar> (10.0);
204 A->replaceGlobalValues (0, rowInds (), rowVals ());
212 TpetraExamples::powerMethod<Scalar,Ordinal> (A, niters, tolerance, verbose);
215 cout << endl <<
"End Result: TEST PASSED" << endl;
Sparse matrix that presents a compressed sparse row interface.
Describes a parallel distribution of objects over processes.
TypeTo as(const TypeFrom &t)