42 #ifndef __TSQR_Trilinos_TsqrTpetraTest_hpp
43 #define __TSQR_Trilinos_TsqrTpetraTest_hpp
46 #include "Tsqr_Random_NormalGenerator.hpp"
47 #include "Teuchos_ParameterList.hpp"
48 #include "Teuchos_Tuple.hpp"
49 #include "Teuchos_Time.hpp"
61 template<
class S,
class LO,
class GO,
class Node >
62 class TpetraTsqrTest {
64 typedef S scalar_type;
65 typedef LO local_ordinal_type;
66 typedef GO global_ordinal_type;
67 typedef Node node_type;
69 typedef typename TSQR::ScalarTraits< S >::magnitude_type magnitude_type;
70 typedef TSQR::Trilinos::TsqrTpetraAdaptor< S, LO, GO, Node > adaptor_type;
72 TpetraTsqrTest (
const Tpetra::global_size_t nrowsGlobal,
74 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
75 const Teuchos::RCP< Node >& node,
76 const Teuchos::ParameterList& params) :
77 results_ (magnitude_type(0), magnitude_type(0))
80 using Teuchos::Exceptions::InvalidParameter;
81 typedef typename adaptor_type::factor_output_type factor_output_type;
82 typedef Teuchos::SerialDenseMatrix< LO, S > matrix_type;
84 bool contiguousCacheBlocks =
false;
86 contiguousCacheBlocks = params.get<
bool>(
"contiguousCacheBlocks");
87 }
catch (InvalidParameter&) {
88 contiguousCacheBlocks =
false;
91 triple_type testProblem =
92 makeTestProblem (nrowsGlobal, ncols, comm, node, params);
98 RCP< MV > A = testProblem[0];
99 RCP< MV > A_copy = testProblem[1];
100 RCP< MV > Q = testProblem[2];
101 matrix_type R (ncols, ncols);
105 adaptor_type adaptor (*A, params);
106 if (contiguousCacheBlocks)
107 adaptor.cacheBlock (*A, *A_copy);
109 factor_output_type factorOutput =
110 adaptor.factor (*A_copy, R, contiguousCacheBlocks);
111 adaptor.explicitQ (*A_copy, factorOutput, *Q, contiguousCacheBlocks);
112 if (contiguousCacheBlocks)
117 adaptor.unCacheBlock (*A_copy, *Q);
119 results_ = adaptor.verify (*A, *Q, R);
124 std::pair< magnitude_type, magnitude_type >
131 typedef Tpetra::MultiVector< S, LO, GO, Node > MV;
132 typedef Teuchos::Tuple< RCP< MV >, 3 > triple_type;
133 typedef Teuchos::RCP< const Teuchos::Comm<int> > comm_ptr;
134 typedef Tpetra::Map< LO, GO, Node > map_type;
135 typedef Teuchos::RCP< const map_type > map_ptr;
136 typedef TSQR::Random::NormalGenerator< LO, S > normalgen_type;
137 typedef Teuchos::RCP< Node > node_ptr;
143 std::pair< magnitude_type, magnitude_type > results_;
154 makeMap (
const Tpetra::global_size_t nrowsGlobal,
155 const comm_ptr& comm,
156 const node_ptr& node)
158 using Tpetra::createUniformContigMapWithNode;
159 return createUniformContigMapWithNode< LO, GO, Node > (nrowsGlobal, comm);
165 makeMultiVector (
const map_ptr& map,
170 return Teuchos::rcp (
new MV (map, ncols,
false));
176 fillMultiVector (
const RCP< MV >& mv,
177 const RCP< normalgen_type >& pGen)
179 using TSQR::Trilinos::TpetraRandomizer;
180 typedef TpetraRandomizer< S, LO, GO, Node, normalgen_type > randomizer_type;
182 const LO ncols = mv->getNumVectors();
183 std::vector< S > singular_values (ncols);
186 singular_values[0] = S(1);
187 for (LO k = 1; k < ncols; ++k)
188 singular_values[k] = singular_values[k-1] / S(2);
190 randomizer_type randomizer (*mv, pGen);
191 randomizer.randomMultiVector (*mv, &singular_values[0]);
195 makeTestProblem (
const Tpetra::global_size_t nrowsGlobal,
197 const comm_ptr& comm,
198 const node_ptr& node,
199 const Teuchos::ParameterList& params)
201 using TSQR::Trilinos::TpetraMessenger;
202 using TSQR::MessengerBase;
204 map_ptr map = makeMap (nrowsGlobal, comm, node);
205 RCP< MV > A = makeMultiVector (map, ncols);
206 RCP< MV > A_copy = makeMultiVector (map, ncols);
207 RCP< MV > Q = makeMultiVector (map, ncols);
210 RCP< normalgen_type > pGen (
new normalgen_type);
211 fillMultiVector (A, pGen);
213 return Teuchos::tuple (A, A_copy, Q);
Partial specialization of Anasazi::MultiVecTraits and Anasazi::OperatorTraits for Tpetra objects.