Tpetra Matrix/Vector Services  Version of the Day
Tpetra_Vector_decl.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_VECTOR_DECL_HPP
43 #define TPETRA_VECTOR_DECL_HPP
44 
45 #include "Tpetra_ConfigDefs.hpp"
46 #include "Tpetra_MultiVector_decl.hpp"
47 
48 namespace Tpetra {
49 
57 template<class Scalar,
58  class LocalOrdinal=int,
59  class GlobalOrdinal=LocalOrdinal,
60  class Node=Kokkos::DefaultNode::DefaultNodeType>
61 class Vector : public MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
62  // need this so that MultiVector::operator() can call Vector's private view constructor
63  friend class MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>;
64 public:
66 
67 
69  explicit Vector(const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map, bool zeroOut=true);
70 
73 
76 
78  virtual ~Vector();
79 
81 
83 
85 
87  void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value);
88 
90 
92  void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value);
93 
95 
97  void replaceLocalValue(LocalOrdinal myRow, const Scalar &value);
98 
100 
102  void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value);
103 
105 
107 
108 
111  void get1dCopy(ArrayView<Scalar> A) const;
112 
116 
117  using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getData; // overloading, not hiding
120 
122 
124 
125 
126  using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::dot; // overloading, not hiding
129 
130  using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::norm1; // overloading, not hiding
133 
134  using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::norm2; // overloading, not hiding
137 
138  using MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::normInf; // overloading, not hiding
141 
145 
148  Scalar meanValue() const;
149 
151 
153 
155  virtual std::string description() const;
156 
158  virtual void
160  const Teuchos::EVerbosityLevel verbLevel =
163 
164 protected:
165 
166  template <class S,class LO,class GO,class N>
167  friend RCP< Vector<S,LO,GO,N> >
168  createVectorFromView(const RCP<const Map<LO,GO,N> > &,const ArrayRCP<S> &);
169 
170  // view constructor, sitting on user allocated data, only for CPU nodes
171  // and his non-member constructor friend
172  Vector (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
173  const ArrayRCP<Scalar> &view,
174  EPrivateHostViewConstructor /* dummy tag */);
175 
177  Vector (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
178  const ArrayRCP<Scalar> & data);
179 
181  Vector (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
182  const ArrayRCP<Scalar> & data,
183  EPrivateComputeViewConstructor /* dummy tag */);
184 
185  typedef Kokkos::MultiVector<Scalar,Node> KMV;
186  typedef Kokkos::DefaultArithmetic<KMV> MVT;
187 }; // class Vector
188 
192 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
195 {
196  const bool DO_INIT_TO_ZERO = true;
197  return rcp (new Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> (map, DO_INIT_TO_ZERO));
198 }
199 
201 
204 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
206 createVectorFromView (const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &map,
207  const ArrayRCP<Scalar> &view)
208 {
209  return rcp(
210  // this is a protected constructor, but we are friends
212  map,
213  // this will fail to compile for unsupported node types
214  Tpetra::details::ViewAccepter<Node>::template acceptView<Scalar>(view),
215  HOST_VIEW_CONSTRUCTOR)
216  );
217 }
218 
219 } // namespace Tpetra
220 
221 #endif // TPETRA_VECTOR_DECL_HPP
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Teuchos::ArrayRCP< Scalar > getDataNonConst()
View of the local values of this vector.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to a FancyOStream.
ViewAccepter provides support for compile-time detection based on Node type, of support for accepting...
Teuchos::ScalarTraits< Scalar >::magnitudeType normWeighted(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
One or more distributed dense vectors.
virtual std::string description() const
A simple one-line description of this object.
void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
Teuchos::ScalarTraits< Scalar >::magnitudeType normInf() const
Compute Inf-norm of this Vector.
RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createVector(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Non-member function to create a Vector from a specified Map.
virtual ~Vector()
Destructor.
void replaceLocalValue(LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
Scalar dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &a) const
Computes dot product of this Vector against input Vector x.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::ArrayRCP< const Scalar > getData() const
Const view of the local values of this vector.
void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Adds specified value to existing value at the specified location.
static const EVerbosityLevel verbLevel_default
Teuchos::ScalarTraits< Scalar >::magnitudeType norm2() const
Compute 2-norm of this Vector.
void get1dCopy(ArrayView< Scalar > A) const
Return multi-vector values in user-provided two-dimensional array (using Teuchos memory management cl...
Describes a parallel distribution of objects over processes.
Vector(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, bool zeroOut=true)
Sets all vector entries to zero.
void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value)
Adds specified value to existing value at the specified location.
A distributed dense vector.
Scalar meanValue() const
Compute mean (average) value of this Vector.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm1() const
Return 1-norm of this Vector.