Xpetra  Version of the Day
Xpetra_EpetraMultiVector.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_EPETRAMULTIVECTOR_HPP
47 #define XPETRA_EPETRAMULTIVECTOR_HPP
48 
49 /* this file is automatically generated - do not edit (see script/epetra.py) */
50 
51 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
52 #include <Kokkos_Core.hpp>
53 #include <Kokkos_DualView.hpp>
54 #endif
55 
56 
58 
59 #include "Xpetra_MultiVector.hpp"
60 #include "Xpetra_Vector.hpp"
61 
62 #include "Xpetra_EpetraMap.hpp"
63 #include "Xpetra_EpetraExport.hpp"
64 #include "Xpetra_Utils.hpp"
65 #include "Xpetra_EpetraUtils.hpp"
66 #include "Xpetra_EpetraImport.hpp"
67 #include "Xpetra_Exceptions.hpp"
68 #include "Epetra_SerialComm.h"
69 
70 #include <Epetra_MultiVector.h>
71 #include <Epetra_Vector.h>
72 
73 namespace Xpetra {
74 
75  // TODO: move that elsewhere
76  template<class GlobalOrdinal, class Node>
77  const Epetra_MultiVector & toEpetra(const MultiVector<double,int,GlobalOrdinal,Node> &);
78  template<class GlobalOrdinal, class Node>
79  Epetra_MultiVector & toEpetra(MultiVector<double, int,GlobalOrdinal,Node> &);
80  template<class GlobalOrdinal, class Node>
81  RCP<MultiVector<double, int, GlobalOrdinal, Node> > toXpetra(RCP<Epetra_MultiVector> vec);
82 
83  // we need this forward declaration
84 #ifndef DOXYGEN_SHOULD_SKIP_THIS
85  template<class GlobalOrdinal, class Node> class EpetraVectorT;
86 #endif
87 
88  template<class EpetraGlobalOrdinal, class Node>
90  : public virtual MultiVector<double, int, EpetraGlobalOrdinal, Node>
91  {
92  typedef double Scalar;
93  typedef int LocalOrdinal;
94  typedef EpetraGlobalOrdinal GlobalOrdinal;
95 
96  public:
97 
99 
100 
102  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true) {
103  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
104  "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
105  }
106 
108  EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Teuchos::DataAccess copyOrView=Teuchos::Copy) {
109  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
110  "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
111  }
112 
114  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
115  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
116  "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
117  }
118 
120  virtual ~EpetraMultiVectorT() {}
121 
123 
125 
126 
128  void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { }
129 
131  void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { }
132 
134  void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { }
135 
137  void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { }
138 
140  void putScalar(const Scalar &value) { }
141 
143 
145 
146 
148  Teuchos::RCP< const Vector< double, int, GlobalOrdinal, Node > > getVector(size_t j) const {
149  return Teuchos::null;
150  }
151 
153  Teuchos::RCP< Vector< double, int, GlobalOrdinal, Node > > getVectorNonConst(size_t j) {
154  return Teuchos::null;
155  }
156 
158  Teuchos::ArrayRCP< const Scalar > getData(size_t j) const {
159  return ArrayRCP<const Scalar>();
160  }
161 
163  Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j) {
164  return ArrayRCP<Scalar>();
165  }
166 
168 
170 
171 
173  void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const { }
174 
177 
180 
182  void scale(const Scalar &alpha) { }
183 
185  void scale (Teuchos::ArrayView< const Scalar > alpha) { }
186 
188  void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta) { }
189 
192 
194  void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { }
195 
197  void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { }
198 
200  void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { }
201 
203  void meanValue(const Teuchos::ArrayView< Scalar > &means) const { }
204 
206  void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta) { }
207 
210 
212 
214 
215 
217  size_t getNumVectors() const { return 0; }
218 
220  size_t getLocalLength() const { return 0; }
221 
223  global_size_t getGlobalLength() const { return 0; }
224 
225  // \brief Checks to see if the local length, number of vectors and size of Scalar type match
226  bool isSameSize(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> & vec) const { return false; }
227 
229 
231 
232 
234  std::string description() const { return std::string(""); }
235 
237  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const { }
238 
240 
242  void randomize(bool bUseXpetraImplementation = false) { }
243 
245  //{@
246 
248  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { return Teuchos::null; }
249 
252 
255 
258 
261 
263  void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map) { }
264 
266 
268 
269 
271  EpetraMultiVectorT(const RCP<Epetra_MultiVector> &vec) { //TODO removed const
272  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
273  "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
274  }
275 
277  RCP<Epetra_MultiVector> getEpetra_MultiVector() const { return Teuchos::null; }
278 
280  void setSeed(unsigned int seed) { }
281 
283 
284  protected:
287  virtual void
289 
290  }; // EpetraMultiVectorT class
291 
292  // specialization on GO=int and Node=EpetraNode
293 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
294  template<>
296  : public virtual MultiVector<double, int, int, EpetraNode>
297  {
298  typedef double Scalar;
299  typedef int LocalOrdinal;
300  typedef int GlobalOrdinal;
301  typedef EpetraNode Node;
302 
303  public:
304 
306 
307 
309  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
310  : vec_(Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal,Node>(map), Teuchos::as<int>(NumVectors), zeroOut))) { }
311 
313  EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Teuchos::DataAccess copyOrView=Teuchos::Copy) {
314  if (copyOrView == Teuchos::Copy)
315  vec_ = Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal,Node>(source)));
316  else {
317  int* indices = new int [source.getNumVectors()];
318  for (size_t i = 0; i < source.getNumVectors(); i++)
319  indices[i] = i;
320  vec_ = Teuchos::rcp(new Epetra_MultiVector(View, toEpetra<GlobalOrdinal,Node>(source), indices, source.getNumVectors()));
321  delete [] indices;
322  }
323  }
324 
326  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
327  //TODO: input argument 'NumVectors' is not necessary in both Xpetra and Tpetra interface. Should it be removed?
328 
329  const std::string tfecfFuncName("MultiVector(ArrayOfPtrs)");
330  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(NumVectors < 1 || NumVectors != Teuchos::as<size_t>(ArrayOfPtrs.size()), std::runtime_error,
331  ": ArrayOfPtrs.size() must be strictly positive and as large as ArrayOfPtrs.");
332 
333  #ifdef HAVE_XPETRA_DEBUG
334  // This cannot be tested by Epetra itself
335  {
336  size_t localLength = map->getNodeNumElements();
337  for(int j=0; j<ArrayOfPtrs.size(); j++) {
338  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Teuchos::as<size_t>(ArrayOfPtrs[j].size()) != localLength, std::runtime_error,
339  ": ArrayOfPtrs[" << j << "].size() (== " << ArrayOfPtrs[j].size() <<
340  ") is not equal to getLocalLength() (== " << localLength);
341 
342  }
343  }
344  #endif
345 
346  // Convert Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > to double**
347  Array<const double*> arrayOfRawPtrs(ArrayOfPtrs.size());
348  for(int i=0; i<ArrayOfPtrs.size(); i++) {
349  arrayOfRawPtrs[i] = ArrayOfPtrs[i].getRawPtr();
350  }
351  double** rawArrayOfRawPtrs = const_cast<double**>(arrayOfRawPtrs.getRawPtr()); // This const_cast should be fine, because Epetra_DataAccess=Copy.
352 
353  vec_ = Teuchos::rcp(new Epetra_MultiVector(Copy, toEpetra<GlobalOrdinal,Node>(map), rawArrayOfRawPtrs, static_cast<int>(NumVectors)));
354  }
355 
357  virtual ~EpetraMultiVectorT() {}
358 
360 
362 
363 
365  void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::replaceGlobalValue"); vec_->ReplaceGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value); }
366 
368  void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::sumIntoGlobalValue"); vec_->SumIntoGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value); }
369 
371  void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::replaceLocalValue"); vec_->ReplaceMyValue(myRow, Teuchos::as<int>(vectorIndex), value); }
372 
374  void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::sumIntoLocalValue"); vec_->SumIntoMyValue(myRow, Teuchos::as<int>(vectorIndex), value); }
375 
377  void putScalar(const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::putScalar"); vec_->PutScalar(value); }
378 
380 
382 
383 
385  Teuchos::RCP< const Vector< double, int, int, EpetraNode > > getVector(size_t j) const;
386 
388  Teuchos::RCP< Vector< double, int, int, EpetraNode > > getVectorNonConst(size_t j);
389 
391  Teuchos::ArrayRCP< const Scalar > getData(size_t j) const {
392  XPETRA_MONITOR("EpetraMultiVectorT::getData");
393 
394  double ** arrayOfPointers;
395 
396  vec_->ExtractView(&arrayOfPointers);
397 
398  double * data = arrayOfPointers[j];
399  int localLength = vec_->MyLength();
400 
401  return ArrayRCP<double>(data, 0, localLength, false); // no ownership
402  }
403 
405  Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j) {
406  XPETRA_MONITOR("EpetraMultiVectorT::getDataNonConst");
407 
408  double ** arrayOfPointers;
409 
410  vec_->ExtractView(&arrayOfPointers);
411 
412  double * data = arrayOfPointers[j];
413  int localLength = vec_->MyLength();
414 
415  return ArrayRCP<double>(data, 0, localLength, false); // no ownership
416  }
417 
419 
421 
422 
424  void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const {
425  XPETRA_MONITOR("EpetraMultiVectorT::dot");
426 
427  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
428  vec_->Dot(*eA.getEpetra_MultiVector(), dots.getRawPtr());
429  }
430 
432  void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A) { XPETRA_MONITOR("EpetraMultiVectorT::abs"); vec_->Abs(toEpetra<GlobalOrdinal,Node>(A)); }
433 
435  void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A) { XPETRA_MONITOR("EpetraMultiVectorT::reciprocal"); vec_->Reciprocal(toEpetra<GlobalOrdinal,Node>(A)); }
436 
438  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraMultiVectorT::scale"); vec_->Scale(alpha); }
439 
441  void scale (Teuchos::ArrayView< const Scalar > alpha) {
442  XPETRA_MONITOR("EpetraMultiVectorT::scale");
443  // Epetra, unlike Tpetra, doesn't implement this version of
444  // scale(). Deal with this by scaling one column at a time.
445  const size_t numVecs = this->getNumVectors ();
446  for (size_t j = 0; j < numVecs; ++j) {
447  Epetra_Vector *v = (*vec_)(j);
448  v->Scale (alpha[j]);
449  }
450  }
451 
453  void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta) { XPETRA_MONITOR("EpetraMultiVectorT::update"); vec_->Update(alpha, toEpetra<GlobalOrdinal,Node>(A), beta); }
454 
456  void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &gamma) { XPETRA_MONITOR("EpetraMultiVectorT::update"); vec_->Update(alpha, toEpetra<GlobalOrdinal,Node>(A), beta, toEpetra<GlobalOrdinal,Node>(B), gamma); }
457 
459  void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::norm1"); vec_->Norm1(norms.getRawPtr()); }
460 
462  void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::norm2"); vec_->Norm2(norms.getRawPtr()); }
463 
465  void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::normInf"); vec_->NormInf(norms.getRawPtr()); }
466 
468  void meanValue(const Teuchos::ArrayView< Scalar > &means) const { XPETRA_MONITOR("EpetraMultiVectorT::meanValue"); vec_->MeanValue(means.getRawPtr()); } //TODO: modify ArrayView size ??
469 
471  void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta) { XPETRA_MONITOR("EpetraMultiVectorT::multiply"); vec_->Multiply(toEpetra(transA), toEpetra(transB), alpha, toEpetra(A), toEpetra(B), beta); }
472 
474  void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis) { XPETRA_MONITOR("EpetraMultiVectorT::elementWiseMultiply"); vec_->Multiply(scalarAB, toEpetra<GlobalOrdinal,Node>(A), toEpetra<GlobalOrdinal,Node>(B), scalarThis); }
475 
477 
479 
480 
482  size_t getNumVectors() const { XPETRA_MONITOR("EpetraMultiVectorT::getNumVectors"); return vec_->NumVectors(); }
483 
485  size_t getLocalLength() const { XPETRA_MONITOR("EpetraMultiVectorT::getLocalLength"); return vec_->MyLength(); }
486 
488  global_size_t getGlobalLength() const { XPETRA_MONITOR("EpetraMultiVectorT::getGlobalLength"); return vec_->GlobalLength64(); }
489 
492  XPETRA_MONITOR("EpetraMultiVectorT::isSameSize");
493  auto vv = toEpetra<GlobalOrdinal,Node>(vec);
494  return ( (vec_->MyLength() == vv.MyLength()) && (vec_->NumVectors() == vv.NumVectors()));
495  }
496 
498 
500 
501 
503  std::string description() const {
504  XPETRA_MONITOR("EpetraMultiVectorT::description");
505  TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO");
506  TEUCHOS_UNREACHABLE_RETURN("TODO");
507  }
508 
510  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel /* verbLevel */=Teuchos::Describable::verbLevel_default) const {
511  XPETRA_MONITOR("EpetraMultiVectorT::describe");
512  vec_->Print(out);
513  }
514 
516 
518  void randomize(bool bUseXpetraImplementation = false) {
519  XPETRA_MONITOR("EpetraMultiVectorT::randomize");
520 
521  if (bUseXpetraImplementation)
523  else
524  vec_->Random();
525  }
526 
528  //{@
529 
531  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraMultiVectorT::getMap"); return toXpetra<GlobalOrdinal,Node>(vec_->Map()); }
532 
535  XPETRA_MONITOR("EpetraMultiVectorT::doImport");
536 
537  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
538  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
539 
540  RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
541  int err = this->getEpetra_MultiVector()->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
542  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra is " << err);
543  }
544 
547  XPETRA_MONITOR("EpetraMultiVectorT::doExport");
548 
549  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
550  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
551 
552  RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
553  int err = this->getEpetra_MultiVector()->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
554  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
555  }
556 
559  XPETRA_MONITOR("EpetraMultiVectorT::doImport");
560 
561  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
562  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
563 
564  RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
565  int err = this->getEpetra_MultiVector()->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
566  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
567  }
568 
571  XPETRA_MONITOR("EpetraMultiVectorT::doExport");
572 
573  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
574  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
575 
576  RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
577  int err = this->getEpetra_MultiVector()->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
578  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
579  }
580 
582  void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map) {
583  XPETRA_MONITOR("EpetraMultiVectorT::replaceMap");
584  int err = 0;
585  if (!map.is_null()) {
586  err = this->getEpetra_MultiVector()->ReplaceMap(toEpetra<GlobalOrdinal,Node>(map));
587 
588  } else {
589  // Replace map with a dummy map to avoid potential hangs later
590  Epetra_SerialComm SComm;
591  Epetra_Map NewMap((GlobalOrdinal) vec_->MyLength(), (GlobalOrdinal) vec_->Map().IndexBase64(), SComm);
592  err = this->getEpetra_MultiVector()->ReplaceMap(NewMap);
593  }
594  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
595  }
596 
598 
600 
601 
603  EpetraMultiVectorT(const RCP<Epetra_MultiVector> &vec) : vec_(vec) { } //TODO removed const
604 
606  RCP<Epetra_MultiVector> getEpetra_MultiVector() const { return vec_; }
607 
609  void setSeed(unsigned int seed) {
610  XPETRA_MONITOR("EpetraMultiVectorT::seedrandom");
611 
612  Teuchos::ScalarTraits< Scalar >::seedrandom(seed);
613  vec_->SetSeed(seed);
614  }
615 
616 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
617 
619 
620  typename dual_view_type::t_host_const_um getHostLocalView (Access::ReadOnlyStruct) const override { return getHostLocalView(Access::ReadWrite);}
621 
622  typename dual_view_type::t_dev_const_um getDeviceLocalView(Access::ReadOnlyStruct) const override { return getDeviceLocalView(Access::ReadWrite);}
623 
624  typename dual_view_type::t_host_um getHostLocalView (Access::OverwriteAllStruct) const override { return getHostLocalView(Access::ReadWrite);}
625 
626  typename dual_view_type::t_dev_um getDeviceLocalView(Access::OverwriteAllStruct) const override { return getDeviceLocalView(Access::ReadWrite);}
627 
628  typename dual_view_type::t_host_um getHostLocalView (Access::ReadWriteStruct) const override {
629  typedef Kokkos::View< typename dual_view_type::t_host::data_type ,
630  Kokkos::LayoutLeft,
631  typename dual_view_type::t_host::device_type ,
632  Kokkos::MemoryUnmanaged> epetra_view_type;
633 
634  // access Epetra multivector data
635  double* data = NULL;
636  int myLDA;
637  vec_->ExtractView(&data, &myLDA);
638  int localLength = vec_->MyLength();
639  int numVectors = getNumVectors();
640 
641  // create view
642  epetra_view_type test = epetra_view_type(data, localLength, numVectors);
643  typename dual_view_type::t_host_um ret = subview(test, Kokkos::ALL(), Kokkos::ALL());
644 
645  return ret;
646  }
647 
648  typename dual_view_type::t_dev_um getDeviceLocalView(Access::ReadWriteStruct) const override {
649  throw std::runtime_error("Epetra does not support device views! in "+std::string(__FILE__)+":"+std::to_string(__LINE__));
650 #ifndef __NVCC__ //prevent nvcc warning
651  typename dual_view_type::t_dev_um ret;
652 #endif
653  TEUCHOS_UNREACHABLE_RETURN(ret);
654  }
655 
656 #endif
657 
659 
660  protected:
663  virtual void
665  typedef EpetraMultiVectorT this_type;
666  const this_type* rhsPtr = dynamic_cast<const this_type*> (&rhs);
667  TEUCHOS_TEST_FOR_EXCEPTION(
668  rhsPtr == NULL, std::invalid_argument, "Xpetra::MultiVector::operator=: "
669  "The left-hand side (LHS) of the assignment has a different type than "
670  "the right-hand side (RHS). The LHS has type Xpetra::EpetraMultiVectorT "
671  "(which means it wraps an Epetra_MultiVector), but the RHS has some "
672  "other type. This probably means that the RHS wraps a Tpetra::Multi"
673  "Vector. Xpetra::MultiVector does not currently implement assignment "
674  "from a Tpetra object to an Epetra object, though this could be added "
675  "with sufficient interest.");
676 
677  RCP<const Epetra_MultiVector> rhsImpl = rhsPtr->getEpetra_MultiVector ();
678  RCP<Epetra_MultiVector> lhsImpl = this->getEpetra_MultiVector ();
679 
680  TEUCHOS_TEST_FOR_EXCEPTION(
681  rhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
682  "(in Xpetra::EpetraMultiVectorT::assign): *this (the right-hand side of "
683  "the assignment) has a null RCP<Epetra_MultiVector> inside. Please "
684  "report this bug to the Xpetra developers.");
685  TEUCHOS_TEST_FOR_EXCEPTION(
686  lhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
687  "(in Xpetra::EpetraMultiVectorT::assign): The left-hand side of the "
688  "assignment has a null RCP<Epetra_MultiVector> inside. Please report "
689  "this bug to the Xpetra developers.");
690 
691  // Epetra_MultiVector's assignment operator does a deep copy.
692  *lhsImpl = *rhsImpl;
693  }
694 
695  private:
697  RCP< Epetra_MultiVector > vec_;
698 
699  }; // EpetraMultiVectorT class (specialization on GO=int, NO=EpetraNode
700 #endif
701 
702  // specialization on GO=long long and EpetraNode
703 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
704  template<>
705  class EpetraMultiVectorT<long long, EpetraNode>
706  : public virtual MultiVector<double, int, long long, EpetraNode>
707  {
708  typedef double Scalar;
709  typedef int LocalOrdinal;
710  typedef long long GlobalOrdinal;
711  typedef EpetraNode Node;
712 
713  public:
714 
716 
717 
719  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
720  : vec_(Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal,Node>(map), Teuchos::as<int>(NumVectors), zeroOut))) { }
721 
724  : vec_(Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal,Node>(source)))) { }
725 
727  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
728  //TODO: input argument 'NumVectors' is not necessary in both Xpetra and Tpetra interface. Should it be removed?
729 
730  const std::string tfecfFuncName("MultiVector(ArrayOfPtrs)");
731  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(NumVectors < 1 || NumVectors != Teuchos::as<size_t>(ArrayOfPtrs.size()), std::runtime_error,
732  ": ArrayOfPtrs.size() must be strictly positive and as large as ArrayOfPtrs.");
733 
734  #ifdef HAVE_XPETRA_DEBUG
735  // This cannot be tested by Epetra itself
736  {
737  size_t localLength = map->getNodeNumElements();
738  for(int j=0; j<ArrayOfPtrs.size(); j++) {
739  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Teuchos::as<size_t>(ArrayOfPtrs[j].size()) != localLength, std::runtime_error,
740  ": ArrayOfPtrs[" << j << "].size() (== " << ArrayOfPtrs[j].size() <<
741  ") is not equal to getLocalLength() (== " << localLength);
742 
743  }
744  }
745  #endif
746 
747  // Convert Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > to double**
748  Array<const double*> arrayOfRawPtrs(ArrayOfPtrs.size());
749  for(int i=0; i<ArrayOfPtrs.size(); i++) {
750  arrayOfRawPtrs[i] = ArrayOfPtrs[i].getRawPtr();
751  }
752  double** rawArrayOfRawPtrs = const_cast<double**>(arrayOfRawPtrs.getRawPtr()); // This const_cast should be fine, because Epetra_DataAccess=Copy.
753 
754  vec_ = Teuchos::rcp(new Epetra_MultiVector(Copy, toEpetra<GlobalOrdinal,Node>(map), rawArrayOfRawPtrs, NumVectors));
755  }
756 
758  virtual ~EpetraMultiVectorT() {}
759 
761 
763 
764 
766  void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::replaceGlobalValue"); vec_->ReplaceGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value); }
767 
769  void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::sumIntoGlobalValue"); vec_->SumIntoGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value); }
770 
772  void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::replaceLocalValue"); vec_->ReplaceMyValue(myRow, Teuchos::as<int>(vectorIndex), value); }
773 
775  void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::sumIntoLocalValue"); vec_->SumIntoMyValue(myRow, Teuchos::as<int>(vectorIndex), value); }
776 
778  void putScalar(const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::putScalar"); vec_->PutScalar(value); }
779 
781 
783 
784 
786  Teuchos::RCP< const Vector< double, int, long long, EpetraNode > > getVector(size_t j) const;
787 
789  Teuchos::RCP< Vector< double, int, long long, EpetraNode > > getVectorNonConst(size_t j);
790 
792  Teuchos::ArrayRCP< const Scalar > getData(size_t j) const {
793  XPETRA_MONITOR("EpetraMultiVectorT::getData");
794 
795  double ** arrayOfPointers;
796 
797  vec_->ExtractView(&arrayOfPointers);
798 
799  double * data = arrayOfPointers[j];
800  int localLength = vec_->MyLength();
801 
802  return ArrayRCP<double>(data, 0, localLength, false); // no ownership
803  }
804 
806  Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j) {
807  XPETRA_MONITOR("EpetraMultiVectorT::getDataNonConst");
808 
809  double ** arrayOfPointers;
810 
811  vec_->ExtractView(&arrayOfPointers);
812 
813  double * data = arrayOfPointers[j];
814  int localLength = vec_->MyLength();
815 
816  return ArrayRCP<double>(data, 0, localLength, false); // no ownership
817  }
818 
820 
822 
823 
825  void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const {
826  XPETRA_MONITOR("EpetraMultiVectorT::dot");
827 
828  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
829  vec_->Dot(*eA.getEpetra_MultiVector(), dots.getRawPtr());
830  }
831 
833  void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A) { XPETRA_MONITOR("EpetraMultiVectorT::abs"); vec_->Abs(toEpetra<GlobalOrdinal,Node>(A)); }
834 
836  void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A) { XPETRA_MONITOR("EpetraMultiVectorT::reciprocal"); vec_->Reciprocal(toEpetra<GlobalOrdinal,Node>(A)); }
837 
839  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraMultiVectorT::scale"); vec_->Scale(alpha); }
840 
842  void scale (Teuchos::ArrayView< const Scalar > alpha) {
843  XPETRA_MONITOR("EpetraMultiVectorT::scale");
844  // Epetra, unlike Tpetra, doesn't implement this version of
845  // scale(). Deal with this by scaling one column at a time.
846  const size_t numVecs = this->getNumVectors ();
847  for (size_t j = 0; j < numVecs; ++j) {
848  Epetra_Vector *v = (*vec_)(j);
849  v->Scale (alpha[j]);
850  }
851  }
852 
854  void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta) { XPETRA_MONITOR("EpetraMultiVectorT::update"); vec_->Update(alpha, toEpetra<GlobalOrdinal,Node>(A), beta); }
855 
857  void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &gamma) { XPETRA_MONITOR("EpetraMultiVectorT::update"); vec_->Update(alpha, toEpetra<GlobalOrdinal,Node>(A), beta, toEpetra<GlobalOrdinal,Node>(B), gamma); }
858 
860  void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::norm1"); vec_->Norm1(norms.getRawPtr()); }
861 
863  void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::norm2"); vec_->Norm2(norms.getRawPtr()); }
864 
866  void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::normInf"); vec_->NormInf(norms.getRawPtr()); }
867 
869  void meanValue(const Teuchos::ArrayView< Scalar > &means) const { XPETRA_MONITOR("EpetraMultiVectorT::meanValue"); vec_->MeanValue(means.getRawPtr()); } //TODO: modify ArrayView size ??
870 
872  void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta) { XPETRA_MONITOR("EpetraMultiVectorT::multiply"); vec_->Multiply(toEpetra(transA), toEpetra(transB), alpha, toEpetra(A), toEpetra(B), beta); }
873 
875  void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis) { XPETRA_MONITOR("EpetraMultiVectorT::elementWiseMultiply"); vec_->Multiply(scalarAB, toEpetra<GlobalOrdinal,Node>(A), toEpetra<GlobalOrdinal,Node>(B), scalarThis); }
876 
878 
880 
881 
883  size_t getNumVectors() const { XPETRA_MONITOR("EpetraMultiVectorT::getNumVectors"); return vec_->NumVectors(); }
884 
886  size_t getLocalLength() const { XPETRA_MONITOR("EpetraMultiVectorT::getLocalLength"); return vec_->MyLength(); }
887 
889  global_size_t getGlobalLength() const { XPETRA_MONITOR("EpetraMultiVectorT::getGlobalLength"); return vec_->GlobalLength64(); }
890 
893  XPETRA_MONITOR("EpetraMultiVectorT::isSameSize");
894  auto vv = toEpetra<GlobalOrdinal,Node>(vec);
895  return ( (vec_->MyLength() == vv.MyLength()) && (vec_->NumVectors() == vv.NumVectors()));
896  }
897 
899 
901 
902 
904  std::string description() const {
905  XPETRA_MONITOR("EpetraMultiVectorT::description");
906  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "TODO");
907  //return "TODO"; // unreachable
908  }
909 
911  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel /* verbLevel */=Teuchos::Describable::verbLevel_default) const {
912  XPETRA_MONITOR("EpetraMultiVectorT::describe");
913  vec_->Print(out);
914  }
915 
917 
919  void randomize(bool bUseXpetraImplementation = false) {
920  XPETRA_MONITOR("EpetraMultiVectorT::randomize");
921 
922  if (bUseXpetraImplementation)
924  else
925  vec_->Random();
926  }
927 
929  //{@
930 
932  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraMultiVectorT::getMap"); return toXpetra<GlobalOrdinal,Node>(vec_->Map()); }
933 
936  XPETRA_MONITOR("EpetraMultiVectorT::doImport");
937 
938  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
939  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
940 
941  RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
942  int err = this->getEpetra_MultiVector()->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
943  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra is " << err);
944  }
945 
948  XPETRA_MONITOR("EpetraMultiVectorT::doExport");
949 
950  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
951  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
952 
953  RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
954  int err = this->getEpetra_MultiVector()->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
955  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
956  }
957 
960  XPETRA_MONITOR("EpetraMultiVectorT::doImport");
961 
962  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
963  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
964 
965  RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
966  int err = this->getEpetra_MultiVector()->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
967  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
968  }
969 
972  XPETRA_MONITOR("EpetraMultiVectorT::doExport");
973 
974  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
975  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
976 
977  RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
978  int err = this->getEpetra_MultiVector()->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
979  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
980  }
981 
983  void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map) {
984  XPETRA_MONITOR("EpetraMultiVectorT::replaceMap");
985  int err = 0;
986  if (!map.is_null()) {
987  err = this->getEpetra_MultiVector()->ReplaceMap(toEpetra<GlobalOrdinal,Node>(map));
988 
989  } else {
990  // Replace map with a dummy map to avoid potential hangs later
991  Epetra_SerialComm SComm;
992  Epetra_Map NewMap((GlobalOrdinal) vec_->MyLength(), (GlobalOrdinal) vec_->Map().IndexBase64(), SComm);
993  err = this->getEpetra_MultiVector()->ReplaceMap(NewMap);
994  }
995  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
996  }
997 
999 
1001 
1002 
1004  EpetraMultiVectorT(const RCP<Epetra_MultiVector> &vec) : vec_(vec) { } //TODO removed const
1005 
1007  RCP<Epetra_MultiVector> getEpetra_MultiVector() const { return vec_; }
1008 
1010  void setSeed(unsigned int seed) {
1011  XPETRA_MONITOR("EpetraMultiVectorT::seedrandom");
1012 
1013  Teuchos::ScalarTraits< Scalar >::seedrandom(seed);
1014  vec_->SetSeed(seed);
1015  }
1016 
1018 
1019  protected:
1022  virtual void
1024  typedef EpetraMultiVectorT this_type;
1025  const this_type* rhsPtr = dynamic_cast<const this_type*> (&rhs);
1026  TEUCHOS_TEST_FOR_EXCEPTION(
1027  rhsPtr == NULL, std::invalid_argument, "Xpetra::MultiVector::operator=: "
1028  "The left-hand side (LHS) of the assignment has a different type than "
1029  "the right-hand side (RHS). The LHS has type Xpetra::EpetraMultiVectorT "
1030  "(which means it wraps an Epetra_MultiVector), but the RHS has some "
1031  "other type. This probably means that the RHS wraps a Tpetra::Multi"
1032  "Vector. Xpetra::MultiVector does not currently implement assignment "
1033  "from a Tpetra object to an Epetra object, though this could be added "
1034  "with sufficient interest.");
1035 
1036  RCP<const Epetra_MultiVector> rhsImpl = rhsPtr->getEpetra_MultiVector ();
1037  RCP<Epetra_MultiVector> lhsImpl = this->getEpetra_MultiVector ();
1038 
1039  TEUCHOS_TEST_FOR_EXCEPTION(
1040  rhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
1041  "(in Xpetra::EpetraMultiVectorT::assign): *this (the right-hand side of "
1042  "the assignment) has a null RCP<Epetra_MultiVector> inside. Please "
1043  "report this bug to the Xpetra developers.");
1044  TEUCHOS_TEST_FOR_EXCEPTION(
1045  lhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
1046  "(in Xpetra::EpetraMultiVectorT::assign): The left-hand side of the "
1047  "assignment has a null RCP<Epetra_MultiVector> inside. Please report "
1048  "this bug to the Xpetra developers.");
1049 
1050  // Epetra_MultiVector's assignment operator does a deep copy.
1051  *lhsImpl = *rhsImpl;
1052  }
1053 
1054  private:
1056  RCP< Epetra_MultiVector > vec_;
1057 
1058  }; // EpetraMultiVectorT class (specialization on GO=long long, NO=EpetraNode
1059 #endif
1060 
1061 } // Xpetra namespace
1062 
1063 #include "Xpetra_EpetraVector.hpp" // to avoid incomplete type instantiated above in out-of-body functions.
1064 
1065 #endif // XPETRA_EPETRAMULTIVECTOR_HPP
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &gamma)
Update: this = gamma*this + alpha*A + beta*B.
EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors)
Set multi-vector values from array of pointers using Teuchos memory management classes. (copy).
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
RCP< Epetra_MultiVector > getEpetra_MultiVector() const
Get the underlying Epetra multivector.
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &gamma)
Update: this = gamma*this + alpha*A + beta*B.
EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors)
Set multi-vector values from array of pointers using Teuchos memory management classes. (copy).
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &gamma)
Update: this = gamma*this + alpha*A + beta*B.
size_t getNumVectors() const
Number of columns in the multivector.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
void meanValue(const Teuchos::ArrayView< Scalar > &means) const
Compute mean (average) value of each vector in multi-vector. The outcome of this routine is undefined...
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const
Compute the dot product of each corresponding pair of vectors (columns) in A and B.
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
void randomize(bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
RCP< Epetra_MultiVector > vec_
The Epetra_MultiVector which this class wraps.
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
void meanValue(const Teuchos::ArrayView< Scalar > &means) const
Compute mean (average) value of each vector in multi-vector. The outcome of this routine is undefined...
Xpetra namespace
size_t getLocalLength() const
Local number of rows on the calling process.
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Basic MultiVector constuctor.
EpetraMultiVectorT(const RCP< Epetra_MultiVector > &vec)
EpetraMultiVectorT constructor to wrap a Epetra_MultiVector object.
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
Checks to see if the local length, number of vectors and size of Scalar type match.
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const
Compute the dot product of each corresponding pair of vectors (columns) in A and B.
void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const
Compute the dot product of each corresponding pair of vectors (columns) in A and B.
Exception throws to report errors in the internal logical of the program.
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Basic MultiVector constuctor.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
void randomize(bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
RCP< Epetra_MultiVector > getEpetra_MultiVector() const
Get the underlying Epetra multivector.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis)
Multiply a Vector A elementwise by a MultiVector B.
void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
size_t getNumVectors() const
Number of columns in the multivector.
void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Replace the underlying Map in place.
void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source)
MultiVector copy constructor.
void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis)
Multiply a Vector A elementwise by a MultiVector B.
std::string description() const
A simple one-line description of this object.
EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Teuchos::DataAccess copyOrView=Teuchos::Copy)
MultiVector copy constructor.
RCP< Epetra_MultiVector > getEpetra_MultiVector() const
Get the underlying Epetra multivector.
void setSeed(unsigned int seed)
Set seed for Random function.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
size_t getLocalLength() const
Local number of rows on the calling process.
void meanValue(const Teuchos::ArrayView< Scalar > &means) const
Compute mean (average) value of each vector in multi-vector. The outcome of this routine is undefined...
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
std::string description() const
A simple one-line description of this object.
void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
Checks to see if the local length, number of vectors and size of Scalar type match.
void randomize(bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
EpetraMultiVectorT(const RCP< Epetra_MultiVector > &vec)
EpetraMultiVectorT constructor to wrap a Epetra_MultiVector object.
virtual ~EpetraMultiVectorT()
MultiVector destructor.
void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors)
Set multi-vector values from array of pointers using Teuchos memory management classes. (copy).
void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Basic MultiVector constuctor.
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Replace the underlying Map in place.
void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
Exception throws when you call an unimplemented method of Xpetra.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
size_t global_size_t
Global size_t object.
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
size_t getNumVectors() const
Number of columns in the multivector.
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
void setSeed(unsigned int seed)
Set seed for Random function.
void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,j).
EpetraMultiVectorT(const RCP< Epetra_MultiVector > &vec)
EpetraMultiVectorT constructor to wrap a Epetra_MultiVector object.
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Teuchos::DataAccess copyOrView=Teuchos::Copy)
MultiVector copy constructor.
void setSeed(unsigned int seed)
Set seed for Random function.
void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
RCP< Epetra_MultiVector > vec_
The Epetra_MultiVector which this class wraps.
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
size_t getLocalLength() const
Local number of rows on the calling process.
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
Teuchos::RCP< const Vector< double, int, GlobalOrdinal, Node > > getVector(size_t j) const
Return a Vector which is a const view of column j.
void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Replace the underlying Map in place.
CombineMode
Xpetra::Combine Mode enumerable type.
constexpr struct ReadWriteStruct ReadWrite
#define XPETRA_MONITOR(funcName)
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
void elementWiseMultiply(Scalar scalarAB, const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Scalar scalarThis)
Multiply a Vector A elementwise by a MultiVector B.
void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,j).
std::string description() const
A simple one-line description of this object.
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
virtual size_t getNumVectors() const =0
Number of columns in the multivector.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,j).
Teuchos::RCP< Vector< double, int, GlobalOrdinal, Node > > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.