42 #ifndef __Tpetra_TsqrAdaptor_hpp 43 #define __Tpetra_TsqrAdaptor_hpp 49 #include <Tpetra_ConfigDefs.hpp> 51 #ifdef HAVE_TPETRA_TSQR 52 # include <Tsqr_NodeTsqrFactory.hpp> 54 # include <Tsqr_DistTsqr.hpp> 57 # include <Tsqr_TeuchosMessenger.hpp> 58 # include <Tpetra_MultiVector.hpp> 59 # include <Teuchos_ParameterListAcceptorDefaultBase.hpp> 88 class TsqrAdaptor :
public Teuchos::ParameterListAcceptorDefaultBase {
91 typedef typename MV::local_ordinal_type ordinal_type;
93 typedef Teuchos::SerialDenseMatrix<ordinal_type, scalar_type> dense_matrix_type;
94 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
98 typedef TSQR::NodeTsqrFactory<node_type, scalar_type, ordinal_type> node_tsqr_factory_type;
99 typedef typename node_tsqr_factory_type::node_tsqr_type node_tsqr_type;
100 typedef TSQR::DistTsqr<ordinal_type, scalar_type> dist_tsqr_type;
101 typedef TSQR::Tsqr<ordinal_type, scalar_type, node_tsqr_type> tsqr_type;
110 TsqrAdaptor (
const Teuchos::RCP<Teuchos::ParameterList>& plist) :
111 nodeTsqr_ (new node_tsqr_type),
112 distTsqr_ (new dist_tsqr_type),
113 tsqr_ (new tsqr_type (nodeTsqr_, distTsqr_)),
116 setParameterList (plist);
121 nodeTsqr_ (new node_tsqr_type),
122 distTsqr_ (new dist_tsqr_type),
123 tsqr_ (new tsqr_type (nodeTsqr_, distTsqr_)),
126 setParameterList (Teuchos::null);
130 Teuchos::RCP<const Teuchos::ParameterList>
131 getValidParameters ()
const 135 using Teuchos::ParameterList;
136 using Teuchos::parameterList;
138 if (defaultParams_.is_null()) {
139 RCP<ParameterList> params = parameterList (
"TSQR implementation");
140 params->set (
"NodeTsqr", *(nodeTsqr_->getValidParameters ()));
141 params->set (
"DistTsqr", *(distTsqr_->getValidParameters ()));
142 defaultParams_ = params;
144 return defaultParams_;
173 setParameterList (
const Teuchos::RCP<Teuchos::ParameterList>& plist)
175 using Teuchos::ParameterList;
176 using Teuchos::parameterList;
178 using Teuchos::sublist;
180 RCP<ParameterList> params = plist.is_null() ?
181 parameterList (*getValidParameters ()) : plist;
182 nodeTsqr_->setParameterList (sublist (params,
"NodeTsqr"));
183 distTsqr_->setParameterList (sublist (params,
"DistTsqr"));
185 this->setMyParamList (params);
210 factorExplicit (MV& A,
212 dense_matrix_type& R,
213 const bool forceNonnegativeDiagonal=
false)
215 typedef KokkosClassic::MultiVector<scalar_type, node_type> KMV;
218 KMV A_view = getNonConstView (A);
219 KMV Q_view = getNonConstView (Q);
220 tsqr_->factorExplicit (A_view, Q_view, R,
false,
221 forceNonnegativeDiagonal);
256 dense_matrix_type& R,
257 const magnitude_type& tol)
259 typedef KokkosClassic::MultiVector<scalar_type, node_type> KMV;
266 KMV Q_view = getNonConstView (Q);
267 return tsqr_->revealRank (Q_view, R, tol,
false);
272 Teuchos::RCP<node_tsqr_type> nodeTsqr_;
275 Teuchos::RCP<dist_tsqr_type> distTsqr_;
278 Teuchos::RCP<tsqr_type> tsqr_;
281 mutable Teuchos::RCP<const Teuchos::ParameterList> defaultParams_;
307 prepareTsqr (
const MV& mv)
310 prepareDistTsqr (mv);
311 prepareNodeTsqr (mv);
320 prepareNodeTsqr (
const MV& mv)
322 node_tsqr_factory_type::prepareNodeTsqr (nodeTsqr_, mv.getMap()->getNode());
332 prepareDistTsqr (
const MV& mv)
335 using Teuchos::rcp_implicit_cast;
336 typedef TSQR::TeuchosMessenger<scalar_type> mess_type;
337 typedef TSQR::MessengerBase<scalar_type> base_mess_type;
339 RCP<const Teuchos::Comm<int> > comm = mv.getMap()->getComm();
340 RCP<mess_type> mess (
new mess_type (comm));
341 RCP<base_mess_type> messBase = rcp_implicit_cast<base_mess_type> (mess);
342 distTsqr_->init (messBase);
357 static KokkosClassic::MultiVector<scalar_type, node_type>
358 getNonConstView (MV& A)
365 TEUCHOS_TEST_FOR_EXCEPTION(
366 ! A.isConstantStride(), std::invalid_argument,
367 "Tpetra::TsqrAdaptor::getNonConstView: TSQR does not currently " 368 "support Tpetra::MultiVector inputs that do not have constant " 370 return A.getLocalMV ();
376 #endif // HAVE_TPETRA_TSQR 378 #endif // __Tpetra_TsqrAdaptor_hpp Namespace Tpetra contains the class and methods constituting the Tpetra library.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
double scalar_type
Default value of Scalar template parameter.