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 
72 namespace Xpetra {
73 
74  // TODO: move that elsewhere
75  template<class GlobalOrdinal, class Node>
76  const Epetra_MultiVector & toEpetra(const MultiVector<double,int,GlobalOrdinal,Node> &);
77  template<class GlobalOrdinal, class Node>
78  Epetra_MultiVector & toEpetra(MultiVector<double, int,GlobalOrdinal,Node> &);
79  template<class GlobalOrdinal, class Node>
80  RCP<MultiVector<double, int, GlobalOrdinal, Node> > toXpetra(RCP<Epetra_MultiVector> vec);
81 
82  // we need this forward declaration
83 #ifndef DOXYGEN_SHOULD_SKIP_THIS
84  template<class GlobalOrdinal, class Node> class EpetraVectorT;
85 #endif
86 
87  template<class EpetraGlobalOrdinal, class Node>
89  : public virtual MultiVector<double, int, EpetraGlobalOrdinal, Node>
90  {
91  typedef double Scalar;
92  typedef int LocalOrdinal;
93  typedef EpetraGlobalOrdinal GlobalOrdinal;
94 
95  public:
96 
98 
99 
101  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true) {
102  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
103  "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
104  }
105 
108  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
109  "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
110  }
111 
113  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
114  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
115  "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
116  }
117 
119  virtual ~EpetraMultiVectorT() {}
120 
122 
124 
125 
127  void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { }
128 
130  void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { }
131 
133  void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { }
134 
136  void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { }
137 
139  void putScalar(const Scalar &value) { }
140 
142 
144 
145 
147  Teuchos::RCP< const Vector< double, int, GlobalOrdinal, Node > > getVector(size_t j) const {
148  return Teuchos::null;
149  }
150 
152  Teuchos::RCP< Vector< double, int, GlobalOrdinal, Node > > getVectorNonConst(size_t j) {
153  return Teuchos::null;
154  }
155 
157  Teuchos::ArrayRCP< const Scalar > getData(size_t j) const {
158  return ArrayRCP<const Scalar>();
159  }
160 
162  Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j) {
163  return ArrayRCP<Scalar>();
164  }
165 
167 
169 
170 
172  void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const { }
173 
176 
179 
181  void scale(const Scalar &alpha) { }
182 
184  void scale (Teuchos::ArrayView< const Scalar > alpha) { }
185 
187  void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta) { }
188 
191 
193  void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { }
194 
196  void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { }
197 
199  void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { }
200 
202  void meanValue(const Teuchos::ArrayView< Scalar > &means) const { }
203 
205  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) { }
206 
209 
211 
213 
214 
216  size_t getNumVectors() const { return 0; }
217 
219  size_t getLocalLength() const { return 0; }
220 
222  global_size_t getGlobalLength() const { return 0; }
223 
225 
227 
228 
230  std::string description() const { return std::string(""); }
231 
233  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const { }
234 
236 
238  void randomize(bool bUseXpetraImplementation = false) { }
239 
241  //{@
242 
244  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { return Teuchos::null; }
245 
248 
251 
254 
257 
259  void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map) { }
260 
262 
264 
265 
267  EpetraMultiVectorT(const RCP<Epetra_MultiVector> &vec) { //TODO removed const
268  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
269  "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
270  }
271 
273  RCP<Epetra_MultiVector> getEpetra_MultiVector() const { return Teuchos::null; }
274 
276  void setSeed(unsigned int seed) { }
277 
278 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
279 
281 
292  template<class TargetDeviceType>
293  typename Kokkos::Impl::if_c<
294  Kokkos::Impl::is_same<
295  typename dual_view_type::t_dev_um::execution_space::memory_space,
296  typename TargetDeviceType::memory_space>::value,
297  typename dual_view_type::t_dev_um,
298  typename dual_view_type::t_host_um>::type
299  getLocalView () const {
300  typename Kokkos::Impl::if_c<
301  Kokkos::Impl::is_same<
302  typename dual_view_type::t_dev_um::execution_space::memory_space,
303  typename TargetDeviceType::memory_space>::value,
304  typename dual_view_type::t_dev_um,
305  typename dual_view_type::t_host_um>::type dummy;
306  return dummy;
307  }
308 
309  typename dual_view_type::t_host_um getHostLocalView () const {
310  return typename dual_view_type::t_host_um();
311  }
312 
313  typename dual_view_type::t_dev_um getDeviceLocalView() const {
314  throw std::runtime_error("Epetra does not support device views!");
315  typename dual_view_type::t_dev_um ret;
316  return ret; // make compiler happy
317  }
318 
319 #endif
320 
322 
323  protected:
326  virtual void
328 
329  }; // EpetraMultiVectorT class
330 
331  // specialization on GO=int and Node=EpetraNode
332 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
333  template<>
335  : public virtual MultiVector<double, int, int, EpetraNode>
336  {
337  typedef double Scalar;
338  typedef int LocalOrdinal;
339  typedef int GlobalOrdinal;
340  typedef EpetraNode Node;
341 
342  public:
343 
345 
346 
348  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
349  : vec_(Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal,Node>(map), Teuchos::as<int>(NumVectors), zeroOut))) { }
350 
353  : vec_(Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal,Node>(source)))) { }
354 
356  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
357  //TODO: input argument 'NumVectors' is not necessary in both Xpetra and Tpetra interface. Should it be removed?
358 
359  const std::string tfecfFuncName("MultiVector(ArrayOfPtrs)");
360  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(NumVectors < 1 || NumVectors != Teuchos::as<size_t>(ArrayOfPtrs.size()), std::runtime_error,
361  ": ArrayOfPtrs.size() must be strictly positive and as large as ArrayOfPtrs.");
362 
363  #ifdef HAVE_XPETRA_DEBUG
364  // This cannot be tested by Epetra itself
365  {
366  size_t localLength = map->getNodeNumElements();
367  for(int j=0; j<ArrayOfPtrs.size(); j++) {
368  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Teuchos::as<size_t>(ArrayOfPtrs[j].size()) != localLength, std::runtime_error,
369  ": ArrayOfPtrs[" << j << "].size() (== " << ArrayOfPtrs[j].size() <<
370  ") is not equal to getLocalLength() (== " << localLength);
371 
372  }
373  }
374  #endif
375 
376  // Convert Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > to double**
377  Array<const double*> arrayOfRawPtrs(ArrayOfPtrs.size());
378  for(int i=0; i<ArrayOfPtrs.size(); i++) {
379  arrayOfRawPtrs[i] = ArrayOfPtrs[i].getRawPtr();
380  }
381  double** rawArrayOfRawPtrs = const_cast<double**>(arrayOfRawPtrs.getRawPtr()); // This const_cast should be fine, because Epetra_DataAccess=Copy.
382 
383  vec_ = Teuchos::rcp(new Epetra_MultiVector(Copy, toEpetra<GlobalOrdinal,Node>(map), rawArrayOfRawPtrs, NumVectors));
384  }
385 
387  virtual ~EpetraMultiVectorT() {}
388 
390 
392 
393 
395  void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::replaceGlobalValue"); vec_->ReplaceGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value); }
396 
398  void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::sumIntoGlobalValue"); vec_->SumIntoGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value); }
399 
401  void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::replaceLocalValue"); vec_->ReplaceMyValue(myRow, Teuchos::as<int>(vectorIndex), value); }
402 
404  void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::sumIntoLocalValue"); vec_->SumIntoMyValue(myRow, Teuchos::as<int>(vectorIndex), value); }
405 
407  void putScalar(const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::putScalar"); vec_->PutScalar(value); }
408 
410 
412 
413 
415  Teuchos::RCP< const Vector< double, int, int, EpetraNode > > getVector(size_t j) const;
416 
418  Teuchos::RCP< Vector< double, int, int, EpetraNode > > getVectorNonConst(size_t j);
419 
421  Teuchos::ArrayRCP< const Scalar > getData(size_t j) const {
422  XPETRA_MONITOR("EpetraMultiVectorT::getData");
423 
424  double ** arrayOfPointers;
425 
426  vec_->ExtractView(&arrayOfPointers);
427 
428  double * data = arrayOfPointers[j];
429  int localLength = vec_->MyLength();
430 
431  return ArrayRCP<double>(data, 0, localLength, false); // no ownership
432  }
433 
435  Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j) {
436  XPETRA_MONITOR("EpetraMultiVectorT::getDataNonConst");
437 
438  double ** arrayOfPointers;
439 
440  vec_->ExtractView(&arrayOfPointers);
441 
442  double * data = arrayOfPointers[j];
443  int localLength = vec_->MyLength();
444 
445  return ArrayRCP<double>(data, 0, localLength, false); // no ownership
446  }
447 
449 
451 
452 
454  void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const {
455  XPETRA_MONITOR("EpetraMultiVectorT::dot");
456 
457  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
458  vec_->Dot(*eA.getEpetra_MultiVector(), dots.getRawPtr());
459  }
460 
462  void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A) { XPETRA_MONITOR("EpetraMultiVectorT::abs"); vec_->Abs(toEpetra<GlobalOrdinal,Node>(A)); }
463 
465  void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A) { XPETRA_MONITOR("EpetraMultiVectorT::reciprocal"); vec_->Reciprocal(toEpetra<GlobalOrdinal,Node>(A)); }
466 
468  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraMultiVectorT::scale"); vec_->Scale(alpha); }
469 
471  void scale (Teuchos::ArrayView< const Scalar > alpha) {
472  XPETRA_MONITOR("EpetraMultiVectorT::scale");
473  // Epetra, unlike Tpetra, doesn't implement this version of
474  // scale(). Deal with this by scaling one column at a time.
475  const size_t numVecs = this->getNumVectors ();
476  for (size_t j = 0; j < numVecs; ++j) {
477  vec_->Scale (alpha[j]);
478  }
479  }
480 
482  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); }
483 
485  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); }
486 
488  void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::norm1"); vec_->Norm1(norms.getRawPtr()); }
489 
491  void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::norm2"); vec_->Norm2(norms.getRawPtr()); }
492 
494  void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::normInf"); vec_->NormInf(norms.getRawPtr()); }
495 
497  void meanValue(const Teuchos::ArrayView< Scalar > &means) const { XPETRA_MONITOR("EpetraMultiVectorT::meanValue"); vec_->MeanValue(means.getRawPtr()); } //TODO: modify ArrayView size ??
498 
500  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); }
501 
503  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); }
504 
506 
508 
509 
511  size_t getNumVectors() const { XPETRA_MONITOR("EpetraMultiVectorT::getNumVectors"); return vec_->NumVectors(); }
512 
514  size_t getLocalLength() const { XPETRA_MONITOR("EpetraMultiVectorT::getLocalLength"); return vec_->MyLength(); }
515 
517  global_size_t getGlobalLength() const { XPETRA_MONITOR("EpetraMultiVectorT::getGlobalLength"); return vec_->GlobalLength64(); }
518 
520 
522 
523 
525  std::string description() const {
526  XPETRA_MONITOR("EpetraMultiVectorT::description");
527  TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO");
528  return "TODO";
529  }
530 
532  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const {
533  XPETRA_MONITOR("EpetraMultiVectorT::describe");
534  vec_->Print(out);
535  }
536 
538 
540  void randomize(bool bUseXpetraImplementation = false) {
541  XPETRA_MONITOR("EpetraMultiVectorT::randomize");
542 
543  if (bUseXpetraImplementation)
545  else
546  vec_->Random();
547  }
548 
550  //{@
551 
553  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraMultiVectorT::getMap"); return toXpetra<GlobalOrdinal,Node>(vec_->Map()); }
554 
557  XPETRA_MONITOR("EpetraMultiVectorT::doImport");
558 
559  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
560  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
561 
562  RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
563  int err = this->getEpetra_MultiVector()->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
564  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra is " << err);
565  }
566 
569  XPETRA_MONITOR("EpetraMultiVectorT::doExport");
570 
571  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
572  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
573 
574  RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
575  int err = this->getEpetra_MultiVector()->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
576  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
577  }
578 
581  XPETRA_MONITOR("EpetraMultiVectorT::doImport");
582 
583  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
584  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
585 
586  RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
587  int err = this->getEpetra_MultiVector()->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
588  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
589  }
590 
593  XPETRA_MONITOR("EpetraMultiVectorT::doExport");
594 
595  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
596  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
597 
598  RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
599  int err = this->getEpetra_MultiVector()->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
600  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
601  }
602 
604  void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map) {
605  XPETRA_MONITOR("EpetraMultiVectorT::replaceMap");
606  int err = 0;
607  if (!map.is_null()) {
608  err = this->getEpetra_MultiVector()->ReplaceMap(toEpetra<GlobalOrdinal,Node>(map));
609 
610  } else {
611  // Replace map with a dummy map to avoid potential hangs later
612  Epetra_SerialComm SComm;
613  Epetra_Map NewMap((GlobalOrdinal) vec_->MyLength(), (GlobalOrdinal) vec_->Map().IndexBase64(), SComm);
614  err = this->getEpetra_MultiVector()->ReplaceMap(NewMap);
615  }
616  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
617  }
618 
620 
622 
623 
625  EpetraMultiVectorT(const RCP<Epetra_MultiVector> &vec) : vec_(vec) { } //TODO removed const
626 
628  RCP<Epetra_MultiVector> getEpetra_MultiVector() const { return vec_; }
629 
631  void setSeed(unsigned int seed) {
632  XPETRA_MONITOR("EpetraMultiVectorT::seedrandom");
633 
634  Teuchos::ScalarTraits< Scalar >::seedrandom(seed);
635  vec_->SetSeed(seed);
636  }
637 
638 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
639 
641 
652  template<class TargetDeviceType>
653  typename Kokkos::Impl::if_c<
654  Kokkos::Impl::is_same<
655  typename dual_view_type::t_dev_um::execution_space::memory_space,
656  typename TargetDeviceType::memory_space>::value,
657  typename dual_view_type::t_dev_um,
658  typename dual_view_type::t_host_um>::type
659  getLocalView () const {
660  return this->MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::template getLocalView<TargetDeviceType>();
661  }
662 
663  typename dual_view_type::t_host_um getHostLocalView () const {
664  typedef Kokkos::View< typename dual_view_type::t_host::data_type ,
665  Kokkos::LayoutLeft,
666  typename dual_view_type::t_host::device_type ,
667  Kokkos::MemoryUnmanaged> epetra_view_type;
668 
669  // access Epetra multivector data
670  double* data = NULL;
671  int myLDA;
672  vec_->ExtractView(&data, &myLDA);
673  int localLength = vec_->MyLength();
674  int numVectors = getNumVectors();
675 
676  // create view
677  epetra_view_type test = epetra_view_type(data, localLength, numVectors);
678  typename dual_view_type::t_host_um ret = subview(test, Kokkos::ALL(), Kokkos::ALL());
679 
680  return ret;
681  }
682 
683  typename dual_view_type::t_dev_um getDeviceLocalView() const {
684  throw std::runtime_error("Epetra does not support device views!");
685  typename dual_view_type::t_dev_um ret;
686  return ret; // make compiler happy
687  }
688 
689 #endif
690 
692 
693  protected:
696  virtual void
698  typedef EpetraMultiVectorT this_type;
699  const this_type* rhsPtr = dynamic_cast<const this_type*> (&rhs);
700  TEUCHOS_TEST_FOR_EXCEPTION(
701  rhsPtr == NULL, std::invalid_argument, "Xpetra::MultiVector::operator=: "
702  "The left-hand side (LHS) of the assignment has a different type than "
703  "the right-hand side (RHS). The LHS has type Xpetra::EpetraMultiVectorT "
704  "(which means it wraps an Epetra_MultiVector), but the RHS has some "
705  "other type. This probably means that the RHS wraps a Tpetra::Multi"
706  "Vector. Xpetra::MultiVector does not currently implement assignment "
707  "from a Tpetra object to an Epetra object, though this could be added "
708  "with sufficient interest.");
709 
710  RCP<const Epetra_MultiVector> rhsImpl = rhsPtr->getEpetra_MultiVector ();
711  RCP<Epetra_MultiVector> lhsImpl = this->getEpetra_MultiVector ();
712 
713  TEUCHOS_TEST_FOR_EXCEPTION(
714  rhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
715  "(in Xpetra::EpetraMultiVectorT::assign): *this (the right-hand side of "
716  "the assignment) has a null RCP<Epetra_MultiVector> inside. Please "
717  "report this bug to the Xpetra developers.");
718  TEUCHOS_TEST_FOR_EXCEPTION(
719  lhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
720  "(in Xpetra::EpetraMultiVectorT::assign): The left-hand side of the "
721  "assignment has a null RCP<Epetra_MultiVector> inside. Please report "
722  "this bug to the Xpetra developers.");
723 
724  // Epetra_MultiVector's assignment operator does a deep copy.
725  *lhsImpl = *rhsImpl;
726  }
727 
728  private:
730  RCP< Epetra_MultiVector > vec_;
731 
732  }; // EpetraMultiVectorT class (specialization on GO=int, NO=EpetraNode
733 #endif
734 
735  // specialization on GO=long long and EpetraNode
736 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
737  template<>
738  class EpetraMultiVectorT<long long, EpetraNode>
739  : public virtual MultiVector<double, int, long long, EpetraNode>
740  {
741  typedef double Scalar;
742  typedef int LocalOrdinal;
743  typedef long long GlobalOrdinal;
744  typedef EpetraNode Node;
745 
746  public:
747 
749 
750 
752  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
753  : vec_(Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal,Node>(map), Teuchos::as<int>(NumVectors), zeroOut))) { }
754 
757  : vec_(Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal,Node>(source)))) { }
758 
760  EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > &ArrayOfPtrs, size_t NumVectors) {
761  //TODO: input argument 'NumVectors' is not necessary in both Xpetra and Tpetra interface. Should it be removed?
762 
763  const std::string tfecfFuncName("MultiVector(ArrayOfPtrs)");
764  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(NumVectors < 1 || NumVectors != Teuchos::as<size_t>(ArrayOfPtrs.size()), std::runtime_error,
765  ": ArrayOfPtrs.size() must be strictly positive and as large as ArrayOfPtrs.");
766 
767  #ifdef HAVE_XPETRA_DEBUG
768  // This cannot be tested by Epetra itself
769  {
770  size_t localLength = map->getNodeNumElements();
771  for(int j=0; j<ArrayOfPtrs.size(); j++) {
772  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Teuchos::as<size_t>(ArrayOfPtrs[j].size()) != localLength, std::runtime_error,
773  ": ArrayOfPtrs[" << j << "].size() (== " << ArrayOfPtrs[j].size() <<
774  ") is not equal to getLocalLength() (== " << localLength);
775 
776  }
777  }
778  #endif
779 
780  // Convert Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > to double**
781  Array<const double*> arrayOfRawPtrs(ArrayOfPtrs.size());
782  for(int i=0; i<ArrayOfPtrs.size(); i++) {
783  arrayOfRawPtrs[i] = ArrayOfPtrs[i].getRawPtr();
784  }
785  double** rawArrayOfRawPtrs = const_cast<double**>(arrayOfRawPtrs.getRawPtr()); // This const_cast should be fine, because Epetra_DataAccess=Copy.
786 
787  vec_ = Teuchos::rcp(new Epetra_MultiVector(Copy, toEpetra<GlobalOrdinal,Node>(map), rawArrayOfRawPtrs, NumVectors));
788  }
789 
791  virtual ~EpetraMultiVectorT() {}
792 
794 
796 
797 
799  void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::replaceGlobalValue"); vec_->ReplaceGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value); }
800 
802  void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::sumIntoGlobalValue"); vec_->SumIntoGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value); }
803 
805  void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::replaceLocalValue"); vec_->ReplaceMyValue(myRow, Teuchos::as<int>(vectorIndex), value); }
806 
808  void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::sumIntoLocalValue"); vec_->SumIntoMyValue(myRow, Teuchos::as<int>(vectorIndex), value); }
809 
811  void putScalar(const Scalar &value) { XPETRA_MONITOR("EpetraMultiVectorT::putScalar"); vec_->PutScalar(value); }
812 
814 
816 
817 
819  Teuchos::RCP< const Vector< double, int, long long, EpetraNode > > getVector(size_t j) const;
820 
822  Teuchos::RCP< Vector< double, int, long long, EpetraNode > > getVectorNonConst(size_t j);
823 
825  Teuchos::ArrayRCP< const Scalar > getData(size_t j) const {
826  XPETRA_MONITOR("EpetraMultiVectorT::getData");
827 
828  double ** arrayOfPointers;
829 
830  vec_->ExtractView(&arrayOfPointers);
831 
832  double * data = arrayOfPointers[j];
833  int localLength = vec_->MyLength();
834 
835  return ArrayRCP<double>(data, 0, localLength, false); // no ownership
836  }
837 
839  Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j) {
840  XPETRA_MONITOR("EpetraMultiVectorT::getDataNonConst");
841 
842  double ** arrayOfPointers;
843 
844  vec_->ExtractView(&arrayOfPointers);
845 
846  double * data = arrayOfPointers[j];
847  int localLength = vec_->MyLength();
848 
849  return ArrayRCP<double>(data, 0, localLength, false); // no ownership
850  }
851 
853 
855 
856 
858  void dot(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Teuchos::ArrayView< Scalar > &dots) const {
859  XPETRA_MONITOR("EpetraMultiVectorT::dot");
860 
861  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
862  vec_->Dot(*eA.getEpetra_MultiVector(), dots.getRawPtr());
863  }
864 
866  void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A) { XPETRA_MONITOR("EpetraMultiVectorT::abs"); vec_->Abs(toEpetra<GlobalOrdinal,Node>(A)); }
867 
869  void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A) { XPETRA_MONITOR("EpetraMultiVectorT::reciprocal"); vec_->Reciprocal(toEpetra<GlobalOrdinal,Node>(A)); }
870 
872  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraMultiVectorT::scale"); vec_->Scale(alpha); }
873 
875  void scale (Teuchos::ArrayView< const Scalar > alpha) {
876  XPETRA_MONITOR("EpetraMultiVectorT::scale");
877  // Epetra, unlike Tpetra, doesn't implement this version of
878  // scale(). Deal with this by scaling one column at a time.
879  const size_t numVecs = this->getNumVectors ();
880  for (size_t j = 0; j < numVecs; ++j) {
881  vec_->Scale (alpha[j]);
882  }
883  }
884 
886  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); }
887 
889  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); }
890 
892  void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::norm1"); vec_->Norm1(norms.getRawPtr()); }
893 
895  void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::norm2"); vec_->Norm2(norms.getRawPtr()); }
896 
898  void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const { XPETRA_MONITOR("EpetraMultiVectorT::normInf"); vec_->NormInf(norms.getRawPtr()); }
899 
901  void meanValue(const Teuchos::ArrayView< Scalar > &means) const { XPETRA_MONITOR("EpetraMultiVectorT::meanValue"); vec_->MeanValue(means.getRawPtr()); } //TODO: modify ArrayView size ??
902 
904  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); }
905 
907  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); }
908 
910 
912 
913 
915  size_t getNumVectors() const { XPETRA_MONITOR("EpetraMultiVectorT::getNumVectors"); return vec_->NumVectors(); }
916 
918  size_t getLocalLength() const { XPETRA_MONITOR("EpetraMultiVectorT::getLocalLength"); return vec_->MyLength(); }
919 
921  global_size_t getGlobalLength() const { XPETRA_MONITOR("EpetraMultiVectorT::getGlobalLength"); return vec_->GlobalLength64(); }
922 
924 
926 
927 
929  std::string description() const {
930  XPETRA_MONITOR("EpetraMultiVectorT::description");
931  TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO");
932  return "TODO";
933  }
934 
936  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const {
937  XPETRA_MONITOR("EpetraMultiVectorT::describe");
938  vec_->Print(out);
939  }
940 
942 
944  void randomize(bool bUseXpetraImplementation = false) {
945  XPETRA_MONITOR("EpetraMultiVectorT::randomize");
946 
947  if (bUseXpetraImplementation)
949  else
950  vec_->Random();
951  }
952 
954  //{@
955 
957  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraMultiVectorT::getMap"); return toXpetra<GlobalOrdinal,Node>(vec_->Map()); }
958 
961  XPETRA_MONITOR("EpetraMultiVectorT::doImport");
962 
963  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
964  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
965 
966  RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
967  int err = this->getEpetra_MultiVector()->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
968  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra is " << err);
969  }
970 
973  XPETRA_MONITOR("EpetraMultiVectorT::doExport");
974 
975  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
976  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
977 
978  RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
979  int err = this->getEpetra_MultiVector()->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
980  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
981  }
982 
985  XPETRA_MONITOR("EpetraMultiVectorT::doImport");
986 
987  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
988  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
989 
990  RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
991  int err = this->getEpetra_MultiVector()->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
992  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
993  }
994 
997  XPETRA_MONITOR("EpetraMultiVectorT::doExport");
998 
999  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
1000  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1001 
1002  RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
1003  int err = this->getEpetra_MultiVector()->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1004  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1005  }
1006 
1008  void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map) {
1009  XPETRA_MONITOR("EpetraMultiVectorT::replaceMap");
1010  int err = 0;
1011  if (!map.is_null()) {
1012  err = this->getEpetra_MultiVector()->ReplaceMap(toEpetra<GlobalOrdinal,Node>(map));
1013 
1014  } else {
1015  // Replace map with a dummy map to avoid potential hangs later
1016  Epetra_SerialComm SComm;
1017  Epetra_Map NewMap((GlobalOrdinal) vec_->MyLength(), (GlobalOrdinal) vec_->Map().IndexBase64(), SComm);
1018  err = this->getEpetra_MultiVector()->ReplaceMap(NewMap);
1019  }
1020  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1021  }
1022 
1024 
1026 
1027 
1029  EpetraMultiVectorT(const RCP<Epetra_MultiVector> &vec) : vec_(vec) { } //TODO removed const
1030 
1032  RCP<Epetra_MultiVector> getEpetra_MultiVector() const { return vec_; }
1033 
1035  void setSeed(unsigned int seed) {
1036  XPETRA_MONITOR("EpetraMultiVectorT::seedrandom");
1037 
1038  Teuchos::ScalarTraits< Scalar >::seedrandom(seed);
1039  vec_->SetSeed(seed);
1040  }
1041 
1042 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1043 
1045 
1056  template<class TargetDeviceType>
1057  typename Kokkos::Impl::if_c<
1058  Kokkos::Impl::is_same<
1059  typename dual_view_type::t_dev_um::execution_space::memory_space,
1060  typename TargetDeviceType::memory_space>::value,
1061  typename dual_view_type::t_dev_um,
1062  typename dual_view_type::t_host_um>::type
1063  getLocalView () const {
1064  return this->MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::template getLocalView<TargetDeviceType>();
1065  }
1066 
1067  typename dual_view_type::t_host_um getHostLocalView () const {
1068  typedef Kokkos::View< typename dual_view_type::t_host::data_type ,
1069  Kokkos::LayoutLeft,
1070  typename dual_view_type::t_host::device_type ,
1071  Kokkos::MemoryUnmanaged> epetra_view_type;
1072 
1073  // access Epetra multivector data
1074  double* data = NULL;
1075  int myLDA;
1076  vec_->ExtractView(&data, &myLDA);
1077  int localLength = vec_->MyLength();
1078  int numVectors = getNumVectors();
1079 
1080  // create view
1081  epetra_view_type test = epetra_view_type(data, localLength, numVectors);
1082  typename dual_view_type::t_host_um ret = subview(test, Kokkos::ALL(), Kokkos::ALL());
1083 
1084  return ret;
1085  }
1086 
1087  typename dual_view_type::t_dev_um getDeviceLocalView() const {
1088  throw std::runtime_error("Epetra does not support device views!");
1089  typename dual_view_type::t_dev_um ret;
1090  return ret; // make compiler happy
1091  }
1092 
1093 #endif
1094 
1096 
1097  protected:
1100  virtual void
1102  typedef EpetraMultiVectorT this_type;
1103  const this_type* rhsPtr = dynamic_cast<const this_type*> (&rhs);
1104  TEUCHOS_TEST_FOR_EXCEPTION(
1105  rhsPtr == NULL, std::invalid_argument, "Xpetra::MultiVector::operator=: "
1106  "The left-hand side (LHS) of the assignment has a different type than "
1107  "the right-hand side (RHS). The LHS has type Xpetra::EpetraMultiVectorT "
1108  "(which means it wraps an Epetra_MultiVector), but the RHS has some "
1109  "other type. This probably means that the RHS wraps a Tpetra::Multi"
1110  "Vector. Xpetra::MultiVector does not currently implement assignment "
1111  "from a Tpetra object to an Epetra object, though this could be added "
1112  "with sufficient interest.");
1113 
1114  RCP<const Epetra_MultiVector> rhsImpl = rhsPtr->getEpetra_MultiVector ();
1115  RCP<Epetra_MultiVector> lhsImpl = this->getEpetra_MultiVector ();
1116 
1117  TEUCHOS_TEST_FOR_EXCEPTION(
1118  rhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
1119  "(in Xpetra::EpetraMultiVectorT::assign): *this (the right-hand side of "
1120  "the assignment) has a null RCP<Epetra_MultiVector> inside. Please "
1121  "report this bug to the Xpetra developers.");
1122  TEUCHOS_TEST_FOR_EXCEPTION(
1123  lhsImpl.is_null (), std::logic_error, "Xpetra::MultiVector::operator= "
1124  "(in Xpetra::EpetraMultiVectorT::assign): The left-hand side of the "
1125  "assignment has a null RCP<Epetra_MultiVector> inside. Please report "
1126  "this bug to the Xpetra developers.");
1127 
1128  // Epetra_MultiVector's assignment operator does a deep copy.
1129  *lhsImpl = *rhsImpl;
1130  }
1131 
1132  private:
1134  RCP< Epetra_MultiVector > vec_;
1135 
1136  }; // EpetraMultiVectorT class (specialization on GO=long long, NO=EpetraNode
1137 #endif
1138 
1139 } // Xpetra namespace
1140 
1141 #include "Xpetra_EpetraVector.hpp" // to avoid incomplete type instantiated above in out-of-body functions.
1142 
1143 #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.
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.
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.
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
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 describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
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.
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.
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 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.
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.
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].
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.
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.
EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source)
MultiVector copy constructor.
CombineMode
Xpetra::Combine Mode enumerable type.
#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.
EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source)
MultiVector copy constructor.
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.