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 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_EPETRACRSMATRIX_HPP
47 #define XPETRA_EPETRACRSMATRIX_HPP
48 
49 /* this file is automatically generated - do not edit (see script/epetra.py) */
50 
51 #ifdef HAVE_XPETRA_TPETRA
52 #include <Kokkos_Core.hpp>
53 #endif
54 
56 
57 #include "Xpetra_CrsMatrix.hpp"
58 
59 #include <Epetra_CrsMatrix.h>
60 #include <Epetra_Map.h>
61 
62 #include "Xpetra_EpetraMap.hpp"
63 #include "Xpetra_EpetraVector.hpp"
66 
67 #include "Xpetra_MapFactory.hpp"
68 
69 #include "Xpetra_Utils.hpp"
70 #include "Xpetra_Exceptions.hpp"
71 
72 #if defined(XPETRA_ENABLE_DEPRECATED_CODE)
73 #ifdef __GNUC__
74 #warning "The header file Trilinos/packages/xpetra/src/CrsMatrix/Xpetra_EpetraCrsMatrix.hpp is deprecated."
75 #endif
76 #else
77 #error "The header file Trilinos/packages/xpetra/src/CrsMatrix/Xpetra_EpetraCrsMatrix.hpp is deprecated."
78 #endif
79 
80 namespace Xpetra {
81 
82 // general implementation: empty stub
83 template <class EpetraGlobalOrdinal, class Node>
84 class XPETRA_DEPRECATED EpetraCrsMatrixT
85  : public CrsMatrix<double, int, EpetraGlobalOrdinal, Node> {
86  typedef EpetraGlobalOrdinal GlobalOrdinal;
89 
90 #ifdef HAVE_XPETRA_TPETRA
93 #endif
94 
95  public:
96  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
97  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
98  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
99  }
100  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
101  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
102  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
103  }
104  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."); }
105  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."); }
106  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."); }
109  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
110  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
111  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::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  }
117  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
118  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
119  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
120  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
121  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
122  }
125  const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
126  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
127  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
128  const Teuchos::RCP<Teuchos::ParameterList> &params) {
129  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
130  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
131  }
134  const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
135  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
136  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
137  const Teuchos::RCP<Teuchos::ParameterList> &params) {
138  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
139  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
140  }
141 #ifdef HAVE_XPETRA_TPETRA
142  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
143  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
144  const local_matrix_type &lclMatrix,
145  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
146  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
147  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
148  }
150  const local_matrix_type &lclMatrix,
151  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
152  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
153  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
154  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
155  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
156  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
157  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
158  }
159 #endif
160  virtual ~EpetraCrsMatrixT() {}
161 
162  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
163  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
164  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
165  void replaceLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
166  void setAllToScalar(const Scalar &alpha) {}
167  void scale(const Scalar &alpha) {}
168  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {}
169  void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {}
170  void getAllValues(ArrayRCP<const size_t> &rowptr, ArrayRCP<const LocalOrdinal> &colind, ArrayRCP<const Scalar> &values) const {}
171  void getAllValues(ArrayRCP<Scalar> &values) {}
172  bool haveGlobalConstants() const { return true; }
174  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
175  const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
176  const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
177  const RCP<ParameterList> &params = Teuchos::null) {}
178 
179  void resumeFill(const RCP<ParameterList> &params = null) {}
180  void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = null) {}
181  void fillComplete(const RCP<ParameterList> &params = null) {}
182  void replaceDomainMapAndImporter(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newDomainMap, Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &newImporter) {}
183  const RCP<const Comm<int> > getComm() const { return Teuchos::null; }
184  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { return Teuchos::null; }
185  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { return Teuchos::null; }
186  RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { return Teuchos::null; }
187  global_size_t getGlobalNumRows() const { return 0; }
188  global_size_t getGlobalNumCols() const { return 0; }
189  size_t getLocalNumRows() const { return 0; }
190  size_t getLocalNumCols() const { return 0; }
191  global_size_t getGlobalNumEntries() const { return 0; }
192  size_t getLocalNumEntries() const { return 0; }
193  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { return 0; }
194  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { return 0; }
195  size_t getGlobalMaxNumRowEntries() const { return 0; }
196  size_t getLocalMaxNumRowEntries() const { return 0; }
197  bool isLocallyIndexed() const { return false; }
198  bool isGloballyIndexed() const { return false; }
199  bool isFillComplete() const { return false; }
200  bool isFillActive() const { return false; }
201  typename ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const { return ScalarTraits<Scalar>::magnitude(ScalarTraits<Scalar>::zero()); }
202  bool supportsRowViews() const { return false; }
203  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {}
204  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {}
205  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {}
206  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {}
208  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &offsets) const {}
209  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &diag, const Teuchos::ArrayView<const size_t> &offsets) const {}
210  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &diag, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> &offsets) const {}
214 
215  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 {}
216  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 {}
217  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const { return Teuchos::null; }
218  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const { return Teuchos::null; }
219 
220  std::string description() const { return std::string(""); }
221  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {}
222  void setObjectLabel(const std::string &objectLabel) {}
223 
225  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
226  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
227  }
228 
229  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getMap() const { return Teuchos::null; }
234  void removeEmptyProcessesInPlace(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newMap) {}
235 
236  bool hasMatrix() const { return false; }
237  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix> &mtx) {
238  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
239  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
240  }
241  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
242  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } // TODO: remove
243 #ifdef HAVE_XPETRA_TPETRA
245  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
246  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
247  }
248  typename local_matrix_type::HostMirror getLocalMatrixHost() const {
249  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
250  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
251  }
252 
253  void setAllValues(const typename local_matrix_type::row_map_type &ptr,
254  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
255  const typename local_matrix_type::values_type &val) {
256  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
257  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
258  }
259 
260  LocalOrdinal GetStorageBlockSize() const { return 1; }
261 
262 #else
263 #ifdef __GNUC__
264 #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."
265 #endif
266 #endif
267 
271  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
272  apply(X, R);
273  R.update(one, B, negone);
274  }
275 
276 }; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
277 
278 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
279 template <>
281  : public CrsMatrix<double, int, int, EpetraNode> {
282  typedef int GlobalOrdinal;
283  typedef EpetraNode Node;
286 
287  // The following typedefs are used by the Kokkos interface
288 #ifdef HAVE_XPETRA_TPETRA
291 #endif
292 
293  public:
295 
296 
298  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap)
299  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), 0, false)))
300  , isFillResumed_(false) {}
301 
303  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
304  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), maxNumEntriesPerRow, true)))
305  , isFillResumed_(false) {}
306 
308  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
309  : isFillResumed_(false) {
310  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
311  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
312  }
313 
315  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)
316  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), maxNumEntriesPerRow, true)))
317  , isFillResumed_(false) {}
318 
320  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)
321  : isFillResumed_(false) {
322  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
323  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
324  }
325 
327  EpetraCrsMatrixT(const Teuchos::RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
328  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(graph))))
329  , isFillResumed_(false) {}
330 
334  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
335  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
336  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
337  : isFillResumed_(false) {
338  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
339  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
340 
341  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
342  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
343 
344  // Follows the Tpetra parameters
345  bool restrictComm = false;
346  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
347  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), myDomainMap, myRangeMap, restrictComm));
348  if (restrictComm && mtx_->NumMyRows() == 0)
349  mtx_ = Teuchos::null;
350  }
351 
355  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
356  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
357  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
358  : isFillResumed_(false) {
359  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
360  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
361 
362  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
363  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
364 
365  // Follows the Tpetra parameters
366  bool restrictComm = false;
367  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
368 
369  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), myDomainMap, myRangeMap, restrictComm));
370  }
371 
374  const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
375  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
376  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
377  const Teuchos::RCP<Teuchos::ParameterList> &params)
378  : isFillResumed_(false) {
379  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
380  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
381  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
382 
383  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
384  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
385 
386  // Follows the Tpetra parameters
387  bool restrictComm = false;
388  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
389  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), tdImporter->getEpetra_Import().get(), myDomainMap, myRangeMap, restrictComm));
390  if (restrictComm && mtx_->NumMyRows() == 0)
391  mtx_ = Teuchos::null;
392  }
393 
396  const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
397  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
398  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
399  const Teuchos::RCP<Teuchos::ParameterList> &params)
400  : isFillResumed_(false) {
401  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
402  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
403  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
404 
405  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
406  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
407 
408  // Follows the Tpetra parameters
409  bool restrictComm = false;
410  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
411 
412  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), tdExporter->getEpetra_Export().get(), myDomainMap, myRangeMap, restrictComm));
413  }
414 
415 #ifdef HAVE_XPETRA_TPETRA
416  // NOTE: TPETRA means we can use C++11 here
417 
439  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
440  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
441  const local_matrix_type &lclMatrix,
442  const Teuchos::RCP<Teuchos::ParameterList> &params = null)
443  : EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params) {}
444 
446  const local_matrix_type &lclMatrix,
447  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
448  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
449  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
450  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
451  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
452  // local typedefs from local_matrix_type
453  // typedef typename local_matrix_type::size_type size_type;
454  typedef typename local_matrix_type::value_type value_type;
455  typedef typename local_matrix_type::ordinal_type ordinal_type;
456 
457  // The number of rows in the sparse matrix.
458  ordinal_type lclNumRows = lclMatrix.numRows();
459  ordinal_type lclNumCols = lclMatrix.numCols(); // do we need this?
460 
461  // plausibility checks
462  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
463  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
464  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
465  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
466 
467  Teuchos::ArrayRCP<size_t> NumEntriesPerRowToAlloc(lclNumRows);
468  for (ordinal_type r = 0; r < lclNumRows; ++r) {
469  // extract data from current row r
470  auto rowview = lclMatrix.row(r);
471  NumEntriesPerRowToAlloc[r] = rowview.length;
472  }
473 
474  // setup matrix
475  isFillResumed_ = false;
476  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
477  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
478 
479  // loop over all rows and colums of local matrix and fill matrix
480  for (ordinal_type r = 0; r < lclNumRows; ++r) {
481  // extract data from current row r
482  auto rowview = lclMatrix.row(r);
483 
484  // arrays for current row data
485  Teuchos::ArrayRCP<ordinal_type> indout(rowview.length, Teuchos::ScalarTraits<ordinal_type>::zero());
486  Teuchos::ArrayRCP<value_type> valout(rowview.length, Teuchos::ScalarTraits<value_type>::zero());
487 
488  for (ordinal_type c = 0; c < rowview.length; c++) {
489  value_type value = rowview.value(c);
490  ordinal_type colidx = rowview.colidx(c);
491 
492  TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError,
493  "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
494 
495  indout[c] = colidx;
496  valout[c] = value;
497  }
498  insertLocalValues(r, indout.view(0, indout.size()), valout.view(0, valout.size()));
499  }
500 
501  // call fill complete
502  if (!domainMap.is_null() && !rangeMap.is_null())
503  this->fillComplete(domainMap, rowMap, params);
504  else
505  this->fillComplete(rowMap, rowMap, params);
506  }
507 #endif
508 
510  virtual ~EpetraCrsMatrixT() {}
511 
513 
515 
516 
518  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
519  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
520  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
521  }
522 
524  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
525  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
526  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
527  }
528 
530  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &indices, const ArrayView<const Scalar> &values) {
531  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
532 
533  {
534  const std::string tfecfFuncName("replaceGlobalValues");
535  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
536  ": Fill must be active in order to call this method. If you have already "
537  "called fillComplete(), you need to call resumeFill() before you can "
538  "replace values.");
539 
540  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
541  std::runtime_error, ": values.size() must equal indices.size().");
542  }
543 
544  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
545  }
546 
548  void replaceLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &indices, const ArrayView<const Scalar> &values) {
549  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
550 
551  {
552  const std::string tfecfFuncName("replaceLocalValues");
553  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
554  ": Fill must be active in order to call this method. If you have already "
555  "called fillComplete(), you need to call resumeFill() before you can "
556  "replace values.");
557 
558  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
559  std::runtime_error, ": values.size() must equal indices.size().");
560  }
561 
562  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
563  }
564 
566  void setAllToScalar(const Scalar &alpha) {
567  XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar");
568  mtx_->PutScalar(alpha);
569  }
570 
572  void scale(const Scalar &alpha) {
573  XPETRA_MONITOR("EpetraCrsMatrixT::scale");
574  mtx_->Scale(alpha);
575  }
576 
578  //** \warning This is an expert-only routine and should not be called from user code. */
579  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {
580  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
581 
582  // Row offsets
583  // Unfortunately, we cannot do this in the same manner as column indices
584  // and values (see below). The problem is that Tpetra insists on using
585  // size_t, and Epetra uses int internally. So we only resize here, and
586  // will need to copy in setAllValues
587  rowptr.resize(getLocalNumRows() + 1);
588 
589  int lowerOffset = 0;
590  bool ownMemory = false;
591 
592  // Column indices
593  // Extract, resize, set colind
594  Epetra_IntSerialDenseVector &myColind = mtx_->ExpertExtractIndices();
595  myColind.Resize(numNonZeros);
596  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
597 
598  // Values
599  // Extract, reallocate, set values
600  double *&myValues = mtx_->ExpertExtractValues();
601  delete[] myValues;
602  myValues = new double[numNonZeros];
603  values = Teuchos::arcp(myValues, lowerOffset, numNonZeros, ownMemory);
604  }
605 
607  void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {
608  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
609 
610  // Check sizes
611  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
612  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
613  TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
614  "An exception is thrown to let you know that you mismatched your pointers.");
615 
616  // Check pointers
617  if (values.size() > 0) {
618  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
619  "An exception is thrown to let you know that you mismatched your pointers.");
620  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
621  "An exception is thrown to let you know that you mismatched your pointers.");
622  }
623 
624  // We have to make a copy here, it is unavoidable
625  // See comments in allocateAllValues
626  const size_t N = getLocalNumRows();
627 
628  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
629  myRowptr.Resize(N + 1);
630  for (size_t i = 0; i < N + 1; i++)
631  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
632  }
633 
635  void getAllValues(ArrayRCP<const size_t> &rowptr, ArrayRCP<const LocalOrdinal> &colind, ArrayRCP<const Scalar> &values) const {
636  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
637 
638  int lowerOffset = 0;
639  bool ownMemory = false;
640 
641  const size_t n = getLocalNumRows();
642  const size_t nnz = getLocalNumEntries();
643 
644  // Row offsets
645  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
646  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
647  rowptr.resize(n + 1);
648  for (size_t i = 0; i < n + 1; i++)
649  (*const_cast<size_t *>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
650 
651  // Column indices
652  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
653 
654  // Values
655  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
656  }
657 
659  void getAllValues(ArrayRCP<Scalar> &values) {
660  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
661 
662  int lowerOffset = 0;
663  bool ownMemory = false;
664 
665  const size_t nnz = getLocalNumEntries();
666  // Values
667  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
668  }
669 
670  // Epetra always has global constants
671  bool haveGlobalConstants() const { return true; }
673  //** \warning This is an expert-only routine and should not be called from user code. */
675  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
676  const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
677  const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
678  const RCP<ParameterList> & /* params */ = Teuchos::null) {
679  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
680 
681  // For Epetra matrices, resumeFill() is a fictive operation.
682  isFillResumed_ = false;
683 
684  int rv = 0;
685  const Epetra_Import *myimport = 0;
686  const Epetra_Export *myexport = 0;
687 
688  if (!importer.is_null()) {
689  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
690  myimport = eImporter.getEpetra_Import().getRawPtr();
691  }
692  if (!exporter.is_null()) {
693  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
694  myexport = eExporter.getEpetra_Export().getRawPtr();
695  }
696 
697  rv = mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), myimport, myexport);
698 
699  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
700  }
702 
704 
705 
707  void resumeFill(const RCP<ParameterList> & /* params */ = Teuchos::null) {
708  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
709 
710  // According to Tpetra documentation, resumeFill() may be called repeatedly.
711  isFillResumed_ = true;
712  }
713 
715  void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = Teuchos::null) {
716  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
717 
718  // For Epetra matrices, resumeFill() is a fictive operation.
719  isFillResumed_ = false;
720 
721  bool doOptimizeStorage = true;
722  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
723  mtx_->FillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), doOptimizeStorage);
724  }
725 
727  void fillComplete(const RCP<ParameterList> &params = Teuchos::null) {
728  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
729 
730  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
731  if (isFillResumed_ == true) {
732  isFillResumed_ = false;
733  return;
734  }
735 
736  bool doOptimizeStorage = true;
737  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
738  mtx_->FillComplete(doOptimizeStorage);
739  }
740 
742  void replaceDomainMapAndImporter(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newDomainMap, Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &newImporter) {
743  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
744  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
745 
746  const RCP<const Epetra_Import> &myImport = eImporter.getEpetra_Import();
747  int rv = 0;
748  if (myImport == Teuchos::null)
749  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), 0);
750  else
751  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), &*myImport);
752  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
753  }
754 
756 
758 
759 
761  const RCP<const Comm<int> > getComm() const {
762  XPETRA_MONITOR("EpetraCrsMatrixT::getComm");
763  return toXpetra(mtx_->Comm());
764  }
765 
767  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {
768  XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap");
769  return toXpetra<GlobalOrdinal, Node>(mtx_->RowMap());
770  }
771 
773  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const {
774  XPETRA_MONITOR("EpetraCrsMatrixT::getColMap");
775  return toXpetra<GlobalOrdinal, Node>(mtx_->ColMap());
776  }
777 
779  RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const {
780  XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph");
781  return toXpetra<GlobalOrdinal, Node>(mtx_->Graph());
782  }
783 
786  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows");
787  return mtx_->NumGlobalRows64();
788  }
789 
792  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols");
793  return mtx_->NumGlobalCols64();
794  }
795 
797  size_t getLocalNumRows() const {
798  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows");
799  return mtx_->NumMyRows();
800  }
801 
803  size_t getLocalNumCols() const {
804  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols");
805  return mtx_->NumMyCols();
806  }
807 
810  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries");
811  return mtx_->NumGlobalNonzeros64();
812  }
813 
815  size_t getLocalNumEntries() const {
816  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries");
817  return mtx_->NumMyNonzeros();
818  }
819 
821  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
822  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow");
823  return mtx_->NumMyEntries(localRow);
824  }
825 
827  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
828  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow");
829  return mtx_->NumGlobalEntries(globalRow);
830  }
831 
833  size_t getGlobalMaxNumRowEntries() const {
834  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries");
835  return mtx_->GlobalMaxNumEntries();
836  }
837 
839  size_t getLocalMaxNumRowEntries() const {
840  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries");
841  return mtx_->MaxNumEntries();
842  }
843 
845  bool isLocallyIndexed() const {
846  XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed");
847  return mtx_->IndicesAreLocal();
848  }
849 
851  bool isGloballyIndexed() const {
852  XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed");
853  return mtx_->IndicesAreGlobal();
854  }
855 
857  bool isFillComplete() const {
858  XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete");
859  if (isFillResumed_)
860  return false;
861  else
862  return mtx_->Filled();
863  }
864 
866  bool isFillActive() const {
867  XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive");
868  return !isFillComplete();
869  }
870 
872  ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const {
873  XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm");
874  return mtx_->NormFrobenius();
875  }
876 
878  bool supportsRowViews() const {
879  XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews");
880  return true;
881  }
882 
884  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
885  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
886 
887  int numEntries = -1;
888  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
889  NumEntries = numEntries;
890  }
891 
893  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
894  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
895 
896  int numEntries = -1;
897  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
898  NumEntries = numEntries;
899  }
900 
902  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
903  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
904 
905  int numEntries;
906  double *eValues;
907  GlobalOrdinal *eIndices;
908 
909  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
910  if (numEntries == 0) {
911  eValues = NULL;
912  eIndices = NULL;
913  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
914 
915  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
916  values = ArrayView<const double>(eValues, numEntries);
917  }
918 
920  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
921  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
922 
923  int numEntries;
924  double *eValues;
925  int *eIndices;
926 
927  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
928  if (numEntries == 0) {
929  eValues = NULL;
930  eIndices = NULL;
931  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
932 
933  indices = ArrayView<const int>(eIndices, numEntries);
934  values = ArrayView<const double>(eValues, numEntries);
935  }
936 
939  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
940  XPETRA_ERR_CHECK(mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal, Node>(diag)));
941  }
942 
944  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> & /* offsets */) const {
945  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
946  }
947 
949  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Teuchos::ArrayView<const size_t> & /* offsets */) const {
950  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
951  }
952 
954  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> & /* offsets */) const {
955  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
956  }
957 
960  mtx_->ReplaceDiagonalValues(toEpetra<GlobalOrdinal, Node>(diag));
961  }
962 
964  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal, Node>(x)));
965  };
967  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal, Node>(x)));
968  };
969 
971 
973 
974 
976  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 {
977  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
978 
979  // TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
980 
981  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
982  XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
983 
984  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");
985  bool eTrans = toEpetra(mode);
986 
987  // /!\ UseTranspose value
988  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.");
989 
990  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
991 
992  // helper vector: tmp = A*x
993  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
994  tmp->PutScalar(0.0);
995  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
996 
997  // calculate alpha * A * x + beta * y
998  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
999  }
1000 
1002  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 {
1003  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
1004  }
1005 
1007  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
1008  XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap");
1009  return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap());
1010  }
1011 
1013  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
1014  XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap");
1015  return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap());
1016  }
1017 
1019 
1021 
1022 
1024  std::string description() const {
1025  XPETRA_MONITOR("EpetraCrsMatrixT::description");
1026 
1027  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1028  std::ostringstream oss;
1029  // TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
1030  if (isFillComplete()) {
1031  oss << "{status = fill complete"
1032  << ", global rows = " << getGlobalNumRows()
1033  << ", global cols = " << getGlobalNumCols()
1034  << ", global num entries = " << getGlobalNumEntries()
1035  << "}";
1036  } else {
1037  oss << "{status = fill not complete"
1038  << ", global rows = " << getGlobalNumRows()
1039  << "}";
1040  }
1041  return oss.str();
1042  }
1043 
1045  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
1046  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
1047 
1048  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1049  using std::endl;
1050  using std::setw;
1051  using Teuchos::VERB_DEFAULT;
1052  using Teuchos::VERB_EXTREME;
1053  using Teuchos::VERB_HIGH;
1054  using Teuchos::VERB_LOW;
1055  using Teuchos::VERB_MEDIUM;
1056  using Teuchos::VERB_NONE;
1057  Teuchos::EVerbosityLevel vl = verbLevel;
1058  if (vl == VERB_DEFAULT) vl = VERB_LOW;
1059  RCP<const Comm<int> > comm = this->getComm();
1060  const int myImageID = comm->getRank(),
1061  numImages = comm->getSize();
1062  size_t width = 1;
1063  for (size_t dec = 10; dec < getGlobalNumRows(); dec *= 10) {
1064  ++width;
1065  }
1066  width = std::max<size_t>(width, 11) + 2;
1067  Teuchos::OSTab tab(out);
1068  // none: print nothing
1069  // low: print O(1) info from node 0
1070  // medium: print O(P) info, num entries per node
1071  // high: print O(N) info, num entries per row
1072  // extreme: print O(NNZ) info: print indices and values
1073  //
1074  // for medium and higher, print constituent objects at specified verbLevel
1075  if (vl != VERB_NONE) {
1076  if (myImageID == 0) out << this->description() << std::endl;
1077  // O(1) globals, minus what was already printed by description()
1078  if (isFillComplete() && myImageID == 0) {
1079  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1080  }
1081  // constituent objects
1082  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1083  if (myImageID == 0) out << "\nRow map: " << std::endl;
1084  getRowMap()->describe(out, vl);
1085  //
1086  if (getColMap() != null) {
1087  if (getColMap() == getRowMap()) {
1088  if (myImageID == 0) out << "\nColumn map is row map.";
1089  } else {
1090  if (myImageID == 0) out << "\nColumn map: " << std::endl;
1091  getColMap()->describe(out, vl);
1092  }
1093  }
1094  if (getDomainMap() != null) {
1095  if (getDomainMap() == getRowMap()) {
1096  if (myImageID == 0) out << "\nDomain map is row map.";
1097  } else if (getDomainMap() == getColMap()) {
1098  if (myImageID == 0) out << "\nDomain map is row map.";
1099  } else {
1100  if (myImageID == 0) out << "\nDomain map: " << std::endl;
1101  getDomainMap()->describe(out, vl);
1102  }
1103  }
1104  if (getRangeMap() != null) {
1105  if (getRangeMap() == getDomainMap()) {
1106  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1107  } else if (getRangeMap() == getRowMap()) {
1108  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1109  } else {
1110  if (myImageID == 0) out << "\nRange map: " << std::endl;
1111  getRangeMap()->describe(out, vl);
1112  }
1113  }
1114  if (myImageID == 0) out << std::endl;
1115  }
1116  // O(P) data
1117  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1118  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1119  if (myImageID == imageCtr) {
1120  out << "Node ID = " << imageCtr << std::endl;
1121  // TODO: need a graph
1122  // if (staticGraph_->indicesAreAllocated() == false) {
1123  // out << "Node not allocated" << std::endl;
1124  // }
1125  // else {
1126  // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
1127  // }
1128 
1129  // TMP:
1130  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1131  // End of TMP
1132 
1133  out << "Node number of entries = " << getLocalNumEntries() << std::endl;
1134  out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
1135  }
1136  comm->barrier();
1137  comm->barrier();
1138  comm->barrier();
1139  }
1140  }
1141  // O(N) and O(NNZ) data
1142  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1143  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1144  if (myImageID == imageCtr) {
1145  out << std::setw(width) << "Node ID"
1146  << std::setw(width) << "Global Row"
1147  << std::setw(width) << "Num Entries";
1148  if (vl == VERB_EXTREME) {
1149  out << std::setw(width) << "(Index,Value)";
1150  }
1151  out << std::endl;
1152  for (size_t r = 0; r < getLocalNumRows(); ++r) {
1153  const size_t nE = getNumEntriesInLocalRow(r);
1154  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1155  out << std::setw(width) << myImageID
1156  << std::setw(width) << gid
1157  << std::setw(width) << nE;
1158  if (vl == VERB_EXTREME) {
1159  if (isGloballyIndexed()) {
1160  ArrayView<const GlobalOrdinal> rowinds;
1161  ArrayView<const Scalar> rowvals;
1162  getGlobalRowView(gid, rowinds, rowvals);
1163  for (size_t j = 0; j < nE; ++j) {
1164  out << " (" << rowinds[j]
1165  << ", " << rowvals[j]
1166  << ") ";
1167  }
1168  } else if (isLocallyIndexed()) {
1169  ArrayView<const LocalOrdinal> rowinds;
1170  ArrayView<const Scalar> rowvals;
1171  getLocalRowView(r, rowinds, rowvals);
1172  for (size_t j = 0; j < nE; ++j) {
1173  out << " (" << getColMap()->getGlobalElement(rowinds[j])
1174  << ", " << rowvals[j]
1175  << ") ";
1176  }
1177  }
1178  }
1179  out << std::endl;
1180  }
1181  }
1182  comm->barrier();
1183  comm->barrier();
1184  comm->barrier();
1185  }
1186  }
1187  }
1188  }
1189 
1190  void setObjectLabel(const std::string &objectLabel) {
1191  Teuchos::LabeledObject::setObjectLabel(objectLabel);
1192  mtx_->SetLabel(objectLabel.c_str());
1193  }
1195 
1198  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_))))
1199  , isFillResumed_(false) {}
1200 
1202  //{@
1203 
1205  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getMap() const {
1206  XPETRA_MONITOR("EpetraCrsMatrixT::getMap");
1207  return toXpetra<GlobalOrdinal, Node>(mtx_->Map());
1208  }
1209 
1213  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1214 
1215  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1216  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1217 
1218  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1219  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1220  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1221  }
1222 
1226  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1227 
1228  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1229  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1230 
1231  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1232  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1233  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1234  }
1235 
1239  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1240 
1241  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1242  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1243 
1244  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1245  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1246  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1247  }
1248 
1252  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1253 
1254  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1255  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1256 
1257  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1258  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1259  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1260  }
1261 
1262  void removeEmptyProcessesInPlace(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newMap) {
1263  XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
1264  const Epetra_Map *newMapEpetra = (!newMap.is_null()) ? &toEpetra<GlobalOrdinal, Node>(newMap) : 0;
1265  int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
1266  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1267  }
1268 
1270 
1272 
1273 
1275  bool hasMatrix() const { return !mtx_.is_null(); }
1276 
1278  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix> &mtx)
1279  : mtx_(mtx)
1280  , isFillResumed_(false) {}
1281 
1283  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
1284 
1286  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } // TODO: remove
1287 
1288 #ifdef HAVE_XPETRA_TPETRA
1289 
1292 #if 0
1293  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented,
1294  "Xpetra::EpetraCrsMatrx only available on host for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
1295  TEUCHOS_UNREACHABLE_RETURN((local_matrix_type()));
1296 #endif
1297  return getLocalMatrixHost();
1298  }
1299 
1300  typename local_matrix_type::HostMirror getLocalMatrixHost() const {
1301  RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
1302 
1303  const int numRows = matrix->NumMyRows();
1304  const int numCols = matrix->NumMyCols();
1305  const int nnz = matrix->NumMyNonzeros();
1306 
1307  int *rowptr;
1308  int *colind;
1309  double *vals;
1310  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1311  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1312 
1313  // Transform int* rowptr array to size_type* array
1314  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows + 1);
1315  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1316  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
1317 
1318  // create Kokkos::Views
1319  typename local_matrix_type::index_type kokkosColind(colind, nnz);
1320  typename local_matrix_type::values_type kokkosVals(vals, nnz);
1321 
1322  local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1323 
1324  return localMatrix;
1325  }
1326 
1327  void setAllValues(const typename local_matrix_type::row_map_type &ptr,
1328  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
1329  const typename local_matrix_type::values_type &val) {
1330  // Check sizes
1331  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(ptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
1332  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1333  TEUCHOS_TEST_FOR_EXCEPTION(val.size() != ind.size(), Xpetra::Exceptions::RuntimeError,
1334  "An exception is thrown to let you know that you mismatched your pointers.");
1335 
1336  // Check pointers
1337  if (val.size() > 0) {
1338  std::cout << ind.data() << " " << mtx_->ExpertExtractIndices().Values() << std::endl;
1339  TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1340  "An exception is thrown to let you know that you mismatched your pointers.");
1341  TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1342  "An exception is thrown to let you know that you mismatched your pointers.");
1343  }
1344 
1345  // We have to make a copy here, it is unavoidable
1346  // See comments in allocateAllValues
1347  const size_t N = getLocalNumRows();
1348 
1349  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1350  myRowptr.Resize(N + 1);
1351  for (size_t i = 0; i < N + 1; i++)
1352  myRowptr[i] = Teuchos::as<int>(ptr(i));
1353  }
1354 
1355  LocalOrdinal GetStorageBlockSize() const { return 1; }
1356 
1357  private:
1358 #else
1359 #ifdef __GNUC__
1360 #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."
1361 #endif
1362 #endif
1363 
1364 
1368  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
1369 
1370  apply(X, R);
1371  R.update(one, B, negone);
1372  }
1373 
1374  private:
1376  RCP<Epetra_CrsMatrix> mtx_;
1377 
1385 
1386 }; // EpetraCrsMatrixT class
1387 
1388 #endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1389 
1390 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1391 template <>
1392 class EpetraCrsMatrixT<long long, EpetraNode>
1393  : public CrsMatrix<double, int, long long, EpetraNode> {
1394  typedef long long GlobalOrdinal;
1395  typedef EpetraNode Node;
1398 
1399  // The following typedefs are used by the Kokkos interface
1400 #ifdef HAVE_XPETRA_TPETRA
1403 #endif
1404 
1405  public:
1407 
1408 
1410  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1411  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), maxNumEntriesPerRow, true)))
1412  , isFillResumed_(false) {}
1413 
1415  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1416  : isFillResumed_(false) {
1417  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1418  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1419  }
1420 
1422  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)
1423  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), maxNumEntriesPerRow, true)))
1424  , isFillResumed_(false) {}
1425 
1427  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)
1428  : isFillResumed_(false) {
1429  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1430  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1431  }
1432 
1434  EpetraCrsMatrixT(const Teuchos::RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1435  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(graph))))
1436  , isFillResumed_(false) {}
1437 
1441  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1442  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1443  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
1444  : isFillResumed_(false) {
1445  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1446  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1447 
1448  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1449  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1450 
1451  // Follows the Tpetra parameters
1452  bool restrictComm = false;
1453  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1454  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), myDomainMap, myRangeMap, restrictComm));
1455  if (restrictComm && mtx_->NumMyRows() == 0)
1456  mtx_ = Teuchos::null;
1457  }
1458 
1462  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1463  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1464  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
1465  : isFillResumed_(false) {
1466  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1467  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1468 
1469  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1470  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1471 
1472  // Follows the Tpetra parameters
1473  bool restrictComm = false;
1474  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1475 
1476  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), myDomainMap, myRangeMap, restrictComm));
1477  }
1478 
1480  const Import<LocalOrdinal, GlobalOrdinal, Node> &RowImporter,
1481  const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
1482  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
1483  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1484  const Teuchos::RCP<Teuchos::ParameterList> &params)
1485  : isFillResumed_(false) {
1486  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1487  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1488  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1489 
1490  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1491  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1492 
1493  // Follows the Tpetra parameters
1494  bool restrictComm = false;
1495  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1496  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), tdImporter->getEpetra_Import().get(), myDomainMap, myRangeMap, restrictComm));
1497  if (restrictComm && mtx_->NumMyRows() == 0)
1498  mtx_ = Teuchos::null;
1499  }
1500 
1502  const Export<LocalOrdinal, GlobalOrdinal, Node> &RowExporter,
1503  const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
1504  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
1505  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1506  const Teuchos::RCP<Teuchos::ParameterList> &params)
1507  : isFillResumed_(false) {
1508  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1509  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1510  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1511 
1512  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1513  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1514 
1515  // Follows the Tpetra parameters
1516  bool restrictComm = false;
1517  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1518 
1519  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), tdExporter->getEpetra_Export().get(), myDomainMap, myRangeMap, restrictComm));
1520  }
1521 
1522 #ifdef HAVE_XPETRA_TPETRA
1523  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
1544  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
1545  const local_matrix_type &lclMatrix,
1546  const Teuchos::RCP<Teuchos::ParameterList> &params = null)
1547  : EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params) {}
1548 
1550  const local_matrix_type &lclMatrix,
1551  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
1552  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
1553  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1554  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1555  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
1556  // local typedefs from local_matrix_type
1557  // typedef typename local_matrix_type::size_type size_type;
1558  typedef typename local_matrix_type::value_type value_type;
1559  typedef typename local_matrix_type::ordinal_type ordinal_type;
1560 
1561  // The number of rows in the sparse matrix.
1562  ordinal_type lclNumRows = lclMatrix.numRows();
1563  ordinal_type lclNumCols = lclMatrix.numCols(); // do we need this?
1564 
1565  // plausibility checks
1566  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
1567  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1568  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
1569  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1570 
1571  Teuchos::ArrayRCP<size_t> NumEntriesPerRowToAlloc(lclNumRows);
1572  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1573  // extract data from current row r
1574  auto rowview = lclMatrix.row(r);
1575  NumEntriesPerRowToAlloc[r] = rowview.length;
1576  }
1577 
1578  // setup matrix
1579  isFillResumed_ = false;
1580  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1581  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1582 
1583  // loop over all rows and colums of local matrix and fill matrix
1584  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1585  // extract data from current row r
1586  auto rowview = lclMatrix.row(r);
1587 
1588  // arrays for current row data
1589  Teuchos::ArrayRCP<ordinal_type> indout(rowview.length, Teuchos::ScalarTraits<ordinal_type>::zero());
1590  Teuchos::ArrayRCP<value_type> valout(rowview.length, Teuchos::ScalarTraits<value_type>::zero());
1591 
1592  for (ordinal_type c = 0; c < rowview.length; c++) {
1593  value_type value = rowview.value(c);
1594  ordinal_type colidx = rowview.colidx(c);
1595 
1596  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!");
1597 
1598  indout[c] = colidx;
1599  valout[c] = value;
1600  }
1601  insertLocalValues(r, indout.view(0, indout.size()), valout.view(0, valout.size()));
1602  }
1603 
1604  // call fill complete
1605  if (!domainMap.is_null() && !rangeMap.is_null())
1606  this->fillComplete(domainMap, rowMap, params);
1607  else
1608  this->fillComplete(rowMap, rowMap, params);
1609  }
1610 #endif
1611 
1613  virtual ~EpetraCrsMatrixT() {}
1614 
1616 
1618 
1619 
1621  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1622  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1623  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1624  }
1625 
1627  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1628  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1629  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1630  }
1631 
1633  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &indices, const ArrayView<const Scalar> &values) {
1634  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1635 
1636  {
1637  const std::string tfecfFuncName("replaceGlobalValues");
1638  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
1639  ": Fill must be active in order to call this method. If you have already "
1640  "called fillComplete(), you need to call resumeFill() before you can "
1641  "replace values.");
1642 
1643  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1644  std::runtime_error, ": values.size() must equal indices.size().");
1645  }
1646 
1647  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1648  }
1649 
1651  void replaceLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &indices, const ArrayView<const Scalar> &values) {
1652  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
1653 
1654  {
1655  const std::string tfecfFuncName("replaceLocalValues");
1656  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
1657  ": Fill must be active in order to call this method. If you have already "
1658  "called fillComplete(), you need to call resumeFill() before you can "
1659  "replace values.");
1660 
1661  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1662  std::runtime_error, ": values.size() must equal indices.size().");
1663  }
1664 
1665  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1666  }
1667 
1669  void setAllToScalar(const Scalar &alpha) {
1670  XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar");
1671  mtx_->PutScalar(alpha);
1672  }
1673 
1675  void scale(const Scalar &alpha) {
1676  XPETRA_MONITOR("EpetraCrsMatrixT::scale");
1677  mtx_->Scale(alpha);
1678  }
1679 
1681  //** \warning This is an expert-only routine and should not be called from user code. */
1682  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {
1683  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1684 
1685  // Row offsets
1686  // Unfortunately, we cannot do this in the same manner as column indices
1687  // and values (see below). The problem is that Tpetra insists on using
1688  // size_t, and Epetra uses int internally. So we only resize here, and
1689  // will need to copy in setAllValues
1690  rowptr.resize(getLocalNumRows() + 1);
1691 
1692  int lowerOffset = 0;
1693  bool ownMemory = false;
1694 
1695  // Column indices
1696  // Extract, resize, set colind
1697  Epetra_IntSerialDenseVector &myColind = mtx_->ExpertExtractIndices();
1698  myColind.Resize(numNonZeros);
1699  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1700 
1701  // Values
1702  // Extract, reallocate, set values
1703  double *&myValues = mtx_->ExpertExtractValues();
1704  delete[] myValues;
1705  myValues = new double[numNonZeros];
1706  values = Teuchos::arcp(myValues, lowerOffset, numNonZeros, ownMemory);
1707  }
1708 
1710  void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {
1711  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1712 
1713  // Check sizes
1714  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
1715  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1716  TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
1717  "An exception is thrown to let you know that you mismatched your pointers.");
1718 
1719  // Check pointers
1720  if (values.size() > 0) {
1721  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1722  "An exception is thrown to let you know that you mismatched your pointers.");
1723  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1724  "An exception is thrown to let you know that you mismatched your pointers.");
1725  }
1726 
1727  // We have to make a copy here, it is unavoidable
1728  // See comments in allocateAllValues
1729  const size_t N = getLocalNumRows();
1730 
1731  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1732  myRowptr.Resize(N + 1);
1733  for (size_t i = 0; i < N + 1; i++)
1734  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1735  }
1736 
1738  void getAllValues(ArrayRCP<const size_t> &rowptr, ArrayRCP<const LocalOrdinal> &colind, ArrayRCP<const Scalar> &values) const {
1739  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1740 
1741  int lowerOffset = 0;
1742  bool ownMemory = false;
1743 
1744  const size_t n = getLocalNumRows();
1745  const size_t nnz = getLocalNumEntries();
1746 
1747  // Row offsets
1748  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1749  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1750  rowptr.resize(n + 1);
1751  for (size_t i = 0; i < n + 1; i++)
1752  (*const_cast<size_t *>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1753 
1754  // Column indices
1755  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1756 
1757  // Values
1758  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1759  }
1760 
1762  void getAllValues(ArrayRCP<Scalar> &values) {
1763  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1764 
1765  int lowerOffset = 0;
1766  bool ownMemory = false;
1767 
1768  const size_t nnz = getLocalNumEntries();
1769  // Values
1770  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1771  }
1772 
1773  // Epetra always has global constants
1774  bool haveGlobalConstants() const { return true; }
1775 
1777  //** \warning This is an expert-only routine and should not be called from user code. */
1779  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1780  const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
1781  const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
1782  const RCP<ParameterList> & /* params */ = Teuchos::null) {
1783  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1784 
1785  // For Epetra matrices, resumeFill() is a fictive operation.
1786  isFillResumed_ = false;
1787 
1788  int rv = 0;
1789  const Epetra_Import *myimport = 0;
1790  const Epetra_Export *myexport = 0;
1791 
1792  if (!importer.is_null()) {
1793  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1794  myimport = eImporter.getEpetra_Import().getRawPtr();
1795  }
1796  if (!exporter.is_null()) {
1797  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1798  myexport = eExporter.getEpetra_Export().getRawPtr();
1799  }
1800 
1801  rv = mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), myimport, myexport);
1802 
1803  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1804  }
1806 
1808 
1809 
1811  void resumeFill(const RCP<ParameterList> & /* params */ = Teuchos::null) {
1812  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1813 
1814  // According to Tpetra documentation, resumeFill() may be called repeatedly.
1815  isFillResumed_ = true;
1816  }
1817 
1819  void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = Teuchos::null) {
1820  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1821 
1822  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1823  if (isFillResumed_ == true) {
1824  isFillResumed_ = false;
1825  return;
1826  }
1827 
1828  bool doOptimizeStorage = true;
1829  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
1830  mtx_->FillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), doOptimizeStorage);
1831  }
1832 
1834  void fillComplete(const RCP<ParameterList> &params = Teuchos::null) {
1835  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1836 
1837  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1838  if (isFillResumed_ == true) {
1839  isFillResumed_ = false;
1840  return;
1841  }
1842 
1843  bool doOptimizeStorage = true;
1844  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
1845  mtx_->FillComplete(doOptimizeStorage);
1846  }
1847 
1849  void replaceDomainMapAndImporter(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newDomainMap, Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &newImporter) {
1850  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1851  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1852 
1853  const RCP<const Epetra_Import> &myImport = eImporter.getEpetra_Import();
1854  int rv = 0;
1855  if (myImport == Teuchos::null)
1856  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), 0);
1857  else
1858  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), &*myImport);
1859  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1860  }
1861 
1863 
1865 
1866 
1868  const RCP<const Comm<int> > getComm() const {
1869  XPETRA_MONITOR("EpetraCrsMatrixT::getComm");
1870  return toXpetra(mtx_->Comm());
1871  }
1872 
1874  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {
1875  XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap");
1876  return toXpetra<GlobalOrdinal, Node>(mtx_->RowMap());
1877  }
1878 
1880  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const {
1881  XPETRA_MONITOR("EpetraCrsMatrixT::getColMap");
1882  return toXpetra<GlobalOrdinal, Node>(mtx_->ColMap());
1883  }
1884 
1886  RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const {
1887  XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph");
1888  return toXpetra<GlobalOrdinal, Node>(mtx_->Graph());
1889  }
1890 
1893  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows");
1894  return mtx_->NumGlobalRows64();
1895  }
1896 
1899  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols");
1900  return mtx_->NumGlobalCols64();
1901  }
1902 
1904  size_t getLocalNumRows() const {
1905  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows");
1906  return mtx_->NumMyRows();
1907  }
1908 
1910  size_t getLocalNumCols() const {
1911  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols");
1912  return mtx_->NumMyCols();
1913  }
1914 
1917  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries");
1918  return mtx_->NumGlobalNonzeros64();
1919  }
1920 
1922  size_t getLocalNumEntries() const {
1923  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries");
1924  return mtx_->NumMyNonzeros();
1925  }
1926 
1928  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
1929  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow");
1930  return mtx_->NumMyEntries(localRow);
1931  }
1932 
1934  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
1935  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow");
1936  return mtx_->NumGlobalEntries(globalRow);
1937  }
1938 
1940  size_t getGlobalMaxNumRowEntries() const {
1941  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries");
1942  return mtx_->GlobalMaxNumEntries();
1943  }
1944 
1946  size_t getLocalMaxNumRowEntries() const {
1947  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries");
1948  return mtx_->MaxNumEntries();
1949  }
1950 
1952  bool isLocallyIndexed() const {
1953  XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed");
1954  return mtx_->IndicesAreLocal();
1955  }
1956 
1958  bool isGloballyIndexed() const {
1959  XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed");
1960  return mtx_->IndicesAreGlobal();
1961  }
1962 
1964  bool isFillComplete() const {
1965  XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete");
1966  if (isFillResumed_)
1967  return false;
1968  else
1969  return mtx_->Filled();
1970  }
1971 
1973  bool isFillActive() const {
1974  XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive");
1975  return !isFillComplete();
1976  }
1977 
1979  typename ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const {
1980  XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm");
1981  return mtx_->NormFrobenius();
1982  }
1983 
1985  bool supportsRowViews() const {
1986  XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews");
1987  return true;
1988  }
1989 
1991  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1992  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1993 
1994  int numEntries = -1;
1995  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1996  NumEntries = numEntries;
1997  }
1998 
2000  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
2001  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
2002 
2003  int numEntries = -1;
2004  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
2005  NumEntries = numEntries;
2006  }
2007 
2009  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
2010  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
2011 
2012  int numEntries;
2013  double *eValues;
2014  GlobalOrdinal *eIndices;
2015 
2016  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
2017  if (numEntries == 0) {
2018  eValues = NULL;
2019  eIndices = NULL;
2020  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
2021 
2022  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
2023  values = ArrayView<const double>(eValues, numEntries);
2024  }
2025 
2027  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
2028  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
2029 
2030  int numEntries;
2031  double *eValues;
2032  int *eIndices;
2033 
2034  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
2035  if (numEntries == 0) {
2036  eValues = NULL;
2037  eIndices = NULL;
2038  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
2039 
2040  indices = ArrayView<const int>(eIndices, numEntries);
2041  values = ArrayView<const double>(eValues, numEntries);
2042  }
2043 
2046  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
2047  mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal, Node>(diag));
2048  }
2049 
2051  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> & /* offsets */) const {
2052  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
2053  }
2054 
2056  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Teuchos::ArrayView<const size_t> & /* offsets */) const {
2057  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
2058  }
2059 
2061  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> & /* offsets */) const {
2062  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
2063  }
2064 
2067  mtx_->ReplaceDiagonalValues(toEpetra<GlobalOrdinal, Node>(diag));
2068  }
2069 
2071  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal, Node>(x)));
2072  };
2074  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal, Node>(x)));
2075  };
2076 
2078 
2080 
2081 
2083  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 {
2084  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
2085 
2086  // TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
2087 
2088  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
2089  XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
2090 
2091  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");
2092  bool eTrans = toEpetra(mode);
2093 
2094  // /!\ UseTranspose value
2095  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.");
2096 
2097  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
2098 
2099  // helper vector: tmp = A*x
2100  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
2101  tmp->PutScalar(0.0);
2102  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
2103 
2104  // calculate alpha * A * x + beta * y
2105  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
2106  }
2107 
2108  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 {
2109  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
2110  }
2111 
2113  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
2114  XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap");
2115  return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap());
2116  }
2117 
2119  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
2120  XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap");
2121  return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap());
2122  }
2123 
2125 
2127 
2128 
2130  std::string description() const {
2131  XPETRA_MONITOR("EpetraCrsMatrixT::description");
2132 
2133  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2134  std::ostringstream oss;
2135  // TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
2136  if (isFillComplete()) {
2137  oss << "{status = fill complete"
2138  << ", global rows = " << getGlobalNumRows()
2139  << ", global cols = " << getGlobalNumCols()
2140  << ", global num entries = " << getGlobalNumEntries()
2141  << "}";
2142  } else {
2143  oss << "{status = fill not complete"
2144  << ", global rows = " << getGlobalNumRows()
2145  << "}";
2146  }
2147  return oss.str();
2148  }
2149 
2151  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
2152  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
2153 
2154  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2155  using std::endl;
2156  using std::setw;
2157  using Teuchos::VERB_DEFAULT;
2158  using Teuchos::VERB_EXTREME;
2159  using Teuchos::VERB_HIGH;
2160  using Teuchos::VERB_LOW;
2161  using Teuchos::VERB_MEDIUM;
2162  using Teuchos::VERB_NONE;
2163  Teuchos::EVerbosityLevel vl = verbLevel;
2164  if (vl == VERB_DEFAULT) vl = VERB_LOW;
2165  RCP<const Comm<int> > comm = this->getComm();
2166  const int myImageID = comm->getRank(),
2167  numImages = comm->getSize();
2168  size_t width = 1;
2169  for (size_t dec = 10; dec < getGlobalNumRows(); dec *= 10) {
2170  ++width;
2171  }
2172  width = std::max<size_t>(width, 11) + 2;
2173  Teuchos::OSTab tab(out);
2174  // none: print nothing
2175  // low: print O(1) info from node 0
2176  // medium: print O(P) info, num entries per node
2177  // high: print O(N) info, num entries per row
2178  // extreme: print O(NNZ) info: print indices and values
2179  //
2180  // for medium and higher, print constituent objects at specified verbLevel
2181  if (vl != VERB_NONE) {
2182  if (myImageID == 0) out << this->description() << std::endl;
2183  // O(1) globals, minus what was already printed by description()
2184  if (isFillComplete() && myImageID == 0) {
2185  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
2186  }
2187  // constituent objects
2188  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2189  if (myImageID == 0) out << "\nRow map: " << std::endl;
2190  getRowMap()->describe(out, vl);
2191  //
2192  if (getColMap() != null) {
2193  if (getColMap() == getRowMap()) {
2194  if (myImageID == 0) out << "\nColumn map is row map.";
2195  } else {
2196  if (myImageID == 0) out << "\nColumn map: " << std::endl;
2197  getColMap()->describe(out, vl);
2198  }
2199  }
2200  if (getDomainMap() != null) {
2201  if (getDomainMap() == getRowMap()) {
2202  if (myImageID == 0) out << "\nDomain map is row map.";
2203  } else if (getDomainMap() == getColMap()) {
2204  if (myImageID == 0) out << "\nDomain map is row map.";
2205  } else {
2206  if (myImageID == 0) out << "\nDomain map: " << std::endl;
2207  getDomainMap()->describe(out, vl);
2208  }
2209  }
2210  if (getRangeMap() != null) {
2211  if (getRangeMap() == getDomainMap()) {
2212  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
2213  } else if (getRangeMap() == getRowMap()) {
2214  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
2215  } else {
2216  if (myImageID == 0) out << "\nRange map: " << std::endl;
2217  getRangeMap()->describe(out, vl);
2218  }
2219  }
2220  if (myImageID == 0) out << std::endl;
2221  }
2222  // O(P) data
2223  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2224  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2225  if (myImageID == imageCtr) {
2226  out << "Node ID = " << imageCtr << std::endl;
2227  // TODO: need a graph
2228  // if (staticGraph_->indicesAreAllocated() == false) {
2229  // out << "Node not allocated" << std::endl;
2230  // }
2231  // else {
2232  // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
2233  // }
2234 
2235  // TMP:
2236  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2237  // End of TMP
2238 
2239  out << "Node number of entries = " << getLocalNumEntries() << std::endl;
2240  out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
2241  }
2242  comm->barrier();
2243  comm->barrier();
2244  comm->barrier();
2245  }
2246  }
2247  // O(N) and O(NNZ) data
2248  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2249  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2250  if (myImageID == imageCtr) {
2251  out << std::setw(width) << "Node ID"
2252  << std::setw(width) << "Global Row"
2253  << std::setw(width) << "Num Entries";
2254  if (vl == VERB_EXTREME) {
2255  out << std::setw(width) << "(Index,Value)";
2256  }
2257  out << std::endl;
2258  for (size_t r = 0; r < getLocalNumRows(); ++r) {
2259  const size_t nE = getNumEntriesInLocalRow(r);
2260  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2261  out << std::setw(width) << myImageID
2262  << std::setw(width) << gid
2263  << std::setw(width) << nE;
2264  if (vl == VERB_EXTREME) {
2265  if (isGloballyIndexed()) {
2266  ArrayView<const GlobalOrdinal> rowinds;
2267  ArrayView<const Scalar> rowvals;
2268  getGlobalRowView(gid, rowinds, rowvals);
2269  for (size_t j = 0; j < nE; ++j) {
2270  out << " (" << rowinds[j]
2271  << ", " << rowvals[j]
2272  << ") ";
2273  }
2274  } else if (isLocallyIndexed()) {
2275  ArrayView<const LocalOrdinal> rowinds;
2276  ArrayView<const Scalar> rowvals;
2277  getLocalRowView(r, rowinds, rowvals);
2278  for (size_t j = 0; j < nE; ++j) {
2279  out << " (" << getColMap()->getGlobalElement(rowinds[j])
2280  << ", " << rowvals[j]
2281  << ") ";
2282  }
2283  }
2284  }
2285  out << std::endl;
2286  }
2287  }
2288  comm->barrier();
2289  comm->barrier();
2290  comm->barrier();
2291  }
2292  }
2293  }
2294  }
2295 
2296  void setObjectLabel(const std::string &objectLabel) {
2297  Teuchos::LabeledObject::setObjectLabel(objectLabel);
2298  mtx_->SetLabel(objectLabel.c_str());
2299  }
2301 
2304  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_))))
2305  , isFillResumed_(false) {}
2306 
2308  //{@
2309 
2311  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getMap() const {
2312  XPETRA_MONITOR("EpetraCrsMatrixT::getMap");
2313  return toXpetra<GlobalOrdinal, Node>(mtx_->Map());
2314  }
2315 
2319  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2320 
2321  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2322  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2323 
2324  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2325  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2326  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2327  }
2328 
2332  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2333 
2334  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2335  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2336 
2337  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2338  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2339  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2340  }
2341 
2345  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2346 
2347  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2348  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2349 
2350  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2351  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2352  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2353  }
2354 
2358  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2359 
2360  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2361  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2362 
2363  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2364  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2365  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2366  }
2367 
2368  void removeEmptyProcessesInPlace(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newMap) {
2369  XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
2370  const Epetra_Map *newMapEpetra = (!newMap.is_null()) ? &toEpetra<GlobalOrdinal, Node>(newMap) : 0;
2371  int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
2372  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
2373  }
2374 
2376 
2378 
2379 
2381  bool hasMatrix() const { return !mtx_.is_null(); }
2382 
2384  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix> &mtx)
2385  : mtx_(mtx)
2386  , isFillResumed_(false) {}
2387 
2389  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
2390 
2392  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } // TODO: remove
2393 
2394 #ifdef HAVE_XPETRA_TPETRA
2395  local_matrix_type getLocalMatrix() const {
2397  RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
2398 
2399  const int numRows = matrix->NumMyRows();
2400  const int numCols = matrix->NumMyCols();
2401  const int nnz = matrix->NumMyNonzeros();
2402 
2403  int *rowptr;
2404  int *colind;
2405  double *vals;
2406  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2407  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2408 
2409  // Transform int* rowptr array to size_type* array
2410  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows + 1);
2411  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2412  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
2413 
2414  // create Kokkos::Views
2415  typename local_matrix_type::index_type kokkosColind(colind, nnz);
2416  typename local_matrix_type::values_type kokkosVals(vals, nnz);
2417 
2418  local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2419 
2420  return localMatrix;
2421  }
2422 
2423  void setAllValues(const typename local_matrix_type::row_map_type &ptr,
2424  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
2425  const typename local_matrix_type::values_type &val) {
2426  // Check sizes
2427  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(ptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
2428  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
2429  TEUCHOS_TEST_FOR_EXCEPTION(val.size() != ind.size(), Xpetra::Exceptions::RuntimeError,
2430  "An exception is thrown to let you know that you mismatched your pointers.");
2431 
2432  // Check pointers
2433  if (val.size() > 0) {
2434  TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
2435  "An exception is thrown to let you know that you mismatched your pointers.");
2436  TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
2437  "An exception is thrown to let you know that you mismatched your pointers.");
2438  }
2439 
2440  // We have to make a copy here, it is unavoidable
2441  // See comments in allocateAllValues
2442  const size_t N = getLocalNumRows();
2443 
2444  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
2445  myRowptr.Resize(N + 1);
2446  for (size_t i = 0; i < N + 1; i++)
2447  myRowptr[i] = Teuchos::as<int>(ptr(i));
2448  }
2449 
2450  LocalOrdinal GetStorageBlockSize() const { return 1; }
2451 
2452  private:
2453 #else
2454 #ifdef __GNUC__
2455 #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."
2456 #endif
2457 #endif
2458 
2460 
2464  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
2465  apply(X, R);
2466  R.update(one, B, negone);
2467  }
2468 
2469  private:
2470  RCP<Epetra_CrsMatrix> mtx_;
2471 
2472  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.
2473 
2474 }; // EpetraCrsMatrixT class
2475 
2476 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2477 
2478 } // namespace Xpetra
2479 
2480 #define XPETRA_EPETRACRSMATRIX_SHORT
2481 #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)