29 #ifndef __TSQR_Trilinos_TsqrTpetraTest_hpp 30 #define __TSQR_Trilinos_TsqrTpetraTest_hpp 33 #include "Tsqr_Random_NormalGenerator.hpp" 34 #include "Teuchos_ParameterList.hpp" 35 #include "Teuchos_Tuple.hpp" 36 #include "Teuchos_Time.hpp" 48 template<
class S,
class LO,
class GO,
class Node >
49 class TpetraTsqrTest {
51 typedef S scalar_type;
52 typedef LO local_ordinal_type;
53 typedef GO global_ordinal_type;
54 typedef Node node_type;
56 typedef typename TSQR::ScalarTraits< S >::magnitude_type magnitude_type;
57 typedef TSQR::Trilinos::TsqrTpetraAdaptor< S, LO, GO, Node > adaptor_type;
59 TpetraTsqrTest (
const Tpetra::global_size_t nrowsGlobal,
61 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
62 const Teuchos::RCP< Node >& node,
63 const Teuchos::ParameterList& params) :
64 results_ (magnitude_type(0), magnitude_type(0))
67 using Teuchos::Exceptions::InvalidParameter;
68 typedef typename adaptor_type::factor_output_type factor_output_type;
69 typedef Teuchos::SerialDenseMatrix< LO, S > matrix_type;
71 bool contiguousCacheBlocks =
false;
73 contiguousCacheBlocks = params.get<
bool>(
"contiguousCacheBlocks");
74 }
catch (InvalidParameter&) {
75 contiguousCacheBlocks =
false;
78 triple_type testProblem =
79 makeTestProblem (nrowsGlobal, ncols, comm, node, params);
85 RCP< MV > A = testProblem[0];
86 RCP< MV > A_copy = testProblem[1];
87 RCP< MV > Q = testProblem[2];
88 matrix_type R (ncols, ncols);
92 adaptor_type adaptor (*A, params);
93 if (contiguousCacheBlocks)
94 adaptor.cacheBlock (*A, *A_copy);
96 factor_output_type factorOutput =
97 adaptor.factor (*A_copy, R, contiguousCacheBlocks);
98 adaptor.explicitQ (*A_copy, factorOutput, *Q, contiguousCacheBlocks);
99 if (contiguousCacheBlocks)
104 adaptor.unCacheBlock (*A_copy, *Q);
106 results_ = adaptor.verify (*A, *Q, R);
111 std::pair< magnitude_type, magnitude_type >
118 typedef Tpetra::MultiVector< S, LO, GO, Node > MV;
119 typedef Teuchos::Tuple< RCP< MV >, 3 > triple_type;
120 typedef Teuchos::RCP< const Teuchos::Comm<int> > comm_ptr;
121 typedef Tpetra::Map< LO, GO, Node > map_type;
122 typedef Teuchos::RCP< const map_type > map_ptr;
123 typedef TSQR::Random::NormalGenerator< LO, S > normalgen_type;
124 typedef Teuchos::RCP< Node > node_ptr;
130 std::pair< magnitude_type, magnitude_type > results_;
141 makeMap (
const Tpetra::global_size_t nrowsGlobal,
142 const comm_ptr& comm,
143 const node_ptr& node)
145 using Tpetra::createUniformContigMapWithNode;
146 return createUniformContigMapWithNode< LO, GO, Node > (nrowsGlobal,
153 makeMultiVector (
const map_ptr& map,
158 return Teuchos::rcp (
new MV (map, ncols,
false));
164 fillMultiVector (
const RCP< MV >& mv,
165 const RCP< normalgen_type >& pGen)
167 using TSQR::Trilinos::TpetraRandomizer;
168 typedef TpetraRandomizer< S, LO, GO, Node, normalgen_type > randomizer_type;
170 const LO ncols = mv->getNumVectors();
171 std::vector< S > singular_values (ncols);
174 singular_values[0] = S(1);
175 for (LO k = 1; k < ncols; ++k)
176 singular_values[k] = singular_values[k-1] / S(2);
178 randomizer_type randomizer (*mv, pGen);
179 randomizer.randomMultiVector (*mv, &singular_values[0]);
183 makeTestProblem (
const Tpetra::global_size_t nrowsGlobal,
185 const comm_ptr& comm,
186 const node_ptr& node,
187 const Teuchos::ParameterList& params)
189 using TSQR::Trilinos::TpetraMessenger;
190 using TSQR::MessengerBase;
192 map_ptr map = makeMap (nrowsGlobal, comm, node);
193 RCP< MV > A = makeMultiVector (map, ncols);
194 RCP< MV > A_copy = makeMultiVector (map, ncols);
195 RCP< MV > Q = makeMultiVector (map, ncols);
198 RCP< normalgen_type > pGen (
new normalgen_type);
199 fillMultiVector (A, pGen);
201 return Teuchos::tuple (A, A_copy, Q);
209 #endif // __TSQR_Trilinos_TsqrTpetraTest_hpp Partial specialization of Anasazi::MultiVecTraits and Anasazi::OperatorTraits for Tpetra objects...