Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Amesos2_Solver_MP_Vector.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef AMESOS2_SOLVER_MP_VECTOR_HPP
43 #define AMESOS2_SOLVER_MP_VECTOR_HPP
44 
45 #include "Amesos2_Solver.hpp"
46 #include "Amesos2_Factory.hpp"
49 
50 namespace Amesos2 {
51 
52  template <class S, class LO, class GO, class N>
54  const Teuchos::RCP<const Tpetra::CrsMatrix<Sacado::MP::Vector<S>, LO, GO, N> >& A = Teuchos::null,
55  const Teuchos::RCP<Tpetra::MultiVector<Sacado::MP::Vector<S>, LO, GO, N> >& X = Teuchos::null,
56  const Teuchos::RCP<const Tpetra::MultiVector<Sacado::MP::Vector<S>, LO, GO, N> >& B = Teuchos::null)
57  {
58  // Without KokkosRefactor, can only do static
59  return S::static_size;
60  }
61 
62 #if defined(TPETRA_HAVE_KOKKOS_REFACTOR)
63  template <class S, class LO, class GO, class D>
65  const Teuchos::RCP<const Tpetra::CrsMatrix<Sacado::MP::Vector<S>, LO, GO, Kokkos::Compat::KokkosDeviceWrapperNode<D> > >& A = Teuchos::null,
66  const Teuchos::RCP<Tpetra::MultiVector<Sacado::MP::Vector<S>, LO, GO, Kokkos::Compat::KokkosDeviceWrapperNode<D> > >& X = Teuchos::null,
67  const Teuchos::RCP<const Tpetra::MultiVector<Sacado::MP::Vector<S>, LO, GO, Kokkos::Compat::KokkosDeviceWrapperNode<D> > >& B = Teuchos::null)
68  {
69  if (A != Teuchos::null) {
70  return Kokkos::dimension_scalar(A->getLocalValuesView());
71  }
72  else if (X != Teuchos::null) {
73  return Kokkos::dimension_scalar(X->template getLocalView<D>());
74  }
75  else if (B != Teuchos::null) {
76  return Kokkos::dimension_scalar(B->template getLocalView<D>());
77  }
78  return 0;
79  }
80 #endif
81 
88  template <class Storage, class LocalOrdinal, class GlobalOrdinal, class Node,
89  template<class,class> class ConcreteSolver>
91  public Solver< Tpetra::CrsMatrix<Sacado::MP::Vector<Storage>,
92  LocalOrdinal,
93  GlobalOrdinal,
94  Node>,
95  Tpetra::MultiVector<Sacado::MP::Vector<Storage>,
96  LocalOrdinal,
97  GlobalOrdinal,
98  Node>
99  >
100  {
101  public:
102 
104  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Matrix;
105  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Vector;
106 
107  typedef typename Scalar::value_type BaseScalar;
108  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Map;
109  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> FlatGraph;
110  typedef Tpetra::CrsMatrix<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> FlatMatrix;
111  typedef Tpetra::MultiVector<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> FlatVector;
112  typedef ConcreteSolver<FlatMatrix,FlatVector> FlatConcreteSolver;
113  typedef Solver<FlatMatrix,FlatVector> FlatSolver;
114 
115  typedef Solver<Matrix,Vector> solver_type;
116  typedef typename solver_type::type type;
117 
120  const Teuchos::RCP<const Matrix>& A_,
121  const Teuchos::RCP<Vector>& X_,
122  const Teuchos::RCP<const Vector>& B_) :
123  A(A_), X(X_), B(B_) {
124  const LocalOrdinal mp_size = get_mp_vector_size(A, X, B);
125  flat_graph = Stokhos::create_flat_mp_graph(*(A->getCrsGraph()),
126  flat_X_map,
127  flat_B_map,
128  mp_size);
129  if (A != Teuchos::null)
131  if (X != Teuchos::null)
133  if (B != Teuchos::null)
135  flat_solver =
136  create_solver_with_supported_type<ConcreteSolver,FlatMatrix,FlatVector>::apply(flat_A, flat_X, flat_B);
137  }
138 
140 
141 
149  virtual type& preOrdering( void ) {
150  flat_solver->preOrdering();
151  return *this;
152  }
153 
154 
160  virtual type& symbolicFactorization( void ) {
161  flat_solver->symbolicFactorization();
162  return *this;
163  }
164 
165 
178  virtual type& numericFactorization( void ) {
179  flat_solver->numericFactorization();
180  return *this;
181  }
182 
183 
196  virtual void solve( void ) {
197  flat_solver->solve();
198  }
199 
200 
218  virtual void solve(const Teuchos::Ptr<Vector> XX,
219  const Teuchos::Ptr<const Vector> BB) const {
220  flat_solver->solve(
223  }
224 
225 
243  virtual void solve(Vector* XX, const Vector* BB) const {
244  flat_solver->solve(
247  }
248 
250 
251 
268  virtual type& setParameters(
269  const Teuchos::RCP<Teuchos::ParameterList> & parameterList ) {
270  flat_solver->setParameters(parameterList);
271  return *this;
272  }
273 
274 
280  getValidParameters( void ) const {
281  return flat_solver->getValidParameters();
282  }
283 
285 
286 
310  virtual void setA( const Teuchos::RCP<const Matrix> a,
311  EPhase keep_phase = CLEAN ) {
312  A = a;
313 
314  // Rebuild flat matrix/graph
315  const LocalOrdinal mp_size = get_mp_vector_size(A);
316  if (keep_phase <= CLEAN) {
320  flat_graph = Stokhos::create_flat_mp_graph(*(A->getCrsGraph()),
321  flat_X_map,
322  flat_B_map,
323  mp_size);
324  }
325  if (keep_phase <= SYMBFACT) // should this by NUMFACT???
327 
328  flat_solver->setA(flat_A, keep_phase);
329  }
330 
350  virtual void setA( const Matrix* a, EPhase keep_phase = CLEAN ) {
351  this->setA(Teuchos::rcp(a,false), keep_phase);
352  }
353 
354 
356  virtual bool matrixShapeOK( void ) {
357  return flat_solver->matrixShapeOK();
358  }
359 
360 
362  virtual void setX( const Teuchos::RCP<Vector> x ) {
363  X = x;
364  if (x != Teuchos::null)
366  else
368  flat_solver->setX(flat_X);
369  }
370 
371 
373  virtual void setX( Vector* x ) {
374  if (x != 0) {
375  X = Teuchos::rcp(x, false);
377  }
378  else {
379  X = Teuchos::null;
381  }
382  flat_solver->setX(flat_X);
383  }
384 
385 
387  virtual const Teuchos::RCP<Vector> getX( void ) {
388  return X;
389  }
390 
391 
393  virtual Vector* getXRaw( void ) {
394  return X.get();
395  }
396 
397 
399  virtual void setB( const Teuchos::RCP<const Vector> b ) {
400  B = b;
401  if (b != Teuchos::null)
403  else
405  flat_solver->setB(flat_B);
406  }
407 
408 
410  virtual void setB( const Vector* b ) {
411  if (b != 0) {
412  B = Teuchos::rcp(b, false);
414  }
415  else {
416  B = Teuchos::null;
418  }
419  flat_solver->setB(flat_B);
420  }
421 
422 
424  virtual const Teuchos::RCP<const Vector> getB( void ) {
425  return B;
426  }
427 
428 
430  virtual const Vector* getBRaw( void ) {
431  return B.get();
432  }
433 
434 
437  return flat_solver->getComm();
438  }
439 
440 
442  virtual Status& getStatus() const {
443  return flat_solver->getStatus();
444  }
445 
446 
448  virtual std::string name( void ) const {
449  return flat_solver->name();
450  }
451 
453 
454 
459  virtual std::string description( void ) const {
461  return flat_solver->description();
462  }
463 
464 
467  virtual void describe( Teuchos::FancyOStream &out,
469  flat_solver->describe(out, verbLevel);
470  }
471 
473 
474 
479  virtual void printTiming( Teuchos::FancyOStream &out,
482  flat_solver->printTiming(out, verbLevel);
483  }
484 
485 
494  virtual void getTiming( Teuchos::ParameterList& timingParameterList ) const{
495  flat_solver->getTiming(timingParameterList);
496  }
497 
499 
500  protected:
501 
511 
512  };
513 
514  template < template <class,class> class ConcreteSolver,
515  class ST, class LO, class GO, class NO >
518  typedef Tpetra::CrsMatrix<SC,LO,GO,NO> Matrix;
519  typedef Tpetra::MultiVector<SC,LO,GO,NO> Vector;
524  ctassert<
525  Meta::is_same<
526  typename MatrixTraits<Matrix>::scalar_t,
527  typename MultiVecAdapter<Vector>::scalar_t
528  >::value
529  > same_scalar_assertion;
530  (void)same_scalar_assertion; // This stops the compiler from warning about unused declared variables
531 
532  // If our assertion did not fail, then create and return a new solver
534  }
535  };
536 
537  // Specialization of create_solver_with_supported_type for
538  // Sacado::MP::Vector where we create MPVectorSolverAdapter wrapping
539  // each solver
540  template < template <class,class> class ConcreteSolver,
541  class ST, class LO, class GO, class NO >
542  struct create_solver_with_supported_type<
543  ConcreteSolver,
544  Tpetra::CrsMatrix<Sacado::MP::Vector<ST>,LO,GO,NO>,
545  Tpetra::MultiVector<Sacado::MP::Vector<ST>,LO,GO,NO> > :
546  public create_mp_vector_solver_impl<ConcreteSolver, ST, LO, GO, NO> {};
547 
548  // Specialization for solver_supports_scalar for Sacado::MP::Vector<Storage>
549  // value == true if and only if
550  // solver_supprts_scalar<ConcreteSolver,Storage::value_type> == true
551  template <template <class,class> class ConcreteSolver,
552  typename Storage>
553  struct solver_supports_scalar<ConcreteSolver, Sacado::MP::Vector<Storage> > {
555  typedef typename Scalar::value_type BaseScalar;
556  typedef typename solver_traits<ConcreteSolver>::supported_scalars supported_scalars;
557  static const bool value =
558  Meta::if_then_else<Meta::is_same<supported_scalars, Meta::nil_t>::value,
559  Meta::true_type,
560  Meta::type_list_contains<supported_scalars,
561  BaseScalar> >::type::value;
562  };
563 
564 } // namespace Amesos2
565 
566 #endif // AMESOS2_SOLVER_MP_VECTOR_HPP
virtual void setX(Vector *x)
Sets the LHS vector X using a raw pointer.
Stokhos::StandardStorage< int, double > Storage
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
virtual std::string description(void) const
Returns a short description of this Solver.
virtual std::string name(void) const
Return the name of this solver.
virtual void setA(const Teuchos::RCP< const Matrix > a, EPhase keep_phase=CLEAN)
Sets the matrix A of this solver.
virtual void solve(void)
Solves (or )
virtual type & preOrdering(void)
Pre-orders the matrix.
virtual const Teuchos::RCP< Vector > getX(void)
Returns the vector that is the LHS of the linear system.
virtual const Vector * getBRaw(void)
Returns a raw pointer to the RHS of the linear system.
virtual void setB(const Vector *b)
Sets the RHS vector B using a raw pointer.
Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > FlatGraph
Solver< FlatMatrix, FlatVector > FlatSolver
virtual void solve(Vector *XX, const Vector *BB) const
Solve using the given XX and BB (multi)vectors.
Teuchos::RCP< const FlatGraph > flat_graph
T * get() const
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
Teuchos::RCP< FlatSolver > flat_solver
virtual type & symbolicFactorization(void)
Performs symbolic factorization on the matrix.
virtual Status & getStatus() const
Returns a reference to this solver&#39;s internal status object.
virtual void getTiming(Teuchos::ParameterList &timingParameterList) const
Extracts timing information from the current solver.
static Teuchos::RCP< Solver< Matrix, Vector > > apply(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Teuchos::RCP< const FlatMatrix > flat_A
Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > Matrix
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Tpetra::MultiVector< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_vector_view(const Tpetra::MultiVector< Sacado::MP::Vector< Storage >, LocalOrdinal, GlobalOrdinal, Node > &vec_const, const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_map)
ConcreteSolver< FlatMatrix, FlatVector > FlatConcreteSolver
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters(void) const
Return a const parameter list of all of the valid parameters that this-&gt;setParameterList(...) will accept.
virtual void setX(const Teuchos::RCP< Vector > x)
Sets the LHS vector X.
virtual void printTiming(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Prints timing information about the current solver.
KokkosClassic::DefaultNode::DefaultNodeType Node
Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > create_flat_mp_graph(const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_domain_map, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_range_map, const LocalOrdinal block_size)
Tpetra::MultiVector< BaseScalar, LocalOrdinal, GlobalOrdinal, Node > FlatVector
Teuchos::RCP< Tpetra::CrsMatrix< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_matrix(const Tpetra::CrsMatrix< Sacado::MP::Vector< Storage >, LocalOrdinal, GlobalOrdinal, Node > &mat, const Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &flat_graph, const LocalOrdinal block_size)
virtual void setA(const Matrix *a, EPhase keep_phase=CLEAN)
Sets the matrix A of this solver.
virtual bool matrixShapeOK(void)
Returns true if the solver can handle the matrix shape.
static const EVerbosityLevel verbLevel_default
virtual void setB(const Teuchos::RCP< const Vector > b)
Sets the RHS vector B.
Tpetra::MultiVector< SC, LO, GO, NO > Vector
MPVectorSolverAdapter(const Teuchos::RCP< const Matrix > &A_, const Teuchos::RCP< Vector > &X_, const Teuchos::RCP< const Vector > &B_)
Constructor.
virtual void solve(const Teuchos::Ptr< Vector > XX, const Teuchos::Ptr< const Vector > BB) const
Solve using the given XX and BB (multi)vectors.
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > Vector
Tpetra::CrsMatrix< SC, LO, GO, NO > Matrix
Amesos2 solver adapter for MP::Vector scalar type.
virtual type & setParameters(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Set/update internal variables and solver options.
LO get_mp_vector_size(const Teuchos::RCP< const Tpetra::CrsMatrix< Sacado::MP::Vector< S >, LO, GO, N > > &A=Teuchos::null, const Teuchos::RCP< Tpetra::MultiVector< Sacado::MP::Vector< S >, LO, GO, N > > &X=Teuchos::null, const Teuchos::RCP< const Tpetra::MultiVector< Sacado::MP::Vector< S >, LO, GO, N > > &B=Teuchos::null)
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > Map
Teuchos::RCP< const FlatVector > flat_B
virtual type & numericFactorization(void)
Performs numeric factorization on the matrix.
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm(void) const
Returns a pointer to the Teuchos::Comm communicator with this matrix.
Tpetra::CrsMatrix< BaseScalar, LocalOrdinal, GlobalOrdinal, Node > FlatMatrix
virtual Vector * getXRaw(void)
Returns a raw pointer to the LHS of the linear system.
virtual const Teuchos::RCP< const Vector > getB(void)
Returns the vector that is the RHS of the linear system.
Sacado::MP::Vector< Storage > Scalar