Xpetra_EpetraIntVector.cpp
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
47 #include "Xpetra_EpetraImport.hpp"
48 #include "Xpetra_EpetraExport.hpp"
49 
50 namespace Xpetra {
51 
52  template<class EpetraGlobalOrdinal>
54 
55  template<class EpetraGlobalOrdinal>
57 
58  template<class EpetraGlobalOrdinal>
60 
61  template<class EpetraGlobalOrdinal>
63 
64  template<class EpetraGlobalOrdinal>
66 
67  template<class EpetraGlobalOrdinal>
69 
70  template<class EpetraGlobalOrdinal>
72 
73  template<class EpetraGlobalOrdinal>
75 
76  template<class EpetraGlobalOrdinal>
78 
79  template<class EpetraGlobalOrdinal>
81 
82  template<class EpetraGlobalOrdinal>
84 
85  template<class EpetraGlobalOrdinal>
86  void EpetraIntVectorT<EpetraGlobalOrdinal>::randomize(bool bUseXpetraImplementation) { XPETRA_MONITOR("EpetraIntVectorT::randomize"); TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraIntVectorT::randomize(): Functionnality not available in Epetra"); }
87 
88  template<class EpetraGlobalOrdinal>
89  void EpetraIntVectorT<EpetraGlobalOrdinal>::setSeed(unsigned int seed) { XPETRA_MONITOR("EpetraIntVectorT::setSeed"); TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraIntVectorT::setSeed(): Functionnality not available in Epetra"); }
90 
91  template<class EpetraGlobalOrdinal>
94  }
95 
96  template<class EpetraGlobalOrdinal>
99  }
100 
101  template<class EpetraGlobalOrdinal>
103  XPETRA_MONITOR("EpetraIntVectorT::getData");
104 
105  int * data = vec_->Values();
106  int localLength = vec_->MyLength();
107 
108  return ArrayRCP<int>(data, 0, localLength, false); // not ownership
109  }
110 
111  template<class EpetraGlobalOrdinal>
113  XPETRA_MONITOR("EpetraIntVectorT::getDataNonConst");
114 
115  int * data = vec_->Values();
116  int localLength = vec_->MyLength();
117 
118  return ArrayRCP<int>(data, 0, localLength, false); // not ownership
119  }
120 
121  template<class EpetraGlobalOrdinal>
123  XPETRA_MONITOR("EpetraIntVectorT::dot");
124 
125  //XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
127  }
128 
129  template<class EpetraGlobalOrdinal>
131  XPETRA_MONITOR("EpetraIntVectorT::abs");
132 
133  //XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
135  }
136 
137  template<class EpetraGlobalOrdinal>
139  XPETRA_MONITOR("EpetraIntVectorT::reciprocal");
140 
141  //XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
143  }
144 
145  template<class EpetraGlobalOrdinal>
147  XPETRA_MONITOR("EpetraIntVectorT::scale");
149  }
150 
151  template<class EpetraGlobalOrdinal>
153  XPETRA_MONITOR("EpetraIntVectorT::scale");
155  }
156 
157  template<class EpetraGlobalOrdinal>
159  XPETRA_MONITOR("EpetraIntVectorT::update");
160 
161  // XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
163  }
164 
165  template<class EpetraGlobalOrdinal>
166  void EpetraIntVectorT<EpetraGlobalOrdinal>::update(const int &alpha, const MultiVector<int,int,GlobalOrdinal,Node> &A, const int &beta, const MultiVector<int,int,GlobalOrdinal,Node> &B, const int &gamma) {
167  XPETRA_MONITOR("EpetraIntVectorT::update");
168 
169  //XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
170  //XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT, B, eB, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
172  }
173 
174  template<class EpetraGlobalOrdinal>
176 
177  template<class EpetraGlobalOrdinal>
179 
180  template<class EpetraGlobalOrdinal>
182 
183  template<class EpetraGlobalOrdinal>
185 
186  template<class EpetraGlobalOrdinal>
188 
189  template<class EpetraGlobalOrdinal>
191 
192  template<class EpetraGlobalOrdinal>
194 
195  template<class EpetraGlobalOrdinal>
197  XPETRA_MONITOR("EpetraIntVectorT::elementWiseMultiply");
198  TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "Xpetra_EpetraIntVector: elementWiseMultiply not implemented because Epetra_IntVector does not support this operation");
199  }
200 
201  template<class EpetraGlobalOrdinal>
202  void EpetraIntVectorT<EpetraGlobalOrdinal>::replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraIntVectorT::replaceGlobalValue"); TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO"); }
203 
204  template<class EpetraGlobalOrdinal>
205  void EpetraIntVectorT<EpetraGlobalOrdinal>::sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraIntVectorT::sumIntoGlobalValue"); TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO"); }
206 
207  template<class EpetraGlobalOrdinal>
208  void EpetraIntVectorT<EpetraGlobalOrdinal>::replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraIntVectorT::replaceLocalValue"); TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO"); }
209 
210  template<class EpetraGlobalOrdinal>
211  void EpetraIntVectorT<EpetraGlobalOrdinal>::sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraIntVectorT::sumIntoLocalValue"); TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO"); }
212 
213  template<class EpetraGlobalOrdinal>
214  size_t EpetraIntVectorT<EpetraGlobalOrdinal>::getNumVectors() const { XPETRA_MONITOR("EpetraIntVectorT::getNumVectors"); return 1; }
215 
216  template<class EpetraGlobalOrdinal>
218  XPETRA_MONITOR("EpetraIntVectorT::description");
219 
220  // This implementation come from Epetra_Vector_def.hpp (without modification)
221  std::ostringstream oss;
223  oss << "{length="<<this->getGlobalLength()
224  << "}";
225  return oss.str();
226  }
227 
228  template<class EpetraGlobalOrdinal>
230  XPETRA_MONITOR("EpetraIntVectorT::describe");
231 
232  // This implementation come from Tpetra_Vector_def.hpp (without modification) // JG: true?
233  using std::endl;
234  using std::setw;
235  using Teuchos::VERB_DEFAULT;
236  using Teuchos::VERB_NONE;
237  using Teuchos::VERB_LOW;
238  using Teuchos::VERB_MEDIUM;
239  using Teuchos::VERB_HIGH;
240  using Teuchos::VERB_EXTREME;
241 
242  if (verbLevel > Teuchos::VERB_NONE)
243  vec_->Print(out);
244  }
245 
246  template<class EpetraGlobalOrdinal>
248  const Import<int, GlobalOrdinal> &importer, CombineMode CM) {
249  XPETRA_MONITOR("EpetraIntVectorT::doImport");
250 
251  XPETRA_DYNAMIC_CAST(const EpetraIntVectorT<GlobalOrdinal>, source, tSource, "Xpetra::EpetraIntVectorT::doImport only accept Xpetra::EpetraIntVectorT as input arguments.");
252  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal>, importer, tImporter, "Xpetra::EpetraIntVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
253 
254  const Epetra_IntVector & v = *tSource.getEpetra_IntVector();
255  int err = vec_->Import(v, *tImporter.getEpetra_Import(), toEpetra(CM));
256  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
257  }
258 
259  template<class EpetraGlobalOrdinal>
261  const Import<int, GlobalOrdinal>& importer, CombineMode CM) {
262  XPETRA_MONITOR("EpetraIntVectorT::doExport");
263 
264  XPETRA_DYNAMIC_CAST(const EpetraIntVectorT<GlobalOrdinal>, dest, tDest, "Xpetra::EpetraIntVectorT::doImport only accept Xpetra::EpetraIntVectorT as input arguments.");
265  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal>, importer, tImporter, "Xpetra::EpetraIntVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
266 
267  const Epetra_IntVector & v = *tDest.getEpetra_IntVector();
268  int err = vec_->Import(v, *tImporter.getEpetra_Import(), toEpetra(CM));
269  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
270  }
271 
272  template<class EpetraGlobalOrdinal>
274  const Export<int, GlobalOrdinal>& exporter, CombineMode CM) {
275  XPETRA_MONITOR("EpetraIntVectorT::doImport");
276 
277  XPETRA_DYNAMIC_CAST(const EpetraIntVectorT<GlobalOrdinal>, source, tSource, "Xpetra::EpetraIntVectorT::doImport only accept Xpetra::EpetraIntVectorT as input arguments.");
278  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal>, exporter, tExporter, "Xpetra::EpetraIntVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
279 
280  const Epetra_IntVector & v = *tSource.getEpetra_IntVector();
281  int err = vec_->Import(v, *tExporter.getEpetra_Export(), toEpetra(CM));
282  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
283  }
284 
285  template<class EpetraGlobalOrdinal>
287  const Export<int, GlobalOrdinal>& exporter, CombineMode CM) {
288  XPETRA_MONITOR("EpetraIntVectorT::doExport");
289 
290  XPETRA_DYNAMIC_CAST(const EpetraIntVectorT<GlobalOrdinal>, dest, tDest, "Xpetra::EpetraIntVectorT::doImport only accept Xpetra::EpetraIntVectorT as input arguments.");
291  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal>, exporter, tExporter, "Xpetra::EpetraIntVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
292 
293  const Epetra_IntVector & v = *tDest.getEpetra_IntVector();
294  int err = vec_->Export(v, *tExporter.getEpetra_Export(), toEpetra(CM));
295  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
296  }
297 
298  template<class EpetraGlobalOrdinal>
301  {
302  typedef EpetraIntVectorT<GlobalOrdinal> this_type;
303  const this_type* rhsPtr = dynamic_cast<const this_type*> (&rhs);
305  rhsPtr == NULL, std::invalid_argument, "Xpetra::MultiVector::operator=: "
306  "The left-hand side (LHS) of the assignment has a different type than "
307  "the right-hand side (RHS). The LHS has type Xpetra::EpetraIntVectorT "
308  "(which means it wraps an Epetra_IntVector), but the RHS has some "
309  "other type. This probably means that the RHS wraps either an "
310  "Tpetra::MultiVector, or an Epetra_MultiVector. Xpetra::MultiVector "
311  "does not currently implement assignment from a Tpetra object to an "
312  "Epetra object, though this could be added with sufficient interest.");
313 
314  RCP<const Epetra_IntVector> rhsImpl = rhsPtr->getEpetra_IntVector ();
315  RCP<Epetra_IntVector> lhsImpl = this->getEpetra_IntVector ();
316 
318  rhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
319  "(in Xpetra::EpetraIntVectorT::assign): *this (the right-hand side of "
320  "the assignment) has a null RCP<Epetra_IntVector> inside. Please "
321  "report this bug to the Xpetra developers.");
323  lhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
324  "(in Xpetra::EpetraIntVectorT::assign): The left-hand side of the "
325  "assignment has a null RCP<Epetra_IntVector> inside. Please report "
326  "this bug to the Xpetra developers.");
327 
328  // Epetra_IntVector's assignment operator does a deep copy.
329  *lhsImpl = *rhsImpl;
330  }
331 
332 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
333 template class EpetraIntVectorT<int>;
334 #endif
335 
336 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
337 template class EpetraIntVectorT<long long>;
338 #endif
339 
340 } // namespace Xpetra
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.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal > > &graph)
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.
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.
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal > &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
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.
virtual std::string description() const
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
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
Teuchos::ScalarTraits< int >::magnitudeType normWeighted(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
void setSeed(unsigned int seed)
Set seed for Random function.
void randomize(bool bUseXpetraImplementation=true)
Set multi-vector values to random numbers.
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.
#define XPETRA_MONITOR(funcName)
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).
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.
bool is_null() const