Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_EpetraMultiVector.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Xpetra: A linear algebra interface package
4//
5// Copyright 2012 NTESS and the Xpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef XPETRA_EPETRAMULTIVECTOR_HPP
11#define XPETRA_EPETRAMULTIVECTOR_HPP
12
13/* this file is automatically generated - do not edit (see script/epetra.py) */
14
15#include <Kokkos_Core.hpp>
16#include <Kokkos_DualView.hpp>
17
19
20#include "Xpetra_MultiVector.hpp"
21#include "Xpetra_Vector.hpp"
22
23#include "Xpetra_EpetraMap.hpp"
25#include "Xpetra_Utils.hpp"
28#include "Xpetra_Exceptions.hpp"
29#include "Epetra_SerialComm.h"
30
31#include <Epetra_MultiVector.h>
32#include <Epetra_Vector.h>
33
34#if defined(XPETRA_ENABLE_DEPRECATED_CODE)
35#ifdef __GNUC__
36#if defined(Xpetra_SHOW_DEPRECATED_WARNINGS)
37#warning "The header file Trilinos/packages/xpetra/src/MultiVector/Xpetra_EpetraMultiVector.hpp is deprecated."
38#endif
39#endif
40#else
41#error "The header file Trilinos/packages/xpetra/src/MultiVector/Xpetra_EpetraMultiVector.hpp is deprecated."
42#endif
43
44namespace Xpetra {
45
46// TODO: move that elsewhere
47template <class GlobalOrdinal, class Node>
48XPETRA_DEPRECATED const Epetra_MultiVector &toEpetra(const MultiVector<double, int, GlobalOrdinal, Node> &);
49template <class GlobalOrdinal, class Node>
50XPETRA_DEPRECATED Epetra_MultiVector &toEpetra(MultiVector<double, int, GlobalOrdinal, Node> &);
51template <class GlobalOrdinal, class Node>
52XPETRA_DEPRECATED RCP<MultiVector<double, int, GlobalOrdinal, Node> > toXpetra(RCP<Epetra_MultiVector> vec);
53
54// we need this forward declaration
55#ifndef DOXYGEN_SHOULD_SKIP_THIS
56template <class GlobalOrdinal, class Node>
57class EpetraVectorT;
58#endif
59
60template <class EpetraGlobalOrdinal, class Node>
61class XPETRA_DEPRECATED EpetraMultiVectorT
62 : public virtual MultiVector<double, int, EpetraGlobalOrdinal, Node> {
63 typedef double Scalar;
64 typedef int LocalOrdinal;
65 typedef EpetraGlobalOrdinal GlobalOrdinal;
66
67 public:
69
70
72 EpetraMultiVectorT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, bool zeroOut = true) {
74 "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
75 }
76
80 "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
81 }
82
86 "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
87 }
88
91
93
95
96
98 void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) {}
99
101 void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) {}
102
104 void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) {}
105
107 void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) {}
108
110 void putScalar(const Scalar &value) {}
111
113
115
116
119 return Teuchos::null;
120 }
121
126
131
136
138
140
141
144
147
150
152 void scale(const Scalar &alpha) {}
153
156
159
162
165
168
171
173 void meanValue(const Teuchos::ArrayView<Scalar> &means) const {}
174
177
180
182
184
185
187 size_t getNumVectors() const { return 0; }
188
190 size_t getLocalLength() const { return 0; }
191
193 global_size_t getGlobalLength() const { return 0; }
194
195 // \brief Checks to see if the local length, number of vectors and size of Scalar type match
197
199
201
202
204 std::string description() const { return std::string(""); }
205
208
210
212 void randomize(bool bUseXpetraImplementation = false) {}
213
215 void randomize(const Scalar &minVal, const Scalar &maxVal, bool bUseXpetraImplementation = false) {}
216
218 //{@
219
222
225
228
231
234
237
239
241
242
244 EpetraMultiVectorT(const RCP<Epetra_MultiVector> &vec) { // TODO removed const
246 "Xpetra::EpetraMultiVector only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
247 }
248
250 RCP<Epetra_MultiVector> getEpetra_MultiVector() const { return Teuchos::null; }
251
253 void setSeed(unsigned int seed) {}
254
256
257 protected:
260 virtual void
262
263}; // EpetraMultiVectorT class
264
265// specialization on GO=int and Node=EpetraNode
266#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
267template <>
269 : public virtual MultiVector<double, int, int, EpetraNode> {
270 typedef double Scalar;
271 typedef int LocalOrdinal;
272 typedef int GlobalOrdinal;
274
275 public:
277
278
280 EpetraMultiVectorT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, bool zeroOut = true)
281 : vec_(Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal, Node>(map), Teuchos::as<int>(NumVectors), zeroOut))) {}
282
285 if (copyOrView == Teuchos::Copy)
286 vec_ = Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal, Node>(source)));
287 else {
288 int *indices = new int[source.getNumVectors()];
289 for (size_t i = 0; i < source.getNumVectors(); i++)
290 indices[i] = i;
291 vec_ = Teuchos::rcp(new Epetra_MultiVector(View, toEpetra<GlobalOrdinal, Node>(source), indices, source.getNumVectors()));
292 delete[] indices;
293 }
294 }
295
298 // TODO: input argument 'NumVectors' is not necessary in both Xpetra and Tpetra interface. Should it be removed?
299
300 const std::string tfecfFuncName("MultiVector(ArrayOfPtrs)");
301 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(NumVectors < 1 || NumVectors != Teuchos::as<size_t>(ArrayOfPtrs.size()), std::runtime_error,
302 ": ArrayOfPtrs.size() must be strictly positive and as large as ArrayOfPtrs.");
303
304#ifdef HAVE_XPETRA_DEBUG
305 // This cannot be tested by Epetra itself
306 {
307 size_t localLength = map->getLocalNumElements();
308 for (int j = 0; j < ArrayOfPtrs.size(); j++) {
309 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Teuchos::as<size_t>(ArrayOfPtrs[j].size()) != localLength, std::runtime_error,
310 ": ArrayOfPtrs[" << j << "].size() (== " << ArrayOfPtrs[j].size() << ") is not equal to getLocalLength() (== " << localLength);
311 }
312 }
313#endif
314
315 // Convert Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > to double**
316 Array<const double *> arrayOfRawPtrs(ArrayOfPtrs.size());
317 for (int i = 0; i < ArrayOfPtrs.size(); i++) {
318 arrayOfRawPtrs[i] = ArrayOfPtrs[i].getRawPtr();
319 }
320 double **rawArrayOfRawPtrs = const_cast<double **>(arrayOfRawPtrs.getRawPtr()); // This const_cast should be fine, because Epetra_DataAccess=Copy.
321
322 vec_ = Teuchos::rcp(new Epetra_MultiVector(Copy, toEpetra<GlobalOrdinal, Node>(map), rawArrayOfRawPtrs, static_cast<int>(NumVectors)));
323 }
324
327
329
331
332
334 void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) {
335 XPETRA_MONITOR("EpetraMultiVectorT::replaceGlobalValue");
336 vec_->ReplaceGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value);
337 }
338
340 void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) {
341 XPETRA_MONITOR("EpetraMultiVectorT::sumIntoGlobalValue");
342 vec_->SumIntoGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value);
343 }
344
346 void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) {
347 XPETRA_MONITOR("EpetraMultiVectorT::replaceLocalValue");
348 vec_->ReplaceMyValue(myRow, Teuchos::as<int>(vectorIndex), value);
349 }
350
352 void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) {
353 XPETRA_MONITOR("EpetraMultiVectorT::sumIntoLocalValue");
354 vec_->SumIntoMyValue(myRow, Teuchos::as<int>(vectorIndex), value);
355 }
356
358 void putScalar(const Scalar &value) {
359 XPETRA_MONITOR("EpetraMultiVectorT::putScalar");
360 vec_->PutScalar(value);
361 }
362
364
366
367
370
373
376 XPETRA_MONITOR("EpetraMultiVectorT::getData");
377
378 double **arrayOfPointers;
379
380 vec_->ExtractView(&arrayOfPointers);
381
382 double *data = arrayOfPointers[j];
383 int localLength = vec_->MyLength();
384
385 return ArrayRCP<double>(data, 0, localLength, false); // no ownership
386 }
387
390 XPETRA_MONITOR("EpetraMultiVectorT::getDataNonConst");
391
392 double **arrayOfPointers;
393
394 vec_->ExtractView(&arrayOfPointers);
395
396 double *data = arrayOfPointers[j];
397 int localLength = vec_->MyLength();
398
399 return ArrayRCP<double>(data, 0, localLength, false); // no ownership
400 }
401
403
405
406
409 XPETRA_MONITOR("EpetraMultiVectorT::dot");
410
411 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
412 vec_->Dot(*eA.getEpetra_MultiVector(), dots.getRawPtr());
413 }
414
417 XPETRA_MONITOR("EpetraMultiVectorT::abs");
418 vec_->Abs(toEpetra<GlobalOrdinal, Node>(A));
419 }
420
423 XPETRA_MONITOR("EpetraMultiVectorT::reciprocal");
424 vec_->Reciprocal(toEpetra<GlobalOrdinal, Node>(A));
425 }
426
428 void scale(const Scalar &alpha) {
429 XPETRA_MONITOR("EpetraMultiVectorT::scale");
430 vec_->Scale(alpha);
431 }
432
435 XPETRA_MONITOR("EpetraMultiVectorT::scale");
436 // Epetra, unlike Tpetra, doesn't implement this version of
437 // scale(). Deal with this by scaling one column at a time.
438 const size_t numVecs = this->getNumVectors();
439 for (size_t j = 0; j < numVecs; ++j) {
440 Epetra_Vector *v = (*vec_)(j);
441 v->Scale(alpha[j]);
442 }
443 }
444
447 XPETRA_MONITOR("EpetraMultiVectorT::update");
448 vec_->Update(alpha, toEpetra<GlobalOrdinal, Node>(A), beta);
449 }
450
453 XPETRA_MONITOR("EpetraMultiVectorT::update");
454 vec_->Update(alpha, toEpetra<GlobalOrdinal, Node>(A), beta, toEpetra<GlobalOrdinal, Node>(B), gamma);
455 }
456
459 XPETRA_MONITOR("EpetraMultiVectorT::norm1");
460 vec_->Norm1(norms.getRawPtr());
461 }
462
465 XPETRA_MONITOR("EpetraMultiVectorT::norm2");
466 vec_->Norm2(norms.getRawPtr());
467 }
468
471 XPETRA_MONITOR("EpetraMultiVectorT::normInf");
472 vec_->NormInf(norms.getRawPtr());
473 }
474
476 void meanValue(const Teuchos::ArrayView<Scalar> &means) const {
477 XPETRA_MONITOR("EpetraMultiVectorT::meanValue");
478 vec_->MeanValue(means.getRawPtr());
479 } // TODO: modify ArrayView size ??
480
483 XPETRA_MONITOR("EpetraMultiVectorT::multiply");
484 vec_->Multiply(toEpetra(transA), toEpetra(transB), alpha, toEpetra(A), toEpetra(B), beta);
485 }
486
489 XPETRA_MONITOR("EpetraMultiVectorT::elementWiseMultiply");
490 vec_->Multiply(scalarAB, toEpetra<GlobalOrdinal, Node>(A), toEpetra<GlobalOrdinal, Node>(B), scalarThis);
491 }
492
494
496
497
499 size_t getNumVectors() const {
500 XPETRA_MONITOR("EpetraMultiVectorT::getNumVectors");
501 return vec_->NumVectors();
502 }
503
505 size_t getLocalLength() const {
506 XPETRA_MONITOR("EpetraMultiVectorT::getLocalLength");
507 return vec_->MyLength();
508 }
509
512 XPETRA_MONITOR("EpetraMultiVectorT::getGlobalLength");
513 return vec_->GlobalLength64();
514 }
515
518 XPETRA_MONITOR("EpetraMultiVectorT::isSameSize");
519 auto vv = toEpetra<GlobalOrdinal, Node>(vec);
520 return ((vec_->MyLength() == vv.MyLength()) && (vec_->NumVectors() == vv.NumVectors()));
521 }
522
524
526
527
529 std::string description() const {
530 XPETRA_MONITOR("EpetraMultiVectorT::description");
533 }
534
537 XPETRA_MONITOR("EpetraMultiVectorT::describe");
538 vec_->Print(out);
539 }
540
542
544 void randomize(bool bUseXpetraImplementation = false) {
545 XPETRA_MONITOR("EpetraMultiVectorT::randomize");
546
547 if (bUseXpetraImplementation)
549 else
550 vec_->Random();
551 }
552
554 void randomize(const Scalar &minVal, const Scalar &maxVal, bool bUseXpetraImplementation = false) {
555 XPETRA_MONITOR("EpetraMultiVectorT::randomize");
556
557 if (bUseXpetraImplementation)
559 else {
560 vec_->Random();
561 const size_t numVectors = getNumVectors();
562 for (size_t i = 0; i < numVectors; i++) {
564
565 const size_t myLength = getLocalLength();
566 for (size_t j = 0; j < myLength; j++) {
567 datai[j] = 0.5 * (maxVal - minVal) * datai[j] + 0.5 * (maxVal + minVal);
568 }
569 }
570 }
571 }
572
574 //{@
575
578 XPETRA_MONITOR("EpetraMultiVectorT::getMap");
579 return toXpetra<GlobalOrdinal, Node>(vec_->Map());
580 }
581
584 XPETRA_MONITOR("EpetraMultiVectorT::doImport");
585
586 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
587 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
588
589 RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
590 int err = this->getEpetra_MultiVector()->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
591 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra is " << err);
592 }
593
596 XPETRA_MONITOR("EpetraMultiVectorT::doExport");
597
598 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
599 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
600
601 RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
602 int err = this->getEpetra_MultiVector()->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
603 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
604 }
605
608 XPETRA_MONITOR("EpetraMultiVectorT::doImport");
609
610 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
611 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
612
613 RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
614 int err = this->getEpetra_MultiVector()->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
615 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
616 }
617
620 XPETRA_MONITOR("EpetraMultiVectorT::doExport");
621
622 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
623 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
624
625 RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
626 int err = this->getEpetra_MultiVector()->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
627 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
628 }
629
632 XPETRA_MONITOR("EpetraMultiVectorT::replaceMap");
633 int err = 0;
634 if (!map.is_null()) {
635 err = this->getEpetra_MultiVector()->ReplaceMap(toEpetra<GlobalOrdinal, Node>(map));
636
637 } else {
638 // Replace map with a dummy map to avoid potential hangs later
639 Epetra_SerialComm SComm;
640 Epetra_Map NewMap((GlobalOrdinal)vec_->MyLength(), (GlobalOrdinal)vec_->Map().IndexBase64(), SComm);
641 err = this->getEpetra_MultiVector()->ReplaceMap(NewMap);
642 }
643 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
644 }
645
647
649
650
653 : vec_(vec) {} // TODO removed const
654
657
659 void setSeed(unsigned int seed) {
660 XPETRA_MONITOR("EpetraMultiVectorT::seedrandom");
661
663 vec_->SetSeed(seed);
664 }
665
667
668 typename dual_view_type::t_host_const_um getLocalViewHost(Access::ReadOnlyStruct) const override { return getLocalViewHost(Access::ReadWrite); }
669
670 typename dual_view_type::t_dev_const_um getLocalViewDevice(Access::ReadOnlyStruct) const override { return getLocalViewDevice(Access::ReadWrite); }
671
672 typename dual_view_type::t_host_um getLocalViewHost(Access::OverwriteAllStruct) const override { return getLocalViewHost(Access::ReadWrite); }
673
674 typename dual_view_type::t_dev_um getLocalViewDevice(Access::OverwriteAllStruct) const override { return getLocalViewDevice(Access::ReadWrite); }
675
676 typename dual_view_type::t_host_um getLocalViewHost(Access::ReadWriteStruct) const override {
677 typedef Kokkos::View<typename dual_view_type::t_host::data_type,
678 Kokkos::LayoutLeft,
679 typename dual_view_type::t_host::device_type,
680 Kokkos::MemoryUnmanaged>
681 epetra_view_type;
682
683 // access Epetra multivector data
684 double *data = NULL;
685 int myLDA;
686 vec_->ExtractView(&data, &myLDA);
687 int localLength = vec_->MyLength();
688 int numVectors = getNumVectors();
689
690 // create view
691 epetra_view_type test = epetra_view_type(data, localLength, numVectors);
692 typename dual_view_type::t_host_um ret = subview(test, Kokkos::ALL(), Kokkos::ALL());
693
694 return ret;
695 }
696
697 typename dual_view_type::t_dev_um getLocalViewDevice(Access::ReadWriteStruct) const override { return getLocalViewHost(Access::ReadWrite); }
698
700
701 protected:
704 virtual void
706 typedef EpetraMultiVectorT this_type;
707 const this_type *rhsPtr = dynamic_cast<const this_type *>(&rhs);
709 rhsPtr == NULL, std::invalid_argument,
710 "Xpetra::MultiVector::operator=: "
711 "The left-hand side (LHS) of the assignment has a different type than "
712 "the right-hand side (RHS). The LHS has type Xpetra::EpetraMultiVectorT "
713 "(which means it wraps an Epetra_MultiVector), but the RHS has some "
714 "other type. This probably means that the RHS wraps a Tpetra::Multi"
715 "Vector. Xpetra::MultiVector does not currently implement assignment "
716 "from a Tpetra object to an Epetra object, though this could be added "
717 "with sufficient interest.");
718
719 RCP<const Epetra_MultiVector> rhsImpl = rhsPtr->getEpetra_MultiVector();
721
723 rhsImpl.is_null(), std::logic_error,
724 "Xpetra::MultiVector::operator= "
725 "(in Xpetra::EpetraMultiVectorT::assign): *this (the right-hand side of "
726 "the assignment) has a null RCP<Epetra_MultiVector> inside. Please "
727 "report this bug to the Xpetra developers.");
729 lhsImpl.is_null(), std::logic_error,
730 "Xpetra::MultiVector::operator= "
731 "(in Xpetra::EpetraMultiVectorT::assign): The left-hand side of the "
732 "assignment has a null RCP<Epetra_MultiVector> inside. Please report "
733 "this bug to the Xpetra developers.");
734
735 // Epetra_MultiVector's assignment operator does a deep copy.
736 *lhsImpl = *rhsImpl;
737 }
738
739 private:
742
743}; // EpetraMultiVectorT class (specialization on GO=int, NO=EpetraNode
744#endif
745
746// specialization on GO=long long and EpetraNode
747#ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
748template <>
750 : public virtual MultiVector<double, int, long long, EpetraNode> {
751 typedef double Scalar;
752 typedef int LocalOrdinal;
753 typedef long long GlobalOrdinal;
755
756 public:
758
759
761 EpetraMultiVectorT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, bool zeroOut = true)
762 : vec_(Teuchos::rcp(new Epetra_MultiVector(toEpetra<GlobalOrdinal, Node>(map), Teuchos::as<int>(NumVectors), zeroOut))) {}
763
767
770 // TODO: input argument 'NumVectors' is not necessary in both Xpetra and Tpetra interface. Should it be removed?
771
772 const std::string tfecfFuncName("MultiVector(ArrayOfPtrs)");
773 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(NumVectors < 1 || NumVectors != Teuchos::as<size_t>(ArrayOfPtrs.size()), std::runtime_error,
774 ": ArrayOfPtrs.size() must be strictly positive and as large as ArrayOfPtrs.");
775
776#ifdef HAVE_XPETRA_DEBUG
777 // This cannot be tested by Epetra itself
778 {
779 size_t localLength = map->getLocalNumElements();
780 for (int j = 0; j < ArrayOfPtrs.size(); j++) {
781 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Teuchos::as<size_t>(ArrayOfPtrs[j].size()) != localLength, std::runtime_error,
782 ": ArrayOfPtrs[" << j << "].size() (== " << ArrayOfPtrs[j].size() << ") is not equal to getLocalLength() (== " << localLength);
783 }
784 }
785#endif
786
787 // Convert Teuchos::ArrayView< const Teuchos::ArrayView< const Scalar > > to double**
788 Array<const double *> arrayOfRawPtrs(ArrayOfPtrs.size());
789 for (int i = 0; i < ArrayOfPtrs.size(); i++) {
790 arrayOfRawPtrs[i] = ArrayOfPtrs[i].getRawPtr();
791 }
792 double **rawArrayOfRawPtrs = const_cast<double **>(arrayOfRawPtrs.getRawPtr()); // This const_cast should be fine, because Epetra_DataAccess=Copy.
793
794 vec_ = Teuchos::rcp(new Epetra_MultiVector(Copy, toEpetra<GlobalOrdinal, Node>(map), rawArrayOfRawPtrs, NumVectors));
795 }
796
799
801
803
804
806 void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) {
807 XPETRA_MONITOR("EpetraMultiVectorT::replaceGlobalValue");
808 vec_->ReplaceGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value);
809 }
810
812 void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) {
813 XPETRA_MONITOR("EpetraMultiVectorT::sumIntoGlobalValue");
814 vec_->SumIntoGlobalValue(globalRow, Teuchos::as<int>(vectorIndex), value);
815 }
816
818 void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) {
819 XPETRA_MONITOR("EpetraMultiVectorT::replaceLocalValue");
820 vec_->ReplaceMyValue(myRow, Teuchos::as<int>(vectorIndex), value);
821 }
822
824 void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) {
825 XPETRA_MONITOR("EpetraMultiVectorT::sumIntoLocalValue");
826 vec_->SumIntoMyValue(myRow, Teuchos::as<int>(vectorIndex), value);
827 }
828
830 void putScalar(const Scalar &value) {
831 XPETRA_MONITOR("EpetraMultiVectorT::putScalar");
832 vec_->PutScalar(value);
833 }
834
836
838
839
842
845
848 XPETRA_MONITOR("EpetraMultiVectorT::getData");
849
850 double **arrayOfPointers;
851
852 vec_->ExtractView(&arrayOfPointers);
853
854 double *data = arrayOfPointers[j];
855 int localLength = vec_->MyLength();
856
857 return ArrayRCP<double>(data, 0, localLength, false); // no ownership
858 }
859
862 XPETRA_MONITOR("EpetraMultiVectorT::getDataNonConst");
863
864 double **arrayOfPointers;
865
866 vec_->ExtractView(&arrayOfPointers);
867
868 double *data = arrayOfPointers[j];
869 int localLength = vec_->MyLength();
870
871 return ArrayRCP<double>(data, 0, localLength, false); // no ownership
872 }
873
875
877
878
881 XPETRA_MONITOR("EpetraMultiVectorT::dot");
882
883 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, A, eA, "This Xpetra::EpetraMultiVectorT method only accept Xpetra::EpetraMultiVectorT as input arguments.");
884 vec_->Dot(*eA.getEpetra_MultiVector(), dots.getRawPtr());
885 }
886
889 XPETRA_MONITOR("EpetraMultiVectorT::abs");
890 vec_->Abs(toEpetra<GlobalOrdinal, Node>(A));
891 }
892
895 XPETRA_MONITOR("EpetraMultiVectorT::reciprocal");
896 vec_->Reciprocal(toEpetra<GlobalOrdinal, Node>(A));
897 }
898
900 void scale(const Scalar &alpha) {
901 XPETRA_MONITOR("EpetraMultiVectorT::scale");
902 vec_->Scale(alpha);
903 }
904
907 XPETRA_MONITOR("EpetraMultiVectorT::scale");
908 // Epetra, unlike Tpetra, doesn't implement this version of
909 // scale(). Deal with this by scaling one column at a time.
910 const size_t numVecs = this->getNumVectors();
911 for (size_t j = 0; j < numVecs; ++j) {
912 Epetra_Vector *v = (*vec_)(j);
913 v->Scale(alpha[j]);
914 }
915 }
916
919 XPETRA_MONITOR("EpetraMultiVectorT::update");
920 vec_->Update(alpha, toEpetra<GlobalOrdinal, Node>(A), beta);
921 }
922
925 XPETRA_MONITOR("EpetraMultiVectorT::update");
926 vec_->Update(alpha, toEpetra<GlobalOrdinal, Node>(A), beta, toEpetra<GlobalOrdinal, Node>(B), gamma);
927 }
928
931 XPETRA_MONITOR("EpetraMultiVectorT::norm1");
932 vec_->Norm1(norms.getRawPtr());
933 }
934
937 XPETRA_MONITOR("EpetraMultiVectorT::norm2");
938 vec_->Norm2(norms.getRawPtr());
939 }
940
943 XPETRA_MONITOR("EpetraMultiVectorT::normInf");
944 vec_->NormInf(norms.getRawPtr());
945 }
946
948 void meanValue(const Teuchos::ArrayView<Scalar> &means) const {
949 XPETRA_MONITOR("EpetraMultiVectorT::meanValue");
950 vec_->MeanValue(means.getRawPtr());
951 } // TODO: modify ArrayView size ??
952
955 XPETRA_MONITOR("EpetraMultiVectorT::multiply");
956 vec_->Multiply(toEpetra(transA), toEpetra(transB), alpha, toEpetra(A), toEpetra(B), beta);
957 }
958
961 XPETRA_MONITOR("EpetraMultiVectorT::elementWiseMultiply");
962 vec_->Multiply(scalarAB, toEpetra<GlobalOrdinal, Node>(A), toEpetra<GlobalOrdinal, Node>(B), scalarThis);
963 }
964
966
968
969
971 size_t getNumVectors() const {
972 XPETRA_MONITOR("EpetraMultiVectorT::getNumVectors");
973 return vec_->NumVectors();
974 }
975
977 size_t getLocalLength() const {
978 XPETRA_MONITOR("EpetraMultiVectorT::getLocalLength");
979 return vec_->MyLength();
980 }
981
984 XPETRA_MONITOR("EpetraMultiVectorT::getGlobalLength");
985 return vec_->GlobalLength64();
986 }
987
990 XPETRA_MONITOR("EpetraMultiVectorT::isSameSize");
991 auto vv = toEpetra<GlobalOrdinal, Node>(vec);
992 return ((vec_->MyLength() == vv.MyLength()) && (vec_->NumVectors() == vv.NumVectors()));
993 }
994
996
998
999
1001 std::string description() const {
1002 XPETRA_MONITOR("EpetraMultiVectorT::description");
1004 // return "TODO"; // unreachable
1005 }
1006
1009 XPETRA_MONITOR("EpetraMultiVectorT::describe");
1010 vec_->Print(out);
1011 }
1012
1014
1016 void randomize(bool bUseXpetraImplementation = false) {
1017 XPETRA_MONITOR("EpetraMultiVectorT::randomize");
1018
1019 if (bUseXpetraImplementation)
1021 else
1022 vec_->Random();
1023 }
1024
1026 void randomize(const Scalar &minVal, const Scalar &maxVal, bool bUseXpetraImplementation = false) {
1027 XPETRA_MONITOR("EpetraMultiVectorT::randomize");
1028
1029 if (bUseXpetraImplementation)
1031 else {
1032 vec_->Random();
1033 const size_t numVectors = getNumVectors();
1034 for (size_t i = 0; i < numVectors; i++) {
1036
1037 const size_t myLength = getLocalLength();
1038 for (size_t j = 0; j < myLength; j++) {
1039 datai[j] = 0.5 * (maxVal - minVal) * datai[j] + 0.5 * (maxVal + minVal);
1040 }
1041 }
1042 }
1043 }
1044
1046 //{@
1047
1050 XPETRA_MONITOR("EpetraMultiVectorT::getMap");
1051 return toXpetra<GlobalOrdinal, Node>(vec_->Map());
1052 }
1053
1056 XPETRA_MONITOR("EpetraMultiVectorT::doImport");
1057
1058 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
1059 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1060
1061 RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
1062 int err = this->getEpetra_MultiVector()->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1063 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra is " << err);
1064 }
1065
1068 XPETRA_MONITOR("EpetraMultiVectorT::doExport");
1069
1070 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
1071 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1072
1073 RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
1074 int err = this->getEpetra_MultiVector()->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1075 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1076 }
1077
1080 XPETRA_MONITOR("EpetraMultiVectorT::doImport");
1081
1082 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
1083 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1084
1085 RCP<Epetra_MultiVector> v = tSource.getEpetra_MultiVector();
1086 int err = this->getEpetra_MultiVector()->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1087 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1088 }
1089
1092 XPETRA_MONITOR("EpetraMultiVectorT::doExport");
1093
1094 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraMultiVectorT as input arguments.");
1095 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraMultiVectorT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1096
1097 RCP<Epetra_MultiVector> v = tDest.getEpetra_MultiVector();
1098 int err = this->getEpetra_MultiVector()->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1099 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1100 }
1101
1104 XPETRA_MONITOR("EpetraMultiVectorT::replaceMap");
1105 int err = 0;
1106 if (!map.is_null()) {
1107 err = this->getEpetra_MultiVector()->ReplaceMap(toEpetra<GlobalOrdinal, Node>(map));
1108
1109 } else {
1110 // Replace map with a dummy map to avoid potential hangs later
1111 Epetra_SerialComm SComm;
1112 Epetra_Map NewMap((GlobalOrdinal)vec_->MyLength(), (GlobalOrdinal)vec_->Map().IndexBase64(), SComm);
1113 err = this->getEpetra_MultiVector()->ReplaceMap(NewMap);
1114 }
1115 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1116 }
1117
1119
1121
1122
1125 : vec_(vec) {} // TODO removed const
1126
1129
1131 void setSeed(unsigned int seed) {
1132 XPETRA_MONITOR("EpetraMultiVectorT::seedrandom");
1133
1135 vec_->SetSeed(seed);
1136 }
1137
1139
1140 protected:
1143 virtual void
1145 typedef EpetraMultiVectorT this_type;
1146 const this_type *rhsPtr = dynamic_cast<const this_type *>(&rhs);
1148 rhsPtr == NULL, std::invalid_argument,
1149 "Xpetra::MultiVector::operator=: "
1150 "The left-hand side (LHS) of the assignment has a different type than "
1151 "the right-hand side (RHS). The LHS has type Xpetra::EpetraMultiVectorT "
1152 "(which means it wraps an Epetra_MultiVector), but the RHS has some "
1153 "other type. This probably means that the RHS wraps a Tpetra::Multi"
1154 "Vector. Xpetra::MultiVector does not currently implement assignment "
1155 "from a Tpetra object to an Epetra object, though this could be added "
1156 "with sufficient interest.");
1157
1158 RCP<const Epetra_MultiVector> rhsImpl = rhsPtr->getEpetra_MultiVector();
1160
1162 rhsImpl.is_null(), std::logic_error,
1163 "Xpetra::MultiVector::operator= "
1164 "(in Xpetra::EpetraMultiVectorT::assign): *this (the right-hand side of "
1165 "the assignment) has a null RCP<Epetra_MultiVector> inside. Please "
1166 "report this bug to the Xpetra developers.");
1168 lhsImpl.is_null(), std::logic_error,
1169 "Xpetra::MultiVector::operator= "
1170 "(in Xpetra::EpetraMultiVectorT::assign): The left-hand side of the "
1171 "assignment has a null RCP<Epetra_MultiVector> inside. Please report "
1172 "this bug to the Xpetra developers.");
1173
1174 // Epetra_MultiVector's assignment operator does a deep copy.
1175 *lhsImpl = *rhsImpl;
1176 }
1177
1178 private:
1181
1182}; // EpetraMultiVectorT class (specialization on GO=long long, NO=EpetraNode
1183#endif
1184
1185} // namespace Xpetra
1186
1187#include "Xpetra_EpetraVector.hpp" // to avoid incomplete type instantiated above in out-of-body functions.
1188
1189#endif // XPETRA_EPETRAMULTIVECTOR_HPP
#define XPETRA_MONITOR(funcName)
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
int Scale(double ScalarValue)
T * getRawPtr() const
static const EVerbosityLevel verbLevel_default
bool is_null() const
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
std::string description() const
A simple one-line description of this object.
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 replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
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.
size_t getLocalLength() const
Local number of rows on the calling process.
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.
RCP< Epetra_MultiVector > getEpetra_MultiVector() const
Get the underlying Epetra multivector.
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.
dual_view_type::t_dev_const_um getLocalViewDevice(Access::ReadOnlyStruct) const override
void randomize(bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
dual_view_type::t_dev_um getLocalViewDevice(Access::OverwriteAllStruct) const override
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 setSeed(unsigned int seed)
Set seed for Random function.
Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::dual_view_type dual_view_type
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.
void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Teuchos::DataAccess copyOrView=Teuchos::Copy)
MultiVector copy constructor.
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(const Scalar &minVal, const Scalar &maxVal, bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
RCP< Epetra_MultiVector > vec_
The Epetra_MultiVector which this class wraps.
dual_view_type::t_host_um getLocalViewHost(Access::OverwriteAllStruct) const override
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,...
void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
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.
size_t getNumVectors() const
Number of columns in the multivector.
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
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....
dual_view_type::t_host_um getLocalViewHost(Access::ReadWriteStruct) const override
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Basic MultiVector constuctor.
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
EpetraMultiVectorT(const RCP< Epetra_MultiVector > &vec)
EpetraMultiVectorT constructor to wrap a Epetra_MultiVector object.
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
dual_view_type::t_host_const_um getLocalViewHost(Access::ReadOnlyStruct) const override
void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
dual_view_type::t_dev_um getLocalViewDevice(Access::ReadWriteStruct) const override
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...
global_size_t getGlobalLength() const
Global number of rows in the multivector.
void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
EpetraMultiVectorT(const RCP< Epetra_MultiVector > &vec)
EpetraMultiVectorT constructor to wrap a Epetra_MultiVector object.
Teuchos::RCP< const Vector< double, int, long long, EpetraNode > > getVector(size_t j) const
Return a Vector which is a const view of column j.
void normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Basic MultiVector constuctor.
size_t getNumVectors() const
Number of columns in the multivector.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
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 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(const Scalar &minVal, const Scalar &maxVal, bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
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....
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
Teuchos::RCP< Vector< double, int, long long, EpetraNode > > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.
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,...
void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
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.
virtual void assign(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
RCP< Epetra_MultiVector > vec_
The Epetra_MultiVector which this class wraps.
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
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).
EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source)
MultiVector copy constructor.
size_t getLocalLength() const
Local number of rows on the calling process.
void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
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 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 doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
std::string description() const
A simple one-line description of this object.
void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
void setSeed(unsigned int seed)
Set seed for Random function.
void randomize(bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
void norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
RCP< Epetra_MultiVector > getEpetra_MultiVector() const
Get the underlying Epetra multivector.
void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
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 replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Replace the underlying Map in place.
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
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 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 doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
void norm1(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
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 doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
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 norm2(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
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 setSeed(unsigned int seed)
Set seed for Random function.
Teuchos::RCP< Vector< double, int, GlobalOrdinal, Node > > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.
EpetraMultiVectorT(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Teuchos::DataAccess copyOrView=Teuchos::Copy)
MultiVector copy constructor.
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 normInf(const Teuchos::ArrayView< Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
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.
void abs(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
void replaceMap(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Replace the underlying Map in place.
std::string description() const
A simple one-line description of this object.
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.
bool isSameSize(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &vec) const
void randomize(const Scalar &minVal, const Scalar &maxVal, bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
EpetraMultiVectorT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Basic MultiVector constuctor.
Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this 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...
EpetraMultiVectorT(const RCP< Epetra_MultiVector > &vec)
EpetraMultiVectorT constructor to wrap a Epetra_MultiVector object.
void scale(const Scalar &alpha)
Scale in place: this = alpha*this.
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,...
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....
void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
size_t getLocalLength() const
Local number of rows on the calling process.
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)
Update: this = beta*this + alpha*A.
size_t getNumVectors() const
Number of columns in the multivector.
void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
virtual ~EpetraMultiVectorT()
MultiVector destructor.
void randomize(bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.
global_size_t getGlobalLength() const
Global number of rows in the multivector.
void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
Exception throws when you call an unimplemented method of Xpetra.
Exception throws to report errors in the internal logical of the program.
virtual size_t getNumVectors() const =0
Number of columns in the multivector.
virtual dual_view_type::t_host_const_um getLocalViewHost(Access::ReadOnlyStruct) const
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutStride, typename node_type::device_type, Kokkos::MemoryUnmanaged > dual_view_type
#define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
constexpr struct ReadWriteStruct ReadWrite
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
size_t global_size_t
Global size_t object.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
CombineMode
Xpetra::Combine Mode enumerable type.
static void seedrandom(unsigned int s)