Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Epetra_TsqrAdaptor.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef EPETRA_TSQRADAPTOR_HPP
11 #define EPETRA_TSQRADAPTOR_HPP
12 
24 
25 #include "Tpetra_ConfigDefs.hpp"
26 
27 #if defined(TPETRA_ENABLE_DEPRECATED_CODE)
28 #if defined(TPETRA_DEPRECATED_DECLARATIONS)
29 #warning This file is deprecated due to Epetra removal and will be removed
30 #endif
31 #else
32 #error This file is deprecated due to Epetra removal and will be removed
33 #endif
34 
35 #if defined(TPETRA_ENABLE_DEPRECATED_CODE) && defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
36 
37 #include "Tsqr_NodeTsqrFactory.hpp" // create intranode TSQR object
38 #include "Tsqr.hpp" // full (internode + intranode) TSQR
39 #include "Tsqr_DistTsqr.hpp" // internode TSQR
40 #include "Epetra_Comm.h"
41 // Subclass of TSQR::MessengerBase, implemented using Teuchos
42 // communicator template helper functions
43 #include "Epetra_TsqrMessenger.hpp"
44 #include "Epetra_MultiVector.h"
45 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
46 #include <stdexcept>
47 
48 namespace Epetra {
49 
74  TPETRA_DEPRECATED_MSG("epetra removal")
75  class TsqrAdaptor : public Teuchos::ParameterListAcceptorDefaultBase {
76  public:
77  typedef Epetra_MultiVector MV;
78 
85  typedef double scalar_type;
86 
93  typedef int ordinal_type;
94 
100  using device_type =
101  Kokkos::Device<Kokkos::DefaultHostExecutionSpace,
102  Kokkos::HostSpace>;
103 
112  using dense_matrix_type =
113  Teuchos::SerialDenseMatrix<ordinal_type, scalar_type>;
114 
120  using magnitude_type = double;
121 
122  private:
123  using matview_type = TSQR::MatView<ordinal_type, scalar_type>;
124  using node_tsqr_factory_type =
125  TSQR::NodeTsqrFactory<scalar_type, ordinal_type, device_type>;
126  // Don't need a "typename" here, because there are no template
127  // parameters involved in the type definition.
128  using node_tsqr_type = TSQR::NodeTsqr<ordinal_type, scalar_type>;
129  using dist_tsqr_type = TSQR::DistTsqr<ordinal_type, scalar_type>;
130  using tsqr_type = TSQR::Tsqr<ordinal_type, scalar_type>;
131 
132  public:
139  TsqrAdaptor (const Teuchos::RCP<Teuchos::ParameterList>& plist) :
140  nodeTsqr_ (node_tsqr_factory_type::getNodeTsqr ()),
141  distTsqr_ (new dist_tsqr_type),
142  tsqr_ (new tsqr_type (nodeTsqr_, distTsqr_)),
143  ready_ (false)
144  {
145  setParameterList (plist);
146  }
147 
149  TsqrAdaptor () :
150  nodeTsqr_ (node_tsqr_factory_type::getNodeTsqr ()),
151  distTsqr_ (new dist_tsqr_type),
152  tsqr_ (new tsqr_type (nodeTsqr_, distTsqr_)),
153  ready_ (false)
154  {
155  setParameterList (Teuchos::null);
156  }
157 
158  Teuchos::RCP<const Teuchos::ParameterList>
159  getValidParameters () const
160  {
161  using Teuchos::RCP;
162  using Teuchos::rcp;
163  using Teuchos::ParameterList;
164  using Teuchos::parameterList;
165 
166  if (defaultParams_.is_null()) {
167  RCP<ParameterList> params = parameterList ("TSQR implementation");
168  params->set ("NodeTsqr", *(nodeTsqr_->getValidParameters ()));
169  params->set ("DistTsqr", *(distTsqr_->getValidParameters ()));
170  defaultParams_ = params;
171  }
172  return defaultParams_;
173  }
174 
175  void
176  setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& plist)
177  {
178  using Teuchos::ParameterList;
179  using Teuchos::parameterList;
180  using Teuchos::RCP;
181  using Teuchos::sublist;
182 
183  RCP<ParameterList> params = plist.is_null() ?
184  parameterList (*getValidParameters ()) : plist;
185  nodeTsqr_->setParameterList (sublist (params, "NodeTsqr"));
186  distTsqr_->setParameterList (sublist (params, "DistTsqr"));
187 
188  this->setMyParamList (params);
189  }
190 
212  void
213  factorExplicit (MV& A,
214  MV& Q,
215  dense_matrix_type& R,
216  const bool forceNonnegativeDiagonal=false)
217  {
218  prepareTsqr (Q); // Finish initializing TSQR.
219 
220  scalar_type* const A_ptr = A.Values ();
221  scalar_type* const Q_ptr = Q.Values ();
222  scalar_type* const R_ptr = R.values ();
223  const ordinal_type numRows = A.MyLength ();
224  const ordinal_type numCols = A.NumVectors ();
225  const ordinal_type lda = A.Stride ();
226  const ordinal_type ldq = Q.Stride ();
227  const ordinal_type ldr = R.stride ();
228 
229  const bool contiguousCacheBlocks = false;
230  tsqr_->factorExplicitRaw (numRows, numCols, A_ptr, lda,
231  Q_ptr, ldq, R_ptr, ldr,
232  contiguousCacheBlocks,
233  forceNonnegativeDiagonal);
234  }
235 
266  int
267  revealRank (MV& Q,
268  dense_matrix_type& R,
269  const magnitude_type& tol)
270  {
271  TEUCHOS_TEST_FOR_EXCEPTION
272  (! Q.ConstantStride (), std::invalid_argument, "TsqrAdaptor::"
273  "revealRank: Input MultiVector Q must have constant stride.");
274  prepareTsqr (Q); // Finish initializing TSQR.
275  // FIXME (mfh 25 Oct 2010) Check Epetra_Comm object in Q to make
276  // sure it is the same communicator as the one we are using in
277  // our dist_tsqr_type implementation.
278  return tsqr_->revealRankRaw (Q.MyLength (), Q.NumVectors (),
279  Q.Values (), Q.Stride (),
280  R.values (), R.stride (), tol, false);
281  }
282 
283  private:
285  Teuchos::RCP<node_tsqr_type> nodeTsqr_;
286 
288  Teuchos::RCP<dist_tsqr_type> distTsqr_;
289 
291  Teuchos::RCP<tsqr_type> tsqr_;
292 
294  mutable Teuchos::RCP<const Teuchos::ParameterList> defaultParams_;
295 
297  bool ready_;
298 
317  void
318  prepareTsqr (const MV& mv)
319  {
320  if (! ready_) {
321  prepareDistTsqr (mv);
322  ready_ = true;
323  }
324  }
325 
332  void
333  prepareDistTsqr (const MV& mv)
334  {
335  using Teuchos::RCP;
336  using Teuchos::rcp;
337  using TSQR::Epetra::makeTsqrMessenger;
338  typedef TSQR::MessengerBase<scalar_type> base_mess_type;
339 
340  // If mv falls out of scope, its Epetra_Comm may become invalid.
341  // Thus, we clone the input Epetra_Comm, so that the messenger
342  // owns the object.
343  RCP<const Epetra_Comm> comm = rcp (mv.Comm().Clone());
344  RCP<base_mess_type> messBase = makeTsqrMessenger<scalar_type> (comm);
345  distTsqr_->init (messBase);
346  }
347  };
348 
349 } // namespace Epetra
350 
351 #endif // defined(TPETRA_ENABLE_DEPRECATED_CODE) && defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
352 
353 #endif // EPETRA_TSQRADAPTOR_HPP
354 
Function for wrapping Epetra_Comm in a communicator wrapper that TSQR can use.