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 namespace Xpetra {
73 
74 // general implementation: empty stub
75 template <class EpetraGlobalOrdinal, class Node>
77  : public CrsMatrix<double, int, EpetraGlobalOrdinal, Node> {
78  typedef EpetraGlobalOrdinal GlobalOrdinal;
81 
82 #ifdef HAVE_XPETRA_TPETRA
85 #endif
86 
87  public:
88  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
89  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
90  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
91  }
92  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
93  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
94  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
95  }
96  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."); }
97  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."); }
98  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."); }
101  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
102  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
103  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
104  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
105  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
106  }
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 Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
118  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
119  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
120  const Teuchos::RCP<Teuchos::ParameterList> &params) {
121  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
122  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
123  }
126  const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
127  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
128  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
129  const Teuchos::RCP<Teuchos::ParameterList> &params) {
130  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
131  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
132  }
133 #ifdef HAVE_XPETRA_TPETRA
134  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
135  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
136  const local_matrix_type &lclMatrix,
137  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
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  }
142  const local_matrix_type &lclMatrix,
143  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
144  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
145  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
146  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
147  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
148  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
149  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
150  }
151 #endif
152  virtual ~EpetraCrsMatrixT() {}
153 
154  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
155  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
156  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
157  void replaceLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {}
158  void setAllToScalar(const Scalar &alpha) {}
159  void scale(const Scalar &alpha) {}
160  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {}
161  void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {}
162  void getAllValues(ArrayRCP<const size_t> &rowptr, ArrayRCP<const LocalOrdinal> &colind, ArrayRCP<const Scalar> &values) const {}
163  void getAllValues(ArrayRCP<Scalar> &values) {}
164  bool haveGlobalConstants() const { return true; }
166  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
167  const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
168  const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
169  const RCP<ParameterList> &params = Teuchos::null) {}
170 
171  void resumeFill(const RCP<ParameterList> &params = null) {}
172  void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = null) {}
173  void fillComplete(const RCP<ParameterList> &params = null) {}
174  void replaceDomainMapAndImporter(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newDomainMap, Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &newImporter) {}
175  const RCP<const Comm<int> > getComm() const { return Teuchos::null; }
176  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { return Teuchos::null; }
177  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { return Teuchos::null; }
178  RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { return Teuchos::null; }
179  global_size_t getGlobalNumRows() const { return 0; }
180  global_size_t getGlobalNumCols() const { return 0; }
181  size_t getLocalNumRows() const { return 0; }
182  size_t getLocalNumCols() const { return 0; }
183  global_size_t getGlobalNumEntries() const { return 0; }
184  size_t getLocalNumEntries() const { return 0; }
185  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { return 0; }
186  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { return 0; }
187  size_t getGlobalMaxNumRowEntries() const { return 0; }
188  size_t getLocalMaxNumRowEntries() const { return 0; }
189  bool isLocallyIndexed() const { return false; }
190  bool isGloballyIndexed() const { return false; }
191  bool isFillComplete() const { return false; }
192  bool isFillActive() const { return false; }
193  typename ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const { return ScalarTraits<Scalar>::magnitude(ScalarTraits<Scalar>::zero()); }
194  bool supportsRowViews() const { return false; }
195  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {}
196  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {}
197  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {}
198  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {}
200  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &offsets) const {}
201  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &diag, const Teuchos::ArrayView<const size_t> &offsets) const {}
202  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &diag, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> &offsets) const {}
206 
207  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 {}
208  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 {}
209  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const { return Teuchos::null; }
210  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const { return Teuchos::null; }
211 
212  std::string description() const { return std::string(""); }
213  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {}
214  void setObjectLabel(const std::string &objectLabel) {}
215 
217  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
218  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
219  }
220 
221  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getMap() const { return Teuchos::null; }
226  void removeEmptyProcessesInPlace(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newMap) {}
227 
228  bool hasMatrix() const { return false; }
229  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix> &mtx) {
230  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
231  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
232  }
233  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
234  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } // TODO: remove
235 #ifdef HAVE_XPETRA_TPETRA
237  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
238  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
239  }
240  typename local_matrix_type::HostMirror getLocalMatrixHost() const {
241  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
242  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
243  }
244 
245  void setAllValues(const typename local_matrix_type::row_map_type &ptr,
246  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
247  const typename local_matrix_type::values_type &val) {
248  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
249  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
250  }
251 
252  LocalOrdinal GetStorageBlockSize() const { return 1; }
253 
254 #else
255 #ifdef __GNUC__
256 #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."
257 #endif
258 #endif
259 
263  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
264  apply(X, R);
265  R.update(one, B, negone);
266  }
267 
268 }; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
269 
270 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
271 template <>
273  : public CrsMatrix<double, int, int, EpetraNode> {
274  typedef int GlobalOrdinal;
275  typedef EpetraNode Node;
278 
279  // The following typedefs are used by the Kokkos interface
280 #ifdef HAVE_XPETRA_TPETRA
283 #endif
284 
285  public:
287 
288 
290  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap)
291  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), 0, false)))
292  , isFillResumed_(false) {}
293 
295  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
296  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), maxNumEntriesPerRow, true)))
297  , isFillResumed_(false) {}
298 
300  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
301  : isFillResumed_(false) {
302  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
303  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
304  }
305 
307  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)
308  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), maxNumEntriesPerRow, true)))
309  , isFillResumed_(false) {}
310 
312  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)
313  : isFillResumed_(false) {
314  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
315  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
316  }
317 
319  EpetraCrsMatrixT(const Teuchos::RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
320  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(graph))))
321  , isFillResumed_(false) {}
322 
326  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
327  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
328  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
329  : isFillResumed_(false) {
330  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
331  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
332 
333  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
334  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
335 
336  // Follows the Tpetra parameters
337  bool restrictComm = false;
338  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
339  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), myDomainMap, myRangeMap, restrictComm));
340  if (restrictComm && mtx_->NumMyRows() == 0)
341  mtx_ = Teuchos::null;
342  }
343 
347  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
348  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
349  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
350  : isFillResumed_(false) {
351  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
352  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
353 
354  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
355  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
356 
357  // Follows the Tpetra parameters
358  bool restrictComm = false;
359  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
360 
361  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), myDomainMap, myRangeMap, restrictComm));
362  }
363 
366  const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
367  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
368  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
369  const Teuchos::RCP<Teuchos::ParameterList> &params)
370  : isFillResumed_(false) {
371  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
372  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
373  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
374 
375  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
376  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
377 
378  // Follows the Tpetra parameters
379  bool restrictComm = false;
380  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
381  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), tdImporter->getEpetra_Import().get(), myDomainMap, myRangeMap, restrictComm));
382  if (restrictComm && mtx_->NumMyRows() == 0)
383  mtx_ = Teuchos::null;
384  }
385 
388  const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
389  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
390  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
391  const Teuchos::RCP<Teuchos::ParameterList> &params)
392  : isFillResumed_(false) {
393  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
394  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
395  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
396 
397  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
398  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
399 
400  // Follows the Tpetra parameters
401  bool restrictComm = false;
402  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
403 
404  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), tdExporter->getEpetra_Export().get(), myDomainMap, myRangeMap, restrictComm));
405  }
406 
407 #ifdef HAVE_XPETRA_TPETRA
408  // NOTE: TPETRA means we can use C++11 here
409 
431  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
432  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
433  const local_matrix_type &lclMatrix,
434  const Teuchos::RCP<Teuchos::ParameterList> &params = null)
435  : EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params) {}
436 
438  const local_matrix_type &lclMatrix,
439  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
440  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
441  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
442  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
443  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
444  // local typedefs from local_matrix_type
445  // typedef typename local_matrix_type::size_type size_type;
446  typedef typename local_matrix_type::value_type value_type;
447  typedef typename local_matrix_type::ordinal_type ordinal_type;
448 
449  // The number of rows in the sparse matrix.
450  ordinal_type lclNumRows = lclMatrix.numRows();
451  ordinal_type lclNumCols = lclMatrix.numCols(); // do we need this?
452 
453  // plausibility checks
454  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
455  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
456  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
457  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
458 
459  Teuchos::ArrayRCP<size_t> NumEntriesPerRowToAlloc(lclNumRows);
460  for (ordinal_type r = 0; r < lclNumRows; ++r) {
461  // extract data from current row r
462  auto rowview = lclMatrix.row(r);
463  NumEntriesPerRowToAlloc[r] = rowview.length;
464  }
465 
466  // setup matrix
467  isFillResumed_ = false;
468  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
469  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
470 
471  // loop over all rows and colums of local matrix and fill matrix
472  for (ordinal_type r = 0; r < lclNumRows; ++r) {
473  // extract data from current row r
474  auto rowview = lclMatrix.row(r);
475 
476  // arrays for current row data
477  Teuchos::ArrayRCP<ordinal_type> indout(rowview.length, Teuchos::ScalarTraits<ordinal_type>::zero());
478  Teuchos::ArrayRCP<value_type> valout(rowview.length, Teuchos::ScalarTraits<value_type>::zero());
479 
480  for (ordinal_type c = 0; c < rowview.length; c++) {
481  value_type value = rowview.value(c);
482  ordinal_type colidx = rowview.colidx(c);
483 
484  TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError,
485  "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
486 
487  indout[c] = colidx;
488  valout[c] = value;
489  }
490  insertLocalValues(r, indout.view(0, indout.size()), valout.view(0, valout.size()));
491  }
492 
493  // call fill complete
494  if (!domainMap.is_null() && !rangeMap.is_null())
495  this->fillComplete(domainMap, rowMap, params);
496  else
497  this->fillComplete(rowMap, rowMap, params);
498  }
499 #endif
500 
502  virtual ~EpetraCrsMatrixT() {}
503 
505 
507 
508 
510  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
511  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
512  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
513  }
514 
516  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
517  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
518  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
519  }
520 
522  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &indices, const ArrayView<const Scalar> &values) {
523  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
524 
525  {
526  const std::string tfecfFuncName("replaceGlobalValues");
527  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
528  ": Fill must be active in order to call this method. If you have already "
529  "called fillComplete(), you need to call resumeFill() before you can "
530  "replace values.");
531 
532  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
533  std::runtime_error, ": values.size() must equal indices.size().");
534  }
535 
536  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
537  }
538 
540  void replaceLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &indices, const ArrayView<const Scalar> &values) {
541  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
542 
543  {
544  const std::string tfecfFuncName("replaceLocalValues");
545  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
546  ": Fill must be active in order to call this method. If you have already "
547  "called fillComplete(), you need to call resumeFill() before you can "
548  "replace values.");
549 
550  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
551  std::runtime_error, ": values.size() must equal indices.size().");
552  }
553 
554  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
555  }
556 
558  void setAllToScalar(const Scalar &alpha) {
559  XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar");
560  mtx_->PutScalar(alpha);
561  }
562 
564  void scale(const Scalar &alpha) {
565  XPETRA_MONITOR("EpetraCrsMatrixT::scale");
566  mtx_->Scale(alpha);
567  }
568 
570  //** \warning This is an expert-only routine and should not be called from user code. */
571  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {
572  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
573 
574  // Row offsets
575  // Unfortunately, we cannot do this in the same manner as column indices
576  // and values (see below). The problem is that Tpetra insists on using
577  // size_t, and Epetra uses int internally. So we only resize here, and
578  // will need to copy in setAllValues
579  rowptr.resize(getLocalNumRows() + 1);
580 
581  int lowerOffset = 0;
582  bool ownMemory = false;
583 
584  // Column indices
585  // Extract, resize, set colind
586  Epetra_IntSerialDenseVector &myColind = mtx_->ExpertExtractIndices();
587  myColind.Resize(numNonZeros);
588  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
589 
590  // Values
591  // Extract, reallocate, set values
592  double *&myValues = mtx_->ExpertExtractValues();
593  delete[] myValues;
594  myValues = new double[numNonZeros];
595  values = Teuchos::arcp(myValues, lowerOffset, numNonZeros, ownMemory);
596  }
597 
599  void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {
600  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
601 
602  // Check sizes
603  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
604  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
605  TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
606  "An exception is thrown to let you know that you mismatched your pointers.");
607 
608  // Check pointers
609  if (values.size() > 0) {
610  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
611  "An exception is thrown to let you know that you mismatched your pointers.");
612  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
613  "An exception is thrown to let you know that you mismatched your pointers.");
614  }
615 
616  // We have to make a copy here, it is unavoidable
617  // See comments in allocateAllValues
618  const size_t N = getLocalNumRows();
619 
620  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
621  myRowptr.Resize(N + 1);
622  for (size_t i = 0; i < N + 1; i++)
623  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
624  }
625 
627  void getAllValues(ArrayRCP<const size_t> &rowptr, ArrayRCP<const LocalOrdinal> &colind, ArrayRCP<const Scalar> &values) const {
628  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
629 
630  int lowerOffset = 0;
631  bool ownMemory = false;
632 
633  const size_t n = getLocalNumRows();
634  const size_t nnz = getLocalNumEntries();
635 
636  // Row offsets
637  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
638  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
639  rowptr.resize(n + 1);
640  for (size_t i = 0; i < n + 1; i++)
641  (*const_cast<size_t *>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
642 
643  // Column indices
644  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
645 
646  // Values
647  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
648  }
649 
651  void getAllValues(ArrayRCP<Scalar> &values) {
652  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
653 
654  int lowerOffset = 0;
655  bool ownMemory = false;
656 
657  const size_t nnz = getLocalNumEntries();
658  // Values
659  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
660  }
661 
662  // Epetra always has global constants
663  bool haveGlobalConstants() const { return true; }
665  //** \warning This is an expert-only routine and should not be called from user code. */
667  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
668  const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
669  const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
670  const RCP<ParameterList> & /* params */ = Teuchos::null) {
671  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
672 
673  // For Epetra matrices, resumeFill() is a fictive operation.
674  isFillResumed_ = false;
675 
676  int rv = 0;
677  const Epetra_Import *myimport = 0;
678  const Epetra_Export *myexport = 0;
679 
680  if (!importer.is_null()) {
681  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
682  myimport = eImporter.getEpetra_Import().getRawPtr();
683  }
684  if (!exporter.is_null()) {
685  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
686  myexport = eExporter.getEpetra_Export().getRawPtr();
687  }
688 
689  rv = mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), myimport, myexport);
690 
691  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
692  }
694 
696 
697 
699  void resumeFill(const RCP<ParameterList> & /* params */ = Teuchos::null) {
700  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
701 
702  // According to Tpetra documentation, resumeFill() may be called repeatedly.
703  isFillResumed_ = true;
704  }
705 
707  void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = Teuchos::null) {
708  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
709 
710  // For Epetra matrices, resumeFill() is a fictive operation.
711  isFillResumed_ = false;
712 
713  bool doOptimizeStorage = true;
714  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
715  mtx_->FillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), doOptimizeStorage);
716  }
717 
719  void fillComplete(const RCP<ParameterList> &params = Teuchos::null) {
720  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
721 
722  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
723  if (isFillResumed_ == true) {
724  isFillResumed_ = false;
725  return;
726  }
727 
728  bool doOptimizeStorage = true;
729  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
730  mtx_->FillComplete(doOptimizeStorage);
731  }
732 
734  void replaceDomainMapAndImporter(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newDomainMap, Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &newImporter) {
735  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
736  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
737 
738  const RCP<const Epetra_Import> &myImport = eImporter.getEpetra_Import();
739  int rv = 0;
740  if (myImport == Teuchos::null)
741  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), 0);
742  else
743  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), &*myImport);
744  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
745  }
746 
748 
750 
751 
753  const RCP<const Comm<int> > getComm() const {
754  XPETRA_MONITOR("EpetraCrsMatrixT::getComm");
755  return toXpetra(mtx_->Comm());
756  }
757 
759  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {
760  XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap");
761  return toXpetra<GlobalOrdinal, Node>(mtx_->RowMap());
762  }
763 
765  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const {
766  XPETRA_MONITOR("EpetraCrsMatrixT::getColMap");
767  return toXpetra<GlobalOrdinal, Node>(mtx_->ColMap());
768  }
769 
771  RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const {
772  XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph");
773  return toXpetra<GlobalOrdinal, Node>(mtx_->Graph());
774  }
775 
778  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows");
779  return mtx_->NumGlobalRows64();
780  }
781 
784  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols");
785  return mtx_->NumGlobalCols64();
786  }
787 
789  size_t getLocalNumRows() const {
790  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows");
791  return mtx_->NumMyRows();
792  }
793 
795  size_t getLocalNumCols() const {
796  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols");
797  return mtx_->NumMyCols();
798  }
799 
802  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries");
803  return mtx_->NumGlobalNonzeros64();
804  }
805 
807  size_t getLocalNumEntries() const {
808  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries");
809  return mtx_->NumMyNonzeros();
810  }
811 
813  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
814  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow");
815  return mtx_->NumMyEntries(localRow);
816  }
817 
819  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
820  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow");
821  return mtx_->NumGlobalEntries(globalRow);
822  }
823 
825  size_t getGlobalMaxNumRowEntries() const {
826  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries");
827  return mtx_->GlobalMaxNumEntries();
828  }
829 
831  size_t getLocalMaxNumRowEntries() const {
832  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries");
833  return mtx_->MaxNumEntries();
834  }
835 
837  bool isLocallyIndexed() const {
838  XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed");
839  return mtx_->IndicesAreLocal();
840  }
841 
843  bool isGloballyIndexed() const {
844  XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed");
845  return mtx_->IndicesAreGlobal();
846  }
847 
849  bool isFillComplete() const {
850  XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete");
851  if (isFillResumed_)
852  return false;
853  else
854  return mtx_->Filled();
855  }
856 
858  bool isFillActive() const {
859  XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive");
860  return !isFillComplete();
861  }
862 
864  ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const {
865  XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm");
866  return mtx_->NormFrobenius();
867  }
868 
870  bool supportsRowViews() const {
871  XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews");
872  return true;
873  }
874 
876  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
877  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
878 
879  int numEntries = -1;
880  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
881  NumEntries = numEntries;
882  }
883 
885  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
886  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
887 
888  int numEntries = -1;
889  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
890  NumEntries = numEntries;
891  }
892 
894  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
895  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
896 
897  int numEntries;
898  double *eValues;
899  GlobalOrdinal *eIndices;
900 
901  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
902  if (numEntries == 0) {
903  eValues = NULL;
904  eIndices = NULL;
905  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
906 
907  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
908  values = ArrayView<const double>(eValues, numEntries);
909  }
910 
912  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
913  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
914 
915  int numEntries;
916  double *eValues;
917  int *eIndices;
918 
919  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
920  if (numEntries == 0) {
921  eValues = NULL;
922  eIndices = NULL;
923  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
924 
925  indices = ArrayView<const int>(eIndices, numEntries);
926  values = ArrayView<const double>(eValues, numEntries);
927  }
928 
931  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
932  XPETRA_ERR_CHECK(mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal, Node>(diag)));
933  }
934 
936  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> & /* offsets */) const {
937  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
938  }
939 
941  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Teuchos::ArrayView<const size_t> & /* offsets */) const {
942  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
943  }
944 
946  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> & /* offsets */) const {
947  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
948  }
949 
952  mtx_->ReplaceDiagonalValues(toEpetra<GlobalOrdinal, Node>(diag));
953  }
954 
956  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal, Node>(x)));
957  };
959  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal, Node>(x)));
960  };
961 
963 
965 
966 
968  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 {
969  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
970 
971  // TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
972 
973  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
974  XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
975 
976  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");
977  bool eTrans = toEpetra(mode);
978 
979  // /!\ UseTranspose value
980  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.");
981 
982  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
983 
984  // helper vector: tmp = A*x
985  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
986  tmp->PutScalar(0.0);
987  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
988 
989  // calculate alpha * A * x + beta * y
990  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
991  }
992 
994  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 {
995  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
996  }
997 
999  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
1000  XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap");
1001  return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap());
1002  }
1003 
1005  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
1006  XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap");
1007  return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap());
1008  }
1009 
1011 
1013 
1014 
1016  std::string description() const {
1017  XPETRA_MONITOR("EpetraCrsMatrixT::description");
1018 
1019  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1020  std::ostringstream oss;
1021  // TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
1022  if (isFillComplete()) {
1023  oss << "{status = fill complete"
1024  << ", global rows = " << getGlobalNumRows()
1025  << ", global cols = " << getGlobalNumCols()
1026  << ", global num entries = " << getGlobalNumEntries()
1027  << "}";
1028  } else {
1029  oss << "{status = fill not complete"
1030  << ", global rows = " << getGlobalNumRows()
1031  << "}";
1032  }
1033  return oss.str();
1034  }
1035 
1037  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
1038  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
1039 
1040  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1041  using std::endl;
1042  using std::setw;
1043  using Teuchos::VERB_DEFAULT;
1044  using Teuchos::VERB_EXTREME;
1045  using Teuchos::VERB_HIGH;
1046  using Teuchos::VERB_LOW;
1047  using Teuchos::VERB_MEDIUM;
1048  using Teuchos::VERB_NONE;
1049  Teuchos::EVerbosityLevel vl = verbLevel;
1050  if (vl == VERB_DEFAULT) vl = VERB_LOW;
1051  RCP<const Comm<int> > comm = this->getComm();
1052  const int myImageID = comm->getRank(),
1053  numImages = comm->getSize();
1054  size_t width = 1;
1055  for (size_t dec = 10; dec < getGlobalNumRows(); dec *= 10) {
1056  ++width;
1057  }
1058  width = std::max<size_t>(width, 11) + 2;
1059  Teuchos::OSTab tab(out);
1060  // none: print nothing
1061  // low: print O(1) info from node 0
1062  // medium: print O(P) info, num entries per node
1063  // high: print O(N) info, num entries per row
1064  // extreme: print O(NNZ) info: print indices and values
1065  //
1066  // for medium and higher, print constituent objects at specified verbLevel
1067  if (vl != VERB_NONE) {
1068  if (myImageID == 0) out << this->description() << std::endl;
1069  // O(1) globals, minus what was already printed by description()
1070  if (isFillComplete() && myImageID == 0) {
1071  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1072  }
1073  // constituent objects
1074  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1075  if (myImageID == 0) out << "\nRow map: " << std::endl;
1076  getRowMap()->describe(out, vl);
1077  //
1078  if (getColMap() != null) {
1079  if (getColMap() == getRowMap()) {
1080  if (myImageID == 0) out << "\nColumn map is row map.";
1081  } else {
1082  if (myImageID == 0) out << "\nColumn map: " << std::endl;
1083  getColMap()->describe(out, vl);
1084  }
1085  }
1086  if (getDomainMap() != null) {
1087  if (getDomainMap() == getRowMap()) {
1088  if (myImageID == 0) out << "\nDomain map is row map.";
1089  } else if (getDomainMap() == getColMap()) {
1090  if (myImageID == 0) out << "\nDomain map is row map.";
1091  } else {
1092  if (myImageID == 0) out << "\nDomain map: " << std::endl;
1093  getDomainMap()->describe(out, vl);
1094  }
1095  }
1096  if (getRangeMap() != null) {
1097  if (getRangeMap() == getDomainMap()) {
1098  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1099  } else if (getRangeMap() == getRowMap()) {
1100  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1101  } else {
1102  if (myImageID == 0) out << "\nRange map: " << std::endl;
1103  getRangeMap()->describe(out, vl);
1104  }
1105  }
1106  if (myImageID == 0) out << std::endl;
1107  }
1108  // O(P) data
1109  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1110  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1111  if (myImageID == imageCtr) {
1112  out << "Node ID = " << imageCtr << std::endl;
1113  // TODO: need a graph
1114  // if (staticGraph_->indicesAreAllocated() == false) {
1115  // out << "Node not allocated" << std::endl;
1116  // }
1117  // else {
1118  // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
1119  // }
1120 
1121  // TMP:
1122  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1123  // End of TMP
1124 
1125  out << "Node number of entries = " << getLocalNumEntries() << std::endl;
1126  out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
1127  }
1128  comm->barrier();
1129  comm->barrier();
1130  comm->barrier();
1131  }
1132  }
1133  // O(N) and O(NNZ) data
1134  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1135  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1136  if (myImageID == imageCtr) {
1137  out << std::setw(width) << "Node ID"
1138  << std::setw(width) << "Global Row"
1139  << std::setw(width) << "Num Entries";
1140  if (vl == VERB_EXTREME) {
1141  out << std::setw(width) << "(Index,Value)";
1142  }
1143  out << std::endl;
1144  for (size_t r = 0; r < getLocalNumRows(); ++r) {
1145  const size_t nE = getNumEntriesInLocalRow(r);
1146  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1147  out << std::setw(width) << myImageID
1148  << std::setw(width) << gid
1149  << std::setw(width) << nE;
1150  if (vl == VERB_EXTREME) {
1151  if (isGloballyIndexed()) {
1152  ArrayView<const GlobalOrdinal> rowinds;
1153  ArrayView<const Scalar> rowvals;
1154  getGlobalRowView(gid, rowinds, rowvals);
1155  for (size_t j = 0; j < nE; ++j) {
1156  out << " (" << rowinds[j]
1157  << ", " << rowvals[j]
1158  << ") ";
1159  }
1160  } else if (isLocallyIndexed()) {
1161  ArrayView<const LocalOrdinal> rowinds;
1162  ArrayView<const Scalar> rowvals;
1163  getLocalRowView(r, rowinds, rowvals);
1164  for (size_t j = 0; j < nE; ++j) {
1165  out << " (" << getColMap()->getGlobalElement(rowinds[j])
1166  << ", " << rowvals[j]
1167  << ") ";
1168  }
1169  }
1170  }
1171  out << std::endl;
1172  }
1173  }
1174  comm->barrier();
1175  comm->barrier();
1176  comm->barrier();
1177  }
1178  }
1179  }
1180  }
1181 
1182  void setObjectLabel(const std::string &objectLabel) {
1183  Teuchos::LabeledObject::setObjectLabel(objectLabel);
1184  mtx_->SetLabel(objectLabel.c_str());
1185  }
1187 
1190  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_))))
1191  , isFillResumed_(false) {}
1192 
1194  //{@
1195 
1197  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getMap() const {
1198  XPETRA_MONITOR("EpetraCrsMatrixT::getMap");
1199  return toXpetra<GlobalOrdinal, Node>(mtx_->Map());
1200  }
1201 
1205  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1206 
1207  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1208  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1209 
1210  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1211  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1212  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1213  }
1214 
1218  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1219 
1220  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1221  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1222 
1223  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1224  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1225  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1226  }
1227 
1231  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1232 
1233  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1234  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1235 
1236  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1237  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1238  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1239  }
1240 
1244  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1245 
1246  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1247  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1248 
1249  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1250  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1251  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1252  }
1253 
1254  void removeEmptyProcessesInPlace(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newMap) {
1255  XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
1256  const Epetra_Map *newMapEpetra = (!newMap.is_null()) ? &toEpetra<GlobalOrdinal, Node>(newMap) : 0;
1257  int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
1258  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1259  }
1260 
1262 
1264 
1265 
1267  bool hasMatrix() const { return !mtx_.is_null(); }
1268 
1270  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix> &mtx)
1271  : mtx_(mtx)
1272  , isFillResumed_(false) {}
1273 
1275  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
1276 
1278  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } // TODO: remove
1279 
1280 #ifdef HAVE_XPETRA_TPETRA
1281 
1284 #if 0
1285  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented,
1286  "Xpetra::EpetraCrsMatrx only available on host for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
1287  TEUCHOS_UNREACHABLE_RETURN((local_matrix_type()));
1288 #endif
1289  return getLocalMatrixHost();
1290  }
1291 
1292  typename local_matrix_type::HostMirror getLocalMatrixHost() const {
1293  RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
1294 
1295  const int numRows = matrix->NumMyRows();
1296  const int numCols = matrix->NumMyCols();
1297  const int nnz = matrix->NumMyNonzeros();
1298 
1299  int *rowptr;
1300  int *colind;
1301  double *vals;
1302  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1303  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1304 
1305  // Transform int* rowptr array to size_type* array
1306  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows + 1);
1307  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1308  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
1309 
1310  // create Kokkos::Views
1311  typename local_matrix_type::index_type kokkosColind(colind, nnz);
1312  typename local_matrix_type::values_type kokkosVals(vals, nnz);
1313 
1314  local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1315 
1316  return localMatrix;
1317  }
1318 
1319  void setAllValues(const typename local_matrix_type::row_map_type &ptr,
1320  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
1321  const typename local_matrix_type::values_type &val) {
1322  // Check sizes
1323  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(ptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
1324  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1325  TEUCHOS_TEST_FOR_EXCEPTION(val.size() != ind.size(), Xpetra::Exceptions::RuntimeError,
1326  "An exception is thrown to let you know that you mismatched your pointers.");
1327 
1328  // Check pointers
1329  if (val.size() > 0) {
1330  std::cout << ind.data() << " " << mtx_->ExpertExtractIndices().Values() << std::endl;
1331  TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1332  "An exception is thrown to let you know that you mismatched your pointers.");
1333  TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1334  "An exception is thrown to let you know that you mismatched your pointers.");
1335  }
1336 
1337  // We have to make a copy here, it is unavoidable
1338  // See comments in allocateAllValues
1339  const size_t N = getLocalNumRows();
1340 
1341  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1342  myRowptr.Resize(N + 1);
1343  for (size_t i = 0; i < N + 1; i++)
1344  myRowptr[i] = Teuchos::as<int>(ptr(i));
1345  }
1346 
1347  LocalOrdinal GetStorageBlockSize() const { return 1; }
1348 
1349  private:
1350 #else
1351 #ifdef __GNUC__
1352 #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."
1353 #endif
1354 #endif
1355 
1356 
1360  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
1361 
1362  apply(X, R);
1363  R.update(one, B, negone);
1364  }
1365 
1366  private:
1368  RCP<Epetra_CrsMatrix> mtx_;
1369 
1377 
1378 }; // EpetraCrsMatrixT class
1379 
1380 #endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1381 
1382 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1383 template <>
1384 class EpetraCrsMatrixT<long long, EpetraNode>
1385  : public CrsMatrix<double, int, long long, EpetraNode> {
1386  typedef long long GlobalOrdinal;
1387  typedef EpetraNode Node;
1390 
1391  // The following typedefs are used by the Kokkos interface
1392 #ifdef HAVE_XPETRA_TPETRA
1395 #endif
1396 
1397  public:
1399 
1400 
1402  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1403  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), maxNumEntriesPerRow, true)))
1404  , isFillResumed_(false) {}
1405 
1407  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1408  : isFillResumed_(false) {
1409  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1410  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1411  }
1412 
1414  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)
1415  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), maxNumEntriesPerRow, true)))
1416  , isFillResumed_(false) {}
1417 
1419  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)
1420  : isFillResumed_(false) {
1421  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1422  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1423  }
1424 
1426  EpetraCrsMatrixT(const Teuchos::RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1427  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(graph))))
1428  , isFillResumed_(false) {}
1429 
1433  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1434  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1435  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
1436  : isFillResumed_(false) {
1437  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1438  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1439 
1440  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1441  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1442 
1443  // Follows the Tpetra parameters
1444  bool restrictComm = false;
1445  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1446  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), myDomainMap, myRangeMap, restrictComm));
1447  if (restrictComm && mtx_->NumMyRows() == 0)
1448  mtx_ = Teuchos::null;
1449  }
1450 
1454  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1455  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1456  const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
1457  : isFillResumed_(false) {
1458  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1459  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1460 
1461  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1462  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1463 
1464  // Follows the Tpetra parameters
1465  bool restrictComm = false;
1466  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1467 
1468  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), myDomainMap, myRangeMap, restrictComm));
1469  }
1470 
1472  const Import<LocalOrdinal, GlobalOrdinal, Node> &RowImporter,
1473  const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
1474  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
1475  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1476  const Teuchos::RCP<Teuchos::ParameterList> &params)
1477  : isFillResumed_(false) {
1478  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1479  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1480  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1481 
1482  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1483  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1484 
1485  // Follows the Tpetra parameters
1486  bool restrictComm = false;
1487  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1488  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), tdImporter->getEpetra_Import().get(), myDomainMap, myRangeMap, restrictComm));
1489  if (restrictComm && mtx_->NumMyRows() == 0)
1490  mtx_ = Teuchos::null;
1491  }
1492 
1494  const Export<LocalOrdinal, GlobalOrdinal, Node> &RowExporter,
1495  const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
1496  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap,
1497  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1498  const Teuchos::RCP<Teuchos::ParameterList> &params)
1499  : isFillResumed_(false) {
1500  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1501  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1502  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1503 
1504  const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1505  const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1506 
1507  // Follows the Tpetra parameters
1508  bool restrictComm = false;
1509  if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1510 
1511  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), tdExporter->getEpetra_Export().get(), myDomainMap, myRangeMap, restrictComm));
1512  }
1513 
1514 #ifdef HAVE_XPETRA_TPETRA
1515  EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
1536  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
1537  const local_matrix_type &lclMatrix,
1538  const Teuchos::RCP<Teuchos::ParameterList> &params = null)
1539  : EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params) {}
1540 
1542  const local_matrix_type &lclMatrix,
1543  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap,
1544  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap,
1545  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1546  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1547  const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
1548  // local typedefs from local_matrix_type
1549  // typedef typename local_matrix_type::size_type size_type;
1550  typedef typename local_matrix_type::value_type value_type;
1551  typedef typename local_matrix_type::ordinal_type ordinal_type;
1552 
1553  // The number of rows in the sparse matrix.
1554  ordinal_type lclNumRows = lclMatrix.numRows();
1555  ordinal_type lclNumCols = lclMatrix.numCols(); // do we need this?
1556 
1557  // plausibility checks
1558  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
1559  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1560  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
1561  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1562 
1563  Teuchos::ArrayRCP<size_t> NumEntriesPerRowToAlloc(lclNumRows);
1564  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1565  // extract data from current row r
1566  auto rowview = lclMatrix.row(r);
1567  NumEntriesPerRowToAlloc[r] = rowview.length;
1568  }
1569 
1570  // setup matrix
1571  isFillResumed_ = false;
1572  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1573  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1574 
1575  // loop over all rows and colums of local matrix and fill matrix
1576  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1577  // extract data from current row r
1578  auto rowview = lclMatrix.row(r);
1579 
1580  // arrays for current row data
1581  Teuchos::ArrayRCP<ordinal_type> indout(rowview.length, Teuchos::ScalarTraits<ordinal_type>::zero());
1582  Teuchos::ArrayRCP<value_type> valout(rowview.length, Teuchos::ScalarTraits<value_type>::zero());
1583 
1584  for (ordinal_type c = 0; c < rowview.length; c++) {
1585  value_type value = rowview.value(c);
1586  ordinal_type colidx = rowview.colidx(c);
1587 
1588  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!");
1589 
1590  indout[c] = colidx;
1591  valout[c] = value;
1592  }
1593  insertLocalValues(r, indout.view(0, indout.size()), valout.view(0, valout.size()));
1594  }
1595 
1596  // call fill complete
1597  if (!domainMap.is_null() && !rangeMap.is_null())
1598  this->fillComplete(domainMap, rowMap, params);
1599  else
1600  this->fillComplete(rowMap, rowMap, params);
1601  }
1602 #endif
1603 
1605  virtual ~EpetraCrsMatrixT() {}
1606 
1608 
1610 
1611 
1613  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1614  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1615  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1616  }
1617 
1619  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1620  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1621  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1622  }
1623 
1625  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &indices, const ArrayView<const Scalar> &values) {
1626  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1627 
1628  {
1629  const std::string tfecfFuncName("replaceGlobalValues");
1630  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
1631  ": Fill must be active in order to call this method. If you have already "
1632  "called fillComplete(), you need to call resumeFill() before you can "
1633  "replace values.");
1634 
1635  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1636  std::runtime_error, ": values.size() must equal indices.size().");
1637  }
1638 
1639  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1640  }
1641 
1643  void replaceLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &indices, const ArrayView<const Scalar> &values) {
1644  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
1645 
1646  {
1647  const std::string tfecfFuncName("replaceLocalValues");
1648  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!isFillActive(), std::runtime_error,
1649  ": Fill must be active in order to call this method. If you have already "
1650  "called fillComplete(), you need to call resumeFill() before you can "
1651  "replace values.");
1652 
1653  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1654  std::runtime_error, ": values.size() must equal indices.size().");
1655  }
1656 
1657  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1658  }
1659 
1661  void setAllToScalar(const Scalar &alpha) {
1662  XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar");
1663  mtx_->PutScalar(alpha);
1664  }
1665 
1667  void scale(const Scalar &alpha) {
1668  XPETRA_MONITOR("EpetraCrsMatrixT::scale");
1669  mtx_->Scale(alpha);
1670  }
1671 
1673  //** \warning This is an expert-only routine and should not be called from user code. */
1674  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {
1675  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1676 
1677  // Row offsets
1678  // Unfortunately, we cannot do this in the same manner as column indices
1679  // and values (see below). The problem is that Tpetra insists on using
1680  // size_t, and Epetra uses int internally. So we only resize here, and
1681  // will need to copy in setAllValues
1682  rowptr.resize(getLocalNumRows() + 1);
1683 
1684  int lowerOffset = 0;
1685  bool ownMemory = false;
1686 
1687  // Column indices
1688  // Extract, resize, set colind
1689  Epetra_IntSerialDenseVector &myColind = mtx_->ExpertExtractIndices();
1690  myColind.Resize(numNonZeros);
1691  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1692 
1693  // Values
1694  // Extract, reallocate, set values
1695  double *&myValues = mtx_->ExpertExtractValues();
1696  delete[] myValues;
1697  myValues = new double[numNonZeros];
1698  values = Teuchos::arcp(myValues, lowerOffset, numNonZeros, ownMemory);
1699  }
1700 
1702  void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {
1703  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1704 
1705  // Check sizes
1706  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
1707  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1708  TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
1709  "An exception is thrown to let you know that you mismatched your pointers.");
1710 
1711  // Check pointers
1712  if (values.size() > 0) {
1713  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1714  "An exception is thrown to let you know that you mismatched your pointers.");
1715  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1716  "An exception is thrown to let you know that you mismatched your pointers.");
1717  }
1718 
1719  // We have to make a copy here, it is unavoidable
1720  // See comments in allocateAllValues
1721  const size_t N = getLocalNumRows();
1722 
1723  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1724  myRowptr.Resize(N + 1);
1725  for (size_t i = 0; i < N + 1; i++)
1726  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1727  }
1728 
1730  void getAllValues(ArrayRCP<const size_t> &rowptr, ArrayRCP<const LocalOrdinal> &colind, ArrayRCP<const Scalar> &values) const {
1731  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1732 
1733  int lowerOffset = 0;
1734  bool ownMemory = false;
1735 
1736  const size_t n = getLocalNumRows();
1737  const size_t nnz = getLocalNumEntries();
1738 
1739  // Row offsets
1740  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1741  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1742  rowptr.resize(n + 1);
1743  for (size_t i = 0; i < n + 1; i++)
1744  (*const_cast<size_t *>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1745 
1746  // Column indices
1747  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1748 
1749  // Values
1750  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1751  }
1752 
1754  void getAllValues(ArrayRCP<Scalar> &values) {
1755  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1756 
1757  int lowerOffset = 0;
1758  bool ownMemory = false;
1759 
1760  const size_t nnz = getLocalNumEntries();
1761  // Values
1762  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1763  }
1764 
1765  // Epetra always has global constants
1766  bool haveGlobalConstants() const { return true; }
1767 
1769  //** \warning This is an expert-only routine and should not be called from user code. */
1771  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1772  const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
1773  const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
1774  const RCP<ParameterList> & /* params */ = Teuchos::null) {
1775  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1776 
1777  // For Epetra matrices, resumeFill() is a fictive operation.
1778  isFillResumed_ = false;
1779 
1780  int rv = 0;
1781  const Epetra_Import *myimport = 0;
1782  const Epetra_Export *myexport = 0;
1783 
1784  if (!importer.is_null()) {
1785  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1786  myimport = eImporter.getEpetra_Import().getRawPtr();
1787  }
1788  if (!exporter.is_null()) {
1789  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1790  myexport = eExporter.getEpetra_Export().getRawPtr();
1791  }
1792 
1793  rv = mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), myimport, myexport);
1794 
1795  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1796  }
1798 
1800 
1801 
1803  void resumeFill(const RCP<ParameterList> & /* params */ = Teuchos::null) {
1804  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1805 
1806  // According to Tpetra documentation, resumeFill() may be called repeatedly.
1807  isFillResumed_ = true;
1808  }
1809 
1811  void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = Teuchos::null) {
1812  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1813 
1814  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1815  if (isFillResumed_ == true) {
1816  isFillResumed_ = false;
1817  return;
1818  }
1819 
1820  bool doOptimizeStorage = true;
1821  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
1822  mtx_->FillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), doOptimizeStorage);
1823  }
1824 
1826  void fillComplete(const RCP<ParameterList> &params = Teuchos::null) {
1827  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1828 
1829  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1830  if (isFillResumed_ == true) {
1831  isFillResumed_ = false;
1832  return;
1833  }
1834 
1835  bool doOptimizeStorage = true;
1836  if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
1837  mtx_->FillComplete(doOptimizeStorage);
1838  }
1839 
1841  void replaceDomainMapAndImporter(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newDomainMap, Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &newImporter) {
1842  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1843  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1844 
1845  const RCP<const Epetra_Import> &myImport = eImporter.getEpetra_Import();
1846  int rv = 0;
1847  if (myImport == Teuchos::null)
1848  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), 0);
1849  else
1850  rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), &*myImport);
1851  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1852  }
1853 
1855 
1857 
1858 
1860  const RCP<const Comm<int> > getComm() const {
1861  XPETRA_MONITOR("EpetraCrsMatrixT::getComm");
1862  return toXpetra(mtx_->Comm());
1863  }
1864 
1866  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {
1867  XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap");
1868  return toXpetra<GlobalOrdinal, Node>(mtx_->RowMap());
1869  }
1870 
1872  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const {
1873  XPETRA_MONITOR("EpetraCrsMatrixT::getColMap");
1874  return toXpetra<GlobalOrdinal, Node>(mtx_->ColMap());
1875  }
1876 
1878  RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const {
1879  XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph");
1880  return toXpetra<GlobalOrdinal, Node>(mtx_->Graph());
1881  }
1882 
1885  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows");
1886  return mtx_->NumGlobalRows64();
1887  }
1888 
1891  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols");
1892  return mtx_->NumGlobalCols64();
1893  }
1894 
1896  size_t getLocalNumRows() const {
1897  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows");
1898  return mtx_->NumMyRows();
1899  }
1900 
1902  size_t getLocalNumCols() const {
1903  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols");
1904  return mtx_->NumMyCols();
1905  }
1906 
1909  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries");
1910  return mtx_->NumGlobalNonzeros64();
1911  }
1912 
1914  size_t getLocalNumEntries() const {
1915  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries");
1916  return mtx_->NumMyNonzeros();
1917  }
1918 
1920  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
1921  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow");
1922  return mtx_->NumMyEntries(localRow);
1923  }
1924 
1926  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
1927  XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow");
1928  return mtx_->NumGlobalEntries(globalRow);
1929  }
1930 
1932  size_t getGlobalMaxNumRowEntries() const {
1933  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries");
1934  return mtx_->GlobalMaxNumEntries();
1935  }
1936 
1938  size_t getLocalMaxNumRowEntries() const {
1939  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries");
1940  return mtx_->MaxNumEntries();
1941  }
1942 
1944  bool isLocallyIndexed() const {
1945  XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed");
1946  return mtx_->IndicesAreLocal();
1947  }
1948 
1950  bool isGloballyIndexed() const {
1951  XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed");
1952  return mtx_->IndicesAreGlobal();
1953  }
1954 
1956  bool isFillComplete() const {
1957  XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete");
1958  if (isFillResumed_)
1959  return false;
1960  else
1961  return mtx_->Filled();
1962  }
1963 
1965  bool isFillActive() const {
1966  XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive");
1967  return !isFillComplete();
1968  }
1969 
1971  typename ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const {
1972  XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm");
1973  return mtx_->NormFrobenius();
1974  }
1975 
1977  bool supportsRowViews() const {
1978  XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews");
1979  return true;
1980  }
1981 
1983  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1984  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1985 
1986  int numEntries = -1;
1987  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1988  NumEntries = numEntries;
1989  }
1990 
1992  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1993  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
1994 
1995  int numEntries = -1;
1996  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1997  NumEntries = numEntries;
1998  }
1999 
2001  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
2002  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
2003 
2004  int numEntries;
2005  double *eValues;
2006  GlobalOrdinal *eIndices;
2007 
2008  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
2009  if (numEntries == 0) {
2010  eValues = NULL;
2011  eIndices = NULL;
2012  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
2013 
2014  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
2015  values = ArrayView<const double>(eValues, numEntries);
2016  }
2017 
2019  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
2020  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
2021 
2022  int numEntries;
2023  double *eValues;
2024  int *eIndices;
2025 
2026  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
2027  if (numEntries == 0) {
2028  eValues = NULL;
2029  eIndices = NULL;
2030  } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
2031 
2032  indices = ArrayView<const int>(eIndices, numEntries);
2033  values = ArrayView<const double>(eValues, numEntries);
2034  }
2035 
2038  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
2039  mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal, Node>(diag));
2040  }
2041 
2043  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> & /* offsets */) const {
2044  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
2045  }
2046 
2048  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Teuchos::ArrayView<const size_t> & /* offsets */) const {
2049  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
2050  }
2051 
2053  void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> & /* offsets */) const {
2054  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
2055  }
2056 
2059  mtx_->ReplaceDiagonalValues(toEpetra<GlobalOrdinal, Node>(diag));
2060  }
2061 
2063  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal, Node>(x)));
2064  };
2066  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal, Node>(x)));
2067  };
2068 
2070 
2072 
2073 
2075  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 {
2076  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
2077 
2078  // TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
2079 
2080  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
2081  XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
2082 
2083  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");
2084  bool eTrans = toEpetra(mode);
2085 
2086  // /!\ UseTranspose value
2087  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.");
2088 
2089  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
2090 
2091  // helper vector: tmp = A*x
2092  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
2093  tmp->PutScalar(0.0);
2094  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
2095 
2096  // calculate alpha * A * x + beta * y
2097  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
2098  }
2099 
2100  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 {
2101  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
2102  }
2103 
2105  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
2106  XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap");
2107  return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap());
2108  }
2109 
2111  const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
2112  XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap");
2113  return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap());
2114  }
2115 
2117 
2119 
2120 
2122  std::string description() const {
2123  XPETRA_MONITOR("EpetraCrsMatrixT::description");
2124 
2125  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2126  std::ostringstream oss;
2127  // TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
2128  if (isFillComplete()) {
2129  oss << "{status = fill complete"
2130  << ", global rows = " << getGlobalNumRows()
2131  << ", global cols = " << getGlobalNumCols()
2132  << ", global num entries = " << getGlobalNumEntries()
2133  << "}";
2134  } else {
2135  oss << "{status = fill not complete"
2136  << ", global rows = " << getGlobalNumRows()
2137  << "}";
2138  }
2139  return oss.str();
2140  }
2141 
2143  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const {
2144  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
2145 
2146  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2147  using std::endl;
2148  using std::setw;
2149  using Teuchos::VERB_DEFAULT;
2150  using Teuchos::VERB_EXTREME;
2151  using Teuchos::VERB_HIGH;
2152  using Teuchos::VERB_LOW;
2153  using Teuchos::VERB_MEDIUM;
2154  using Teuchos::VERB_NONE;
2155  Teuchos::EVerbosityLevel vl = verbLevel;
2156  if (vl == VERB_DEFAULT) vl = VERB_LOW;
2157  RCP<const Comm<int> > comm = this->getComm();
2158  const int myImageID = comm->getRank(),
2159  numImages = comm->getSize();
2160  size_t width = 1;
2161  for (size_t dec = 10; dec < getGlobalNumRows(); dec *= 10) {
2162  ++width;
2163  }
2164  width = std::max<size_t>(width, 11) + 2;
2165  Teuchos::OSTab tab(out);
2166  // none: print nothing
2167  // low: print O(1) info from node 0
2168  // medium: print O(P) info, num entries per node
2169  // high: print O(N) info, num entries per row
2170  // extreme: print O(NNZ) info: print indices and values
2171  //
2172  // for medium and higher, print constituent objects at specified verbLevel
2173  if (vl != VERB_NONE) {
2174  if (myImageID == 0) out << this->description() << std::endl;
2175  // O(1) globals, minus what was already printed by description()
2176  if (isFillComplete() && myImageID == 0) {
2177  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
2178  }
2179  // constituent objects
2180  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2181  if (myImageID == 0) out << "\nRow map: " << std::endl;
2182  getRowMap()->describe(out, vl);
2183  //
2184  if (getColMap() != null) {
2185  if (getColMap() == getRowMap()) {
2186  if (myImageID == 0) out << "\nColumn map is row map.";
2187  } else {
2188  if (myImageID == 0) out << "\nColumn map: " << std::endl;
2189  getColMap()->describe(out, vl);
2190  }
2191  }
2192  if (getDomainMap() != null) {
2193  if (getDomainMap() == getRowMap()) {
2194  if (myImageID == 0) out << "\nDomain map is row map.";
2195  } else if (getDomainMap() == getColMap()) {
2196  if (myImageID == 0) out << "\nDomain map is row map.";
2197  } else {
2198  if (myImageID == 0) out << "\nDomain map: " << std::endl;
2199  getDomainMap()->describe(out, vl);
2200  }
2201  }
2202  if (getRangeMap() != null) {
2203  if (getRangeMap() == getDomainMap()) {
2204  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
2205  } else if (getRangeMap() == getRowMap()) {
2206  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
2207  } else {
2208  if (myImageID == 0) out << "\nRange map: " << std::endl;
2209  getRangeMap()->describe(out, vl);
2210  }
2211  }
2212  if (myImageID == 0) out << std::endl;
2213  }
2214  // O(P) data
2215  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2216  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2217  if (myImageID == imageCtr) {
2218  out << "Node ID = " << imageCtr << std::endl;
2219  // TODO: need a graph
2220  // if (staticGraph_->indicesAreAllocated() == false) {
2221  // out << "Node not allocated" << std::endl;
2222  // }
2223  // else {
2224  // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
2225  // }
2226 
2227  // TMP:
2228  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2229  // End of TMP
2230 
2231  out << "Node number of entries = " << getLocalNumEntries() << std::endl;
2232  out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
2233  }
2234  comm->barrier();
2235  comm->barrier();
2236  comm->barrier();
2237  }
2238  }
2239  // O(N) and O(NNZ) data
2240  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2241  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2242  if (myImageID == imageCtr) {
2243  out << std::setw(width) << "Node ID"
2244  << std::setw(width) << "Global Row"
2245  << std::setw(width) << "Num Entries";
2246  if (vl == VERB_EXTREME) {
2247  out << std::setw(width) << "(Index,Value)";
2248  }
2249  out << std::endl;
2250  for (size_t r = 0; r < getLocalNumRows(); ++r) {
2251  const size_t nE = getNumEntriesInLocalRow(r);
2252  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2253  out << std::setw(width) << myImageID
2254  << std::setw(width) << gid
2255  << std::setw(width) << nE;
2256  if (vl == VERB_EXTREME) {
2257  if (isGloballyIndexed()) {
2258  ArrayView<const GlobalOrdinal> rowinds;
2259  ArrayView<const Scalar> rowvals;
2260  getGlobalRowView(gid, rowinds, rowvals);
2261  for (size_t j = 0; j < nE; ++j) {
2262  out << " (" << rowinds[j]
2263  << ", " << rowvals[j]
2264  << ") ";
2265  }
2266  } else if (isLocallyIndexed()) {
2267  ArrayView<const LocalOrdinal> rowinds;
2268  ArrayView<const Scalar> rowvals;
2269  getLocalRowView(r, rowinds, rowvals);
2270  for (size_t j = 0; j < nE; ++j) {
2271  out << " (" << getColMap()->getGlobalElement(rowinds[j])
2272  << ", " << rowvals[j]
2273  << ") ";
2274  }
2275  }
2276  }
2277  out << std::endl;
2278  }
2279  }
2280  comm->barrier();
2281  comm->barrier();
2282  comm->barrier();
2283  }
2284  }
2285  }
2286  }
2287 
2288  void setObjectLabel(const std::string &objectLabel) {
2289  Teuchos::LabeledObject::setObjectLabel(objectLabel);
2290  mtx_->SetLabel(objectLabel.c_str());
2291  }
2293 
2296  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_))))
2297  , isFillResumed_(false) {}
2298 
2300  //{@
2301 
2303  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getMap() const {
2304  XPETRA_MONITOR("EpetraCrsMatrixT::getMap");
2305  return toXpetra<GlobalOrdinal, Node>(mtx_->Map());
2306  }
2307 
2311  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2312 
2313  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2314  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2315 
2316  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2317  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2318  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2319  }
2320 
2324  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2325 
2326  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2327  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2328 
2329  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2330  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2331  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2332  }
2333 
2337  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2338 
2339  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2340  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2341 
2342  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2343  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2344  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2345  }
2346 
2350  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2351 
2352  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2353  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2354 
2355  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2356  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2357  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2358  }
2359 
2360  void removeEmptyProcessesInPlace(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &newMap) {
2361  XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
2362  const Epetra_Map *newMapEpetra = (!newMap.is_null()) ? &toEpetra<GlobalOrdinal, Node>(newMap) : 0;
2363  int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
2364  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
2365  }
2366 
2368 
2370 
2371 
2373  bool hasMatrix() const { return !mtx_.is_null(); }
2374 
2376  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix> &mtx)
2377  : mtx_(mtx)
2378  , isFillResumed_(false) {}
2379 
2381  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
2382 
2384  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } // TODO: remove
2385 
2386 #ifdef HAVE_XPETRA_TPETRA
2387  local_matrix_type getLocalMatrix() const {
2389  RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
2390 
2391  const int numRows = matrix->NumMyRows();
2392  const int numCols = matrix->NumMyCols();
2393  const int nnz = matrix->NumMyNonzeros();
2394 
2395  int *rowptr;
2396  int *colind;
2397  double *vals;
2398  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2399  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2400 
2401  // Transform int* rowptr array to size_type* array
2402  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows + 1);
2403  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2404  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
2405 
2406  // create Kokkos::Views
2407  typename local_matrix_type::index_type kokkosColind(colind, nnz);
2408  typename local_matrix_type::values_type kokkosVals(vals, nnz);
2409 
2410  local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2411 
2412  return localMatrix;
2413  }
2414 
2415  void setAllValues(const typename local_matrix_type::row_map_type &ptr,
2416  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
2417  const typename local_matrix_type::values_type &val) {
2418  // Check sizes
2419  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(ptr.size()) != getLocalNumRows() + 1, Xpetra::Exceptions::RuntimeError,
2420  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
2421  TEUCHOS_TEST_FOR_EXCEPTION(val.size() != ind.size(), Xpetra::Exceptions::RuntimeError,
2422  "An exception is thrown to let you know that you mismatched your pointers.");
2423 
2424  // Check pointers
2425  if (val.size() > 0) {
2426  TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
2427  "An exception is thrown to let you know that you mismatched your pointers.");
2428  TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
2429  "An exception is thrown to let you know that you mismatched your pointers.");
2430  }
2431 
2432  // We have to make a copy here, it is unavoidable
2433  // See comments in allocateAllValues
2434  const size_t N = getLocalNumRows();
2435 
2436  Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
2437  myRowptr.Resize(N + 1);
2438  for (size_t i = 0; i < N + 1; i++)
2439  myRowptr[i] = Teuchos::as<int>(ptr(i));
2440  }
2441 
2442  LocalOrdinal GetStorageBlockSize() const { return 1; }
2443 
2444  private:
2445 #else
2446 #ifdef __GNUC__
2447 #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."
2448 #endif
2449 #endif
2450 
2452 
2456  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
2457  apply(X, R);
2458  R.update(one, B, negone);
2459  }
2460 
2461  private:
2462  RCP<Epetra_CrsMatrix> mtx_;
2463 
2464  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.
2465 
2466 }; // EpetraCrsMatrixT class
2467 
2468 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2469 
2470 } // namespace Xpetra
2471 
2472 #define XPETRA_EPETRACRSMATRIX_SHORT
2473 #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
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
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...
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)