Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_EpetraCrsMatrix.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_EPETRACRSMATRIX_HPP
11 #define XPETRA_EPETRACRSMATRIX_HPP
12 
13 /* this file is automatically generated - do not edit (see script/epetra.py) */
14 
15 #ifdef HAVE_XPETRA_TPETRA
16 #include <Kokkos_Core.hpp>
17 #endif
18 
20 
21 #include "Xpetra_CrsMatrix.hpp"
22 
23 #include <Epetra_CrsMatrix.h>
24 #include <Epetra_Map.h>
25 
26 #include "Xpetra_EpetraMap.hpp"
27 #include "Xpetra_EpetraVector.hpp"
30 
31 #include "Xpetra_MapFactory.hpp"
32 
33 #include "Xpetra_Utils.hpp"
34 #include "Xpetra_Exceptions.hpp"
35 
36 #if defined(XPETRA_ENABLE_DEPRECATED_CODE)
37 #ifdef __GNUC__
38 #if defined(Xpetra_SHOW_DEPRECATED_WARNINGS)
39 #warning "The header file Trilinos/packages/xpetra/src/CrsMatrix/Xpetra_EpetraCrsMatrix.hpp is deprecated."
40 #endif
41 #endif
42 #else
43 #error "The header file Trilinos/packages/xpetra/src/CrsMatrix/Xpetra_EpetraCrsMatrix.hpp is deprecated."
44 #endif
45 
46 namespace Xpetra {
47 
48 // general implementation: empty stub
49 template <class EpetraGlobalOrdinal, class Node>
50 class XPETRA_DEPRECATED EpetraCrsMatrixT
51  : public CrsMatrix<double, int, EpetraGlobalOrdinal, Node> {
52  typedef EpetraGlobalOrdinal GlobalOrdinal;
55 
56 #ifdef HAVE_XPETRA_TPETRA
59 #endif
60 
61  public:
62  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
63  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
64  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
65  }
66  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
67  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
68  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
69  }
70  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Tpetra::KokkosCompat::KokkosSerialWrapperNode."); }
71  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Tpetra::KokkosCompat::KokkosSerialWrapperNode."); }
72  EpetraCrsMatrixT(const Teuchos::RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Tpetra::KokkosCompat::KokkosSerialWrapperNode."); }
75  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
76  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
77  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
78  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
79  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
80  }
83  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
84  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
85  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
86  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
87  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
88  }
91  const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
92  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
93  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
94  const Teuchos::RCP<Teuchos::ParameterList> &params) {
95  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
96  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
97  }
100  const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
101  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
102  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
103  const Teuchos::RCP<Teuchos::ParameterList> &params) {
104  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
105  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
106  }
107 #ifdef HAVE_XPETRA_TPETRA
108  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
109  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
110  const local_matrix_type &lclMatrix,
111  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
112  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
113  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
114  }
116  const local_matrix_type &lclMatrix,
117  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
118  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
119  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
120  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
121  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
122  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
123  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
124  }
125 #endif
126  virtual ~EpetraCrsMatrixT() {}
127 
128  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
129  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
130  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
131  void replaceLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
132  void setAllToScalar(const Scalar &alpha) {}
133  void scale(const Scalar &alpha) {}
134  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {}
135  void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {}
136  void getAllValues(ArrayRCP<const size_t> &rowptr, ArrayRCP<const LocalOrdinal> &colind, ArrayRCP<const Scalar> &values) const {}
137  void getAllValues(ArrayRCP<Scalar> &values) {}
138  bool haveGlobalConstants() const { return true; }
140  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
141  const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
142  const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
143  const RCP<ParameterList> &params = Teuchos::null) {}
144 
145  void resumeFill(const RCP<ParameterList> &params = null) {}
146  void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = null) {}
147  void fillComplete(const RCP<ParameterList> &params = null) {}
148  void replaceDomainMapAndImporter(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newDomainMap, Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &newImporter) {}
149  const RCP<const Comm<int> > getComm() const { return Teuchos::null; }
150  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { return Teuchos::null; }
151  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { return Teuchos::null; }
152  RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { return Teuchos::null; }
153  global_size_t getGlobalNumRows() const { return 0; }
154  global_size_t getGlobalNumCols() const { return 0; }
155  size_t getLocalNumRows() const { return 0; }
156  size_t getLocalNumCols() const { return 0; }
157  global_size_t getGlobalNumEntries() const { return 0; }
158  size_t getLocalNumEntries() const { return 0; }
159  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { return 0; }
160  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { return 0; }
161  size_t getGlobalMaxNumRowEntries() const { return 0; }
162  size_t getLocalMaxNumRowEntries() const { return 0; }
163  bool isLocallyIndexed() const { return false; }
164  bool isGloballyIndexed() const { return false; }
165  bool isFillComplete() const { return false; }
166  bool isFillActive() const { return false; }
167  typename ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const { return ScalarTraits<Scalar>::magnitude(ScalarTraits<Scalar>::zero()); }
168  bool supportsRowViews() const { return false; }
169  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {}
170  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {}
171  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {}
172  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {}
174  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &offsets) const {}
175  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &diag, const Teuchos::ArrayView<const size_t> &offsets) const {}
176  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &diag, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> &offsets) const {}
180 
181  void apply(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &X, MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &Y, Teuchos::ETransp mode = Teuchos::NO_TRANS, Scalar alpha = ScalarTraits<Scalar>::one(), Scalar beta = ScalarTraits<Scalar>::zero()) const {}
182  void apply(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &X, MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &Y, Teuchos::ETransp mode, Scalar alpha, Scalar beta, bool sumInterfaceValues, const RCP<Import<LocalOrdinal, GlobalOrdinal, Node> > &regionInterfaceImporter, const Teuchos::ArrayRCP<LocalOrdinal> &regionInterfaceLIDs) const {}
183  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const { return Teuchos::null; }
184  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const { return Teuchos::null; }
185 
186  std::string description() const { return std::string(""); }
187  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {}
188  void setObjectLabel(const std::string &objectLabel) {}
189 
191  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
192  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
193  }
194 
195  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getMap() const { return Teuchos::null; }
200  void removeEmptyProcessesInPlace(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newMap) {}
201 
202  bool hasMatrix() const { return false; }
203  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix> &mtx) {
204  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
205  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
206  }
207  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
208  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } // TODO: remove
209 #ifdef HAVE_XPETRA_TPETRA
211  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
212  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
213  }
214 #if KOKKOS_VERSION >= 40799
215  typename local_matrix_type::host_mirror_type getLocalMatrixHost() const {
216 #else
217  typename local_matrix_type::HostMirror getLocalMatrixHost() const {
218 #endif
219  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
220  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
221 }
222 
223 void
224 setAllValues(const typename local_matrix_type::row_map_type &ptr,
225  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
226  const typename local_matrix_type::values_type &val) {
227  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
228  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
229 }
230 
231 LocalOrdinal GetStorageBlockSize() const { return 1; }
232 
233 #else
234 #ifdef __GNUC__
235 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
236 #endif
237 #endif
238 
242  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
243  apply(X, R);
244  R.update(one, B, negone);
245 }
246 
247 }; // namespace Xpetra
248 
249 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
250 template <>
252  : public CrsMatrix<double, int, int, EpetraNode> {
253  typedef int GlobalOrdinal;
254  typedef EpetraNode Node;
257 
258  // The following typedefs are used by the Kokkos interface
259 #ifdef HAVE_XPETRA_TPETRA
262 #endif
263 
264  public:
266 
267 
269  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap)
270  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), 0, false)))
271  , isFillResumed_(false) {}
272 
274  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
275  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), maxNumEntriesPerRow, true)))
276  , isFillResumed_(false) {}
277 
279  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
280  : isFillResumed_(false) {
281  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
282  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
283  }
284 
286  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
287  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), maxNumEntriesPerRow, true)))
288  , isFillResumed_(false) {}
289 
291  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
292  : isFillResumed_(false) {
293  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
294  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
295  }
296 
298  EpetraCrsMatrixT(const Teuchos::RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
299  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(graph))))
300  , isFillResumed_(false) {}
301 
305  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
306  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
307  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
308  : isFillResumed_(false) {
309  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
310  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
311 
312  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
313  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
314 
315  // Follows the Tpetra parameters
316  bool restrictComm = false;
317  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
318  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), myDomainMap, myRangeMap, restrictComm));
319  if (restrictComm && mtx_->NumMyRows() == 0)
320  mtx_ = Teuchos::null;
321  }
322 
326  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
327  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
328  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
329  : isFillResumed_(false) {
330  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
331  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
332 
333  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
334  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
335 
336  // Follows the Tpetra parameters
337  bool restrictComm = false;
338  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
339 
340  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), myDomainMap, myRangeMap, restrictComm));
341  }
342 
345  const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
346  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
347  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
348  const Teuchos::RCP<Teuchos::ParameterList> &params)
349  : isFillResumed_(false) {
350  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
351  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
352  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
353 
354  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
355  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
356 
357  // Follows the Tpetra parameters
358  bool restrictComm = false;
359  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
360  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), tdImporter->getEpetra_Import().get(), myDomainMap, myRangeMap, restrictComm));
361  if (restrictComm && mtx_->NumMyRows() == 0)
362  mtx_ = Teuchos::null;
363  }
364 
367  const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
368  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
369  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
370  const Teuchos::RCP<Teuchos::ParameterList> &params)
371  : isFillResumed_(false) {
372  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
373  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
374  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
375 
376  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
377  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
378 
379  // Follows the Tpetra parameters
380  bool restrictComm = false;
381  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
382 
383  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), tdExporter->getEpetra_Export().get(), myDomainMap, myRangeMap, restrictComm));
384  }
385 
386 #ifdef HAVE_XPETRA_TPETRA
387  // NOTE: TPETRA means we can use C++11 here
388 
410  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
411  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
412  const local_matrix_type &lclMatrix,
413  const Teuchos::RCP<Teuchos::ParameterList> &params = null)
414  : EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params) {}
415 
417  const local_matrix_type &lclMatrix,
418  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
419  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
420  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
421  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
422  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
423  // local typedefs from local_matrix_type
424  // typedef typename local_matrix_type::size_type size_type;
425  typedef typename local_matrix_type::value_type value_type;
426  typedef typename local_matrix_type::ordinal_type ordinal_type;
427 
428  // The number of rows in the sparse matrix.
429  ordinal_type lclNumRows = lclMatrix.numRows();
430  ordinal_type lclNumCols = lclMatrix.numCols(); // do we need this?
431 
432  // plausibility checks
433  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
434  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
435  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
436  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
437 
438  Teuchos::ArrayRCP<size_t> NumEntriesPerRowToAlloc(lclNumRows);
439  for (ordinal_type r = 0; r < lclNumRows; ++r) {
440  // extract data from current row r
441  auto rowview = lclMatrix.row(r);
442  NumEntriesPerRowToAlloc[r] = rowview.length;
443  }
444 
445  // setup matrix
446  isFillResumed_ = false;
447  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
448  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
449 
450  // loop over all rows and colums of local matrix and fill matrix
451  for (ordinal_type r = 0; r < lclNumRows; ++r) {
452  // extract data from current row r
453  auto rowview = lclMatrix.row(r);
454 
455  // arrays for current row data
456  Teuchos::ArrayRCP<ordinal_type> indout(rowview.length, Teuchos::ScalarTraits<ordinal_type>::zero());
457  Teuchos::ArrayRCP<value_type> valout(rowview.length, Teuchos::ScalarTraits<value_type>::zero());
458 
459  for (ordinal_type c = 0; c < rowview.length; c++) {
460  value_type value = rowview.value(c);
461  ordinal_type colidx = rowview.colidx(c);
462 
463  TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError,
464  "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
465 
466  indout[c] = colidx;
467  valout[c] = value;
468  }
469  insertLocalValues(r, indout.view(0, indout.size()), valout.view(0, valout.size()));
470  }
471 
472  // call fill complete
473  if (!domainMap.is_null() && !rangeMap.is_null())
474  this->fillComplete(domainMap, rowMap, params);
475  else
476  this->fillComplete(rowMap, rowMap, params);
477  }
478 #endif
479 
481  virtual ~EpetraCrsMatrixT() {}
482 
484 
486 
487 
489  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
490  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
491  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
492  }
493 
495  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
496  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
497  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
498  }
499 
501  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &indices, const ArrayView<const Scalar> &values) {
502  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
503 
504  {
505  const std::string tfecfFuncName("replaceGlobalValues");
506  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
507  ": Fill must be active in order to call this method. If you have already "
508  "called fillComplete(), you need to call resumeFill() before you can "
509  "replace values.");
510 
511  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
512  std::runtime_error, ": values.size() must equal indices.size().");
513  }
514 
515  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
516  }
517 
519  void replaceLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &indices, const ArrayView<const Scalar> &values) {
520  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
521 
522  {
523  const std::string tfecfFuncName("replaceLocalValues");
524  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
525  ": Fill must be active in order to call this method. If you have already "
526  "called fillComplete(), you need to call resumeFill() before you can "
527  "replace values.");
528 
529  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
530  std::runtime_error, ": values.size() must equal indices.size().");
531  }
532 
533  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
534  }
535 
537  void setAllToScalar(const Scalar &alpha) {
538  XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar");
539  mtx_->PutScalar(alpha);
540  }
541 
543  void scale(const Scalar &alpha) {
544  XPETRA_MONITOR("EpetraCrsMatrixT::scale");
545  mtx_->Scale(alpha);
546  }
547 
549  //** \warning This is an expert-only routine and should not be called from user code. */
550  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {
551  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
552 
553  // Row offsets
554  // Unfortunately, we cannot do this in the same manner as column indices
555  // and values (see below). The problem is that Tpetra insists on using
556  // size_t, and Epetra uses int internally. So we only resize here, and
557  // will need to copy in setAllValues
558  rowptr.resize(getLocalNumRows() + 1);
559 
560  int lowerOffset = 0;
561  bool ownMemory = false;
562 
563  // Column indices
564  // Extract, resize, set colind
565  Epetra_IntSerialDenseVector &myColind = mtx_->ExpertExtractIndices();
566  myColind.Resize(numNonZeros);
567  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
568 
569  // Values
570  // Extract, reallocate, set values
571  double *&myValues = mtx_->ExpertExtractValues();
572  delete[] myValues;
573  myValues = new double[numNonZeros];
574  values = Teuchos::arcp(myValues, lowerOffset, numNonZeros, ownMemory);
575  }
576 
578  void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {
579  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
580 
581  // Check sizes
582  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
583  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
584  TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
585  "An exception is thrown to let you know that you mismatched your pointers.");
586 
587  // Check pointers
588  if (values.size() > 0) {
589  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
590  "An exception is thrown to let you know that you mismatched your pointers.");
591  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
592  "An exception is thrown to let you know that you mismatched your pointers.");
593  }
594 
595  // We have to make a copy here, it is unavoidable
596  // See comments in allocateAllValues
597  const size_t N = getLocalNumRows();
598 
599  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
600  myRowptr.Resize(N + 1);
601  for (size_t i = 0; i < N + 1; i++)
602  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
603  }
604 
606  void getAllValues(ArrayRCP<const size_t> &rowptr, ArrayRCP<const LocalOrdinal> &colind, ArrayRCP<const Scalar> &values) const {
607  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
608 
609  int lowerOffset = 0;
610  bool ownMemory = false;
611 
612  const size_t n = getLocalNumRows();
613  const size_t nnz = getLocalNumEntries();
614 
615  // Row offsets
616  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
617  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
618  rowptr.resize(n + 1);
619  for (size_t i = 0; i < n + 1; i++)
620  (*const_cast<size_t *>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
621 
622  // Column indices
623  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
624 
625  // Values
626  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
627  }
628 
630  void getAllValues(ArrayRCP<Scalar> &values) {
631  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
632 
633  int lowerOffset = 0;
634  bool ownMemory = false;
635 
636  const size_t nnz = getLocalNumEntries();
637  // Values
638  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
639  }
640 
641  // Epetra always has global constants
642  bool haveGlobalConstants() const { return true; }
644  //** \warning This is an expert-only routine and should not be called from user code. */
646  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
647  const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
648  const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
649  const RCP<ParameterList> & /* params */ = Teuchos::null) {
650  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
651 
652  // For Epetra matrices, resumeFill() is a fictive operation.
653  isFillResumed_ = false;
654 
655  int rv = 0;
656  const Epetra_Import *myimport = 0;
657  const Epetra_Export *myexport = 0;
658 
659  if (!importer.is_null()) {
660  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
661  myimport = eImporter.getEpetra_Import().getRawPtr();
662  }
663  if (!exporter.is_null()) {
664  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
665  myexport = eExporter.getEpetra_Export().getRawPtr();
666  }
667 
668  rv = mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), myimport, myexport);
669 
670  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
671  }
673 
675 
676 
678  void resumeFill(const RCP<ParameterList> & /* params */ = Teuchos::null) {
679  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
680 
681  // According to Tpetra documentation, resumeFill() may be called repeatedly.
682  isFillResumed_ = true;
683  }
684 
686  void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = Teuchos::null) {
687  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
688 
689  // For Epetra matrices, resumeFill() is a fictive operation.
690  isFillResumed_ = false;
691 
692  bool doOptimizeStorage = true;
693  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
694  mtx_->FillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), doOptimizeStorage);
695  }
696 
698  void fillComplete(const RCP<ParameterList> &params = Teuchos::null) {
699  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
700 
701  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
702  if (isFillResumed_ == true) {
703  isFillResumed_ = false;
704  return;
705  }
706 
707  bool doOptimizeStorage = true;
708  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
709  mtx_->FillComplete(doOptimizeStorage);
710  }
711 
713  void replaceDomainMapAndImporter(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newDomainMap, Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &newImporter) {
714  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
715  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
716 
717  const RCP<const Epetra_Import> &myImport = eImporter.getEpetra_Import();
718  int rv = 0;
719  if (myImport == Teuchos::null)
720  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), 0);
721  else
722  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), &*myImport);
723  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
724  }
725 
727 
729 
730 
732  const RCP<const Comm<int> > getComm() const {
733  XPETRA_MONITOR("EpetraCrsMatrixT::getComm");
734  return toXpetra(mtx_->Comm());
735  }
736 
738  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {
739  XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap");
740  return toXpetra<GlobalOrdinal, Node>(mtx_->RowMap());
741  }
742 
744  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const {
745  XPETRA_MONITOR("EpetraCrsMatrixT::getColMap");
746  return toXpetra<GlobalOrdinal, Node>(mtx_->ColMap());
747  }
748 
750  RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const {
751  XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph");
752  return toXpetra<GlobalOrdinal, Node>(mtx_->Graph());
753  }
754 
757  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows");
758  return mtx_->NumGlobalRows64();
759  }
760 
763  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols");
764  return mtx_->NumGlobalCols64();
765  }
766 
768  size_t getLocalNumRows() const {
769  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows");
770  return mtx_->NumMyRows();
771  }
772 
774  size_t getLocalNumCols() const {
775  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols");
776  return mtx_->NumMyCols();
777  }
778 
781  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries");
782  return mtx_->NumGlobalNonzeros64();
783  }
784 
786  size_t getLocalNumEntries() const {
787  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries");
788  return mtx_->NumMyNonzeros();
789  }
790 
792  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
793  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow");
794  return mtx_->NumMyEntries(localRow);
795  }
796 
798  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
799  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow");
800  return mtx_->NumGlobalEntries(globalRow);
801  }
802 
804  size_t getGlobalMaxNumRowEntries() const {
805  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries");
806  return mtx_->GlobalMaxNumEntries();
807  }
808 
810  size_t getLocalMaxNumRowEntries() const {
811  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries");
812  return mtx_->MaxNumEntries();
813  }
814 
816  bool isLocallyIndexed() const {
817  XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed");
818  return mtx_->IndicesAreLocal();
819  }
820 
822  bool isGloballyIndexed() const {
823  XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed");
824  return mtx_->IndicesAreGlobal();
825  }
826 
828  bool isFillComplete() const {
829  XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete");
830  if (isFillResumed_)
831  return false;
832  else
833  return mtx_->Filled();
834  }
835 
837  bool isFillActive() const {
838  XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive");
839  return !isFillComplete();
840  }
841 
843  ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const {
844  XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm");
845  return mtx_->NormFrobenius();
846  }
847 
849  bool supportsRowViews() const {
850  XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews");
851  return true;
852  }
853 
855  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
856  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
857 
858  int numEntries = -1;
859  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
860  NumEntries = numEntries;
861  }
862 
864  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
865  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
866 
867  int numEntries = -1;
868  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
869  NumEntries = numEntries;
870  }
871 
873  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
874  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
875 
876  int numEntries;
877  double *eValues;
878  GlobalOrdinal *eIndices;
879 
880  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
881  if (numEntries == 0) {
882  eValues = NULL;
883  eIndices = NULL;
884  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
885 
886  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
887  values = ArrayView<const double>(eValues, numEntries);
888  }
889 
891  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
892  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
893 
894  int numEntries;
895  double *eValues;
896  int *eIndices;
897 
898  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
899  if (numEntries == 0) {
900  eValues = NULL;
901  eIndices = NULL;
902  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
903 
904  indices = ArrayView<const int>(eIndices, numEntries);
905  values = ArrayView<const double>(eValues, numEntries);
906  }
907 
910  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
911  XPETRA_ERR_CHECK(mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal, Node>(diag)));
912  }
913 
915  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> & /* offsets */) const {
916  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
917  }
918 
920  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Teuchos::ArrayView<const size_t> & /* offsets */) const {
921  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
922  }
923 
925  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> & /* offsets */) const {
926  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
927  }
928 
931  mtx_->ReplaceDiagonalValues(toEpetra<GlobalOrdinal, Node>(diag));
932  }
933 
935  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal, Node>(x)));
936  };
938  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal, Node>(x)));
939  };
940 
942 
944 
945 
947  void apply(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &X, MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &Y, Teuchos::ETransp mode = Teuchos::NO_TRANS, Scalar alpha = ScalarTraits<Scalar>::one(), Scalar beta = ScalarTraits<Scalar>::zero()) const {
948  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
949 
950  // TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
951 
952  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
953  XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
954 
955  TEUCHOS_TEST_FOR_EXCEPTION((mode != Teuchos::NO_TRANS) && (mode != Teuchos::TRANS), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT->apply() only accept mode == NO_TRANS or mode == TRANS");
956  bool eTrans = toEpetra(mode);
957 
958  // /!\ UseTranspose value
959  TEUCHOS_TEST_FOR_EXCEPTION(mtx_->UseTranspose(), Xpetra::Exceptions::NotImplemented, "An exception is throw to let you know that Xpetra::EpetraCrsMatrixT->apply() do not take into account the UseTranspose() parameter of Epetra_CrsMatrix.");
960 
961  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
962 
963  // helper vector: tmp = A*x
964  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
965  tmp->PutScalar(0.0);
966  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
967 
968  // calculate alpha * A * x + beta * y
969  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
970  }
971 
973  void apply(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &X, MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &Y, Teuchos::ETransp mode, Scalar alpha, Scalar beta, bool sumInterfaceValues, const RCP<Import<LocalOrdinal, GlobalOrdinal, Node> > &regionInterfaceImporter, const Teuchos::ArrayRCP<LocalOrdinal> &regionInterfaceLIDs) const {
974  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
975  }
976 
978  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
979  XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap");
980  return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap());
981  }
982 
984  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
985  XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap");
986  return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap());
987  }
988 
990 
992 
993 
995  std::string description() const {
996  XPETRA_MONITOR("EpetraCrsMatrixT::description");
997 
998  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
999  std::ostringstream oss;
1000  // TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
1001  if (isFillComplete()) {
1002  oss << "{status = fill complete"
1003  << ", global rows = " << getGlobalNumRows()
1004  << ", global cols = " << getGlobalNumCols()
1005  << ", global num entries = " << getGlobalNumEntries()
1006  << "}";
1007  } else {
1008  oss << "{status = fill not complete"
1009  << ", global rows = " << getGlobalNumRows()
1010  << "}";
1011  }
1012  return oss.str();
1013  }
1014 
1016  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
1017  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
1018 
1019  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1020  using std::endl;
1021  using std::setw;
1022  using Teuchos::VERB_DEFAULT;
1023  using Teuchos::VERB_EXTREME;
1024  using Teuchos::VERB_HIGH;
1025  using Teuchos::VERB_LOW;
1026  using Teuchos::VERB_MEDIUM;
1027  using Teuchos::VERB_NONE;
1028  Teuchos::EVerbosityLevel vl = verbLevel;
1029  if (vl == VERB_DEFAULT) vl = VERB_LOW;
1030  RCP<const Comm<int> > comm = this->getComm();
1031  const int myImageID = comm->getRank(),
1032  numImages = comm->getSize();
1033  size_t width = 1;
1034  for (size_t dec = 10; dec < getGlobalNumRows(); dec *= 10) {
1035  ++width;
1036  }
1037  width = std::max<size_t>(width, 11) + 2;
1038  Teuchos::OSTab tab(out);
1039  // none: print nothing
1040  // low: print O(1) info from node 0
1041  // medium: print O(P) info, num entries per node
1042  // high: print O(N) info, num entries per row
1043  // extreme: print O(NNZ) info: print indices and values
1044  //
1045  // for medium and higher, print constituent objects at specified verbLevel
1046  if (vl != VERB_NONE) {
1047  if (myImageID == 0) out << this->description() << std::endl;
1048  // O(1) globals, minus what was already printed by description()
1049  if (isFillComplete() && myImageID == 0) {
1050  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1051  }
1052  // constituent objects
1053  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1054  if (myImageID == 0) out << "\nRow map: " << std::endl;
1055  getRowMap()->describe(out, vl);
1056  //
1057  if (getColMap() != null) {
1058  if (getColMap() == getRowMap()) {
1059  if (myImageID == 0) out << "\nColumn map is row map.";
1060  } else {
1061  if (myImageID == 0) out << "\nColumn map: " << std::endl;
1062  getColMap()->describe(out, vl);
1063  }
1064  }
1065  if (getDomainMap() != null) {
1066  if (getDomainMap() == getRowMap()) {
1067  if (myImageID == 0) out << "\nDomain map is row map.";
1068  } else if (getDomainMap() == getColMap()) {
1069  if (myImageID == 0) out << "\nDomain map is row map.";
1070  } else {
1071  if (myImageID == 0) out << "\nDomain map: " << std::endl;
1072  getDomainMap()->describe(out, vl);
1073  }
1074  }
1075  if (getRangeMap() != null) {
1076  if (getRangeMap() == getDomainMap()) {
1077  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1078  } else if (getRangeMap() == getRowMap()) {
1079  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1080  } else {
1081  if (myImageID == 0) out << "\nRange map: " << std::endl;
1082  getRangeMap()->describe(out, vl);
1083  }
1084  }
1085  if (myImageID == 0) out << std::endl;
1086  }
1087  // O(P) data
1088  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1089  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1090  if (myImageID == imageCtr) {
1091  out << "Node ID = " << imageCtr << std::endl;
1092  // TODO: need a graph
1093  // if (staticGraph_->indicesAreAllocated() == false) {
1094  // out << "Node not allocated" << std::endl;
1095  // }
1096  // else {
1097  // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
1098  // }
1099 
1100  // TMP:
1101  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1102  // End of TMP
1103 
1104  out << "Node number of entries = " << getLocalNumEntries() << std::endl;
1105  out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
1106  }
1107  comm->barrier();
1108  comm->barrier();
1109  comm->barrier();
1110  }
1111  }
1112  // O(N) and O(NNZ) data
1113  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1114  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1115  if (myImageID == imageCtr) {
1116  out << std::setw(width) << "Node ID"
1117  << std::setw(width) << "Global Row"
1118  << std::setw(width) << "Num Entries";
1119  if (vl == VERB_EXTREME) {
1120  out << std::setw(width) << "(Index,Value)";
1121  }
1122  out << std::endl;
1123  for (size_t r = 0; r < getLocalNumRows(); ++r) {
1124  const size_t nE = getNumEntriesInLocalRow(r);
1125  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1126  out << std::setw(width) << myImageID
1127  << std::setw(width) << gid
1128  << std::setw(width) << nE;
1129  if (vl == VERB_EXTREME) {
1130  if (isGloballyIndexed()) {
1131  ArrayView<const GlobalOrdinal> rowinds;
1132  ArrayView<const Scalar> rowvals;
1133  getGlobalRowView(gid, rowinds, rowvals);
1134  for (size_t j = 0; j < nE; ++j) {
1135  out << " (" << rowinds[j]
1136  << ", " << rowvals[j]
1137  << ") ";
1138  }
1139  } else if (isLocallyIndexed()) {
1140  ArrayView<const LocalOrdinal> rowinds;
1141  ArrayView<const Scalar> rowvals;
1142  getLocalRowView(r, rowinds, rowvals);
1143  for (size_t j = 0; j < nE; ++j) {
1144  out << " (" << getColMap()->getGlobalElement(rowinds[j])
1145  << ", " << rowvals[j]
1146  << ") ";
1147  }
1148  }
1149  }
1150  out << std::endl;
1151  }
1152  }
1153  comm->barrier();
1154  comm->barrier();
1155  comm->barrier();
1156  }
1157  }
1158  }
1159  }
1160 
1161  void setObjectLabel(const std::string &objectLabel) {
1162  Teuchos::LabeledObject::setObjectLabel(objectLabel);
1163  mtx_->SetLabel(objectLabel.c_str());
1164  }
1166 
1169  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_))))
1170  , isFillResumed_(false) {}
1171 
1173  //{@
1174 
1176  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getMap() const {
1177  XPETRA_MONITOR("EpetraCrsMatrixT::getMap");
1178  return toXpetra<GlobalOrdinal, Node>(mtx_->Map());
1179  }
1180 
1184  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1185 
1186  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1187  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1188 
1189  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1190  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1191  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1192  }
1193 
1197  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1198 
1199  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1200  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1201 
1202  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1203  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1204  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1205  }
1206 
1210  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1211 
1212  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1213  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1214 
1215  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1216  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1217  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1218  }
1219 
1223  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1224 
1225  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1226  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1227 
1228  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1229  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1230  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1231  }
1232 
1233  void removeEmptyProcessesInPlace(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newMap) {
1234  XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
1235  const Epetra_Map *newMapEpetra = (!newMap.is_null()) ? &toEpetra<GlobalOrdinal, Node>(newMap) : 0;
1236  int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
1237  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1238  }
1239 
1241 
1243 
1244 
1246  bool hasMatrix() const { return !mtx_.is_null(); }
1247 
1249  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix> &mtx)
1250  : mtx_(mtx)
1251  , isFillResumed_(false) {}
1252 
1254  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
1255 
1257  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } // TODO: remove
1258 
1259 #ifdef HAVE_XPETRA_TPETRA
1260 
1263 #if 0
1264  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented,
1265  "Xpetra::EpetraCrsMatrx only available on host for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
1266  TEUCHOS_UNREACHABLE_RETURN((local_matrix_type()));
1267 #endif
1268  return getLocalMatrixHost();
1269  }
1270 
1271 #if KOKKOS_VERSION >= 40799
1272  typename local_matrix_type::host_mirror_type getLocalMatrixHost() const {
1273 #else
1274  typename local_matrix_type::HostMirror getLocalMatrixHost() const {
1275 #endif
1276  RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
1277 
1278  const int numRows = matrix->NumMyRows();
1279  const int numCols = matrix->NumMyCols();
1280  const int nnz = matrix->NumMyNonzeros();
1281 
1282  int *rowptr;
1283  int *colind;
1284  double *vals;
1285  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1286  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1287 
1288  // Transform int* rowptr array to size_type* array
1289  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows + 1);
1290  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1291  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
1292 
1293  // create Kokkos::Views
1294  typename local_matrix_type::index_type kokkosColind(colind, nnz);
1295  typename local_matrix_type::values_type kokkosVals(vals, nnz);
1296 
1297  local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1298 
1299  return localMatrix;
1300  }
1301 
1302  void setAllValues(const typename local_matrix_type::row_map_type &ptr,
1303  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
1304  const typename local_matrix_type::values_type &val) {
1305  // Check sizes
1306  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(ptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
1307  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1308  TEUCHOS_TEST_FOR_EXCEPTION(val.size() != ind.size(), Xpetra::Exceptions::RuntimeError,
1309  "An exception is thrown to let you know that you mismatched your pointers.");
1310 
1311  // Check pointers
1312  if (val.size() > 0) {
1313  std::cout << ind.data() << " " << mtx_->ExpertExtractIndices().Values() << std::endl;
1314  TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1315  "An exception is thrown to let you know that you mismatched your pointers.");
1316  TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1317  "An exception is thrown to let you know that you mismatched your pointers.");
1318  }
1319 
1320  // We have to make a copy here, it is unavoidable
1321  // See comments in allocateAllValues
1322  const size_t N = getLocalNumRows();
1323 
1324  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1325  myRowptr.Resize(N + 1);
1326  for (size_t i = 0; i < N + 1; i++)
1327  myRowptr[i] = Teuchos::as<int>(ptr(i));
1328  }
1329 
1330  LocalOrdinal GetStorageBlockSize() const { return 1; }
1331 
1332  private:
1333 #else
1334 #ifdef __GNUC__
1335 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
1336 #endif
1337 #endif
1338 
1339 
1343  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
1344 
1345  apply(X, R);
1346  R.update(one, B, negone);
1347  }
1348 
1349  private:
1351  RCP<Epetra_CrsMatrix> mtx_;
1352 
1360 
1361 }; // EpetraCrsMatrixT class
1362 
1363 #endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1364 
1365 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1366 template <>
1367 class EpetraCrsMatrixT<long long, EpetraNode>
1368  : public CrsMatrix<double, int, long long, EpetraNode> {
1369  typedef long long GlobalOrdinal;
1370  typedef EpetraNode Node;
1373 
1374  // The following typedefs are used by the Kokkos interface
1375 #ifdef HAVE_XPETRA_TPETRA
1378 #endif
1379 
1380  public:
1382 
1383 
1385  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1386  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), maxNumEntriesPerRow, true)))
1387  , isFillResumed_(false) {}
1388 
1390  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1391  : isFillResumed_(false) {
1392  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1393  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1394  }
1395 
1397  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1398  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), maxNumEntriesPerRow, true)))
1399  , isFillResumed_(false) {}
1400 
1402  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1403  : isFillResumed_(false) {
1404  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1405  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1406  }
1407 
1409  EpetraCrsMatrixT(const Teuchos::RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1410  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(graph))))
1411  , isFillResumed_(false) {}
1412 
1416  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1417  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1418  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
1419  : isFillResumed_(false) {
1420  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1421  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1422 
1423  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1424  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1425 
1426  // Follows the Tpetra parameters
1427  bool restrictComm = false;
1428  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1429  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), myDomainMap, myRangeMap, restrictComm));
1430  if (restrictComm && mtx_->NumMyRows() == 0)
1431  mtx_ = Teuchos::null;
1432  }
1433 
1437  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1438  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1439  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
1440  : isFillResumed_(false) {
1441  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1442  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1443 
1444  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1445  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1446 
1447  // Follows the Tpetra parameters
1448  bool restrictComm = false;
1449  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1450 
1451  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), myDomainMap, myRangeMap, restrictComm));
1452  }
1453 
1455  const Import<LocalOrdinal, GlobalOrdinal, Node> &RowImporter,
1456  const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
1457  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
1458  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1459  const Teuchos::RCP<Teuchos::ParameterList> &params)
1460  : isFillResumed_(false) {
1461  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1462  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1463  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1464 
1465  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1466  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1467 
1468  // Follows the Tpetra parameters
1469  bool restrictComm = false;
1470  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1471  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), tdImporter->getEpetra_Import().get(), myDomainMap, myRangeMap, restrictComm));
1472  if (restrictComm && mtx_->NumMyRows() == 0)
1473  mtx_ = Teuchos::null;
1474  }
1475 
1477  const Export<LocalOrdinal, GlobalOrdinal, Node> &RowExporter,
1478  const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
1479  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
1480  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1481  const Teuchos::RCP<Teuchos::ParameterList> &params)
1482  : isFillResumed_(false) {
1483  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1484  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1485  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1486 
1487  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1488  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1489 
1490  // Follows the Tpetra parameters
1491  bool restrictComm = false;
1492  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1493 
1494  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), tdExporter->getEpetra_Export().get(), myDomainMap, myRangeMap, restrictComm));
1495  }
1496 
1497 #ifdef HAVE_XPETRA_TPETRA
1498  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
1519  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
1520  const local_matrix_type &lclMatrix,
1521  const Teuchos::RCP<Teuchos::ParameterList> &params = null)
1522  : EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params) {}
1523 
1525  const local_matrix_type &lclMatrix,
1526  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
1527  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
1528  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1529  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1530  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
1531  // local typedefs from local_matrix_type
1532  // typedef typename local_matrix_type::size_type size_type;
1533  typedef typename local_matrix_type::value_type value_type;
1534  typedef typename local_matrix_type::ordinal_type ordinal_type;
1535 
1536  // The number of rows in the sparse matrix.
1537  ordinal_type lclNumRows = lclMatrix.numRows();
1538  ordinal_type lclNumCols = lclMatrix.numCols(); // do we need this?
1539 
1540  // plausibility checks
1541  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
1542  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1543  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
1544  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1545 
1546  Teuchos::ArrayRCP<size_t> NumEntriesPerRowToAlloc(lclNumRows);
1547  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1548  // extract data from current row r
1549  auto rowview = lclMatrix.row(r);
1550  NumEntriesPerRowToAlloc[r] = rowview.length;
1551  }
1552 
1553  // setup matrix
1554  isFillResumed_ = false;
1555  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1556  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1557 
1558  // loop over all rows and colums of local matrix and fill matrix
1559  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1560  // extract data from current row r
1561  auto rowview = lclMatrix.row(r);
1562 
1563  // arrays for current row data
1564  Teuchos::ArrayRCP<ordinal_type> indout(rowview.length, Teuchos::ScalarTraits<ordinal_type>::zero());
1565  Teuchos::ArrayRCP<value_type> valout(rowview.length, Teuchos::ScalarTraits<value_type>::zero());
1566 
1567  for (ordinal_type c = 0; c < rowview.length; c++) {
1568  value_type value = rowview.value(c);
1569  ordinal_type colidx = rowview.colidx(c);
1570 
1571  TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
1572 
1573  indout[c] = colidx;
1574  valout[c] = value;
1575  }
1576  insertLocalValues(r, indout.view(0, indout.size()), valout.view(0, valout.size()));
1577  }
1578 
1579  // call fill complete
1580  if (!domainMap.is_null() && !rangeMap.is_null())
1581  this->fillComplete(domainMap, rowMap, params);
1582  else
1583  this->fillComplete(rowMap, rowMap, params);
1584  }
1585 #endif
1586 
1588  virtual ~EpetraCrsMatrixT() {}
1589 
1591 
1593 
1594 
1596  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1597  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1598  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1599  }
1600 
1602  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1603  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1604  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1605  }
1606 
1608  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &indices, const ArrayView<const Scalar> &values) {
1609  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1610 
1611  {
1612  const std::string tfecfFuncName("replaceGlobalValues");
1613  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
1614  ": Fill must be active in order to call this method. If you have already "
1615  "called fillComplete(), you need to call resumeFill() before you can "
1616  "replace values.");
1617 
1618  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1619  std::runtime_error, ": values.size() must equal indices.size().");
1620  }
1621 
1622  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1623  }
1624 
1626  void replaceLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &indices, const ArrayView<const Scalar> &values) {
1627  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
1628 
1629  {
1630  const std::string tfecfFuncName("replaceLocalValues");
1631  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
1632  ": Fill must be active in order to call this method. If you have already "
1633  "called fillComplete(), you need to call resumeFill() before you can "
1634  "replace values.");
1635 
1636  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1637  std::runtime_error, ": values.size() must equal indices.size().");
1638  }
1639 
1640  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1641  }
1642 
1644  void setAllToScalar(const Scalar &alpha) {
1645  XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar");
1646  mtx_->PutScalar(alpha);
1647  }
1648 
1650  void scale(const Scalar &alpha) {
1651  XPETRA_MONITOR("EpetraCrsMatrixT::scale");
1652  mtx_->Scale(alpha);
1653  }
1654 
1656  //** \warning This is an expert-only routine and should not be called from user code. */
1657  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {
1658  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1659 
1660  // Row offsets
1661  // Unfortunately, we cannot do this in the same manner as column indices
1662  // and values (see below). The problem is that Tpetra insists on using
1663  // size_t, and Epetra uses int internally. So we only resize here, and
1664  // will need to copy in setAllValues
1665  rowptr.resize(getLocalNumRows() + 1);
1666 
1667  int lowerOffset = 0;
1668  bool ownMemory = false;
1669 
1670  // Column indices
1671  // Extract, resize, set colind
1672  Epetra_IntSerialDenseVector &myColind = mtx_->ExpertExtractIndices();
1673  myColind.Resize(numNonZeros);
1674  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1675 
1676  // Values
1677  // Extract, reallocate, set values
1678  double *&myValues = mtx_->ExpertExtractValues();
1679  delete[] myValues;
1680  myValues = new double[numNonZeros];
1681  values = Teuchos::arcp(myValues, lowerOffset, numNonZeros, ownMemory);
1682  }
1683 
1685  void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {
1686  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1687 
1688  // Check sizes
1689  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
1690  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1691  TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
1692  "An exception is thrown to let you know that you mismatched your pointers.");
1693 
1694  // Check pointers
1695  if (values.size() > 0) {
1696  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1697  "An exception is thrown to let you know that you mismatched your pointers.");
1698  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1699  "An exception is thrown to let you know that you mismatched your pointers.");
1700  }
1701 
1702  // We have to make a copy here, it is unavoidable
1703  // See comments in allocateAllValues
1704  const size_t N = getLocalNumRows();
1705 
1706  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1707  myRowptr.Resize(N + 1);
1708  for (size_t i = 0; i < N + 1; i++)
1709  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1710  }
1711 
1713  void getAllValues(ArrayRCP<const size_t> &rowptr, ArrayRCP<const LocalOrdinal> &colind, ArrayRCP<const Scalar> &values) const {
1714  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1715 
1716  int lowerOffset = 0;
1717  bool ownMemory = false;
1718 
1719  const size_t n = getLocalNumRows();
1720  const size_t nnz = getLocalNumEntries();
1721 
1722  // Row offsets
1723  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1724  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1725  rowptr.resize(n + 1);
1726  for (size_t i = 0; i < n + 1; i++)
1727  (*const_cast<size_t *>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1728 
1729  // Column indices
1730  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1731 
1732  // Values
1733  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1734  }
1735 
1737  void getAllValues(ArrayRCP<Scalar> &values) {
1738  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1739 
1740  int lowerOffset = 0;
1741  bool ownMemory = false;
1742 
1743  const size_t nnz = getLocalNumEntries();
1744  // Values
1745  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1746  }
1747 
1748  // Epetra always has global constants
1749  bool haveGlobalConstants() const { return true; }
1750 
1752  //** \warning This is an expert-only routine and should not be called from user code. */
1754  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1755  const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
1756  const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
1757  const RCP<ParameterList> & /* params */ = Teuchos::null) {
1758  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1759 
1760  // For Epetra matrices, resumeFill() is a fictive operation.
1761  isFillResumed_ = false;
1762 
1763  int rv = 0;
1764  const Epetra_Import *myimport = 0;
1765  const Epetra_Export *myexport = 0;
1766 
1767  if (!importer.is_null()) {
1768  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1769  myimport = eImporter.getEpetra_Import().getRawPtr();
1770  }
1771  if (!exporter.is_null()) {
1772  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1773  myexport = eExporter.getEpetra_Export().getRawPtr();
1774  }
1775 
1776  rv = mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), myimport, myexport);
1777 
1778  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1779  }
1781 
1783 
1784 
1786  void resumeFill(const RCP<ParameterList> & /* params */ = Teuchos::null) {
1787  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1788 
1789  // According to Tpetra documentation, resumeFill() may be called repeatedly.
1790  isFillResumed_ = true;
1791  }
1792 
1794  void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = Teuchos::null) {
1795  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1796 
1797  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1798  if (isFillResumed_ == true) {
1799  isFillResumed_ = false;
1800  return;
1801  }
1802 
1803  bool doOptimizeStorage = true;
1804  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
1805  mtx_->FillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), doOptimizeStorage);
1806  }
1807 
1809  void fillComplete(const RCP<ParameterList> &params = Teuchos::null) {
1810  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1811 
1812  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1813  if (isFillResumed_ == true) {
1814  isFillResumed_ = false;
1815  return;
1816  }
1817 
1818  bool doOptimizeStorage = true;
1819  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
1820  mtx_->FillComplete(doOptimizeStorage);
1821  }
1822 
1824  void replaceDomainMapAndImporter(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newDomainMap, Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &newImporter) {
1825  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1826  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1827 
1828  const RCP<const Epetra_Import> &myImport = eImporter.getEpetra_Import();
1829  int rv = 0;
1830  if (myImport == Teuchos::null)
1831  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), 0);
1832  else
1833  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), &*myImport);
1834  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1835  }
1836 
1838 
1840 
1841 
1843  const RCP<const Comm<int> > getComm() const {
1844  XPETRA_MONITOR("EpetraCrsMatrixT::getComm");
1845  return toXpetra(mtx_->Comm());
1846  }
1847 
1849  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {
1850  XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap");
1851  return toXpetra<GlobalOrdinal, Node>(mtx_->RowMap());
1852  }
1853 
1855  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const {
1856  XPETRA_MONITOR("EpetraCrsMatrixT::getColMap");
1857  return toXpetra<GlobalOrdinal, Node>(mtx_->ColMap());
1858  }
1859 
1861  RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const {
1862  XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph");
1863  return toXpetra<GlobalOrdinal, Node>(mtx_->Graph());
1864  }
1865 
1868  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows");
1869  return mtx_->NumGlobalRows64();
1870  }
1871 
1874  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols");
1875  return mtx_->NumGlobalCols64();
1876  }
1877 
1879  size_t getLocalNumRows() const {
1880  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows");
1881  return mtx_->NumMyRows();
1882  }
1883 
1885  size_t getLocalNumCols() const {
1886  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols");
1887  return mtx_->NumMyCols();
1888  }
1889 
1892  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries");
1893  return mtx_->NumGlobalNonzeros64();
1894  }
1895 
1897  size_t getLocalNumEntries() const {
1898  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries");
1899  return mtx_->NumMyNonzeros();
1900  }
1901 
1903  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
1904  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow");
1905  return mtx_->NumMyEntries(localRow);
1906  }
1907 
1909  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
1910  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow");
1911  return mtx_->NumGlobalEntries(globalRow);
1912  }
1913 
1915  size_t getGlobalMaxNumRowEntries() const {
1916  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries");
1917  return mtx_->GlobalMaxNumEntries();
1918  }
1919 
1921  size_t getLocalMaxNumRowEntries() const {
1922  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries");
1923  return mtx_->MaxNumEntries();
1924  }
1925 
1927  bool isLocallyIndexed() const {
1928  XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed");
1929  return mtx_->IndicesAreLocal();
1930  }
1931 
1933  bool isGloballyIndexed() const {
1934  XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed");
1935  return mtx_->IndicesAreGlobal();
1936  }
1937 
1939  bool isFillComplete() const {
1940  XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete");
1941  if (isFillResumed_)
1942  return false;
1943  else
1944  return mtx_->Filled();
1945  }
1946 
1948  bool isFillActive() const {
1949  XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive");
1950  return !isFillComplete();
1951  }
1952 
1954  typename ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const {
1955  XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm");
1956  return mtx_->NormFrobenius();
1957  }
1958 
1960  bool supportsRowViews() const {
1961  XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews");
1962  return true;
1963  }
1964 
1966  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1967  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1968 
1969  int numEntries = -1;
1970  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1971  NumEntries = numEntries;
1972  }
1973 
1975  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1976  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
1977 
1978  int numEntries = -1;
1979  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1980  NumEntries = numEntries;
1981  }
1982 
1984  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
1985  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
1986 
1987  int numEntries;
1988  double *eValues;
1989  GlobalOrdinal *eIndices;
1990 
1991  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
1992  if (numEntries == 0) {
1993  eValues = NULL;
1994  eIndices = NULL;
1995  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1996 
1997  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
1998  values = ArrayView<const double>(eValues, numEntries);
1999  }
2000 
2002  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
2003  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
2004 
2005  int numEntries;
2006  double *eValues;
2007  int *eIndices;
2008 
2009  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
2010  if (numEntries == 0) {
2011  eValues = NULL;
2012  eIndices = NULL;
2013  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
2014 
2015  indices = ArrayView<const int>(eIndices, numEntries);
2016  values = ArrayView<const double>(eValues, numEntries);
2017  }
2018 
2021  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
2022  mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal, Node>(diag));
2023  }
2024 
2026  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> & /* offsets */) const {
2027  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
2028  }
2029 
2031  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Teuchos::ArrayView<const size_t> & /* offsets */) const {
2032  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
2033  }
2034 
2036  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> & /* offsets */) const {
2037  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
2038  }
2039 
2042  mtx_->ReplaceDiagonalValues(toEpetra<GlobalOrdinal, Node>(diag));
2043  }
2044 
2046  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal, Node>(x)));
2047  };
2049  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal, Node>(x)));
2050  };
2051 
2053 
2055 
2056 
2058  void apply(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &X, MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &Y, Teuchos::ETransp mode = Teuchos::NO_TRANS, Scalar alpha = ScalarTraits<Scalar>::one(), Scalar beta = ScalarTraits<Scalar>::zero()) const {
2059  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
2060 
2061  // TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
2062 
2063  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
2064  XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
2065 
2066  TEUCHOS_TEST_FOR_EXCEPTION((mode != Teuchos::NO_TRANS) && (mode != Teuchos::TRANS), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT->apply() only accept mode == NO_TRANS or mode == TRANS");
2067  bool eTrans = toEpetra(mode);
2068 
2069  // /!\ UseTranspose value
2070  TEUCHOS_TEST_FOR_EXCEPTION(mtx_->UseTranspose(), Xpetra::Exceptions::NotImplemented, "An exception is throw to let you know that Xpetra::EpetraCrsMatrixT->apply() do not take into account the UseTranspose() parameter of Epetra_CrsMatrix.");
2071 
2072  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
2073 
2074  // helper vector: tmp = A*x
2075  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
2076  tmp->PutScalar(0.0);
2077  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
2078 
2079  // calculate alpha * A * x + beta * y
2080  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
2081  }
2082 
2083  void apply(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &X, MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &Y, Teuchos::ETransp mode, Scalar alpha, Scalar beta, bool sumInterfaceValues, const RCP<Import<LocalOrdinal, GlobalOrdinal, Node> > &regionInterfaceImporter, const Teuchos::ArrayRCP<LocalOrdinal> &regionInterfaceLIDs) const {
2084  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
2085  }
2086 
2088  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
2089  XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap");
2090  return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap());
2091  }
2092 
2094  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
2095  XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap");
2096  return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap());
2097  }
2098 
2100 
2102 
2103 
2105  std::string description() const {
2106  XPETRA_MONITOR("EpetraCrsMatrixT::description");
2107 
2108  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2109  std::ostringstream oss;
2110  // TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
2111  if (isFillComplete()) {
2112  oss << "{status = fill complete"
2113  << ", global rows = " << getGlobalNumRows()
2114  << ", global cols = " << getGlobalNumCols()
2115  << ", global num entries = " << getGlobalNumEntries()
2116  << "}";
2117  } else {
2118  oss << "{status = fill not complete"
2119  << ", global rows = " << getGlobalNumRows()
2120  << "}";
2121  }
2122  return oss.str();
2123  }
2124 
2126  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
2127  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
2128 
2129  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2130  using std::endl;
2131  using std::setw;
2132  using Teuchos::VERB_DEFAULT;
2133  using Teuchos::VERB_EXTREME;
2134  using Teuchos::VERB_HIGH;
2135  using Teuchos::VERB_LOW;
2136  using Teuchos::VERB_MEDIUM;
2137  using Teuchos::VERB_NONE;
2138  Teuchos::EVerbosityLevel vl = verbLevel;
2139  if (vl == VERB_DEFAULT) vl = VERB_LOW;
2140  RCP<const Comm<int> > comm = this->getComm();
2141  const int myImageID = comm->getRank(),
2142  numImages = comm->getSize();
2143  size_t width = 1;
2144  for (size_t dec = 10; dec < getGlobalNumRows(); dec *= 10) {
2145  ++width;
2146  }
2147  width = std::max<size_t>(width, 11) + 2;
2148  Teuchos::OSTab tab(out);
2149  // none: print nothing
2150  // low: print O(1) info from node 0
2151  // medium: print O(P) info, num entries per node
2152  // high: print O(N) info, num entries per row
2153  // extreme: print O(NNZ) info: print indices and values
2154  //
2155  // for medium and higher, print constituent objects at specified verbLevel
2156  if (vl != VERB_NONE) {
2157  if (myImageID == 0) out << this->description() << std::endl;
2158  // O(1) globals, minus what was already printed by description()
2159  if (isFillComplete() && myImageID == 0) {
2160  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
2161  }
2162  // constituent objects
2163  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2164  if (myImageID == 0) out << "\nRow map: " << std::endl;
2165  getRowMap()->describe(out, vl);
2166  //
2167  if (getColMap() != null) {
2168  if (getColMap() == getRowMap()) {
2169  if (myImageID == 0) out << "\nColumn map is row map.";
2170  } else {
2171  if (myImageID == 0) out << "\nColumn map: " << std::endl;
2172  getColMap()->describe(out, vl);
2173  }
2174  }
2175  if (getDomainMap() != null) {
2176  if (getDomainMap() == getRowMap()) {
2177  if (myImageID == 0) out << "\nDomain map is row map.";
2178  } else if (getDomainMap() == getColMap()) {
2179  if (myImageID == 0) out << "\nDomain map is row map.";
2180  } else {
2181  if (myImageID == 0) out << "\nDomain map: " << std::endl;
2182  getDomainMap()->describe(out, vl);
2183  }
2184  }
2185  if (getRangeMap() != null) {
2186  if (getRangeMap() == getDomainMap()) {
2187  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
2188  } else if (getRangeMap() == getRowMap()) {
2189  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
2190  } else {
2191  if (myImageID == 0) out << "\nRange map: " << std::endl;
2192  getRangeMap()->describe(out, vl);
2193  }
2194  }
2195  if (myImageID == 0) out << std::endl;
2196  }
2197  // O(P) data
2198  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2199  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2200  if (myImageID == imageCtr) {
2201  out << "Node ID = " << imageCtr << std::endl;
2202  // TODO: need a graph
2203  // if (staticGraph_->indicesAreAllocated() == false) {
2204  // out << "Node not allocated" << std::endl;
2205  // }
2206  // else {
2207  // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
2208  // }
2209 
2210  // TMP:
2211  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2212  // End of TMP
2213 
2214  out << "Node number of entries = " << getLocalNumEntries() << std::endl;
2215  out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
2216  }
2217  comm->barrier();
2218  comm->barrier();
2219  comm->barrier();
2220  }
2221  }
2222  // O(N) and O(NNZ) data
2223  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2224  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2225  if (myImageID == imageCtr) {
2226  out << std::setw(width) << "Node ID"
2227  << std::setw(width) << "Global Row"
2228  << std::setw(width) << "Num Entries";
2229  if (vl == VERB_EXTREME) {
2230  out << std::setw(width) << "(Index,Value)";
2231  }
2232  out << std::endl;
2233  for (size_t r = 0; r < getLocalNumRows(); ++r) {
2234  const size_t nE = getNumEntriesInLocalRow(r);
2235  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2236  out << std::setw(width) << myImageID
2237  << std::setw(width) << gid
2238  << std::setw(width) << nE;
2239  if (vl == VERB_EXTREME) {
2240  if (isGloballyIndexed()) {
2241  ArrayView<const GlobalOrdinal> rowinds;
2242  ArrayView<const Scalar> rowvals;
2243  getGlobalRowView(gid, rowinds, rowvals);
2244  for (size_t j = 0; j < nE; ++j) {
2245  out << " (" << rowinds[j]
2246  << ", " << rowvals[j]
2247  << ") ";
2248  }
2249  } else if (isLocallyIndexed()) {
2250  ArrayView<const LocalOrdinal> rowinds;
2251  ArrayView<const Scalar> rowvals;
2252  getLocalRowView(r, rowinds, rowvals);
2253  for (size_t j = 0; j < nE; ++j) {
2254  out << " (" << getColMap()->getGlobalElement(rowinds[j])
2255  << ", " << rowvals[j]
2256  << ") ";
2257  }
2258  }
2259  }
2260  out << std::endl;
2261  }
2262  }
2263  comm->barrier();
2264  comm->barrier();
2265  comm->barrier();
2266  }
2267  }
2268  }
2269  }
2270 
2271  void setObjectLabel(const std::string &objectLabel) {
2272  Teuchos::LabeledObject::setObjectLabel(objectLabel);
2273  mtx_->SetLabel(objectLabel.c_str());
2274  }
2276 
2279  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_))))
2280  , isFillResumed_(false) {}
2281 
2283  //{@
2284 
2286  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getMap() const {
2287  XPETRA_MONITOR("EpetraCrsMatrixT::getMap");
2288  return toXpetra<GlobalOrdinal, Node>(mtx_->Map());
2289  }
2290 
2294  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2295 
2296  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2297  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2298 
2299  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2300  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2301  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2302  }
2303 
2307  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2308 
2309  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2310  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2311 
2312  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2313  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2314  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2315  }
2316 
2320  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2321 
2322  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2323  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2324 
2325  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2326  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2327  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2328  }
2329 
2333  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2334 
2335  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2336  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2337 
2338  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2339  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2340  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2341  }
2342 
2343  void removeEmptyProcessesInPlace(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newMap) {
2344  XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
2345  const Epetra_Map *newMapEpetra = (!newMap.is_null()) ? &toEpetra<GlobalOrdinal, Node>(newMap) : 0;
2346  int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
2347  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
2348  }
2349 
2351 
2353 
2354 
2356  bool hasMatrix() const { return !mtx_.is_null(); }
2357 
2359  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix> &mtx)
2360  : mtx_(mtx)
2361  , isFillResumed_(false) {}
2362 
2364  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
2365 
2367  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } // TODO: remove
2368 
2369 #ifdef HAVE_XPETRA_TPETRA
2370  local_matrix_type getLocalMatrix() const {
2372  RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
2373 
2374  const int numRows = matrix->NumMyRows();
2375  const int numCols = matrix->NumMyCols();
2376  const int nnz = matrix->NumMyNonzeros();
2377 
2378  int *rowptr;
2379  int *colind;
2380  double *vals;
2381  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2382  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2383 
2384  // Transform int* rowptr array to size_type* array
2385  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows + 1);
2386  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2387  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
2388 
2389  // create Kokkos::Views
2390  typename local_matrix_type::index_type kokkosColind(colind, nnz);
2391  typename local_matrix_type::values_type kokkosVals(vals, nnz);
2392 
2393  local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2394 
2395  return localMatrix;
2396  }
2397 
2398  void setAllValues(const typename local_matrix_type::row_map_type &ptr,
2399  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
2400  const typename local_matrix_type::values_type &val) {
2401  // Check sizes
2402  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(ptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
2403  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
2404  TEUCHOS_TEST_FOR_EXCEPTION(val.size() != ind.size(), Xpetra::Exceptions::RuntimeError,
2405  "An exception is thrown to let you know that you mismatched your pointers.");
2406 
2407  // Check pointers
2408  if (val.size() > 0) {
2409  TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
2410  "An exception is thrown to let you know that you mismatched your pointers.");
2411  TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
2412  "An exception is thrown to let you know that you mismatched your pointers.");
2413  }
2414 
2415  // We have to make a copy here, it is unavoidable
2416  // See comments in allocateAllValues
2417  const size_t N = getLocalNumRows();
2418 
2419  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
2420  myRowptr.Resize(N + 1);
2421  for (size_t i = 0; i < N + 1; i++)
2422  myRowptr[i] = Teuchos::as<int>(ptr(i));
2423  }
2424 
2425  LocalOrdinal GetStorageBlockSize() const { return 1; }
2426 
2427  private:
2428 #else
2429 #ifdef __GNUC__
2430 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
2431 #endif
2432 #endif
2433 
2435 
2439  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
2440  apply(X, R);
2441  R.update(one, B, negone);
2442  }
2443 
2444  private:
2445  RCP<Epetra_CrsMatrix> mtx_;
2446 
2447  bool isFillResumed_; //< For Epetra, fillResume() is a fictive operation but we need to keep track of it. This boolean is true only is resumeFill() have been called and fillComplete() have not been called afterward.
2448 
2449 }; // EpetraCrsMatrixT class
2450 
2451 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2452 
2453 } // namespace Xpetra
2454 
2455 #define XPETRA_EPETRACRSMATRIX_SHORT
2456 #endif // XPETRA_EPETRACRSMATRIX_HPP
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
size_t getLocalNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix. ...
void setObjectLabel(const std::string &objectLabel)
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Kokkos::View< const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged > &offsets) const
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying row and column Maps and number of entries in each row.
size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused import.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
Gets the 1D pointer arrays of the graph.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
size_t getLocalNumRows() const
Returns the number of matrix rows owned on the calling node.
size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
Allocates and returns ArrayRCPs of the Crs arrays — This is an Xpetra-only routine.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
void setAllValues(const typename local_matrix_type::row_map_type &ptr, const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind, const typename local_matrix_type::values_type &val)
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying column Map and number of entries in each row.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
void resumeFill(const RCP< ParameterList > &params=null)
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
void getAllValues(ArrayRCP< Scalar > &values)
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &=Teuchos::null)
Expert static fill complete.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
void replaceDiag(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag)
bool hasMatrix() const
Does this have an underlying matrix.
RCP< Epetra_CrsMatrix > mtx_
The underlying actual matrix object.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
void fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused export.
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::node_type node_type
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
size_t getLocalNumRows() const
Returns the number of matrix rows owned on the calling node.
LocalOrdinal GetStorageBlockSize() const
Returns the block size of the storage mechanism, which is usually 1, except for Tpetra::BlockCrsMatri...
std::string description() const
A simple one-line description of this object.
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::node_type node_type
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Kokkos::View< const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged > &) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
local_matrix_type getLocalMatrixDevice() const
Compatibility layer for accessing the matrix data through a Kokkos interface.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified (locally owned) global row...
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
Exception throws to report errors in the internal logical of the program.
LocalOrdinal local_ordinal_type
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
size_t getLocalNumRows() const
Returns the number of matrix rows owned on the calling node.
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::node_type node_type
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_type local_matrix_type
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replaces the current domainMap and importer with the user-specified objects.
size_t getLocalNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix. ...
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying fixed number of entries for each row.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
std::string description() const
A simple one-line description of this object.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Teuchos::ArrayView< const size_t > &) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
EpetraCrsMatrixT(const local_matrix_type &lclMatrix, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=null)
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)=0
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
const RCP< const Comm< int > > getComm() const
Returns the communicator.
void fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using local IDs.
void resumeFill(const RCP< ParameterList > &=Teuchos::null)
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Kokkos::View< const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged > &) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using global IDs.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replaces the current domainMap and importer with the user-specified objects.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const local_matrix_type &lclMatrix, const Teuchos::RCP< Teuchos::ParameterList > &params=null)
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
Get the underlying Epetra matrix.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
void setAllToScalar(const Scalar &alpha)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying (possibly different) number of entries in each row.
bool hasMatrix() const
Does this have an underlying matrix.
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &=Teuchos::null)
Expert static fill complete.
size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
std::string description() const
A simple one-line description of this object.
size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
#define XPETRA_ERR_CHECK(arg)
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying fixed number of entries for each row.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified (locally owned) global row...
const RCP< const Comm< int > > getComm() const
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &) const
Get offsets of the diagonal entries in the matrix.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
LocalOrdinal GetStorageBlockSize() const
Returns the block size of the storage mechanism, which is usually 1, except for Tpetra::BlockCrsMatri...
void getAllValues(ArrayRCP< Scalar > &values)
Gets the 1D pointer arrays of the graph.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
local_matrix_type::HostMirror getLocalMatrixHost() const
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
bool isFillActive() const
Returns true if the matrix is in edit mode.
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
Get the underlying Epetra matrix.
EpetraCrsMatrixT(const local_matrix_type &lclMatrix, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=null)
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
void getAllValues(ArrayRCP< Scalar > &values)
Gets the 1D pointer arrays of the graph.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
void replaceDiag(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag)
Replace the diagonal entries of the matrix.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode, Scalar alpha, Scalar beta, bool sumInterfaceValues, const RCP< Import< LocalOrdinal, GlobalOrdinal, Node > > &regionInterfaceImporter, const Teuchos::ArrayRCP< LocalOrdinal > &regionInterfaceLIDs) const
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying (possibly different) number of entries in each row.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
Allocates and returns ArrayRCPs of the Crs arrays — This is an Xpetra-only routine.
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
Gets the 1D pointer arrays of the graph.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
void replaceDiag(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag)
Replace the diagonal entries of the matrix.
Exception throws when you call an unimplemented method of Xpetra.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
The Map describing the parallel distribution of this object.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
size_t getLocalNumCols() const
Returns the number of matrix columns owned on the calling node.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
size_t global_size_t
Global size_t object.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_type local_matrix_type
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &params=Teuchos::null)
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
LocalOrdinal GetStorageBlockSize() const
Returns the block size of the storage mechanism, which is usually 1, except for Tpetra::BlockCrsMatri...
const RCP< const Comm< int > > getComm() const
Returns the communicator.
local_matrix_type getLocalMatrixDevice() const
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
void fillComplete(const RCP< ParameterList > &params=null)
Signal that data entry is complete.
size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
#define XPETRA_RCP_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused import.
void setObjectLabel(const std::string &objectLabel)
void scale(const Scalar &alpha)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_type local_matrix_type
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using global IDs.
bool hasMatrix() const
Does this have an underlying matrix.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
bool isFillActive() const
Returns true if the matrix is in edit mode.
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null)
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying a previously constructed graph.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying a previously constructed graph.
bool isFillActive() const
Returns true if the matrix is in edit mode.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
CombineMode
Xpetra::Combine Mode enumerable type.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
#define XPETRA_MONITOR(funcName)
void setAllValues(const typename local_matrix_type::row_map_type &ptr, const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind, const typename local_matrix_type::values_type &val)
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
void setAllValues(const typename local_matrix_type::row_map_type &ptr, const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind, const typename local_matrix_type::values_type &val)
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &) const
Get offsets of the diagonal entries in the matrix.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap)
Constructor for empty DynamicProfile matrix (no space is preallocated).
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode, Scalar alpha, Scalar beta, bool sumInterfaceValues, const RCP< Import< LocalOrdinal, GlobalOrdinal, Node > > &regionInterfaceImporter, const Teuchos::ArrayRCP< LocalOrdinal > &regionInterfaceLIDs) const
KokkosSparse::CrsMatrix< impl_scalar_type, LocalOrdinal, execution_space, void, typename local_graph_type::size_type > local_matrix_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Teuchos::ArrayView< const size_t > &) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
local_matrix_type::HostMirror getLocalMatrixHost() const
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries in the specified global row.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete, specifying domain and range maps.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode, Scalar alpha, Scalar beta, bool sumInterfaceValues, const RCP< Import< LocalOrdinal, GlobalOrdinal, Node > > &regionInterfaceImporter, const Teuchos::ArrayRCP< LocalOrdinal > &regionInterfaceLIDs) const
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying column Map and fixed number of entries for each row.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete, specifying domain and range maps.
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying column Map and fixed number of entries for each row.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
bool isFillResumed_
Flag to keep track of fill status.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused export.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const local_matrix_type &lclMatrix, const Teuchos::RCP< Teuchos::ParameterList > &params=null)
Constructor specifying column Map and a local matrix, which the resulting CrsMatrix views...
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using local IDs.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
EpetraCrsMatrixT(const local_matrix_type &lclMatrix, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=null)
void resumeFill(const RCP< ParameterList > &=Teuchos::null)
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)