17 #include "Tpetra_Core.hpp"
18 #include "Tpetra_Map.hpp"
19 #include "Tpetra_Vector.hpp"
20 #include "Tpetra_CrsGraph.hpp"
21 #include "Tpetra_CrsMatrix.hpp"
25 #ifdef HAVE_STOKHOS_BELOS
26 #include "BelosTpetraAdapter.hpp"
27 #include "BelosLinearProblem.hpp"
28 #include "BelosPseudoBlockGmresSolMgr.hpp"
43 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
44 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
45 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
46 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
50 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
51 RCP<const Tpetra_Map> map =
52 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
54 RCP<Tpetra_CrsGraph> graph =
55 rcp(
new Tpetra_CrsGraph(map,
size_t(2)));
56 Array<GlobalOrdinal> columnIndices(2);
57 ArrayView<const GlobalOrdinal> myGIDs = map->getLocalElementList();
58 const size_t num_my_row = myGIDs.size();
59 for (
size_t i=0; i<num_my_row; ++i) {
61 columnIndices[0] = row;
68 graph->insertGlobalIndices(row, columnIndices(0,ncol));
70 graph->fillComplete();
71 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
74 Array<Scalar> vals(2);
75 for (
size_t i=0; i<num_my_row; ++i) {
77 columnIndices[0] = row;
86 matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
88 matrix->fillComplete();
91 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
94 matrix->describe(*(Teuchos::fancyOStream(
rcp(&std::cout,
false))),
97 x->describe(*(Teuchos::fancyOStream(
rcp(&std::cout,
false))),
101 RCP<Tpetra_Vector> y = Tpetra::createVector<Scalar>(map);
102 matrix->apply(*x, *y);
104 y->describe(*(Teuchos::fancyOStream(
rcp(&std::cout,
false))),
108 auto y_view = y->getLocalViewHost(Tpetra::Access::ReadOnly);
109 for (
size_t i=0; i<num_my_row; ++i) {
120 #if defined(HAVE_STOKHOS_BELOS)
138 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
139 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
140 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
141 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
145 RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
146 RCP<const Tpetra_Map> map =
147 Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
149 RCP<Tpetra_CrsGraph> graph =
150 rcp(
new Tpetra_CrsGraph(map,
size_t(2)));
151 Array<GlobalOrdinal> columnIndices(2);
152 ArrayView<const GlobalOrdinal> myGIDs = map->getLocalElementList();
153 const size_t num_my_row = myGIDs.size();
154 for (
size_t i=0; i<num_my_row; ++i) {
156 columnIndices[0] = row;
162 graph->insertGlobalIndices(row, columnIndices(0,ncol));
164 graph->fillComplete();
165 RCP<Tpetra_CrsMatrix> matrix =
rcp(
new Tpetra_CrsMatrix(graph));
168 Array<Scalar> vals(2);
169 for (
size_t i=0; i<num_my_row; ++i) {
171 columnIndices[0] = row;
180 matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
182 matrix->fillComplete();
185 RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
187 auto b_view = b->getLocalViewHost(Tpetra::Access::OverwriteAll);
188 for (
size_t i=0; i<num_my_row; ++i) {
189 b_view(i, 0) =
Scalar(1.0);
195 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
196 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
197 typedef Belos::LinearProblem<Scalar,MV,OP> BLinProb;
198 RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
199 RCP< BLinProb > problem =
rcp(
new BLinProb(matrix, x, b));
200 RCP<ParameterList> belosParams =
rcp(
new ParameterList);
201 typename ST::magnitudeType tol = 1e-9;
202 belosParams->set(
"Flexible Gmres",
false);
203 belosParams->set(
"Num Blocks", 100);
204 belosParams->set(
"Convergence Tolerance",
Scalar(tol));
205 belosParams->set(
"Maximum Iterations", 100);
206 belosParams->set(
"Verbosity", 33);
207 belosParams->set(
"Output Style", 1);
208 belosParams->set(
"Output Frequency", 1);
209 belosParams->set(
"Output Stream", out.getOStream());
210 RCP<Belos::SolverManager<Scalar,MV,OP> > solver =
211 rcp(
new Belos::PseudoBlockGmresSolMgr<Scalar,MV,OP>(problem, belosParams));
212 problem->setProblem();
213 Belos::ReturnType ret = solver->solve();
225 auto x_view = x->getLocalViewHost(Tpetra::Access::ReadOnly);
227 for (
size_t i=0; i<num_my_row; ++i) {
237 if (ST::magnitude(v) < tol)
255 Tpetra_CrsMatrix, MatVec,
double,
Node )
#define TEST_EQUALITY_CONST(v1, v2)
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_SG_SpMv, CrsProductTensorCijk, Scalar, Device)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
int main(int argc, char **argv)
TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT(Tpetra_CrsMatrix, MatVec, double, Node) TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT(Tpetra_CrsMatrix
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType Node
#define TEST_EQUALITY(v1, v2)