Xpetra_EpetraIntVector.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_EPETRAINTVECTOR_HPP
47 #define XPETRA_EPETRAINTVECTOR_HPP
48 
50 
51 #include "Xpetra_ConfigDefs.hpp"
52 #include "Xpetra_MultiVector.hpp"
53 #include "Xpetra_Vector.hpp"
54 #include "Xpetra_Exceptions.hpp"
55 
56 #include "Xpetra_EpetraMap.hpp"
58 #include "Epetra_IntVector.h"
59 
60 namespace Xpetra {
61 
62  template<class EpetraGlobalOrdinal>
63  class EpetraIntVectorT
64  : public Vector<int,int,EpetraGlobalOrdinal>
65  {
66  typedef int Scalar;
67  typedef int LocalOrdinal;
68  typedef EpetraGlobalOrdinal GlobalOrdinal;
70 
71  public:
72 
74 
75 
77  explicit EpetraIntVectorT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, bool zeroOut=true)
78  {
79  XPETRA_RCP_DYNAMIC_CAST(const EpetraMapT<GlobalOrdinal>, map, eMap, "Xpetra::EpetraCrsMatrixT constructors only accept Xpetra::EpetraMapT as input arguments.");
80  vec_ = rcp(new Epetra_IntVector(eMap->getEpetra_BlockMap(), zeroOut));
81  }
82 
85 
87 
89 
90 
93 
96 
99 
102 
105 
107  int meanValue() const;
108 
110  int maxValue() const;
111 
113 
115 
116 
118  void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value);
119 
121  void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value);
122 
124  void replaceLocalValue(LocalOrdinal myRow, const Scalar &value);
125 
127  void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value);
128 
130  void putScalar(const int &value) { vec_->PutValue(value); }
131 
133  void randomize(bool bUseXpetraImplementation = true);
134 
136 
137  void setSeed(unsigned int seed);
138 
140 
142 
143 
146 
149 
152  Teuchos::ArrayRCP<const int> getData(size_t j) const;
153 
157 
159 
161 
162  void dot(const MultiVector<int,int,GlobalOrdinal,Node> &A, const Teuchos::ArrayView<int> &dots) const;
164 
167 
170 
172  void scale(const int &alpha);
173 
176 
178  void update(const int &alpha, const MultiVector<int,int,GlobalOrdinal,Node> &A, const int &beta);
179 
181  void update(const int &alpha, const MultiVector<int,int,GlobalOrdinal,Node> &A, const int &beta, const MultiVector<int,int,GlobalOrdinal,Node> &B, const int &gamma);
182 
185 
188 
191 
194 
196  void meanValue(const Teuchos::ArrayView<int> &means) const;
197 
199  void maxValue(const Teuchos::ArrayView<int> &maxs) const;
200 
202  void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const int &alpha, const MultiVector<int,int,GlobalOrdinal,Node> &A, const MultiVector<int,int,GlobalOrdinal,Node> &B, const int &beta);
203 
205  void elementWiseMultiply(int scalarAB, const Vector<int,int,GlobalOrdinal,Node> &A, const MultiVector<int,int,GlobalOrdinal,Node> &B, int scalarThis);
206 
208 
210 
211 
213  void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value);
214 
216  void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value);
217 
219  void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value);
220 
222  void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value);
223 
225 
227 
228 
230  size_t getNumVectors() const;
231 
233  size_t getLocalLength() const { return vec_->MyLength(); }
234 
236  global_size_t getGlobalLength() const { return vec_->GlobalLength64(); }
237 
239 
241 
242 
244  std::string description() const;
245 
248 
250 
252 
253  const RCP<const Comm<int> > getComm() const {
254  TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO getComm Epetra MultiVector not implemented");
255  }
256 
257  // Implementing DistObject
259  RCP<const Epetra_BlockMap> map = rcp(new Epetra_BlockMap(vec_->Map()));
260  return rcp (new Xpetra::EpetraMapT<GlobalOrdinal>(map));
261  }
262 
263  void
265  const Import<int, GlobalOrdinal> &importer, CombineMode CM);
266 
267  void
269  const Import<int, GlobalOrdinal>& importer, CombineMode CM);
270 
271  void
273  const Export<int, GlobalOrdinal>& exporter, CombineMode CM);
274 
275  void
277  const Export<int, GlobalOrdinal>& exporter, CombineMode CM);
278 
279  void replaceMap(const RCP<const Map<int, GlobalOrdinal> >& map) {
280  // do nothing
281  }
282 
283 
285 
286 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
288 
289  typename dual_view_type::t_host_um getHostLocalView () const {
290  throw std::runtime_error("EpetraIntVector does not support device views! Must be implemented extra...");
291  typename dual_view_type::t_host_um ret;
292  return ret;
293  }
294 
295  typename dual_view_type::t_dev_um getDeviceLocalView() const {
296  throw std::runtime_error("Epetra does not support device views!");
297  typename dual_view_type::t_dev_um ret;
298  return ret; // make compiler happy
299  }
300 
311  template<class TargetDeviceType>
312  typename Kokkos::Impl::if_c<
313  Kokkos::Impl::is_same<
314  typename dual_view_type::t_dev_um::execution_space::memory_space,
315  typename TargetDeviceType::memory_space>::value,
316  typename dual_view_type::t_dev_um,
317  typename dual_view_type::t_host_um>::type
318  getLocalView () const {
319  return this->MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::template getLocalView<TargetDeviceType>();
320  }
321 #endif
322 
324 
325  protected:
328  virtual void
330 
331  private:
334 
335  }; // class EpetraIntVectorT
336 
337 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
339 #endif
340 
341 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
343 #endif
344 
345 } // namespace Xpetra
346 
347 #endif // XPETRA_EPETRAINTVECTOR_HPP
KokkosClassic::DefaultNode::DefaultNodeType Node
void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Adds specified value to existing value at the specified location.
std::string description() const
Return a simple one-line description of this object.
EpetraIntVectorT< long long > EpetraIntVector64
void elementWiseMultiply(int scalarAB, const Vector< int, int, GlobalOrdinal, Node > &A, const MultiVector< int, int, GlobalOrdinal, Node > &B, int scalarThis)
Element-wise multiply of a Vector A with a EpetraMultiVector B.
Teuchos::ScalarTraits< int >::magnitudeType norm2() const
Compute 2-norm of this Vector.
void reciprocal(const MultiVector< int, int, GlobalOrdinal, Node > &A)
Puts element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,j).
Teuchos::ArrayRCP< int > getDataNonConst(size_t j)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Xpetra namespace
Teuchos::ScalarTraits< int >::magnitudeType norm1() const
Return 1-norm of this Vector.
void update(const int &alpha, const MultiVector< int, int, GlobalOrdinal, Node > &A, const int &beta)
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
const RCP< const Comm< int > > getComm() const
Teuchos::RCP< const Map< int, GlobalOrdinal > > getMap() const
The Map describing the parallel distribution of this object.
int dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &a) const
TODO missing comment.
void doExport(const DistObject< int, int, GlobalOrdinal > &dest, const Import< int, GlobalOrdinal > &importer, CombineMode CM)
void doImport(const DistObject< int, int, GlobalOrdinal > &source, const Import< int, GlobalOrdinal > &importer, CombineMode CM)
Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.
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_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal > &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
RCP< Epetra_IntVector > getEpetra_IntVector() const
void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value)
Adds specified value to existing value at the specified location.
int meanValue() const
Compute mean (average) value of this Vector.
void putScalar(const int &value)
Initialize all values in a multi-vector with specified value.
EpetraIntVectorT< int > EpetraIntVector
void replaceMap(const RCP< const Map< int, GlobalOrdinal > > &map)
size_t getNumVectors() const
Returns the number of vectors in the multi-vector.
void abs(const MultiVector< int, int, GlobalOrdinal, Node > &A)
Puts element-wise absolute values of input Multi-vector in target: A = abs(this)
Exception throws when you call an unimplemented method of Xpetra.
Teuchos::ArrayRCP< const int > getData(size_t j) const
Teuchos::ScalarTraits< int >::magnitudeType normWeighted(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
size_t global_size_t
Global size_t object.
static const EVerbosityLevel verbLevel_default
#define XPETRA_RCP_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
void setSeed(unsigned int seed)
Set seed for Random function.
EpetraIntVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, bool zeroOut=true)
Sets all vector entries to zero.
void randomize(bool bUseXpetraImplementation=true)
Set multi-vector values to random numbers.
RCP< Epetra_IntVector > vec_
The Epetra_IntVector which this class wraps.
Teuchos::ScalarTraits< int >::magnitudeType normInf() const
Compute Inf-norm of this Vector.
void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
CombineMode
Xpetra::Combine Mode enumerable type.
size_t getLocalLength() const
Returns the local vector length on the calling processor of vectors in the multi-vector.
void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const int &alpha, const MultiVector< int, int, GlobalOrdinal, Node > &A, const MultiVector< int, int, GlobalOrdinal, Node > &B, const int &beta)
Matrix-Matrix multiplication, this = beta*this + alpha*op(A)*op(B).
global_size_t getGlobalLength() const
Returns the global vector length of vectors in the multi-vector.
Teuchos::RCP< const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVector(size_t j) const
Return a Vector which is a const view of column j.
void replaceLocalValue(LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
void scale(const int &alpha)
Scale the current values of a multi-vector, this = alpha*this.
int maxValue() const
Compute max value of this Vector.