All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Xpetra_TpetraVector_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_TPETRAVECTOR_DEF_HPP
47 #define XPETRA_TPETRAVECTOR_DEF_HPP
49 
50 #include "Xpetra_TpetraMap.hpp" //TMP
51 #include "Xpetra_Utils.hpp"
52 #include "Xpetra_TpetraImport.hpp"
53 #include "Xpetra_TpetraExport.hpp"
54 
55 #include "Xpetra_TpetraMultiVector.hpp"
57 #include "Tpetra_MultiVector.hpp"
58 #include "Tpetra_Vector.hpp"
59 
60 namespace Xpetra {
61 
62 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
64 : TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map,1,zeroOut)
65 { }
66 
67 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
69 : TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map,A,map->getNodeNumElements(),1)
70 { }
71 
72 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
74 { }
75 
76 
77 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
78 void TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
79 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::replaceGlobalValue"); getTpetra_Vector()->replaceGlobalValue(globalRow, value); }
80 
81 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
82 void TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
83 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::sumIntoGlobalValue"); getTpetra_Vector()->sumIntoGlobalValue(globalRow, value); }
84 
85 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
87 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::replaceLocalValue"); getTpetra_Vector()->replaceLocalValue(myRow, value); }
88 
89 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
91 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::sumIntoLocalValue"); getTpetra_Vector()->sumIntoLocalValue(myRow, value); }
92 
93 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
95 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::norm1"); return getTpetra_Vector()->norm1(); }
96 
97 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
99 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::norm2"); return getTpetra_Vector()->norm2(); }
100 
101 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
103 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::normInf"); return getTpetra_Vector()->normInf(); }
104 
105 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
107 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::meanValue"); return getTpetra_Vector()->meanValue(); }
108 
109 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
111 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::description"); return getTpetra_Vector()->description(); }
112 
113 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
115 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::describe"); getTpetra_Vector()->describe(out, verbLevel); }
116 
117 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
119 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::dot"); return getTpetra_Vector()->dot(*toTpetra(a)); }
120 
121 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
123 { XPETRA_MONITOR("TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::normWeighted"); return getTpetra_Vector()->normWeighted(*toTpetra(weights)); }
124 
125 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
126 TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::TpetraVector(const Teuchos::RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &vec) : TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (vec)
127 { }
128 
129 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
130 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
133 
134 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
135 typename Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::dual_view_type::t_host_um TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getHostLocalView () const {
136  return this->TpetraMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::getHostLocalView();
137  }
138 
139 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
140 typename Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::dual_view_type::t_dev_um TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getDeviceLocalView() const {
141  return this->TpetraMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::getDeviceLocalView();
142  }
143 
144 #if 0
145  template<class TargetDeviceType>
146  typename Kokkos::Impl::if_c<
147  Kokkos::Impl::is_same<
148  typename dual_view_type::t_dev_um::execution_space::memory_space,
149  typename TargetDeviceType::memory_space>::value,
150  typename dual_view_type::t_dev_um,
151  typename dual_view_type::t_host_um>::type
152 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
153  TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getLocalView () const {
154  return this->TpetraMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::template getLocalView<TargetDeviceType>();
155  }
156 #endif
157 
158 #endif
159 
160 
161 #ifdef HAVE_XPETRA_EPETRA
162 
163 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
164  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
165 
166  // specialization of TpetraVector for GO=int and NO=SerialNode
167  template <class Scalar>
168  class TpetraVector<Scalar, int, int, EpetraNode>
169  : public virtual Vector<Scalar,int,int,EpetraNode>,
170  public TpetraMultiVector<Scalar,int,int,EpetraNode>
171  {
172  typedef int LocalOrdinal;
173  typedef int GlobalOrdinal;
174  typedef EpetraNode Node;
175 
176 #undef XPETRA_TPETRAMULTIVECTOR_SHORT
177 #include "Xpetra_UseShortNames.hpp"
178 
179  public:
180 
190 
192 
193 
195  TpetraVector(const Teuchos::RCP<const Map> &map, bool zeroOut=true)
196  : TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map,1,zeroOut) {
198  }
199 
202  : TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map,A,map->getNodeNumElements(),1) {
204  }
205 
207  virtual ~TpetraVector() { }
208 
210 
212 
213 
215  void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { }
216 
218  void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { }
219 
221  void replaceLocalValue(LocalOrdinal myRow, const Scalar &value) { }
222 
224  void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value) { }
225 
227 
229 
230 
233 
236 
239 
242 
244 
246 
247 
249  std::string description() const { return std::string(""); }
250 
253 
255 
257  Scalar dot(const Vector &a) const { return Teuchos::ScalarTraits< Scalar >::zero(); }
258 
261 
262 
264 
265 
267  TpetraVector(const Teuchos::RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &vec) {
269  }
270 
273 
274 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
275 
277 
278  typename dual_view_type::t_host_um getHostLocalView () const {
279  typename dual_view_type::t_host_um ret;
280  return ret;
281  }
282 
283  typename dual_view_type::t_dev_um getDeviceLocalView() const {
284  typename dual_view_type::t_dev_um ret;
285  return ret;
286  }
287 
298  template<class TargetDeviceType>
299  typename Kokkos::Impl::if_c<
300  Kokkos::Impl::is_same<
301  typename dual_view_type::t_dev_um::execution_space::memory_space,
302  typename TargetDeviceType::memory_space>::value,
303  typename dual_view_type::t_dev_um,
304  typename dual_view_type::t_host_um>::type
305  getLocalView () const {
306  typename Kokkos::Impl::if_c<
307  Kokkos::Impl::is_same<
308  typename dual_view_type::t_dev_um::execution_space::memory_space,
309  typename TargetDeviceType::memory_space>::value,
310  typename dual_view_type::t_dev_um,
311  typename dual_view_type::t_host_um>::type ret;
312  return ret;
313  }
314 #endif
315 
317 
318  }; // TpetraVector class (specialization on GO=int, NO=EpetraNode)
319 #endif
320 
321 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
322  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
323 
324  // specialization of TpetraVector for GO=int and NO=SerialNode
325  template <class Scalar>
326  class TpetraVector<Scalar, int, long long, EpetraNode>
327  : public virtual Vector<Scalar,int,long long,EpetraNode>,
328  public TpetraMultiVector<Scalar,int,long long,EpetraNode>
329  {
330  typedef int LocalOrdinal;
331  typedef long long GlobalOrdinal;
332  typedef EpetraNode Node;
333 
334 #undef XPETRA_TPETRAMULTIVECTOR_SHORT
335 #include "Xpetra_UseShortNames.hpp"
336 
337  public:
338 
348 
350 
351 
353  TpetraVector(const Teuchos::RCP<const Map> &map, bool zeroOut=true)
354  : TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map,1,zeroOut) {
356  }
357 
360  : TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map,A,map->getNodeNumElements(),1) {
362  }
363 
365  virtual ~TpetraVector() { }
366 
368 
370 
371 
373  void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { }
374 
376  void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { }
377 
379  void replaceLocalValue(LocalOrdinal myRow, const Scalar &value) { }
380 
382  void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value) { }
383 
385 
387 
388 
391 
394 
397 
400 
402 
404 
405 
407  std::string description() const { return std::string(""); }
408 
411 
413 
415  Scalar dot(const Vector &a) const { return Teuchos::ScalarTraits< Scalar >::zero(); }
416 
419 
420 
422 
423 
425  TpetraVector(const Teuchos::RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &vec) {
427  }
428 
431 
432 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
433 
435 
436  typename dual_view_type::t_host_um getHostLocalView () const {
437  typename dual_view_type::t_host_um ret;
438  return ret;
439  }
440 
441  typename dual_view_type::t_dev_um getDeviceLocalView() const {
442  typename dual_view_type::t_dev_um ret;
443  return ret;
444  }
445 
456  template<class TargetDeviceType>
457  typename Kokkos::Impl::if_c<
458  Kokkos::Impl::is_same<
459  typename dual_view_type::t_dev_um::execution_space::memory_space,
460  typename TargetDeviceType::memory_space>::value,
461  typename dual_view_type::t_dev_um,
462  typename dual_view_type::t_host_um>::type
463  getLocalView () const {
464  typename Kokkos::Impl::if_c<
465  Kokkos::Impl::is_same<
466  typename dual_view_type::t_dev_um::execution_space::memory_space,
467  typename TargetDeviceType::memory_space>::value,
468  typename dual_view_type::t_dev_um,
469  typename dual_view_type::t_host_um>::type ret;
470  return ret;
471  }
472 #endif
473 
474 
475  }; // TpetraVector class (specialization on GO=long long, NO=EpetraNode)
476 #endif
477 
478 #endif // HAVE_XPETRA_EPETRA
479 } //namespace Xpetra
480 
481 #endif
Teuchos::ScalarTraits< Scalar >::magnitudeType norm1() const
Return 1-norm of this Vector.
std::string description() const
Return a simple one-line description of this object.
virtual ~TpetraVector()
Destructor.
void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value)
Adds specified value to existing value at the specified location.
TpetraVector(const Teuchos::RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &vec)
TpetraMultiVector constructor to wrap a Tpetra::MultiVector object.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Adds specified value to existing value at the specified location.
Scalar meanValue() const
Compute mean (average) value of this Vector.
Teuchos::ScalarTraits< Scalar >::magnitudeType normInf() const
Compute Inf-norm of this Vector.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm2() const
Compute 2-norm of this Vector.
#define XPETRA_TPETRA_ETI_EXCEPTION(cl, obj, go, node)
void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
TpetraVector(const Teuchos::RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &vec)
TpetraMultiVector constructor to wrap a Tpetra::MultiVector object.
void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Adds specified value to existing value at the specified location.
TpetraVector(const Teuchos::RCP< const Map > &map, const Teuchos::ArrayView< const Scalar > &A)
Set multi-vector values from an array using Teuchos memory management classes. (copy) ...
void replaceLocalValue(LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
Teuchos::ScalarTraits< Scalar >::magnitudeType normWeighted(const Vector &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
Scalar dot(const Vector &a) const
Computes dot product of this Vector against input Vector x.
void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm1() const
Return 1-norm of this Vector.
void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value)
Adds specified value to existing value at the specified location.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm2() const
Compute 2-norm of this Vector.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm2() const
Compute 2-norm of this Vector.
std::string description() const
Return a simple one-line description of this object.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm1() const
Return 1-norm of this Vector.
Scalar meanValue() const
Compute mean (average) value of this Vector.
static const EVerbosityLevel verbLevel_default
void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Adds specified value to existing value at the specified location.
void replaceLocalValue(LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
static magnitudeType magnitude(T a)
RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_Vector() const
Get the underlying Tpetra multivector.
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_Vector() const
Get the underlying Tpetra multivector.
RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_Vector() const
Get the underlying Tpetra multivector.
Teuchos::ScalarTraits< Scalar >::magnitudeType normWeighted(const Vector &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
Teuchos::ScalarTraits< Scalar >::magnitudeType normInf() const
Compute Inf-norm of this Vector.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Teuchos::ScalarTraits< Scalar >::magnitudeType normInf() const
Compute Inf-norm of this Vector.
void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value)
Adds specified value to existing value at the specified location.
void replaceLocalValue(LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
std::string description() const
Return a simple one-line description of this object.
RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_MultiVector() const
Get the underlying Tpetra multivector.
#define XPETRA_MONITOR(funcName)
TpetraVector(const Teuchos::RCP< const Map > &map, const Teuchos::ArrayView< const Scalar > &A)
Set multi-vector values from an array using Teuchos memory management classes. (copy) ...
TpetraVector(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
Sets all vector entries to zero.
Scalar dot(const Vector &a) const
Computes dot product of this Vector against input Vector x.
void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
Scalar dot(const Vector &a) const
Computes dot product of this Vector against input Vector x.
Scalar meanValue() const
Compute mean (average) value of this Vector.
TpetraVector(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
Sets all vector entries to zero.
Teuchos::ScalarTraits< Scalar >::magnitudeType normWeighted(const Vector &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
TpetraVector(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
Sets all vector entries to zero.