42 #ifndef __Epetra_TsqrAdaptor_hpp
43 #define __Epetra_TsqrAdaptor_hpp
59 #include <Tpetra_ConfigDefs.hpp>
61 #if defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
63 #include <Kokkos_DefaultNode.hpp>
64 #include <Tsqr_NodeTsqrFactory.hpp>
66 #include <Tsqr_DistTsqr.hpp>
67 #include <Epetra_Comm.h>
71 #include <Epetra_MultiVector.h>
72 #include <Teuchos_ParameterListAcceptorDefaultBase.hpp>
102 class TsqrAdaptor :
public Teuchos::ParameterListAcceptorDefaultBase {
104 typedef Epetra_MultiVector MV;
112 typedef double scalar_type;
120 typedef int ordinal_type;
132 typedef Kokkos::SerialNode node_type;
142 typedef Teuchos::SerialDenseMatrix<ordinal_type, scalar_type> dense_matrix_type;
149 typedef double magnitude_type;
152 typedef TSQR::MatView<ordinal_type, scalar_type> matview_type;
153 typedef TSQR::NodeTsqrFactory<node_type, scalar_type, ordinal_type> node_tsqr_factory_type;
156 typedef node_tsqr_factory_type::node_tsqr_type node_tsqr_type;
157 typedef TSQR::DistTsqr<ordinal_type, scalar_type> dist_tsqr_type;
158 typedef TSQR::Tsqr<ordinal_type, scalar_type, node_tsqr_type> tsqr_type;
167 TsqrAdaptor (
const Teuchos::RCP<Teuchos::ParameterList>& plist) :
168 nodeTsqr_ (new node_tsqr_type),
169 distTsqr_ (new dist_tsqr_type),
170 tsqr_ (new tsqr_type (nodeTsqr_, distTsqr_)),
173 setParameterList (plist);
178 nodeTsqr_ (new node_tsqr_type),
179 distTsqr_ (new dist_tsqr_type),
180 tsqr_ (new tsqr_type (nodeTsqr_, distTsqr_)),
183 setParameterList (Teuchos::null);
186 Teuchos::RCP<const Teuchos::ParameterList>
187 getValidParameters ()
const
191 using Teuchos::ParameterList;
192 using Teuchos::parameterList;
194 if (defaultParams_.is_null()) {
195 RCP<ParameterList> params = parameterList (
"TSQR implementation");
196 params->set (
"NodeTsqr", *(nodeTsqr_->getValidParameters ()));
197 params->set (
"DistTsqr", *(distTsqr_->getValidParameters ()));
198 defaultParams_ = params;
200 return defaultParams_;
204 setParameterList (
const Teuchos::RCP<Teuchos::ParameterList>& plist)
206 using Teuchos::ParameterList;
207 using Teuchos::parameterList;
209 using Teuchos::sublist;
211 RCP<ParameterList> params = plist.is_null() ?
212 parameterList (*getValidParameters ()) : plist;
213 nodeTsqr_->setParameterList (sublist (params,
"NodeTsqr"));
214 distTsqr_->setParameterList (sublist (params,
"DistTsqr"));
216 this->setMyParamList (params);
241 factorExplicit (MV& A,
243 dense_matrix_type& R,
244 const bool forceNonnegativeDiagonal=
false)
246 typedef Kokkos::MultiVector<scalar_type, node_type> KMV;
249 KMV A_view = getNonConstView (A);
250 KMV Q_view = getNonConstView (Q);
251 tsqr_->factorExplicit (A_view, Q_view, R,
false,
252 forceNonnegativeDiagonal);
287 dense_matrix_type& R,
288 const magnitude_type& tol)
290 typedef Kokkos::MultiVector<scalar_type, node_type> KMV;
297 KMV Q_view = getNonConstView (Q);
298 return tsqr_->revealRank (Q_view, R, tol,
false);
303 Teuchos::RCP<node_tsqr_type> nodeTsqr_;
306 Teuchos::RCP<dist_tsqr_type> distTsqr_;
309 Teuchos::RCP<tsqr_type> tsqr_;
312 mutable Teuchos::RCP<const Teuchos::ParameterList> defaultParams_;
336 prepareTsqr (
const MV& mv)
339 prepareDistTsqr (mv);
340 prepareNodeTsqr (mv);
349 prepareNodeTsqr (
const MV& mv)
354 Teuchos::ParameterList plist;
355 Teuchos::RCP<node_type> node (
new node_type (plist));
356 node_tsqr_factory_type::prepareNodeTsqr (nodeTsqr_, node);
366 prepareDistTsqr (
const MV& mv)
370 using TSQR::Epetra::makeTsqrMessenger;
371 typedef TSQR::MessengerBase<scalar_type> base_mess_type;
376 RCP<const Epetra_Comm> comm = rcp (mv.Comm().Clone());
377 RCP<base_mess_type> messBase = makeTsqrMessenger<scalar_type> (comm);
378 distTsqr_->init (messBase);
393 static Kokkos::MultiVector<scalar_type, node_type>
394 getNonConstView (MV& A)
401 TEUCHOS_TEST_FOR_EXCEPTION(! A.ConstantStride(), std::invalid_argument,
402 "TSQR does not currently support Epetra_MultiVector "
403 "inputs that do not have constant stride.");
404 const int numRows = A.MyLength();
405 const int numCols = A.NumVectors();
406 const int stride = A.Stride();
410 Teuchos::ArrayRCP<double> A_ptr (A.Values(), 0, numRows*stride,
false);
412 typedef Kokkos::MultiVector<scalar_type, node_type> KMV;
418 Teuchos::ParameterList plist;
419 Teuchos::RCP<node_type> node (
new node_type (plist));
421 A_kmv.initializeValues (numRows, numCols, A_ptr, stride);
428 #endif // defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
430 #endif // __Epetra_TsqrAdaptor_hpp