Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_TpetraCrsMatrixMPVectorUnitTest.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
44 #include "Stokhos_Ensemble_Sizes.hpp"
45 
46 // Teuchos
48 
49 // Tpetra
52 #include "Tpetra_Core.hpp"
53 #include "Tpetra_Map.hpp"
54 #include "Tpetra_MultiVector.hpp"
55 #include "Tpetra_Vector.hpp"
56 #include "Tpetra_CrsGraph.hpp"
57 #include "Tpetra_CrsMatrix.hpp"
58 #include "Stokhos_Tpetra_CG.hpp"
59 
60 // Belos solver
61 #ifdef HAVE_STOKHOS_BELOS
63 #include "BelosLinearProblem.hpp"
64 #include "BelosPseudoBlockGmresSolMgr.hpp"
65 #include "BelosPseudoBlockCGSolMgr.hpp"
66 #endif
67 
68 // Ifpack2 preconditioner
69 #ifdef HAVE_STOKHOS_IFPACK2
71 #include "Ifpack2_Factory.hpp"
72 #endif
73 
74 // MueLu preconditioner
75 #ifdef HAVE_STOKHOS_MUELU
77 #include "MueLu_CreateTpetraPreconditioner.hpp"
78 #endif
79 
80 // Amesos2 solver
81 #ifdef HAVE_STOKHOS_AMESOS2
83 #include "Amesos2_Factory.hpp"
84 #endif
85 
86 template <typename scalar, typename ordinal>
87 inline
88 scalar generate_vector_coefficient( const ordinal nFEM,
89  const ordinal nStoch,
90  const ordinal iColFEM,
91  const ordinal iStoch )
92 {
93  const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
94  const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
95  return X_fem + X_stoch;
96  //return 1.0;
97 }
98 
99 template <typename scalar, typename ordinal>
100 inline
101 scalar generate_multi_vector_coefficient( const ordinal nFEM,
102  const ordinal nVec,
103  const ordinal nStoch,
104  const ordinal iColFEM,
105  const ordinal iVec,
106  const ordinal iStoch)
107 {
108  const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
109  const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
110  const scalar X_col = 0.01 + scalar(iVec) / scalar(nVec);
111  return X_fem + X_stoch + X_col;
112  //return 1.0;
113 }
114 
115 //
116 // Tests
117 //
118 
119 const int VectorSize = STOKHOS_DEFAULT_ENSEMBLE_SIZE;
120 
121 //
122 // Test vector addition
123 //
125  Tpetra_CrsMatrix_MP, VectorAdd, Storage, LocalOrdinal, GlobalOrdinal, Node )
126 {
127  using Teuchos::RCP;
128  using Teuchos::rcp;
129  using Teuchos::ArrayView;
130  using Teuchos::Array;
131  using Teuchos::ArrayRCP;
132 
133  typedef typename Storage::value_type BaseScalar;
135 
136  typedef Teuchos::Comm<int> Tpetra_Comm;
137  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
138  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
139 
140  // Ensure device is initialized
141  if ( !Kokkos::is_initialized() )
142  Kokkos::initialize();
143 
144  // Comm
145  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
146 
147  // Map
148  GlobalOrdinal nrow = 10;
149  RCP<const Tpetra_Map> map =
150  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
151  nrow, comm);
152  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
153  const size_t num_my_row = myGIDs.size();
154 
155  // Fill vectors
156  RCP<Tpetra_Vector> x1 = Tpetra::createVector<Scalar>(map);
157  RCP<Tpetra_Vector> x2 = Tpetra::createVector<Scalar>(map);
158  ArrayRCP<Scalar> x1_view = x1->get1dViewNonConst();
159  ArrayRCP<Scalar> x2_view = x2->get1dViewNonConst();
160  Scalar val1(VectorSize, BaseScalar(0.0)), val2(VectorSize, BaseScalar(0.0));
161  for (size_t i=0; i<num_my_row; ++i) {
162  const GlobalOrdinal row = myGIDs[i];
163  for (LocalOrdinal j=0; j<VectorSize; ++j) {
164  val1.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(nrow, VectorSize, row, j);
165  val2.fastAccessCoeff(j) = 0.12345 * generate_vector_coefficient<BaseScalar,size_t>(nrow, VectorSize, row, j);
166  }
167  x1_view[i] = val1;
168  x2_view[i] = val2;
169  }
170  x1_view = Teuchos::null;
171  x2_view = Teuchos::null;
172 
173  // Add
174  Scalar alpha = 2.1;
175  Scalar beta = 3.7;
176  RCP<Tpetra_Vector> y = Tpetra::createVector<Scalar>(map);
177  y->update(alpha, *x1, beta, *x2, Scalar(0.0));
178 
179  // y->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
180  // Teuchos::VERB_EXTREME);
181 
182  // Check
183  ArrayRCP<Scalar> y_view = y->get1dViewNonConst();
184  Scalar val(VectorSize, BaseScalar(0.0));
185  BaseScalar tol = 1.0e-14;
186  for (size_t i=0; i<num_my_row; ++i) {
187  const GlobalOrdinal row = myGIDs[i];
188  for (LocalOrdinal j=0; j<VectorSize; ++j) {
189  BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
190  nrow, VectorSize, row, j);
191  val.fastAccessCoeff(j) = alpha.coeff(j)*v + 0.12345*beta.coeff(j)*v;
192  }
193  TEST_EQUALITY( y_view[i].size(), VectorSize );
194  for (LocalOrdinal j=0; j<VectorSize; ++j)
195  TEST_FLOATING_EQUALITY( y_view[i].fastAccessCoeff(j), val.fastAccessCoeff(j), tol );
196  }
197 }
198 
199 //
200 // Test vector dot product
201 //
203  Tpetra_CrsMatrix_MP, VectorDot, Storage, LocalOrdinal, GlobalOrdinal, Node )
204 {
205  using Teuchos::RCP;
206  using Teuchos::rcp;
207  using Teuchos::ArrayView;
208  using Teuchos::Array;
209  using Teuchos::ArrayRCP;
210 
211  typedef typename Storage::value_type BaseScalar;
213 
214  typedef Teuchos::Comm<int> Tpetra_Comm;
215  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
216  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
217  typedef typename Tpetra_Vector::dot_type dot_type;
218 
219  // Ensure device is initialized
220  if ( !Kokkos::is_initialized() )
221  Kokkos::initialize();
222 
223  // Comm
224  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
225 
226  // Map
227  GlobalOrdinal nrow = 10;
228  RCP<const Tpetra_Map> map =
229  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
230  nrow, comm);
231  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
232  const size_t num_my_row = myGIDs.size();
233 
234  // Fill vectors
235  RCP<Tpetra_Vector> x1 = Tpetra::createVector<Scalar>(map);
236  RCP<Tpetra_Vector> x2 = Tpetra::createVector<Scalar>(map);
237  ArrayRCP<Scalar> x1_view = x1->get1dViewNonConst();
238  ArrayRCP<Scalar> x2_view = x2->get1dViewNonConst();
239  Scalar val1(VectorSize, BaseScalar(0.0)), val2(VectorSize, BaseScalar(0.0));
240  for (size_t i=0; i<num_my_row; ++i) {
241  const GlobalOrdinal row = myGIDs[i];
242  for (LocalOrdinal j=0; j<VectorSize; ++j) {
243  val1.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(nrow, VectorSize, row, j);
244  val2.fastAccessCoeff(j) = 0.12345 * generate_vector_coefficient<BaseScalar,size_t>(nrow, VectorSize, row, j);
245  }
246  x1_view[i] = val1;
247  x2_view[i] = val2;
248  }
249  x1_view = Teuchos::null;
250  x2_view = Teuchos::null;
251 
252  // Dot product
253  dot_type dot = x1->dot(*x2);
254 
255  // Check
256 
257 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
258 
259  // Local contribution
260  dot_type local_val(0);
261  for (size_t i=0; i<num_my_row; ++i) {
262  const GlobalOrdinal row = myGIDs[i];
263  for (LocalOrdinal j=0; j<VectorSize; ++j) {
264  BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
265  nrow, VectorSize, row, j);
266  local_val += 0.12345 * v * v;
267  }
268  }
269 
270  // Global reduction
271  dot_type val(0);
272  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, local_val,
273  Teuchos::outArg(val));
274 
275 #else
276 
277  // Local contribution
278  dot_type local_val(VectorSize, 0.0);
279  for (size_t i=0; i<num_my_row; ++i) {
280  const GlobalOrdinal row = myGIDs[i];
281  for (LocalOrdinal j=0; j<VectorSize; ++j) {
282  BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
283  nrow, VectorSize, row, j);
284  local_val.fastAccessCoeff(j) += 0.12345 * v * v;
285  }
286  }
287 
288  // Global reduction
289  dot_type val(VectorSize, 0.0);
290  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, local_val,
291  Teuchos::outArg(val));
292 
293 #endif
294 
295  out << "dot = " << dot << " expected = " << val << std::endl;
296 
297  BaseScalar tol = 1.0e-14;
298  TEST_FLOATING_EQUALITY( dot, val, tol );
299 }
300 
301 //
302 // Test multi-vector addition
303 //
305  Tpetra_CrsMatrix_MP, MultiVectorAdd, Storage, LocalOrdinal, GlobalOrdinal, Node )
306 {
307  using Teuchos::RCP;
308  using Teuchos::rcp;
309  using Teuchos::ArrayView;
310  using Teuchos::Array;
311  using Teuchos::ArrayRCP;
312 
313  typedef typename Storage::value_type BaseScalar;
315 
316  typedef Teuchos::Comm<int> Tpetra_Comm;
317  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
318  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
319 
320  // Ensure device is initialized
321  if ( !Kokkos::is_initialized() )
322  Kokkos::initialize();
323 
324  // Comm
325  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
326 
327  // Map
328  GlobalOrdinal nrow = 10;
329  RCP<const Tpetra_Map> map =
330  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
331  nrow, comm);
332  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
333  const size_t num_my_row = myGIDs.size();
334 
335  // Fill vectors
336  size_t ncol = 5;
337  RCP<Tpetra_MultiVector> x1 = Tpetra::createMultiVector<Scalar>(map, ncol);
338  RCP<Tpetra_MultiVector> x2 = Tpetra::createMultiVector<Scalar>(map, ncol);
339  ArrayRCP< ArrayRCP<Scalar> > x1_view = x1->get2dViewNonConst();
340  ArrayRCP< ArrayRCP<Scalar> > x2_view = x2->get2dViewNonConst();
341  Scalar val1(VectorSize, BaseScalar(0.0)), val2(VectorSize, BaseScalar(0.0));
342  for (size_t i=0; i<num_my_row; ++i) {
343  const GlobalOrdinal row = myGIDs[i];
344  for (size_t j=0; j<ncol; ++j) {
345  for (LocalOrdinal k=0; k<VectorSize; ++k) {
346  BaseScalar v =
347  generate_multi_vector_coefficient<BaseScalar,size_t>(
348  nrow, ncol, VectorSize, row, j, k);
349  val1.fastAccessCoeff(k) = v;
350  val2.fastAccessCoeff(k) = 0.12345 * v;
351  }
352  x1_view[j][i] = val1;
353  x2_view[j][i] = val2;
354  }
355  }
356  x1_view = Teuchos::null;
357  x2_view = Teuchos::null;
358 
359  // Add
360  Scalar alpha = 2.1;
361  Scalar beta = 3.7;
362  RCP<Tpetra_MultiVector> y = Tpetra::createMultiVector<Scalar>(map, ncol);
363  y->update(alpha, *x1, beta, *x2, Scalar(0.0));
364 
365  // y->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
366  // Teuchos::VERB_EXTREME);
367 
368  // Check
369  ArrayRCP< ArrayRCP<Scalar> > y_view = y->get2dViewNonConst();
370  Scalar val(VectorSize, BaseScalar(0.0));
371  BaseScalar tol = 1.0e-14;
372  for (size_t i=0; i<num_my_row; ++i) {
373  const GlobalOrdinal row = myGIDs[i];
374  for (size_t j=0; j<ncol; ++j) {
375  for (LocalOrdinal k=0; k<VectorSize; ++k) {
376  BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
377  nrow, ncol, VectorSize, row, j, k);
378  val.fastAccessCoeff(k) = alpha.coeff(k)*v + 0.12345*beta.coeff(k)*v;
379  }
380  TEST_EQUALITY( y_view[j][i].size(), VectorSize );
381  for (LocalOrdinal k=0; k<VectorSize; ++k)
383  val.fastAccessCoeff(k), tol );
384  }
385  }
386 }
387 
388 //
389 // Test multi-vector dot product
390 //
392  Tpetra_CrsMatrix_MP, MultiVectorDot, Storage, LocalOrdinal, GlobalOrdinal, Node )
393 {
394  using Teuchos::RCP;
395  using Teuchos::rcp;
396  using Teuchos::ArrayView;
397  using Teuchos::Array;
398  using Teuchos::ArrayRCP;
399 
400  typedef typename Storage::value_type BaseScalar;
402 
403  typedef Teuchos::Comm<int> Tpetra_Comm;
404  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
405  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
406  typedef typename Tpetra_MultiVector::dot_type dot_type;
407 
408  // Ensure device is initialized
409  if ( !Kokkos::is_initialized() )
410  Kokkos::initialize();
411 
412  // Comm
413  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
414 
415  // Map
416  GlobalOrdinal nrow = 10;
417  RCP<const Tpetra_Map> map =
418  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
419  nrow, comm);
420  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
421  const size_t num_my_row = myGIDs.size();
422 
423  // Fill vectors
424  size_t ncol = 5;
425  RCP<Tpetra_MultiVector> x1 = Tpetra::createMultiVector<Scalar>(map, ncol);
426  RCP<Tpetra_MultiVector> x2 = Tpetra::createMultiVector<Scalar>(map, ncol);
427  ArrayRCP< ArrayRCP<Scalar> > x1_view = x1->get2dViewNonConst();
428  ArrayRCP< ArrayRCP<Scalar> > x2_view = x2->get2dViewNonConst();
429  Scalar val1(VectorSize, BaseScalar(0.0)), val2(VectorSize, BaseScalar(0.0));
430  for (size_t i=0; i<num_my_row; ++i) {
431  const GlobalOrdinal row = myGIDs[i];
432  for (size_t j=0; j<ncol; ++j) {
433  for (LocalOrdinal k=0; k<VectorSize; ++k) {
434  BaseScalar v =
435  generate_multi_vector_coefficient<BaseScalar,size_t>(
436  nrow, ncol, VectorSize, row, j, k);
437  val1.fastAccessCoeff(k) = v;
438  val2.fastAccessCoeff(k) = 0.12345 * v;
439  }
440  x1_view[j][i] = val1;
441  x2_view[j][i] = val2;
442  }
443  }
444  x1_view = Teuchos::null;
445  x2_view = Teuchos::null;
446 
447  // Dot product
448  Array<dot_type> dots(ncol);
449  x1->dot(*x2, dots());
450 
451  // Check
452 
453 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
454 
455  // Local contribution
456  Array<dot_type> local_vals(ncol, dot_type(0));
457  for (size_t i=0; i<num_my_row; ++i) {
458  const GlobalOrdinal row = myGIDs[i];
459  for (size_t j=0; j<ncol; ++j) {
460  for (LocalOrdinal k=0; k<VectorSize; ++k) {
461  BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
462  nrow, ncol, VectorSize, row, j, k);
463  local_vals[j] += 0.12345 * v * v;
464  }
465  }
466  }
467 
468  // Global reduction
469  Array<dot_type> vals(ncol, dot_type(0));
470  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, Teuchos::as<int>(ncol),
471  local_vals.getRawPtr(), vals.getRawPtr());
472 
473 #else
474 
475  // Local contribution
476  Array<dot_type> local_vals(ncol, dot_type(VectorSize, 0.0));
477  for (size_t i=0; i<num_my_row; ++i) {
478  const GlobalOrdinal row = myGIDs[i];
479  for (size_t j=0; j<ncol; ++j) {
480  for (LocalOrdinal k=0; k<VectorSize; ++k) {
481  BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
482  nrow, ncol, VectorSize, row, j, k);
483  local_vals[j].fastAccessCoeff(k) += 0.12345 * v * v;
484  }
485  }
486  }
487 
488  // Global reduction
489  Array<dot_type> vals(ncol, dot_type(VectorSize, 0.0));
490  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, Teuchos::as<int>(ncol),
491  local_vals.getRawPtr(), vals.getRawPtr());
492 
493 #endif
494 
495  BaseScalar tol = 1.0e-14;
496  for (size_t j=0; j<ncol; ++j) {
497  out << "dots(" << j << ") = " << dots[j]
498  << " expected(" << j << ") = " << vals[j] << std::endl;
499  TEST_FLOATING_EQUALITY( dots[j], vals[j], tol );
500  }
501 }
502 
503 //
504 // Test multi-vector dot product using subviews
505 //
507  Tpetra_CrsMatrix_MP, MultiVectorDotSub, Storage, LocalOrdinal, GlobalOrdinal, Node )
508 {
509  using Teuchos::RCP;
510  using Teuchos::rcp;
511  using Teuchos::ArrayView;
512  using Teuchos::Array;
513  using Teuchos::ArrayRCP;
514 
515  typedef typename Storage::value_type BaseScalar;
517 
518  typedef Teuchos::Comm<int> Tpetra_Comm;
519  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
520  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
521  typedef typename Tpetra_MultiVector::dot_type dot_type;
522 
523  // Ensure device is initialized
524  if ( !Kokkos::is_initialized() )
525  Kokkos::initialize();
526 
527  // Comm
528  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
529 
530  // Map
531  GlobalOrdinal nrow = 10;
532  RCP<const Tpetra_Map> map =
533  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
534  nrow, comm);
535  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
536  const size_t num_my_row = myGIDs.size();
537 
538  // Fill vectors
539  size_t ncol = 5;
540  RCP<Tpetra_MultiVector> x1 = Tpetra::createMultiVector<Scalar>(map, ncol);
541  RCP<Tpetra_MultiVector> x2 = Tpetra::createMultiVector<Scalar>(map, ncol);
542  ArrayRCP< ArrayRCP<Scalar> > x1_view = x1->get2dViewNonConst();
543  ArrayRCP< ArrayRCP<Scalar> > x2_view = x2->get2dViewNonConst();
544  Scalar val1(VectorSize, BaseScalar(0.0)), val2(VectorSize, BaseScalar(0.0));
545  for (size_t i=0; i<num_my_row; ++i) {
546  const GlobalOrdinal row = myGIDs[i];
547  for (size_t j=0; j<ncol; ++j) {
548  for (LocalOrdinal k=0; k<VectorSize; ++k) {
549  BaseScalar v =
550  generate_multi_vector_coefficient<BaseScalar,size_t>(
551  nrow, ncol, VectorSize, row, j, k);
552  val1.fastAccessCoeff(k) = v;
553  val2.fastAccessCoeff(k) = 0.12345 * v;
554  }
555  x1_view[j][i] = val1;
556  x2_view[j][i] = val2;
557  }
558  }
559  x1_view = Teuchos::null;
560  x2_view = Teuchos::null;
561 
562  // Get subviews
563  size_t ncol_sub = 2;
564  Teuchos::Array<size_t> cols(ncol_sub);
565  cols[0] = 4; cols[1] = 2;
566  RCP<const Tpetra_MultiVector> x1_sub = x1->subView(cols());
567  RCP<const Tpetra_MultiVector> x2_sub = x2->subView(cols());
568 
569  // Dot product
570  Array<dot_type> dots(ncol_sub);
571  x1_sub->dot(*x2_sub, dots());
572 
573  // Check
574 
575 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
576 
577  // Local contribution
578  Array<dot_type> local_vals(ncol_sub, dot_type(0));
579  for (size_t i=0; i<num_my_row; ++i) {
580  const GlobalOrdinal row = myGIDs[i];
581  for (size_t j=0; j<ncol_sub; ++j) {
582  for (LocalOrdinal k=0; k<VectorSize; ++k) {
583  BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
584  nrow, ncol, VectorSize, row, cols[j], k);
585  local_vals[j] += 0.12345 * v * v;
586  }
587  }
588  }
589 
590  // Global reduction
591  Array<dot_type> vals(ncol_sub, dot_type(0));
592  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM,
593  Teuchos::as<int>(ncol_sub), local_vals.getRawPtr(),
594  vals.getRawPtr());
595 
596 #else
597 
598  // Local contribution
599  Array<dot_type> local_vals(ncol_sub, dot_type(VectorSize, 0.0));
600  for (size_t i=0; i<num_my_row; ++i) {
601  const GlobalOrdinal row = myGIDs[i];
602  for (size_t j=0; j<ncol_sub; ++j) {
603  for (LocalOrdinal k=0; k<VectorSize; ++k) {
604  BaseScalar v = generate_multi_vector_coefficient<BaseScalar,size_t>(
605  nrow, ncol, VectorSize, row, cols[j], k);
606  local_vals[j].fastAccessCoeff(k) += 0.12345 * v * v;
607  }
608  }
609  }
610 
611  // Global reduction
612  Array<dot_type> vals(ncol_sub, dot_type(VectorSize, 0.0));
613  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM,
614  Teuchos::as<int>(ncol_sub), local_vals.getRawPtr(),
615  vals.getRawPtr());
616 
617 #endif
618 
619  BaseScalar tol = 1.0e-14;
620  for (size_t j=0; j<ncol_sub; ++j) {
621  out << "dots(" << j << ") = " << dots[j]
622  << " expected(" << j << ") = " << vals[j] << std::endl;
623  TEST_FLOATING_EQUALITY( dots[j], vals[j], tol );
624  }
625 }
626 
627 //
628 // Test matrix-vector multiplication for a simple banded upper-triangular matrix
629 //
631  Tpetra_CrsMatrix_MP, MatrixVectorMultiply, Storage, LocalOrdinal, GlobalOrdinal, Node )
632 {
633  using Teuchos::RCP;
634  using Teuchos::rcp;
635  using Teuchos::ArrayView;
636  using Teuchos::Array;
637  using Teuchos::ArrayRCP;
638 
639  typedef typename Storage::value_type BaseScalar;
641 
642  typedef Teuchos::Comm<int> Tpetra_Comm;
643  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
644  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
645  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
646  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
647 
648  // Ensure device is initialized
649  if ( !Kokkos::is_initialized() )
650  Kokkos::initialize();
651 
652  // Build banded matrix
653  GlobalOrdinal nrow = 10;
654  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
655  RCP<const Tpetra_Map> map =
656  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
657  nrow, comm);
658  RCP<Tpetra_CrsGraph> graph =
659  rcp(new Tpetra_CrsGraph(map, size_t(2), Tpetra::StaticProfile));
660  Array<GlobalOrdinal> columnIndices(2);
661  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
662  const size_t num_my_row = myGIDs.size();
663  for (size_t i=0; i<num_my_row; ++i) {
664  const GlobalOrdinal row = myGIDs[i];
665  columnIndices[0] = row;
666  size_t ncol = 1;
667  if (row != nrow-1) {
668  columnIndices[1] = row+1;
669  ncol = 2;
670  }
671  graph->insertGlobalIndices(row, columnIndices(0,ncol));
672  }
673  graph->fillComplete();
674  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
675 
676  // Set values in matrix
677  Array<Scalar> vals(2);
678  Scalar val(VectorSize, BaseScalar(0.0));
679  for (size_t i=0; i<num_my_row; ++i) {
680  const GlobalOrdinal row = myGIDs[i];
681  columnIndices[0] = row;
682  for (LocalOrdinal j=0; j<VectorSize; ++j)
683  val.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(
684  nrow, VectorSize, row, j);
685  vals[0] = val;
686  size_t ncol = 1;
687 
688  if (row != nrow-1) {
689  columnIndices[1] = row+1;
690  for (LocalOrdinal j=0; j<VectorSize; ++j)
691  val.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(
692  nrow, VectorSize, row+1, j);
693  vals[1] = val;
694  ncol = 2;
695  }
696  matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
697  }
698  matrix->fillComplete();
699 
700  // Fill vector
701  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
702  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
703  for (size_t i=0; i<num_my_row; ++i) {
704  const GlobalOrdinal row = myGIDs[i];
705  for (LocalOrdinal j=0; j<VectorSize; ++j)
706  val.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(
707  nrow, VectorSize, row, j);
708  x_view[i] = val;
709  }
710  x_view = Teuchos::null;
711 
712  // matrix->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
713  // Teuchos::VERB_EXTREME);
714 
715  // x->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
716  // Teuchos::VERB_EXTREME);
717 
718  // Multiply
719  RCP<Tpetra_Vector> y = Tpetra::createVector<Scalar>(map);
720  matrix->apply(*x, *y);
721 
722  // y->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
723  // Teuchos::VERB_EXTREME);
724 
725  // Check
726  ArrayRCP<Scalar> y_view = y->get1dViewNonConst();
727  BaseScalar tol = 1.0e-14;
728  for (size_t i=0; i<num_my_row; ++i) {
729  const GlobalOrdinal row = myGIDs[i];
730  for (LocalOrdinal j=0; j<VectorSize; ++j) {
731  BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
732  nrow, VectorSize, row, j);
733  val.fastAccessCoeff(j) = v*v;
734  }
735  if (row != nrow-1) {
736  for (LocalOrdinal j=0; j<VectorSize; ++j) {
737  BaseScalar v = generate_vector_coefficient<BaseScalar,size_t>(
738  nrow, VectorSize, row+1, j);
739  val.fastAccessCoeff(j) += v*v;
740  }
741  }
742  TEST_EQUALITY( y_view[i].size(), VectorSize );
743  for (LocalOrdinal j=0; j<VectorSize; ++j)
744  TEST_FLOATING_EQUALITY( y_view[i].fastAccessCoeff(j), val.fastAccessCoeff(j), tol );
745  }
746 }
747 
748 //
749 // Test matrix-multi-vector multiplication for a simple banded upper-triangular matrix
750 //
752  Tpetra_CrsMatrix_MP, MatrixMultiVectorMultiply, Storage, LocalOrdinal, GlobalOrdinal, Node )
753 {
754  using Teuchos::RCP;
755  using Teuchos::rcp;
756  using Teuchos::ArrayView;
757  using Teuchos::Array;
758  using Teuchos::ArrayRCP;
759 
760  typedef typename Storage::value_type BaseScalar;
762 
763  typedef Teuchos::Comm<int> Tpetra_Comm;
764  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
765  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
766  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
767  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
768 
769  // Ensure device is initialized
770  if ( !Kokkos::is_initialized() )
771  Kokkos::initialize();
772 
773  // Build banded matrix
774  GlobalOrdinal nrow = 10;
775  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
776  RCP<const Tpetra_Map> map =
777  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
778  nrow, comm);
779  RCP<Tpetra_CrsGraph> graph =
780  rcp(new Tpetra_CrsGraph(map, size_t(2), Tpetra::StaticProfile));
781  Array<GlobalOrdinal> columnIndices(2);
782  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
783  const size_t num_my_row = myGIDs.size();
784  for (size_t i=0; i<num_my_row; ++i) {
785  const GlobalOrdinal row = myGIDs[i];
786  columnIndices[0] = row;
787  size_t ncol = 1;
788  if (row != nrow-1) {
789  columnIndices[1] = row+1;
790  ncol = 2;
791  }
792  graph->insertGlobalIndices(row, columnIndices(0,ncol));
793  }
794  graph->fillComplete();
795  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
796 
797  // Set values in matrix
798  Array<Scalar> vals(2);
799  Scalar val(VectorSize, BaseScalar(0.0));
800  for (size_t i=0; i<num_my_row; ++i) {
801  const GlobalOrdinal row = myGIDs[i];
802  columnIndices[0] = row;
803  for (LocalOrdinal j=0; j<VectorSize; ++j)
804  val.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(
805  nrow, VectorSize, row, j);
806  vals[0] = val;
807  size_t ncol = 1;
808 
809  if (row != nrow-1) {
810  columnIndices[1] = row+1;
811  for (LocalOrdinal j=0; j<VectorSize; ++j)
812  val.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(
813  nrow, VectorSize, row+1, j);
814  vals[1] = val;
815  ncol = 2;
816  }
817  matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
818  }
819  matrix->fillComplete();
820 
821  // Fill multi-vector
822  size_t ncol = 5;
823  RCP<Tpetra_MultiVector> x = Tpetra::createMultiVector<Scalar>(map, ncol);
824  ArrayRCP< ArrayRCP<Scalar> > x_view = x->get2dViewNonConst();
825  for (size_t i=0; i<num_my_row; ++i) {
826  const GlobalOrdinal row = myGIDs[i];
827  for (size_t j=0; j<ncol; ++j) {
828  for (LocalOrdinal k=0; k<VectorSize; ++k) {
829  BaseScalar v =
830  generate_multi_vector_coefficient<BaseScalar,size_t>(
831  nrow, ncol, VectorSize, row, j, k);
832  val.fastAccessCoeff(k) = v;
833  }
834  x_view[j][i] = val;
835  }
836  }
837  x_view = Teuchos::null;
838 
839  // matrix->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
840  // Teuchos::VERB_EXTREME);
841 
842  // x->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
843  // Teuchos::VERB_EXTREME);
844 
845  // Multiply
846  RCP<Tpetra_MultiVector> y = Tpetra::createMultiVector<Scalar>(map, ncol);
847  matrix->apply(*x, *y);
848 
849  // y->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
850  // Teuchos::VERB_EXTREME);
851 
852  // Check
853  ArrayRCP< ArrayRCP<Scalar> > y_view = y->get2dViewNonConst();
854  BaseScalar tol = 1.0e-14;
855  for (size_t i=0; i<num_my_row; ++i) {
856  const GlobalOrdinal row = myGIDs[i];
857  for (size_t j=0; j<ncol; ++j) {
858  for (LocalOrdinal k=0; k<VectorSize; ++k) {
859  BaseScalar v1 = generate_vector_coefficient<BaseScalar,size_t>(
860  nrow, VectorSize, row, k);
861  BaseScalar v2 = generate_multi_vector_coefficient<BaseScalar,size_t>(
862  nrow, ncol, VectorSize, row, j, k);
863  val.fastAccessCoeff(k) = v1*v2;
864  }
865  if (row != nrow-1) {
866  for (LocalOrdinal k=0; k<VectorSize; ++k) {
867  BaseScalar v1 = generate_vector_coefficient<BaseScalar,size_t>(
868  nrow, VectorSize, row+1, k);
869  BaseScalar v2 = generate_multi_vector_coefficient<BaseScalar,size_t>(
870  nrow, ncol, VectorSize, row+1, j, k);
871  val.fastAccessCoeff(k) += v1*v2;
872  }
873  }
874  TEST_EQUALITY( y_view[j][i].size(), VectorSize );
875  for (LocalOrdinal k=0; k<VectorSize; ++k)
877  val.fastAccessCoeff(k), tol );
878  }
879  }
880 }
881 
882 //
883 // Test flattening MP::Vector matrix
884 //
886  Tpetra_CrsMatrix_MP, Flatten, Storage, LocalOrdinal, GlobalOrdinal, Node )
887 {
888  using Teuchos::RCP;
889  using Teuchos::rcp;
890  using Teuchos::ArrayView;
891  using Teuchos::Array;
892  using Teuchos::ArrayRCP;
893 
894  typedef typename Storage::value_type BaseScalar;
896 
897  typedef Teuchos::Comm<int> Tpetra_Comm;
898  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
899  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
900  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
901  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
902 
903  typedef Tpetra::Vector<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> Flat_Tpetra_Vector;
904  typedef Tpetra::CrsMatrix<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> Flat_Tpetra_CrsMatrix;
905 
906  // Ensure device is initialized
907  if ( !Kokkos::is_initialized() )
908  Kokkos::initialize();
909 
910  // Build banded matrix
911  GlobalOrdinal nrow = 10;
912  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
913  RCP<const Tpetra_Map> map =
914  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
915  nrow, comm);
916  RCP<Tpetra_CrsGraph> graph =
917  rcp(new Tpetra_CrsGraph(map, size_t(2), Tpetra::StaticProfile));
918  Array<GlobalOrdinal> columnIndices(2);
919  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
920  const size_t num_my_row = myGIDs.size();
921  for (size_t i=0; i<num_my_row; ++i) {
922  const GlobalOrdinal row = myGIDs[i];
923  columnIndices[0] = row;
924  size_t ncol = 1;
925  if (row != nrow-1) {
926  columnIndices[1] = row+1;
927  ncol = 2;
928  }
929  graph->insertGlobalIndices(row, columnIndices(0,ncol));
930  }
931  graph->fillComplete();
932  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
933 
934  // Set values in matrix
935  Array<Scalar> vals(2);
936  Scalar val(VectorSize, BaseScalar(0.0));
937  for (size_t i=0; i<num_my_row; ++i) {
938  const GlobalOrdinal row = myGIDs[i];
939  columnIndices[0] = row;
940  for (LocalOrdinal j=0; j<VectorSize; ++j)
941  val.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(
942  nrow, VectorSize, row, j);
943  vals[0] = val;
944  size_t ncol = 1;
945 
946  if (row != nrow-1) {
947  columnIndices[1] = row+1;
948  for (LocalOrdinal j=0; j<VectorSize; ++j)
949  val.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(
950  nrow, VectorSize, row+1, j);
951  vals[1] = val;
952  ncol = 2;
953  }
954  matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
955  }
956  matrix->fillComplete();
957 
958  // Fill vector
959  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
960  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
961  for (size_t i=0; i<num_my_row; ++i) {
962  const GlobalOrdinal row = myGIDs[i];
963  for (LocalOrdinal j=0; j<VectorSize; ++j)
964  val.fastAccessCoeff(j) = generate_vector_coefficient<BaseScalar,size_t>(
965  nrow, VectorSize, row, j);
966  x_view[i] = val;
967  }
968 
969  // Multiply
970  RCP<Tpetra_Vector> y = Tpetra::createVector<Scalar>(map);
971  matrix->apply(*x, *y);
972 
973  // Flatten matrix
974  RCP<const Tpetra_Map> flat_x_map, flat_y_map;
975  RCP<const Tpetra_CrsGraph> flat_graph =
976  Stokhos::create_flat_mp_graph(*graph, flat_x_map, flat_y_map, VectorSize);
977  RCP<Flat_Tpetra_CrsMatrix> flat_matrix =
978  Stokhos::create_flat_matrix(*matrix, flat_graph, VectorSize);
979 
980  // Multiply with flattened matix
981  RCP<Tpetra_Vector> y2 = Tpetra::createVector<Scalar>(map);
982  RCP<Flat_Tpetra_Vector> flat_x =
983  Stokhos::create_flat_vector_view(*x, flat_x_map);
984  RCP<Flat_Tpetra_Vector> flat_y =
985  Stokhos::create_flat_vector_view(*y2, flat_y_map);
986  flat_matrix->apply(*flat_x, *flat_y);
987 
988  // flat_y->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
989  // Teuchos::VERB_EXTREME);
990 
991  // Check
992  BaseScalar tol = 1.0e-14;
993  ArrayRCP<Scalar> y_view = y->get1dViewNonConst();
994  ArrayRCP<Scalar> y2_view = y2->get1dViewNonConst();
995  for (size_t i=0; i<num_my_row; ++i) {
996  TEST_EQUALITY( y_view[i].size(), VectorSize );
997  TEST_EQUALITY( y2_view[i].size(), VectorSize );
998  for (LocalOrdinal j=0; j<VectorSize; ++j)
1000  y2_view[i].fastAccessCoeff(j), tol );
1001  }
1002 }
1003 
1004 //
1005 // Test simple CG solve without preconditioning for a 1-D Laplacian matrix
1006 //
1008  Tpetra_CrsMatrix_MP, SimpleCG, Storage, LocalOrdinal, GlobalOrdinal, Node )
1009 {
1010  using Teuchos::RCP;
1011  using Teuchos::rcp;
1012  using Teuchos::ArrayView;
1013  using Teuchos::Array;
1014  using Teuchos::ArrayRCP;
1015  using Teuchos::ParameterList;
1016 
1017  typedef typename Storage::value_type BaseScalar;
1019 
1020  typedef Teuchos::Comm<int> Tpetra_Comm;
1021  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1022  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1023  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1024  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1025 
1026  // Ensure device is initialized
1027  if ( !Kokkos::is_initialized() )
1028  Kokkos::initialize();
1029 
1030  // 1-D Laplacian matrix
1031  GlobalOrdinal nrow = 50;
1032  BaseScalar h = 1.0 / static_cast<BaseScalar>(nrow-1);
1033  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1034  RCP<const Tpetra_Map> map =
1035  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1036  nrow, comm);
1037  RCP<Tpetra_CrsGraph> graph =
1038  rcp(new Tpetra_CrsGraph(map, size_t(3), Tpetra::StaticProfile));
1039  Array<GlobalOrdinal> columnIndices(3);
1040  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1041  const size_t num_my_row = myGIDs.size();
1042  for (size_t i=0; i<num_my_row; ++i) {
1043  const GlobalOrdinal row = myGIDs[i];
1044  if (row == 0 || row == nrow-1) { // Boundary nodes
1045  columnIndices[0] = row;
1046  graph->insertGlobalIndices(row, columnIndices(0,1));
1047  }
1048  else { // Interior nodes
1049  columnIndices[0] = row-1;
1050  columnIndices[1] = row;
1051  columnIndices[2] = row+1;
1052  graph->insertGlobalIndices(row, columnIndices(0,3));
1053  }
1054  }
1055  graph->fillComplete();
1056  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
1057 
1058  // Set values in matrix
1059  Array<Scalar> vals(3);
1060  Scalar a_val(VectorSize, BaseScalar(0.0));
1061  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1062  a_val.fastAccessCoeff(j) =
1063  BaseScalar(1.0) + BaseScalar(j) / BaseScalar(VectorSize);
1064  }
1065  for (size_t i=0; i<num_my_row; ++i) {
1066  const GlobalOrdinal row = myGIDs[i];
1067  if (row == 0 || row == nrow-1) { // Boundary nodes
1068  columnIndices[0] = row;
1069  vals[0] = Scalar(1.0);
1070  matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
1071  }
1072  else {
1073  columnIndices[0] = row-1;
1074  columnIndices[1] = row;
1075  columnIndices[2] = row+1;
1076  vals[0] = Scalar(-1.0) * a_val;
1077  vals[1] = Scalar(2.0) * a_val;
1078  vals[2] = Scalar(-1.0) * a_val;
1079  matrix->replaceGlobalValues(row, columnIndices(0,3), vals(0,3));
1080  }
1081  }
1082  matrix->fillComplete();
1083 
1084  matrix->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
1086 
1087  // Fill RHS vector
1088  RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1089  ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1090  Scalar b_val(VectorSize, BaseScalar(0.0));
1091  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1092  b_val.fastAccessCoeff(j) =
1093  BaseScalar(-1.0) + BaseScalar(j) / BaseScalar(VectorSize);
1094  }
1095  for (size_t i=0; i<num_my_row; ++i) {
1096  const GlobalOrdinal row = myGIDs[i];
1097  if (row == 0 || row == nrow-1)
1098  b_view[i] = Scalar(0.0);
1099  else
1100  b_view[i] = -Scalar(b_val * h * h);
1101  }
1102 
1103  // Solve
1104  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1105  typedef Kokkos::Details::ArithTraits<BaseScalar> BST;
1106  typedef typename BST::mag_type base_mag_type;
1107  typedef typename Tpetra_Vector::mag_type mag_type;
1108  base_mag_type btol = 1e-9;
1109  mag_type tol = btol;
1110  int max_its = 1000;
1111  bool solved = Stokhos::CG_Solve(*matrix, *x, *b, tol, max_its,
1112  out.getOStream().get());
1113  TEST_EQUALITY_CONST( solved, true );
1114 
1115  // x->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
1116  // Teuchos::VERB_EXTREME);
1117 
1118  // Check -- For a*y'' = b, correct answer is y = 0.5 *(b/a) * x * (x-1)
1119  btol = 1000*btol;
1120  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1121  Scalar val(VectorSize, BaseScalar(0.0));
1122  for (size_t i=0; i<num_my_row; ++i) {
1123  const GlobalOrdinal row = myGIDs[i];
1124  BaseScalar xx = row * h;
1125  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1126  val.fastAccessCoeff(j) =
1127  BaseScalar(0.5) * (b_val.coeff(j)/a_val.coeff(j)) * xx * (xx - BaseScalar(1.0));
1128  }
1129  TEST_EQUALITY( x_view[i].size(), VectorSize );
1130 
1131  // Set small values to zero
1132  Scalar v = x_view[i];
1133  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1134  if (BST::abs(v.coeff(j)) < btol)
1135  v.fastAccessCoeff(j) = BaseScalar(0.0);
1136  if (BST::abs(val.coeff(j)) < btol)
1137  val.fastAccessCoeff(j) = BaseScalar(0.0);
1138  }
1139 
1140  for (LocalOrdinal j=0; j<VectorSize; ++j)
1141  TEST_FLOATING_EQUALITY(v.coeff(j), val.coeff(j), btol);
1142  }
1143 
1144 }
1145 
1146 #if defined(HAVE_STOKHOS_MUELU) && defined(HAVE_STOKHOS_AMESOS2) && defined(HAVE_STOKHOS_IFPACK2)
1147 
1148 //
1149 // Test simple CG solve with MueLu preconditioning for a 1-D Laplacian matrix
1150 //
1152  Tpetra_CrsMatrix_MP, SimplePCG_Muelu, Storage, LocalOrdinal, GlobalOrdinal, Node )
1153 {
1154  using Teuchos::RCP;
1155  using Teuchos::rcp;
1156  using Teuchos::ArrayView;
1157  using Teuchos::Array;
1158  using Teuchos::ArrayRCP;
1159  using Teuchos::ParameterList;
1160  using Teuchos::getParametersFromXmlFile;
1161 
1162  typedef typename Storage::value_type BaseScalar;
1164 
1165  typedef Teuchos::Comm<int> Tpetra_Comm;
1166  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1167  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1168  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1169  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1170 
1171  // Ensure device is initialized
1172  if ( !Kokkos::is_initialized() )
1173  Kokkos::initialize();
1174 
1175  // 1-D Laplacian matrix
1176  GlobalOrdinal nrow = 50;
1177  BaseScalar h = 1.0 / static_cast<BaseScalar>(nrow-1);
1178  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1179  RCP<const Tpetra_Map> map =
1180  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1181  nrow, comm);
1182  RCP<Tpetra_CrsGraph> graph =
1183  rcp(new Tpetra_CrsGraph(map, size_t(3), Tpetra::StaticProfile));
1184  Array<GlobalOrdinal> columnIndices(3);
1185  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1186  const size_t num_my_row = myGIDs.size();
1187  for (size_t i=0; i<num_my_row; ++i) {
1188  const GlobalOrdinal row = myGIDs[i];
1189  if (row == 0 || row == nrow-1) { // Boundary nodes
1190  columnIndices[0] = row;
1191  graph->insertGlobalIndices(row, columnIndices(0,1));
1192  }
1193  else { // Interior nodes
1194  columnIndices[0] = row-1;
1195  columnIndices[1] = row;
1196  columnIndices[2] = row+1;
1197  graph->insertGlobalIndices(row, columnIndices(0,3));
1198  }
1199  }
1200  graph->fillComplete();
1201  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
1202 
1203  // Set values in matrix
1204  Array<Scalar> vals(3);
1205  Scalar a_val(VectorSize, BaseScalar(0.0));
1206  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1207  a_val.fastAccessCoeff(j) =
1208  BaseScalar(1.0) + BaseScalar(j) / BaseScalar(VectorSize);
1209  }
1210  for (size_t i=0; i<num_my_row; ++i) {
1211  const GlobalOrdinal row = myGIDs[i];
1212  if (row == 0 || row == nrow-1) { // Boundary nodes
1213  columnIndices[0] = row;
1214  vals[0] = Scalar(1.0);
1215  matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
1216  }
1217  else {
1218  columnIndices[0] = row-1;
1219  columnIndices[1] = row;
1220  columnIndices[2] = row+1;
1221  vals[0] = Scalar(-1.0) * a_val;
1222  vals[1] = Scalar(2.0) * a_val;
1223  vals[2] = Scalar(-1.0) * a_val;
1224  matrix->replaceGlobalValues(row, columnIndices(0,3), vals(0,3));
1225  }
1226  }
1227  matrix->fillComplete();
1228 
1229  // Fill RHS vector
1230  RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1231  ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1232  Scalar b_val(VectorSize, BaseScalar(0.0));
1233  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1234  b_val.fastAccessCoeff(j) =
1235  BaseScalar(-1.0) + BaseScalar(j) / BaseScalar(VectorSize);
1236  }
1237  for (size_t i=0; i<num_my_row; ++i) {
1238  const GlobalOrdinal row = myGIDs[i];
1239  if (row == 0 || row == nrow-1)
1240  b_view[i] = Scalar(0.0);
1241  else
1242  b_view[i] = -Scalar(b_val * h * h);
1243  }
1244 
1245  // Create preconditioner
1246  typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
1247  RCP<OP> matrix_op = matrix;
1248  RCP<ParameterList> muelu_params =
1249  getParametersFromXmlFile("muelu_cheby.xml");
1250  RCP<OP> M =
1251  MueLu::CreateTpetraPreconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node>(matrix_op, *muelu_params);
1252 
1253  // Solve
1254  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1255  typedef Kokkos::Details::ArithTraits<BaseScalar> BST;
1256  typedef typename BST::mag_type base_mag_type;
1257  typedef typename Tpetra_Vector::mag_type mag_type;
1258  base_mag_type btol = 1e-9;
1259  mag_type tol = btol;
1260  int max_its = 1000;
1261  bool solved = Stokhos::PCG_Solve(*matrix, *x, *b, *M, tol, max_its,
1262  out.getOStream().get());
1263  TEST_EQUALITY_CONST( solved, true );
1264 
1265  // x->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
1266  // Teuchos::VERB_EXTREME);
1267 
1268  // Check -- For a*y'' = b, correct answer is y = 0.5 *(b/a) * x * (x-1)
1269  btol = 1000*btol;
1270  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1271  Scalar val(VectorSize, BaseScalar(0.0));
1272  for (size_t i=0; i<num_my_row; ++i) {
1273  const GlobalOrdinal row = myGIDs[i];
1274  BaseScalar xx = row * h;
1275  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1276  val.fastAccessCoeff(j) =
1277  BaseScalar(0.5) * (b_val.coeff(j)/a_val.coeff(j)) * xx * (xx - BaseScalar(1.0));
1278  }
1279  TEST_EQUALITY( x_view[i].size(), VectorSize );
1280 
1281  // Set small values to zero
1282  Scalar v = x_view[i];
1283  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1284  if (BST::magnitude(v.coeff(j)) < btol)
1285  v.fastAccessCoeff(j) = BaseScalar(0.0);
1286  if (BST::magnitude(val.coeff(j)) < btol)
1287  val.fastAccessCoeff(j) = BaseScalar(0.0);
1288  }
1289 
1290  for (LocalOrdinal j=0; j<VectorSize; ++j)
1291  TEST_FLOATING_EQUALITY(v.coeff(j), val.coeff(j), btol);
1292  }
1293 
1294 }
1295 
1296 #else
1297 
1299  Tpetra_CrsMatrix_MP, SimplePCG_Muelu, Storage, LocalOrdinal, GlobalOrdinal, Node ) {}
1300 
1301 #endif
1302 
1303 #if defined(HAVE_STOKHOS_BELOS)
1304 
1305 //
1306 // Test Belos GMRES solve for a simple banded upper-triangular matrix
1307 //
1309  Tpetra_CrsMatrix_MP, BelosGMRES, Storage, LocalOrdinal, GlobalOrdinal, Node )
1310 {
1311  using Teuchos::RCP;
1312  using Teuchos::rcp;
1313  using Teuchos::ArrayView;
1314  using Teuchos::Array;
1315  using Teuchos::ArrayRCP;
1316  using Teuchos::ParameterList;
1317 
1318  typedef typename Storage::value_type BaseScalar;
1320 
1321  typedef Teuchos::Comm<int> Tpetra_Comm;
1322  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1323  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1324  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1325  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1326 
1327  // Ensure device is initialized
1328  if ( !Kokkos::is_initialized() )
1329  Kokkos::initialize();
1330 
1331  // Build banded matrix
1332  GlobalOrdinal nrow = 10;
1333  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1334  RCP<const Tpetra_Map> map =
1335  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1336  nrow, comm);
1337  RCP<Tpetra_CrsGraph> graph =
1338  rcp(new Tpetra_CrsGraph(map, size_t(2), Tpetra::StaticProfile));
1339  Array<GlobalOrdinal> columnIndices(2);
1340  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1341  const size_t num_my_row = myGIDs.size();
1342  for (size_t i=0; i<num_my_row; ++i) {
1343  const GlobalOrdinal row = myGIDs[i];
1344  columnIndices[0] = row;
1345  size_t ncol = 1;
1346  if (row != nrow-1) {
1347  columnIndices[1] = row+1;
1348  ncol = 2;
1349  }
1350  graph->insertGlobalIndices(row, columnIndices(0,ncol));
1351  }
1352  graph->fillComplete();
1353  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
1354 
1355  // Set values in matrix
1356  Array<Scalar> vals(2);
1357  Scalar val(VectorSize, BaseScalar(0.0));
1358  for (size_t i=0; i<num_my_row; ++i) {
1359  const GlobalOrdinal row = myGIDs[i];
1360  columnIndices[0] = row;
1361  for (LocalOrdinal j=0; j<VectorSize; ++j)
1362  val.fastAccessCoeff(j) = j+1;
1363  vals[0] = val;
1364  size_t ncol = 1;
1365 
1366  if (row != nrow-1) {
1367  columnIndices[1] = row+1;
1368  for (LocalOrdinal j=0; j<VectorSize; ++j)
1369  val.fastAccessCoeff(j) = j+1;
1370  vals[1] = val;
1371  ncol = 2;
1372  }
1373  matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
1374  }
1375  matrix->fillComplete();
1376 
1377  // Fill RHS vector
1378  RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1379  ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1380  for (size_t i=0; i<num_my_row; ++i) {
1381  b_view[i] = Scalar(1.0);
1382  }
1383 
1384  // Solve
1386 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
1387  typedef BaseScalar BelosScalar;
1388 #else
1389  typedef Scalar BelosScalar;
1390 #endif
1391  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
1392  typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
1393  typedef Belos::LinearProblem<BelosScalar,MV,OP> BLinProb;
1394  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1395  RCP< BLinProb > problem = rcp(new BLinProb(matrix, x, b));
1396  RCP<ParameterList> belosParams = rcp(new ParameterList);
1397  typename ST::magnitudeType tol = 1e-9;
1398  belosParams->set("Flexible Gmres", false);
1399  belosParams->set("Num Blocks", 100);
1400  belosParams->set("Convergence Tolerance", BelosScalar(tol));
1401  belosParams->set("Maximum Iterations", 100);
1402  belosParams->set("Verbosity", 33);
1403  belosParams->set("Output Style", 1);
1404  belosParams->set("Output Frequency", 1);
1405  belosParams->set("Output Stream", out.getOStream());
1406  RCP<Belos::SolverManager<BelosScalar,MV,OP> > solver =
1407  rcp(new Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP>(problem, belosParams));
1408  problem->setProblem();
1409  Belos::ReturnType ret = solver->solve();
1410  TEST_EQUALITY_CONST( ret, Belos::Converged );
1411 
1412  // x->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
1413  // Teuchos::VERB_EXTREME);
1414 
1415  // Check -- Correct answer is:
1416  // [ 0, 0, ..., 0 ]
1417  // [ 1, 1/2, ..., 1/VectorSize ]
1418  // [ 0, 0, ..., 0 ]
1419  // [ 1, 1/2, ..., 1/VectorSize ]
1420  // ....
1421  tol = 1000*tol;
1422  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1423  for (size_t i=0; i<num_my_row; ++i) {
1424  const GlobalOrdinal row = myGIDs[i];
1425  if (row % 2) {
1426  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1427  val.fastAccessCoeff(j) = BaseScalar(1.0) / BaseScalar(j+1);
1428  }
1429  }
1430  else
1431  val = Scalar(VectorSize, BaseScalar(0.0));
1432  TEST_EQUALITY( x_view[i].size(), VectorSize );
1433 
1434  // Set small values to zero
1435  Scalar v = x_view[i];
1436  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1437  if (ST::magnitude(v.coeff(j)) < tol)
1438  v.fastAccessCoeff(j) = BaseScalar(0.0);
1439  }
1440 
1441  for (LocalOrdinal j=0; j<VectorSize; ++j)
1442  TEST_FLOATING_EQUALITY(v.coeff(j), val.coeff(j), tol);
1443  }
1444 }
1445 
1446 //
1447 // Test Belos GMRES solve for a simple lower-triangular matrix with lucky breakdown with DGKS orthogonalization
1448 //
1450  Tpetra_CrsMatrix_MP, BelosGMRES_DGKS, Storage, LocalOrdinal, GlobalOrdinal, Node )
1451 {
1452  using Teuchos::RCP;
1453  using Teuchos::rcp;
1454  using Teuchos::tuple;
1455  using Teuchos::ArrayView;
1456  using Teuchos::Array;
1457  using Teuchos::ArrayRCP;
1458  using Teuchos::ParameterList;
1459 
1460  typedef typename Storage::value_type BaseScalar;
1462 
1463  typedef Teuchos::Comm<int> Tpetra_Comm;
1464  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1465  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1466  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1467  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1468 
1469  // Ensure device is initialized
1470  if ( !Kokkos::is_initialized() )
1471  Kokkos::initialize();
1472 
1473  // Build diagonal matrix
1474  GlobalOrdinal nrow = 20;
1475  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1476  RCP<const Tpetra_Map> map =
1477  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1478  nrow, comm);
1479  RCP<Tpetra_CrsGraph> graph =
1480  rcp(new Tpetra_CrsGraph(map, size_t(1), Tpetra::StaticProfile));
1481  Array<GlobalOrdinal> columnIndices(1);
1482  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1483  const size_t num_my_row = myGIDs.size();
1484  for (size_t i=0; i<num_my_row; ++i) {
1485  const GlobalOrdinal row = myGIDs[i];
1486  columnIndices[0] = row;
1487  size_t ncol = 1;
1488  graph->insertGlobalIndices(row, columnIndices(0,ncol));
1489  }
1490  graph->fillComplete();
1491  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
1492 
1493  Array<Scalar> vals(1);
1494  for (size_t i=0; i<num_my_row; ++i) {
1495  const GlobalOrdinal row = myGIDs[i];
1496  columnIndices[0] = row;
1497  vals[0] = Scalar(row+1);
1498  matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
1499  }
1500  matrix->fillComplete();
1501 
1502  // Fill RHS vector:
1503  // [ 0, 0, ..., 0, 0, 1]
1504  // [ 0, 0, ..., 0, 2, 2]
1505  // [ 0, 0, ..., 3, 3, 3]
1506  // [ 0, 0, ..., 4, 4, 4]
1507  // ...
1508 
1509  RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1510  ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1511  for (size_t i=0; i<num_my_row; ++i) {
1512  const GlobalOrdinal row = myGIDs[i];
1513  b_view[i] = Scalar(0.0);
1514  for (LocalOrdinal j=0; j<VectorSize; ++j)
1515  if (int(j+2+row-VectorSize) > 0)
1516  b_view[i].fastAccessCoeff(j) = BaseScalar(row+1);
1517  }
1518 
1519  // Solve
1521 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
1522  typedef BaseScalar BelosScalar;
1523 #else
1524  typedef Scalar BelosScalar;
1525 #endif
1526  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
1527  typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
1528  typedef Belos::LinearProblem<BelosScalar,MV,OP> BLinProb;
1529  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1530  RCP< BLinProb > problem = rcp(new BLinProb(matrix, x, b));
1531  RCP<ParameterList> belosParams = rcp(new ParameterList);
1532  typename ST::magnitudeType tol = 1e-9;
1533  belosParams->set("Flexible Gmres", false);
1534  belosParams->set("Num Blocks", 100);
1535  belosParams->set("Convergence Tolerance", BelosScalar(tol));
1536  belosParams->set("Maximum Iterations", 100);
1537  belosParams->set("Verbosity", 33);
1538  belosParams->set("Output Style", 1);
1539  belosParams->set("Output Frequency", 1);
1540  belosParams->set("Output Stream", out.getOStream());
1541  belosParams->set("Orthogonalization","DGKS");
1542  RCP<Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP> > solver =
1543  rcp(new Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP>(problem, belosParams));
1544  problem->setProblem();
1545  Belos::ReturnType ret = solver->solve();
1546  TEST_EQUALITY_CONST( ret, Belos::Converged );
1547 
1548 #ifndef HAVE_STOKHOS_ENSEMBLE_REDUCT
1549  int numItersExpected = nrow;
1550  int numIters = solver->getNumIters();
1551  out << "numIters = " << numIters << std::endl;
1552  TEST_EQUALITY( numIters, numItersExpected);
1553 
1554  // Get and print number of ensemble iterations
1555  std::vector<int> ensemble_iterations =
1556  static_cast<const Belos::StatusTestImpResNorm<BelosScalar, MV, OP> *>(solver->getResidualStatusTest())->getEnsembleIterations();
1557  out << "Ensemble iterations = ";
1558  for (auto ensemble_iteration : ensemble_iterations)
1559  out << ensemble_iteration << " ";
1560  out << std::endl;
1561 
1562  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1563  if (int(j+1+nrow-VectorSize) > 0) {
1564  TEST_EQUALITY(int(j+1+nrow-VectorSize), ensemble_iterations[j]);
1565  }
1566  else {
1567  TEST_EQUALITY(int(0), ensemble_iterations[j]);
1568  }
1569  }
1570 #endif
1571 
1572  // Check -- Correct answer is:
1573  // [ 0, 0, ..., 0, 0, 1]
1574  // [ 0, 0, ..., 0, 1, 1]
1575  // [ 0, 0, ..., 1, 1, 1]
1576  // [ 0, 0, ..., 1, 1, 1]
1577  // ...
1578  tol = 1000*tol;
1579  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1580  for (size_t i=0; i<num_my_row; ++i) {
1581  const GlobalOrdinal row = myGIDs[i];
1582  Scalar v = x_view[i];
1583 
1584  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1585  if (ST::magnitude(v.coeff(j)) < tol)
1586  v.fastAccessCoeff(j) = BaseScalar(0.0);
1587  }
1588 
1589  Scalar val = Scalar(0.0);
1590 
1591  for (LocalOrdinal j=0; j<VectorSize; ++j)
1592  if (j+2+row-VectorSize > 0)
1593  val.fastAccessCoeff(j) = BaseScalar(1.0);
1594 
1595  for (LocalOrdinal j=0; j<VectorSize; ++j)
1596  TEST_FLOATING_EQUALITY(v.coeff(j), val.coeff(j), tol);
1597  }
1598 }
1599 
1600 //
1601 // Test Belos GMRES solve for a simple lower-triangular matrix with lucky breakdown with ICGS orthogonalization
1602 //
1604  Tpetra_CrsMatrix_MP, BelosGMRES_ICGS, Storage, LocalOrdinal, GlobalOrdinal, Node )
1605 {
1606  using Teuchos::RCP;
1607  using Teuchos::rcp;
1608  using Teuchos::tuple;
1609  using Teuchos::ArrayView;
1610  using Teuchos::Array;
1611  using Teuchos::ArrayRCP;
1612  using Teuchos::ParameterList;
1613 
1614  typedef typename Storage::value_type BaseScalar;
1616 
1617  typedef Teuchos::Comm<int> Tpetra_Comm;
1618  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1619  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1620  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1621  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1622 
1623  // Ensure device is initialized
1624  if ( !Kokkos::is_initialized() )
1625  Kokkos::initialize();
1626 
1627  // Build diagonal matrix
1628  GlobalOrdinal nrow = 20;
1629  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1630  RCP<const Tpetra_Map> map =
1631  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1632  nrow, comm);
1633  RCP<Tpetra_CrsGraph> graph =
1634  rcp(new Tpetra_CrsGraph(map, size_t(1), Tpetra::StaticProfile));
1635  Array<GlobalOrdinal> columnIndices(1);
1636  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1637  const size_t num_my_row = myGIDs.size();
1638  for (size_t i=0; i<num_my_row; ++i) {
1639  const GlobalOrdinal row = myGIDs[i];
1640  columnIndices[0] = row;
1641  size_t ncol = 1;
1642  graph->insertGlobalIndices(row, columnIndices(0,ncol));
1643  }
1644  graph->fillComplete();
1645  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
1646 
1647  Array<Scalar> vals(1);
1648  for (size_t i=0; i<num_my_row; ++i) {
1649  const GlobalOrdinal row = myGIDs[i];
1650  columnIndices[0] = row;
1651  vals[0] = Scalar(row+1);
1652  matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
1653  }
1654  matrix->fillComplete();
1655 
1656  // Fill RHS vector:
1657  // [ 0, 0, ..., 0, 0, 1]
1658  // [ 0, 0, ..., 0, 2, 2]
1659  // [ 0, 0, ..., 3, 3, 3]
1660  // [ 0, 0, ..., 4, 4, 4]
1661  // ...
1662 
1663  RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1664  ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1665  for (size_t i=0; i<num_my_row; ++i) {
1666  const GlobalOrdinal row = myGIDs[i];
1667  b_view[i] = Scalar(0.0);
1668  for (LocalOrdinal j=0; j<VectorSize; ++j)
1669  if (int(j+2+row-VectorSize) > 0)
1670  b_view[i].fastAccessCoeff(j) = BaseScalar(row+1);
1671  }
1672 
1673  // Solve
1675 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
1676  typedef BaseScalar BelosScalar;
1677 #else
1678  typedef Scalar BelosScalar;
1679 #endif
1680  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
1681  typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
1682  typedef Belos::LinearProblem<BelosScalar,MV,OP> BLinProb;
1683  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1684  RCP< BLinProb > problem = rcp(new BLinProb(matrix, x, b));
1685  RCP<ParameterList> belosParams = rcp(new ParameterList);
1686  typename ST::magnitudeType tol = 1e-9;
1687  belosParams->set("Flexible Gmres", false);
1688  belosParams->set("Num Blocks", 100);
1689  belosParams->set("Convergence Tolerance", BelosScalar(tol));
1690  belosParams->set("Maximum Iterations", 100);
1691  belosParams->set("Verbosity", 33);
1692  belosParams->set("Output Style", 1);
1693  belosParams->set("Output Frequency", 1);
1694  belosParams->set("Output Stream", out.getOStream());
1695  belosParams->set("Orthogonalization","ICGS");
1696  RCP<Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP> > solver =
1697  rcp(new Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP>(problem, belosParams));
1698  problem->setProblem();
1699  Belos::ReturnType ret = solver->solve();
1700  TEST_EQUALITY_CONST( ret, Belos::Converged );
1701 
1702 #ifndef HAVE_STOKHOS_ENSEMBLE_REDUCT
1703  int numItersExpected = nrow;
1704  int numIters = solver->getNumIters();
1705  out << "numIters = " << numIters << std::endl;
1706  TEST_EQUALITY( numIters, numItersExpected);
1707 
1708  // Get and print number of ensemble iterations
1709  std::vector<int> ensemble_iterations =
1710  static_cast<const Belos::StatusTestImpResNorm<BelosScalar, MV, OP> *>(solver->getResidualStatusTest())->getEnsembleIterations();
1711  out << "Ensemble iterations = ";
1712  for (auto ensemble_iteration : ensemble_iterations)
1713  out << ensemble_iteration << " ";
1714  out << std::endl;
1715 
1716  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1717  if (int(j+1+nrow-VectorSize) > 0) {
1718  TEST_EQUALITY(int(j+1+nrow-VectorSize), ensemble_iterations[j]);
1719  }
1720  else {
1721  TEST_EQUALITY(int(0), ensemble_iterations[j]);
1722  }
1723  }
1724 #endif
1725 
1726  // Check -- Correct answer is:
1727  // [ 0, 0, ..., 0, 0, 1]
1728  // [ 0, 0, ..., 0, 1, 1]
1729  // [ 0, 0, ..., 1, 1, 1]
1730  // [ 0, 0, ..., 1, 1, 1]
1731  // ...
1732  tol = 1000*tol;
1733  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1734  for (size_t i=0; i<num_my_row; ++i) {
1735  const GlobalOrdinal row = myGIDs[i];
1736  Scalar v = x_view[i];
1737 
1738  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1739  if (ST::magnitude(v.coeff(j)) < tol)
1740  v.fastAccessCoeff(j) = BaseScalar(0.0);
1741  }
1742 
1743  Scalar val = Scalar(0.0);
1744 
1745  for (LocalOrdinal j=0; j<VectorSize; ++j)
1746  if (j+2+row-VectorSize > 0)
1747  val.fastAccessCoeff(j) = BaseScalar(1.0);
1748 
1749  for (LocalOrdinal j=0; j<VectorSize; ++j)
1750  TEST_FLOATING_EQUALITY(v.coeff(j), val.coeff(j), tol);
1751  }
1752 }
1753 
1754 //
1755 // Test Belos GMRES solve for a simple lower-triangular matrix with lucky breakdown with IMGS orthogonalization
1756 //
1758  Tpetra_CrsMatrix_MP, BelosGMRES_IMGS, Storage, LocalOrdinal, GlobalOrdinal, Node )
1759 {
1760  using Teuchos::RCP;
1761  using Teuchos::rcp;
1762  using Teuchos::tuple;
1763  using Teuchos::ArrayView;
1764  using Teuchos::Array;
1765  using Teuchos::ArrayRCP;
1766  using Teuchos::ParameterList;
1767 
1768  typedef typename Storage::value_type BaseScalar;
1770 
1771  typedef Teuchos::Comm<int> Tpetra_Comm;
1772  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1773  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1774  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1775  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1776 
1777  // Ensure device is initialized
1778  if ( !Kokkos::is_initialized() )
1779  Kokkos::initialize();
1780 
1781  // Build diagonal matrix
1782  GlobalOrdinal nrow = 20;
1783  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1784  RCP<const Tpetra_Map> map =
1785  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1786  nrow, comm);
1787  RCP<Tpetra_CrsGraph> graph =
1788  rcp(new Tpetra_CrsGraph(map, size_t(1), Tpetra::StaticProfile));
1789  Array<GlobalOrdinal> columnIndices(1);
1790  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1791  const size_t num_my_row = myGIDs.size();
1792  for (size_t i=0; i<num_my_row; ++i) {
1793  const GlobalOrdinal row = myGIDs[i];
1794  columnIndices[0] = row;
1795  size_t ncol = 1;
1796  graph->insertGlobalIndices(row, columnIndices(0,ncol));
1797  }
1798  graph->fillComplete();
1799  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
1800 
1801  Array<Scalar> vals(1);
1802  for (size_t i=0; i<num_my_row; ++i) {
1803  const GlobalOrdinal row = myGIDs[i];
1804  columnIndices[0] = row;
1805  vals[0] = Scalar(row+1);
1806  matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
1807  }
1808  matrix->fillComplete();
1809 
1810  // Fill RHS vector:
1811  // [ 0, 0, ..., 0, 0, 1]
1812  // [ 0, 0, ..., 0, 2, 2]
1813  // [ 0, 0, ..., 3, 3, 3]
1814  // [ 0, 0, ..., 4, 4, 4]
1815  // ...
1816 
1817  RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
1818  ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
1819  for (size_t i=0; i<num_my_row; ++i) {
1820  const GlobalOrdinal row = myGIDs[i];
1821  b_view[i] = Scalar(0.0);
1822  for (LocalOrdinal j=0; j<VectorSize; ++j)
1823  if (int(j+2+row-VectorSize) > 0)
1824  b_view[i].fastAccessCoeff(j) = BaseScalar(row+1);
1825  }
1826 
1827  // Solve
1829 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
1830  typedef BaseScalar BelosScalar;
1831 #else
1832  typedef Scalar BelosScalar;
1833 #endif
1834  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
1835  typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
1836  typedef Belos::LinearProblem<BelosScalar,MV,OP> BLinProb;
1837  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
1838  RCP< BLinProb > problem = rcp(new BLinProb(matrix, x, b));
1839  RCP<ParameterList> belosParams = rcp(new ParameterList);
1840  typename ST::magnitudeType tol = 1e-9;
1841  belosParams->set("Flexible Gmres", false);
1842  belosParams->set("Num Blocks", 100);
1843  belosParams->set("Convergence Tolerance", BelosScalar(tol));
1844  belosParams->set("Maximum Iterations", 100);
1845  belosParams->set("Verbosity", 33);
1846  belosParams->set("Output Style", 1);
1847  belosParams->set("Output Frequency", 1);
1848  belosParams->set("Output Stream", out.getOStream());
1849  belosParams->set("Orthogonalization","IMGS");
1850  RCP<Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP> > solver =
1851  rcp(new Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP>(problem, belosParams));
1852  problem->setProblem();
1853  Belos::ReturnType ret = solver->solve();
1854  TEST_EQUALITY_CONST( ret, Belos::Converged );
1855 
1856 #ifndef HAVE_STOKHOS_ENSEMBLE_REDUCT
1857  int numItersExpected = nrow;
1858  int numIters = solver->getNumIters();
1859  out << "numIters = " << numIters << std::endl;
1860  TEST_EQUALITY( numIters, numItersExpected);
1861 
1862  // Get and print number of ensemble iterations
1863  std::vector<int> ensemble_iterations =
1864  static_cast<const Belos::StatusTestImpResNorm<BelosScalar, MV, OP> *>(solver->getResidualStatusTest())->getEnsembleIterations();
1865  out << "Ensemble iterations = ";
1866  for (auto ensemble_iteration : ensemble_iterations)
1867  out << ensemble_iteration << " ";
1868  out << std::endl;
1869 
1870  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1871  if (int(j+1+nrow-VectorSize) > 0) {
1872  TEST_EQUALITY(int(j+1+nrow-VectorSize), ensemble_iterations[j]);
1873  }
1874  else {
1875  TEST_EQUALITY(int(0), ensemble_iterations[j]);
1876  }
1877  }
1878 #endif
1879 
1880  // Check -- Correct answer is:
1881  // [ 0, 0, ..., 0, 0, 1]
1882  // [ 0, 0, ..., 0, 1, 1]
1883  // [ 0, 0, ..., 1, 1, 1]
1884  // [ 0, 0, ..., 1, 1, 1]
1885  // ...
1886  tol = 1000*tol;
1887  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
1888  for (size_t i=0; i<num_my_row; ++i) {
1889  const GlobalOrdinal row = myGIDs[i];
1890  Scalar v = x_view[i];
1891 
1892  for (LocalOrdinal j=0; j<VectorSize; ++j) {
1893  if (ST::magnitude(v.coeff(j)) < tol)
1894  v.fastAccessCoeff(j) = BaseScalar(0.0);
1895  }
1896 
1897  Scalar val = Scalar(0.0);
1898 
1899  for (LocalOrdinal j=0; j<VectorSize; ++j)
1900  if (j+2+row-VectorSize > 0)
1901  val.fastAccessCoeff(j) = BaseScalar(1.0);
1902 
1903  for (LocalOrdinal j=0; j<VectorSize; ++j)
1904  TEST_FLOATING_EQUALITY(v.coeff(j), val.coeff(j), tol);
1905  }
1906 }
1907 
1908 #else
1909 
1911  Tpetra_CrsMatrix_MP, BelosGMRES, Storage, LocalOrdinal, GlobalOrdinal, Node )
1912 {}
1913 
1915  Tpetra_CrsMatrix_MP, BelosGMRES_DGKS, Storage, LocalOrdinal, GlobalOrdinal, Node )
1916 {}
1917 
1919  Tpetra_CrsMatrix_MP, BelosGMRES_ICGS, Storage, LocalOrdinal, GlobalOrdinal, Node )
1920 {}
1921 
1923  Tpetra_CrsMatrix_MP, BelosGMRES_IMGS, Storage, LocalOrdinal, GlobalOrdinal, Node )
1924 {}
1925 
1926 #endif
1927 
1928 #if defined(HAVE_STOKHOS_BELOS) && defined(HAVE_STOKHOS_IFPACK2)
1929 
1930 //
1931 // Test Belos GMRES solve with Ifpack2 RILUK preconditioning for a
1932 // simple banded upper-triangular matrix
1933 //
1935  Tpetra_CrsMatrix_MP, BelosGMRES_RILUK, Storage, LocalOrdinal, GlobalOrdinal, Node )
1936 {
1937  using Teuchos::RCP;
1938  using Teuchos::rcp;
1939  using Teuchos::ArrayView;
1940  using Teuchos::Array;
1941  using Teuchos::ArrayRCP;
1942  using Teuchos::ParameterList;
1943 
1944  typedef typename Storage::value_type BaseScalar;
1946 
1947  typedef Teuchos::Comm<int> Tpetra_Comm;
1948  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
1949  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
1950  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
1951  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
1952 
1953  // Ensure device is initialized
1954  if ( !Kokkos::is_initialized() )
1955  Kokkos::initialize();
1956 
1957  // Build banded matrix
1958  GlobalOrdinal nrow = 10;
1959  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
1960  RCP<const Tpetra_Map> map =
1961  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
1962  nrow, comm);
1963  RCP<Tpetra_CrsGraph> graph =
1964  rcp(new Tpetra_CrsGraph(map, size_t(2), Tpetra::StaticProfile));
1965  Array<GlobalOrdinal> columnIndices(2);
1966  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
1967  const size_t num_my_row = myGIDs.size();
1968  for (size_t i=0; i<num_my_row; ++i) {
1969  const GlobalOrdinal row = myGIDs[i];
1970  columnIndices[0] = row;
1971  size_t ncol = 1;
1972  if (row != nrow-1) {
1973  columnIndices[1] = row+1;
1974  ncol = 2;
1975  }
1976  graph->insertGlobalIndices(row, columnIndices(0,ncol));
1977  }
1978  graph->fillComplete();
1979  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
1980 
1981  // Set values in matrix
1982  Array<Scalar> vals(2);
1983  Scalar val(VectorSize, BaseScalar(0.0));
1984  for (size_t i=0; i<num_my_row; ++i) {
1985  const GlobalOrdinal row = myGIDs[i];
1986  columnIndices[0] = row;
1987  for (LocalOrdinal j=0; j<VectorSize; ++j)
1988  val.fastAccessCoeff(j) = j+1;
1989  vals[0] = val;
1990  size_t ncol = 1;
1991 
1992  if (row != nrow-1) {
1993  columnIndices[1] = row+1;
1994  for (LocalOrdinal j=0; j<VectorSize; ++j)
1995  val.fastAccessCoeff(j) = j+1;
1996  vals[1] = val;
1997  ncol = 2;
1998  }
1999  matrix->replaceGlobalValues(row, columnIndices(0,ncol), vals(0,ncol));
2000  }
2001  matrix->fillComplete();
2002 
2003  // Fill RHS vector
2004  RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
2005  ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
2006  for (size_t i=0; i<num_my_row; ++i) {
2007  b_view[i] = Scalar(1.0);
2008  }
2009 
2010  // Create preconditioner
2011  typedef Ifpack2::Preconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node> Prec;
2012  Ifpack2::Factory factory;
2013  RCP<Prec> M = factory.create<Tpetra_CrsMatrix>("RILUK", matrix);
2014  M->initialize();
2015  M->compute();
2016 
2017  // Solve
2019 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
2020  typedef BaseScalar BelosScalar;
2021 #else
2022  typedef Scalar BelosScalar;
2023 #endif
2024  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
2025  typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
2026  typedef Belos::LinearProblem<BelosScalar,MV,OP> BLinProb;
2027  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
2028  RCP< BLinProb > problem = rcp(new BLinProb(matrix, x, b));
2029  problem->setRightPrec(M);
2030  problem->setProblem();
2031  RCP<ParameterList> belosParams = rcp(new ParameterList);
2032  typename ST::magnitudeType tol = 1e-9;
2033  belosParams->set("Flexible Gmres", false);
2034  belosParams->set("Num Blocks", 100);
2035  belosParams->set("Convergence Tolerance", BelosScalar(tol));
2036  belosParams->set("Maximum Iterations", 100);
2037  belosParams->set("Verbosity", 33);
2038  belosParams->set("Output Style", 1);
2039  belosParams->set("Output Frequency", 1);
2040  belosParams->set("Output Stream", out.getOStream());
2041  //belosParams->set("Orthogonalization", "TSQR");
2042  RCP<Belos::SolverManager<BelosScalar,MV,OP> > solver =
2043  rcp(new Belos::PseudoBlockGmresSolMgr<BelosScalar,MV,OP>(problem, belosParams));
2044  Belos::ReturnType ret = solver->solve();
2045  TEST_EQUALITY_CONST( ret, Belos::Converged );
2046 
2047  // x->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
2048  // Teuchos::VERB_EXTREME);
2049 
2050  // Check -- Correct answer is:
2051  // [ 0, 0, ..., 0 ]
2052  // [ 1, 1/2, ..., 1/VectorSize ]
2053  // [ 0, 0, ..., 0 ]
2054  // [ 1, 1/2, ..., 1/VectorSize ]
2055  // ....
2056  tol = 1000*tol;
2057  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
2058  for (size_t i=0; i<num_my_row; ++i) {
2059  const GlobalOrdinal row = myGIDs[i];
2060  if (row % 2) {
2061  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2062  val.fastAccessCoeff(j) = BaseScalar(1.0) / BaseScalar(j+1);
2063  }
2064  }
2065  else
2066  val = Scalar(VectorSize, BaseScalar(0.0));
2067  TEST_EQUALITY( x_view[i].size(), VectorSize );
2068 
2069  // Set small values to zero
2070  Scalar v = x_view[i];
2071  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2072  if (ST::magnitude(v.coeff(j)) < tol)
2073  v.fastAccessCoeff(j) = BaseScalar(0.0);
2074  }
2075 
2076  for (LocalOrdinal j=0; j<VectorSize; ++j)
2077  TEST_FLOATING_EQUALITY(v.coeff(j), val.coeff(j), tol);
2078  }
2079 }
2080 
2081 #else
2082 
2084  Tpetra_CrsMatrix_MP, BelosGMRES_RILUK, Storage, LocalOrdinal, GlobalOrdinal, Node )
2085 {}
2086 
2087 #endif
2088 
2089 #if defined(HAVE_STOKHOS_BELOS) && defined(HAVE_STOKHOS_IFPACK2) && defined(HAVE_STOKHOS_MUELU) && defined(HAVE_STOKHOS_AMESOS2)
2090 
2091 //
2092 // Test Belos CG solve with MueLu preconditioning for a 1-D Laplacian matrix
2093 //
2095  Tpetra_CrsMatrix_MP, BelosCG_Muelu, Storage, LocalOrdinal, GlobalOrdinal, Node )
2096 {
2097  using Teuchos::RCP;
2098  using Teuchos::rcp;
2099  using Teuchos::ArrayView;
2100  using Teuchos::Array;
2101  using Teuchos::ArrayRCP;
2102  using Teuchos::ParameterList;
2103  using Teuchos::getParametersFromXmlFile;
2104 
2105  typedef typename Storage::value_type BaseScalar;
2107 
2108  typedef Teuchos::Comm<int> Tpetra_Comm;
2109  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
2110  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
2111  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
2112  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
2113 
2114  // Ensure device is initialized
2115  if ( !Kokkos::is_initialized() )
2116  Kokkos::initialize();
2117 
2118  // 1-D Laplacian matrix
2119  GlobalOrdinal nrow = 50;
2120  BaseScalar h = 1.0 / static_cast<BaseScalar>(nrow-1);
2121  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
2122  RCP<const Tpetra_Map> map =
2123  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
2124  nrow, comm);
2125  RCP<Tpetra_CrsGraph> graph =
2126  rcp(new Tpetra_CrsGraph(map, size_t(3), Tpetra::StaticProfile));
2127  Array<GlobalOrdinal> columnIndices(3);
2128  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
2129  const size_t num_my_row = myGIDs.size();
2130  for (size_t i=0; i<num_my_row; ++i) {
2131  const GlobalOrdinal row = myGIDs[i];
2132  if (row == 0 || row == nrow-1) { // Boundary nodes
2133  columnIndices[0] = row;
2134  graph->insertGlobalIndices(row, columnIndices(0,1));
2135  }
2136  else { // Interior nodes
2137  columnIndices[0] = row-1;
2138  columnIndices[1] = row;
2139  columnIndices[2] = row+1;
2140  graph->insertGlobalIndices(row, columnIndices(0,3));
2141  }
2142  }
2143  graph->fillComplete();
2144  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
2145 
2146  // Set values in matrix
2147  Array<Scalar> vals(3);
2148  Scalar a_val(VectorSize, BaseScalar(0.0));
2149  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2150  a_val.fastAccessCoeff(j) =
2151  BaseScalar(1.0) + BaseScalar(j) / BaseScalar(VectorSize);
2152  }
2153  for (size_t i=0; i<num_my_row; ++i) {
2154  const GlobalOrdinal row = myGIDs[i];
2155  if (row == 0 || row == nrow-1) { // Boundary nodes
2156  columnIndices[0] = row;
2157  vals[0] = Scalar(1.0);
2158  matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
2159  }
2160  else {
2161  columnIndices[0] = row-1;
2162  columnIndices[1] = row;
2163  columnIndices[2] = row+1;
2164  vals[0] = Scalar(-1.0) * a_val;
2165  vals[1] = Scalar(2.0) * a_val;
2166  vals[2] = Scalar(-1.0) * a_val;
2167  matrix->replaceGlobalValues(row, columnIndices(0,3), vals(0,3));
2168  }
2169  }
2170  matrix->fillComplete();
2171 
2172  // Fill RHS vector
2173  RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
2174  ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
2175  Scalar b_val(VectorSize, BaseScalar(0.0));
2176  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2177  b_val.fastAccessCoeff(j) =
2178  BaseScalar(-1.0) + BaseScalar(j) / BaseScalar(VectorSize);
2179  }
2180  for (size_t i=0; i<num_my_row; ++i) {
2181  const GlobalOrdinal row = myGIDs[i];
2182  if (row == 0 || row == nrow-1)
2183  b_view[i] = Scalar(0.0);
2184  else
2185  b_view[i] = -Scalar(b_val * h * h);
2186  }
2187 
2188  // Create preconditioner
2189  typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> OP;
2190  RCP<ParameterList> muelu_params =
2191  getParametersFromXmlFile("muelu_cheby.xml");
2192  RCP<OP> matrix_op = matrix;
2193  RCP<OP> M =
2194  MueLu::CreateTpetraPreconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node>(matrix_op, *muelu_params);
2195 
2196  // Solve
2198 #ifdef HAVE_STOKHOS_ENSEMBLE_REDUCT
2199  typedef BaseScalar BelosScalar;
2200 #else
2201  typedef Scalar BelosScalar;
2202 #endif
2203  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
2204  typedef Belos::LinearProblem<BelosScalar,MV,OP> BLinProb;
2205  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
2206  RCP< BLinProb > problem = rcp(new BLinProb(matrix, x, b));
2207  problem->setRightPrec(M);
2208  problem->setProblem();
2209  RCP<ParameterList> belosParams = rcp(new ParameterList);
2210  typename ST::magnitudeType tol = 1e-9;
2211  belosParams->set("Num Blocks", 100);
2212  belosParams->set("Convergence Tolerance", BelosScalar(tol));
2213  belosParams->set("Maximum Iterations", 100);
2214  belosParams->set("Verbosity", 33);
2215  belosParams->set("Output Style", 1);
2216  belosParams->set("Output Frequency", 1);
2217  belosParams->set("Output Stream", out.getOStream());
2218  // Turn off residual scaling so we can see some variation in the number
2219  // of iterations across the ensemble when not doing ensemble reductions
2220  belosParams->set("Implicit Residual Scaling", "None");
2221 
2222  RCP<Belos::PseudoBlockCGSolMgr<BelosScalar,MV,OP,true> > solver =
2223  rcp(new Belos::PseudoBlockCGSolMgr<BelosScalar,MV,OP,true>(problem, belosParams));
2224  Belos::ReturnType ret = solver->solve();
2225  TEST_EQUALITY_CONST( ret, Belos::Converged );
2226 
2227 #ifndef HAVE_STOKHOS_ENSEMBLE_REDUCT
2228  // Get and print number of ensemble iterations
2229  std::vector<int> ensemble_iterations =
2230  solver->getResidualStatusTest()->getEnsembleIterations();
2231  out << "Ensemble iterations = ";
2232  for (int i=0; i<VectorSize; ++i)
2233  out << ensemble_iterations[i] << " ";
2234  out << std::endl;
2235 #endif
2236 
2237  // x->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
2238  // Teuchos::VERB_EXTREME);
2239 
2240  // Check -- For a*y'' = b, correct answer is y = 0.5 *(b/a) * x * (x-1)
2241  tol = 1000*tol;
2242  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
2243  Scalar val(VectorSize, BaseScalar(0.0));
2244  for (size_t i=0; i<num_my_row; ++i) {
2245  const GlobalOrdinal row = myGIDs[i];
2246  BaseScalar xx = row * h;
2247  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2248  val.fastAccessCoeff(j) =
2249  BaseScalar(0.5) * (b_val.coeff(j)/a_val.coeff(j)) * xx * (xx - BaseScalar(1.0));
2250  }
2251  TEST_EQUALITY( x_view[i].size(), VectorSize );
2252 
2253  // Set small values to zero
2254  Scalar v = x_view[i];
2255  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2256  if (ST::magnitude(v.coeff(j)) < tol)
2257  v.fastAccessCoeff(j) = BaseScalar(0.0);
2258  if (ST::magnitude(val.coeff(j)) < tol)
2259  val.fastAccessCoeff(j) = BaseScalar(0.0);
2260  }
2261 
2262  for (LocalOrdinal j=0; j<VectorSize; ++j)
2263  TEST_FLOATING_EQUALITY(v.coeff(j), val.coeff(j), tol);
2264  }
2265 
2266 }
2267 
2268 #else
2269 
2271  Tpetra_CrsMatrix_MP, BelosCG_Muelu, Storage, LocalOrdinal, GlobalOrdinal, Node )
2272 {}
2273 
2274 #endif
2275 
2276 #if defined(HAVE_STOKHOS_AMESOS2)
2277 
2278 //
2279 // Test Amesos2 solve for a 1-D Laplacian matrix
2280 //
2282  Tpetra_CrsMatrix_MP, Amesos2, Storage, LocalOrdinal, GlobalOrdinal, Node )
2283 {
2284  using Teuchos::RCP;
2285  using Teuchos::rcp;
2286  using Teuchos::ArrayView;
2287  using Teuchos::Array;
2288  using Teuchos::ArrayRCP;
2289  using Teuchos::ParameterList;
2290 
2291  typedef typename Storage::value_type BaseScalar;
2293 
2294  typedef Teuchos::Comm<int> Tpetra_Comm;
2295  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
2296  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
2297  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_MultiVector;
2298  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
2299  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
2300 
2301  // Ensure device is initialized
2302  if ( !Kokkos::is_initialized() )
2303  Kokkos::initialize();
2304 
2305  // 1-D Laplacian matrix
2306  GlobalOrdinal nrow = 50;
2307  BaseScalar h = 1.0 / static_cast<BaseScalar>(nrow-1);
2308  RCP<const Tpetra_Comm> comm = Tpetra::getDefaultComm();
2309  RCP<const Tpetra_Map> map =
2310  Tpetra::createUniformContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
2311  nrow, comm);
2312  RCP<Tpetra_CrsGraph> graph = Tpetra::createCrsGraph(map, size_t(3));
2313  Array<GlobalOrdinal> columnIndices(3);
2314  ArrayView<const GlobalOrdinal> myGIDs = map->getNodeElementList();
2315  const size_t num_my_row = myGIDs.size();
2316  for (size_t i=0; i<num_my_row; ++i) {
2317  const GlobalOrdinal row = myGIDs[i];
2318  if (row == 0 || row == nrow-1) { // Boundary nodes
2319  columnIndices[0] = row;
2320  graph->insertGlobalIndices(row, columnIndices(0,1));
2321  }
2322  else { // Interior nodes
2323  columnIndices[0] = row-1;
2324  columnIndices[1] = row;
2325  columnIndices[2] = row+1;
2326  graph->insertGlobalIndices(row, columnIndices(0,3));
2327  }
2328  }
2329  graph->fillComplete();
2330  RCP<Tpetra_CrsMatrix> matrix = rcp(new Tpetra_CrsMatrix(graph));
2331 
2332  // Set values in matrix
2333  Array<Scalar> vals(3);
2334  Scalar a_val(VectorSize, BaseScalar(0.0));
2335  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2336  a_val.fastAccessCoeff(j) =
2337  BaseScalar(1.0) + BaseScalar(j) / BaseScalar(VectorSize);
2338  }
2339  for (size_t i=0; i<num_my_row; ++i) {
2340  const GlobalOrdinal row = myGIDs[i];
2341  if (row == 0 || row == nrow-1) { // Boundary nodes
2342  columnIndices[0] = row;
2343  vals[0] = Scalar(1.0);
2344  matrix->replaceGlobalValues(row, columnIndices(0,1), vals(0,1));
2345  }
2346  else {
2347  columnIndices[0] = row-1;
2348  columnIndices[1] = row;
2349  columnIndices[2] = row+1;
2350  vals[0] = Scalar(-1.0) * a_val;
2351  vals[1] = Scalar(2.0) * a_val;
2352  vals[2] = Scalar(-1.0) * a_val;
2353  matrix->replaceGlobalValues(row, columnIndices(0,3), vals(0,3));
2354  }
2355  }
2356  matrix->fillComplete();
2357 
2358  // Fill RHS vector
2359  RCP<Tpetra_Vector> b = Tpetra::createVector<Scalar>(map);
2360  ArrayRCP<Scalar> b_view = b->get1dViewNonConst();
2361  Scalar b_val(VectorSize, BaseScalar(0.0));
2362  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2363  b_val.fastAccessCoeff(j) =
2364  BaseScalar(-1.0) + BaseScalar(j) / BaseScalar(VectorSize);
2365  }
2366  for (size_t i=0; i<num_my_row; ++i) {
2367  const GlobalOrdinal row = myGIDs[i];
2368  if (row == 0 || row == nrow-1)
2369  b_view[i] = Scalar(0.0);
2370  else
2371  b_view[i] = -Scalar(b_val * h * h);
2372  }
2373 
2374  // Solve
2375  typedef Amesos2::Solver<Tpetra_CrsMatrix,Tpetra_MultiVector> Solver;
2376  RCP<Tpetra_Vector> x = Tpetra::createVector<Scalar>(map);
2377  std::string solver_name;
2378 #if defined(HAVE_AMESOS2_BASKER)
2379  solver_name = "basker";
2380 #elif defined(HAVE_AMESOS2_KLU2)
2381  solver_name = "klu2";
2382 #elif defined(HAVE_AMESOS2_SUPERLUDIST)
2383  solver_name = "superlu_dist";
2384 #elif defined(HAVE_AMESOS2_SUPERLUMT)
2385  solver_name = "superlu_mt";
2386 #elif defined(HAVE_AMESOS2_SUPERLU)
2387  solver_name = "superlu";
2388 #elif defined(HAVE_AMESOS2_PARDISO_MKL)
2389  solver_name = "pardisomkl";
2390 #elif defined(HAVE_AMESOS2_LAPACK)
2391  solver_name = "lapack";
2392 #elif defined(HAVE_AMESOS2_CHOLMOD) && defined (HAVE_AMESOS2_EXPERIMENTAL)
2393  solver_name = "lapack";
2394 #else
2395  // if there are no solvers, we just return as a successful test
2396  success = true;
2397  return;
2398 #endif
2399  out << "Solving linear system with " << solver_name << std::endl;
2400  RCP<Solver> solver = Amesos2::create<Tpetra_CrsMatrix,Tpetra_MultiVector>(
2401  solver_name, matrix, x, b);
2402  solver->solve();
2403 
2404  // x->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
2405  // Teuchos::VERB_EXTREME);
2406 
2407  // Check -- For a*y'' = b, correct answer is y = 0.5 *(b/a) * x * (x-1)
2409  typename ST::magnitudeType tol = 1e-9;
2410  ArrayRCP<Scalar> x_view = x->get1dViewNonConst();
2411  Scalar val(VectorSize, BaseScalar(0.0));
2412  for (size_t i=0; i<num_my_row; ++i) {
2413  const GlobalOrdinal row = myGIDs[i];
2414  BaseScalar xx = row * h;
2415  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2416  val.fastAccessCoeff(j) =
2417  BaseScalar(0.5) * (b_val.coeff(j)/a_val.coeff(j)) * xx * (xx - BaseScalar(1.0));
2418  }
2419  TEST_EQUALITY( x_view[i].size(), VectorSize );
2420 
2421  // Set small values to zero
2422  Scalar v = x_view[i];
2423  for (LocalOrdinal j=0; j<VectorSize; ++j) {
2424  if (ST::magnitude(v.coeff(j)) < tol)
2425  v.fastAccessCoeff(j) = BaseScalar(0.0);
2426  if (ST::magnitude(val.coeff(j)) < tol)
2427  val.fastAccessCoeff(j) = BaseScalar(0.0);
2428  }
2429 
2430  for (LocalOrdinal j=0; j<VectorSize; ++j)
2431  TEST_FLOATING_EQUALITY(v.coeff(j), val.coeff(j), tol);
2432  }
2433 }
2434 
2435 #else
2436 
2438  Tpetra_CrsMatrix_MP, Amesos2, Storage, LocalOrdinal, GlobalOrdinal, Node )
2439 {}
2440 
2441 #endif
2442 
2443 #define CRSMATRIX_MP_VECTOR_TESTS_SLGN(S, LO, GO, N) \
2444  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, VectorAdd, S, LO, GO, N ) \
2445  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, VectorDot, S, LO, GO, N ) \
2446  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MultiVectorAdd, S, LO, GO, N ) \
2447  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MultiVectorDot, S, LO, GO, N ) \
2448  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MultiVectorDotSub, S, LO, GO, N ) \
2449  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MatrixVectorMultiply, S, LO, GO, N ) \
2450  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, MatrixMultiVectorMultiply, S, LO, GO, N ) \
2451  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, Flatten, S, LO, GO, N ) \
2452  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, SimpleCG, S, LO, GO, N ) \
2453  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, SimplePCG_Muelu, S, LO, GO, N ) \
2454  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, BelosGMRES, S, LO, GO, N ) \
2455  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, BelosGMRES_DGKS, S, LO, GO, N ) \
2456  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, BelosGMRES_ICGS, S, LO, GO, N ) \
2457  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, BelosGMRES_IMGS, S, LO, GO, N ) \
2458  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, BelosGMRES_RILUK, S, LO, GO, N ) \
2459  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, BelosCG_Muelu, S, LO, GO, N ) \
2460  TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Tpetra_CrsMatrix_MP, Amesos2, S, LO, GO, N )
2461 
2462 #define CRSMATRIX_MP_VECTOR_TESTS_N_SFS(N) \
2463  typedef Stokhos::DeviceForNode<N>::type Device; \
2464  typedef Stokhos::StaticFixedStorage<int,double,VectorSize,Device::execution_space> SFS; \
2465  using default_global_ordinal_type = ::Tpetra::Map<>::global_ordinal_type; \
2466  using default_local_ordinal_type = ::Tpetra::Map<>::local_ordinal_type; \
2467  CRSMATRIX_MP_VECTOR_TESTS_SLGN(SFS, default_local_ordinal_type, default_global_ordinal_type, N)
2468 
2469 #define CRSMATRIX_MP_VECTOR_TESTS_N(N) \
2470  CRSMATRIX_MP_VECTOR_TESTS_N_SFS(N)
2471 
2472 // Disabling testing of dynamic storage -- we don't really need it
2473  // typedef Stokhos::DynamicStorage<int,double,Device> DS;
2474  // using default_global_ordinal_type = ::Tpetra::Map<>::global_ordinal_type;
2475  // using default_local_ordinal_type = ::Tpetra::Map<>::local_ordinal_type;
2476  // CRSMATRIX_MP_VECTOR_TESTS_SLGN(DS, default_global_ordinal_type, default_local_ordinal_type, N)
bool CG_Solve(const Matrix &A, Vector &x, const Vector &b, typename Vector::mag_type tol, Ordinal max_its, std::ostream *out=0)
scalar generate_multi_vector_coefficient(const ordinal nFEM, const ordinal nVec, const ordinal nStoch, const ordinal iColFEM, const ordinal iVec, const ordinal iStoch)
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Tpetra_CrsMatrix_MP, VectorAdd, Storage, LocalOrdinal, GlobalOrdinal, Node)
Convergence test using the implicit residual norm(s), with an explicit residual norm(s) check for los...
#define TEST_EQUALITY_CONST(v1, v2)
scalar generate_vector_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< YD, YP...> >::value, typename Kokkos::Details::InnerProductSpaceTraits< typename Kokkos::View< XD, XP...>::non_const_value_type >::dot_type >::type dot(const Kokkos::View< XD, XP...> &x, const Kokkos::View< YD, YP...> &y)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Tpetra::MultiVector< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_vector_view(const Tpetra::MultiVector< Sacado::MP::Vector< Storage >, LocalOrdinal, GlobalOrdinal, Node > &vec_const, const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_map)
bool PCG_Solve(const Matrix &A, Vector &x, const Vector &b, const Prec &M, typename Vector::mag_type tol, Ordinal max_its, std::ostream *out=0)
KokkosClassic::DefaultNode::DefaultNodeType Node
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > create_flat_mp_graph(const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_domain_map, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_range_map, const LocalOrdinal block_size)
Teuchos::RCP< Tpetra::CrsMatrix< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_matrix(const Tpetra::CrsMatrix< Sacado::MP::Vector< Storage >, LocalOrdinal, GlobalOrdinal, Node > &mat, const Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &flat_graph, const LocalOrdinal block_size)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
expr val()
BelosGMRES
#define TEST_EQUALITY(v1, v2)