40 #ifndef EPETRA_TSQRADAPTOR_HPP
41 #define EPETRA_TSQRADAPTOR_HPP
55 #include "Tpetra_ConfigDefs.hpp"
57 #if defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
59 #include "Tsqr_NodeTsqrFactory.hpp"
61 #include "Tsqr_DistTsqr.hpp"
62 #include "Epetra_Comm.h"
66 #include "Epetra_MultiVector.h"
67 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
96 class TsqrAdaptor :
public Teuchos::ParameterListAcceptorDefaultBase {
98 typedef Epetra_MultiVector MV;
106 typedef double scalar_type;
114 typedef int ordinal_type;
122 Kokkos::Device<Kokkos::DefaultHostExecutionSpace,
133 using dense_matrix_type =
134 Teuchos::SerialDenseMatrix<ordinal_type, scalar_type>;
141 using magnitude_type = double;
144 using matview_type = TSQR::MatView<ordinal_type, scalar_type>;
145 using node_tsqr_factory_type =
146 TSQR::NodeTsqrFactory<scalar_type, ordinal_type, device_type>;
149 using node_tsqr_type = TSQR::NodeTsqr<ordinal_type, scalar_type>;
150 using dist_tsqr_type = TSQR::DistTsqr<ordinal_type, scalar_type>;
151 using tsqr_type = TSQR::Tsqr<ordinal_type, scalar_type>;
160 TsqrAdaptor (
const Teuchos::RCP<Teuchos::ParameterList>& plist) :
161 nodeTsqr_ (node_tsqr_factory_type::getNodeTsqr ()),
162 distTsqr_ (new dist_tsqr_type),
163 tsqr_ (new tsqr_type (nodeTsqr_, distTsqr_)),
166 setParameterList (plist);
171 nodeTsqr_ (node_tsqr_factory_type::getNodeTsqr ()),
172 distTsqr_ (new dist_tsqr_type),
173 tsqr_ (new tsqr_type (nodeTsqr_, distTsqr_)),
176 setParameterList (Teuchos::null);
179 Teuchos::RCP<const Teuchos::ParameterList>
180 getValidParameters ()
const
184 using Teuchos::ParameterList;
185 using Teuchos::parameterList;
187 if (defaultParams_.is_null()) {
188 RCP<ParameterList> params = parameterList (
"TSQR implementation");
189 params->set (
"NodeTsqr", *(nodeTsqr_->getValidParameters ()));
190 params->set (
"DistTsqr", *(distTsqr_->getValidParameters ()));
191 defaultParams_ = params;
193 return defaultParams_;
197 setParameterList (
const Teuchos::RCP<Teuchos::ParameterList>& plist)
199 using Teuchos::ParameterList;
200 using Teuchos::parameterList;
202 using Teuchos::sublist;
204 RCP<ParameterList> params = plist.is_null() ?
205 parameterList (*getValidParameters ()) : plist;
206 nodeTsqr_->setParameterList (sublist (params,
"NodeTsqr"));
207 distTsqr_->setParameterList (sublist (params,
"DistTsqr"));
209 this->setMyParamList (params);
234 factorExplicit (MV& A,
236 dense_matrix_type& R,
237 const bool forceNonnegativeDiagonal=
false)
241 scalar_type*
const A_ptr = A.Values ();
242 scalar_type*
const Q_ptr = Q.Values ();
243 scalar_type*
const R_ptr = R.values ();
244 const ordinal_type numRows = A.MyLength ();
245 const ordinal_type numCols = A.NumVectors ();
246 const ordinal_type lda = A.Stride ();
247 const ordinal_type ldq = Q.Stride ();
248 const ordinal_type ldr = R.stride ();
250 const bool contiguousCacheBlocks =
false;
251 tsqr_->factorExplicitRaw (numRows, numCols, A_ptr, lda,
252 Q_ptr, ldq, R_ptr, ldr,
253 contiguousCacheBlocks,
254 forceNonnegativeDiagonal);
289 dense_matrix_type& R,
290 const magnitude_type& tol)
292 TEUCHOS_TEST_FOR_EXCEPTION
293 (! Q.ConstantStride (), std::invalid_argument,
"TsqrAdaptor::"
294 "revealRank: Input MultiVector Q must have constant stride.");
299 return tsqr_->revealRankRaw (Q.MyLength (), Q.NumVectors (),
300 Q.Values (), Q.Stride (),
301 R.values (), R.stride (), tol,
false);
306 Teuchos::RCP<node_tsqr_type> nodeTsqr_;
309 Teuchos::RCP<dist_tsqr_type> distTsqr_;
312 Teuchos::RCP<tsqr_type> tsqr_;
315 mutable Teuchos::RCP<const Teuchos::ParameterList> defaultParams_;
339 prepareTsqr (
const MV& mv)
342 prepareDistTsqr (mv);
354 prepareDistTsqr (
const MV& mv)
358 using TSQR::Epetra::makeTsqrMessenger;
359 typedef TSQR::MessengerBase<scalar_type> base_mess_type;
364 RCP<const Epetra_Comm> comm = rcp (mv.Comm().Clone());
365 RCP<base_mess_type> messBase = makeTsqrMessenger<scalar_type> (comm);
366 distTsqr_->init (messBase);
372 #endif // defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
374 #endif // EPETRA_TSQRADAPTOR_HPP
Function for wrapping Epetra_Comm in a communicator wrapper that TSQR can use.