Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_EpetraCrsMatrix.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Xpetra: A linear algebra interface package
4//
5// Copyright 2012 NTESS and the Xpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef XPETRA_EPETRACRSMATRIX_HPP
11#define XPETRA_EPETRACRSMATRIX_HPP
12
13/* this file is automatically generated - do not edit (see script/epetra.py) */
14
15#ifdef HAVE_XPETRA_TPETRA
16#include <Kokkos_Core.hpp>
17#endif
18
20
21#include "Xpetra_CrsMatrix.hpp"
22
23#include <Epetra_CrsMatrix.h>
24#include <Epetra_Map.h>
25
26#include "Xpetra_EpetraMap.hpp"
30
31#include "Xpetra_MapFactory.hpp"
32
33#include "Xpetra_Utils.hpp"
34#include "Xpetra_Exceptions.hpp"
35
36#if defined(XPETRA_ENABLE_DEPRECATED_CODE)
37#ifdef __GNUC__
38#if defined(Xpetra_SHOW_DEPRECATED_WARNINGS)
39#warning "The header file Trilinos/packages/xpetra/src/CrsMatrix/Xpetra_EpetraCrsMatrix.hpp is deprecated."
40#endif
41#endif
42#else
43#error "The header file Trilinos/packages/xpetra/src/CrsMatrix/Xpetra_EpetraCrsMatrix.hpp is deprecated."
44#endif
45
46namespace Xpetra {
47
48// general implementation: empty stub
49template <class EpetraGlobalOrdinal, class Node>
50class XPETRA_DEPRECATED EpetraCrsMatrixT
51 : public CrsMatrix<double, int, EpetraGlobalOrdinal, Node> {
52 typedef EpetraGlobalOrdinal GlobalOrdinal;
55
56#ifdef HAVE_XPETRA_TPETRA
59#endif
60
61 public:
62 EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
64 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
65 }
66 EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
68 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
69 }
70 EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Tpetra::KokkosCompat::KokkosSerialWrapperNode."); }
71 EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &colMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Tpetra::KokkosCompat::KokkosSerialWrapperNode."); }
72 EpetraCrsMatrixT(const Teuchos::RCP<const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Tpetra::KokkosCompat::KokkosSerialWrapperNode."); }
75 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
76 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
77 const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
79 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
80 }
83 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
84 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
85 const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null) {
87 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
88 }
96 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
97 }
100 const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
105 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
106 }
107#ifdef HAVE_XPETRA_TPETRA
110 const local_matrix_type &lclMatrix,
111 const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
113 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
114 }
116 const local_matrix_type &lclMatrix,
119 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
120 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
121 const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
123 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
124 }
125#endif
126 virtual ~EpetraCrsMatrixT() {}
127
132 void setAllToScalar(const Scalar &alpha) {}
133 void scale(const Scalar &alpha) {}
134 void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {}
135 void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {}
138 bool haveGlobalConstants() const { return true; }
140 const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
141 const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
142 const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
143 const RCP<ParameterList> &params = Teuchos::null) {}
144
145 void resumeFill(const RCP<ParameterList> &params = null) {}
146 void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = null) {}
147 void fillComplete(const RCP<ParameterList> &params = null) {}
149 const RCP<const Comm<int> > getComm() const { return Teuchos::null; }
150 const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { return Teuchos::null; }
151 const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { return Teuchos::null; }
153 global_size_t getGlobalNumRows() const { return 0; }
154 global_size_t getGlobalNumCols() const { return 0; }
155 size_t getLocalNumRows() const { return 0; }
156 size_t getLocalNumCols() const { return 0; }
157 global_size_t getGlobalNumEntries() const { return 0; }
158 size_t getLocalNumEntries() const { return 0; }
159 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { return 0; }
160 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { return 0; }
161 size_t getGlobalMaxNumRowEntries() const { return 0; }
162 size_t getLocalMaxNumRowEntries() const { return 0; }
163 bool isLocallyIndexed() const { return false; }
164 bool isGloballyIndexed() const { return false; }
165 bool isFillComplete() const { return false; }
166 bool isFillActive() const { return false; }
168 bool supportsRowViews() const { return false; }
169 void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {}
170 void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {}
176 void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &diag, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> &offsets) const {}
180
183 const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const { return Teuchos::null; }
184 const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const { return Teuchos::null; }
185
186 std::string description() const { return std::string(""); }
188 void setObjectLabel(const std::string &objectLabel) {}
189
192 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
193 }
194
201
202 bool hasMatrix() const { return false; }
205 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
206 }
207 RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
208 RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } // TODO: remove
209#ifdef HAVE_XPETRA_TPETRA
212 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
213 }
214 typename local_matrix_type::HostMirror getLocalMatrixHost() const {
216 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
217 }
218
219 void setAllValues(const typename local_matrix_type::row_map_type &ptr,
220 const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
221 const typename local_matrix_type::values_type &val) {
223 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
224 }
225
226 LocalOrdinal GetStorageBlockSize() const { return 1; }
227
228#else
229#ifdef __GNUC__
230#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."
231#endif
232#endif
233
241
242}; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
243
244#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
245template <>
247 : public CrsMatrix<double, int, int, EpetraNode> {
248 typedef int GlobalOrdinal;
252
253 // The following typedefs are used by the Kokkos interface
254#ifdef HAVE_XPETRA_TPETRA
257#endif
258
259 public:
261
262
267
269 EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
270 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), maxNumEntriesPerRow, true)))
271 , isFillResumed_(false) {}
272
274 EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
275 : isFillResumed_(false) {
276 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
277 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
278 }
279
281 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)
282 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), maxNumEntriesPerRow, true)))
283 , isFillResumed_(false) {}
284
286 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)
287 : isFillResumed_(false) {
288 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
289 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
290 }
291
296
300 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
301 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
302 const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
303 : isFillResumed_(false) {
304 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
305 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
306
307 const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
308 const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
309
310 // Follows the Tpetra parameters
311 bool restrictComm = false;
312 if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
313 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), myDomainMap, myRangeMap, restrictComm));
314 if (restrictComm && mtx_->NumMyRows() == 0)
315 mtx_ = Teuchos::null;
316 }
317
321 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
322 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
323 const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
324 : isFillResumed_(false) {
325 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
326 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
327
328 const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
329 const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
330
331 // Follows the Tpetra parameters
332 bool restrictComm = false;
333 if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
334
335 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), myDomainMap, myRangeMap, restrictComm));
336 }
337
340 const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
344 : isFillResumed_(false) {
345 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
346 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
347 XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
348
349 const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
350 const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
351
352 // Follows the Tpetra parameters
353 bool restrictComm = false;
354 if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
355 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), tdImporter->getEpetra_Import().get(), myDomainMap, myRangeMap, restrictComm));
356 if (restrictComm && mtx_->NumMyRows() == 0)
357 mtx_ = Teuchos::null;
358 }
359
362 const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
366 : isFillResumed_(false) {
367 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
368 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
369 XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
370
371 const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
372 const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
373
374 // Follows the Tpetra parameters
375 bool restrictComm = false;
376 if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
377
378 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), tdExporter->getEpetra_Export().get(), myDomainMap, myRangeMap, restrictComm));
379 }
380
381#ifdef HAVE_XPETRA_TPETRA
382 // NOTE: TPETRA means we can use C++11 here
383
407 const local_matrix_type &lclMatrix,
408 const Teuchos::RCP<Teuchos::ParameterList> &params = null)
409 : EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params) {}
410
412 const local_matrix_type &lclMatrix,
415 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
416 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
417 const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
418 // local typedefs from local_matrix_type
419 // typedef typename local_matrix_type::size_type size_type;
420 typedef typename local_matrix_type::value_type value_type;
421 typedef typename local_matrix_type::ordinal_type ordinal_type;
422
423 // The number of rows in the sparse matrix.
424 ordinal_type lclNumRows = lclMatrix.numRows();
425 ordinal_type lclNumCols = lclMatrix.numCols(); // do we need this?
426
427 // plausibility checks
429 "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
431 "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
432
433 Teuchos::ArrayRCP<size_t> NumEntriesPerRowToAlloc(lclNumRows);
434 for (ordinal_type r = 0; r < lclNumRows; ++r) {
435 // extract data from current row r
436 auto rowview = lclMatrix.row(r);
437 NumEntriesPerRowToAlloc[r] = rowview.length;
438 }
439
440 // setup matrix
441 isFillResumed_ = false;
442 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
443 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
444
445 // loop over all rows and colums of local matrix and fill matrix
446 for (ordinal_type r = 0; r < lclNumRows; ++r) {
447 // extract data from current row r
448 auto rowview = lclMatrix.row(r);
449
450 // arrays for current row data
453
454 for (ordinal_type c = 0; c < rowview.length; c++) {
455 value_type value = rowview.value(c);
456 ordinal_type colidx = rowview.colidx(c);
457
458 TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError,
459 "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
460
461 indout[c] = colidx;
462 valout[c] = value;
463 }
464 insertLocalValues(r, indout.view(0, indout.size()), valout.view(0, valout.size()));
465 }
466
467 // call fill complete
468 if (!domainMap.is_null() && !rangeMap.is_null())
469 this->fillComplete(domainMap, rowMap, params);
470 else
471 this->fillComplete(rowMap, rowMap, params);
472 }
473#endif
474
476 virtual ~EpetraCrsMatrixT() {}
477
479
481
482
485 XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
486 XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
487 }
488
491 XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
492 XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
493 }
494
497 XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
498
499 {
500 const std::string tfecfFuncName("replaceGlobalValues");
502 ": Fill must be active in order to call this method. If you have already "
503 "called fillComplete(), you need to call resumeFill() before you can "
504 "replace values.");
505
506 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
507 std::runtime_error, ": values.size() must equal indices.size().");
508 }
509
510 XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
511 }
512
515 XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
516
517 {
518 const std::string tfecfFuncName("replaceLocalValues");
520 ": Fill must be active in order to call this method. If you have already "
521 "called fillComplete(), you need to call resumeFill() before you can "
522 "replace values.");
523
524 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
525 std::runtime_error, ": values.size() must equal indices.size().");
526 }
527
528 XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
529 }
530
532 void setAllToScalar(const Scalar &alpha) {
533 XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar");
534 mtx_->PutScalar(alpha);
535 }
536
538 void scale(const Scalar &alpha) {
539 XPETRA_MONITOR("EpetraCrsMatrixT::scale");
540 mtx_->Scale(alpha);
541 }
542
544 //** \warning This is an expert-only routine and should not be called from user code. */
545 void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {
546 XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
547
548 // Row offsets
549 // Unfortunately, we cannot do this in the same manner as column indices
550 // and values (see below). The problem is that Tpetra insists on using
551 // size_t, and Epetra uses int internally. So we only resize here, and
552 // will need to copy in setAllValues
553 rowptr.resize(getLocalNumRows() + 1);
554
555 int lowerOffset = 0;
556 bool ownMemory = false;
557
558 // Column indices
559 // Extract, resize, set colind
560 Epetra_IntSerialDenseVector &myColind = mtx_->ExpertExtractIndices();
561 myColind.Resize(numNonZeros);
562 colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
563
564 // Values
565 // Extract, reallocate, set values
566 double *&myValues = mtx_->ExpertExtractValues();
567 delete[] myValues;
568 myValues = new double[numNonZeros];
569 values = Teuchos::arcp(myValues, lowerOffset, numNonZeros, ownMemory);
570 }
571
573 void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {
574 XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
575
576 // Check sizes
578 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
580 "An exception is thrown to let you know that you mismatched your pointers.");
581
582 // Check pointers
583 if (values.size() > 0) {
584 TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
585 "An exception is thrown to let you know that you mismatched your pointers.");
587 "An exception is thrown to let you know that you mismatched your pointers.");
588 }
589
590 // We have to make a copy here, it is unavoidable
591 // See comments in allocateAllValues
592 const size_t N = getLocalNumRows();
593
594 Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
595 myRowptr.Resize(N + 1);
596 for (size_t i = 0; i < N + 1; i++)
597 myRowptr[i] = Teuchos::as<int>(rowptr[i]);
598 }
599
602 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
603
604 int lowerOffset = 0;
605 bool ownMemory = false;
606
607 const size_t n = getLocalNumRows();
608 const size_t nnz = getLocalNumEntries();
609
610 // Row offsets
611 // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
612 Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
613 rowptr.resize(n + 1);
614 for (size_t i = 0; i < n + 1; i++)
615 (*const_cast<size_t *>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
616
617 // Column indices
618 colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
619
620 // Values
621 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
622 }
623
626 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
627
628 int lowerOffset = 0;
629 bool ownMemory = false;
630
631 const size_t nnz = getLocalNumEntries();
632 // Values
633 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
634 }
635
636 // Epetra always has global constants
637 bool haveGlobalConstants() const { return true; }
639 //** \warning This is an expert-only routine and should not be called from user code. */
641 const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
642 const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
643 const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
644 const RCP<ParameterList> & /* params */ = Teuchos::null) {
645 XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
646
647 // For Epetra matrices, resumeFill() is a fictive operation.
648 isFillResumed_ = false;
649
650 int rv = 0;
651 const Epetra_Import *myimport = 0;
652 const Epetra_Export *myexport = 0;
653
654 if (!importer.is_null()) {
655 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
656 myimport = eImporter.getEpetra_Import().getRawPtr();
657 }
658 if (!exporter.is_null()) {
659 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
660 myexport = eExporter.getEpetra_Export().getRawPtr();
661 }
662
663 rv = mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), myimport, myexport);
664
665 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
666 }
667
668
670
671
673 void resumeFill(const RCP<ParameterList> & /* params */ = Teuchos::null) {
674 XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
675
676 // According to Tpetra documentation, resumeFill() may be called repeatedly.
677 isFillResumed_ = true;
678 }
679
681 void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = Teuchos::null) {
682 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
683
684 // For Epetra matrices, resumeFill() is a fictive operation.
685 isFillResumed_ = false;
686
687 bool doOptimizeStorage = true;
688 if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
689 mtx_->FillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), doOptimizeStorage);
690 }
691
693 void fillComplete(const RCP<ParameterList> &params = Teuchos::null) {
694 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
695
696 // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
697 if (isFillResumed_ == true) {
698 isFillResumed_ = false;
699 return;
700 }
701
702 bool doOptimizeStorage = true;
703 if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
704 mtx_->FillComplete(doOptimizeStorage);
705 }
706
709 XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
710 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
711
712 const RCP<const Epetra_Import> &myImport = eImporter.getEpetra_Import();
713 int rv = 0;
714 if (myImport == Teuchos::null)
715 rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), 0);
716 else
717 rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), &*myImport);
718 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
719 }
720
722
724
725
727 const RCP<const Comm<int> > getComm() const {
728 XPETRA_MONITOR("EpetraCrsMatrixT::getComm");
729 return toXpetra(mtx_->Comm());
730 }
731
734 XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap");
735 return toXpetra<GlobalOrdinal, Node>(mtx_->RowMap());
736 }
737
740 XPETRA_MONITOR("EpetraCrsMatrixT::getColMap");
741 return toXpetra<GlobalOrdinal, Node>(mtx_->ColMap());
742 }
743
746 XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph");
747 return toXpetra<GlobalOrdinal, Node>(mtx_->Graph());
748 }
749
752 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows");
753 return mtx_->NumGlobalRows64();
754 }
755
758 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols");
759 return mtx_->NumGlobalCols64();
760 }
761
763 size_t getLocalNumRows() const {
764 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows");
765 return mtx_->NumMyRows();
766 }
767
769 size_t getLocalNumCols() const {
770 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols");
771 return mtx_->NumMyCols();
772 }
773
776 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries");
777 return mtx_->NumGlobalNonzeros64();
778 }
779
781 size_t getLocalNumEntries() const {
782 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries");
783 return mtx_->NumMyNonzeros();
784 }
785
787 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
788 XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow");
789 return mtx_->NumMyEntries(localRow);
790 }
791
793 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
794 XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow");
795 return mtx_->NumGlobalEntries(globalRow);
796 }
797
800 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries");
801 return mtx_->GlobalMaxNumEntries();
802 }
803
806 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries");
807 return mtx_->MaxNumEntries();
808 }
809
811 bool isLocallyIndexed() const {
812 XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed");
813 return mtx_->IndicesAreLocal();
814 }
815
817 bool isGloballyIndexed() const {
818 XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed");
819 return mtx_->IndicesAreGlobal();
820 }
821
823 bool isFillComplete() const {
824 XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete");
825 if (isFillResumed_)
826 return false;
827 else
828 return mtx_->Filled();
829 }
830
832 bool isFillActive() const {
833 XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive");
834 return !isFillComplete();
835 }
836
839 XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm");
840 return mtx_->NormFrobenius();
841 }
842
844 bool supportsRowViews() const {
845 XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews");
846 return true;
847 }
848
850 void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
851 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
852
853 int numEntries = -1;
854 XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
855 NumEntries = numEntries;
856 }
857
859 void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
860 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
861
862 int numEntries = -1;
863 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
864 NumEntries = numEntries;
865 }
866
869 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
870
871 int numEntries;
872 double *eValues;
873 GlobalOrdinal *eIndices;
874
875 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
876 if (numEntries == 0) {
877 eValues = NULL;
878 eIndices = NULL;
879 } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
880
881 indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
882 values = ArrayView<const double>(eValues, numEntries);
883 }
884
887 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
888
889 int numEntries;
890 double *eValues;
891 int *eIndices;
892
893 XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
894 if (numEntries == 0) {
895 eValues = NULL;
896 eIndices = NULL;
897 } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
898
899 indices = ArrayView<const int>(eIndices, numEntries);
900 values = ArrayView<const double>(eValues, numEntries);
901 }
902
905 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
906 XPETRA_ERR_CHECK(mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal, Node>(diag)));
907 }
908
910 void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> & /* offsets */) const {
911 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
912 }
913
916 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
917 }
918
920 void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> & /* offsets */) const {
921 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
922 }
923
926 mtx_->ReplaceDiagonalValues(toEpetra<GlobalOrdinal, Node>(diag));
927 }
928
935
937
939
940
943 XPETRA_MONITOR("EpetraCrsMatrixT::apply");
944
945 // TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
946
947 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
948 XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
949
950 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");
951 bool eTrans = toEpetra(mode);
952
953 // /!\ UseTranspose value
954 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.");
955
956 RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
957
958 // helper vector: tmp = A*x
960 tmp->PutScalar(0.0);
961 XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
962
963 // calculate alpha * A * x + beta * y
964 XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
965 }
966
969 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
970 }
971
974 XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap");
975 return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap());
976 }
977
980 XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap");
981 return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap());
982 }
983
985
987
988
990 std::string description() const {
991 XPETRA_MONITOR("EpetraCrsMatrixT::description");
992
993 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
994 std::ostringstream oss;
995 // TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
996 if (isFillComplete()) {
997 oss << "{status = fill complete"
998 << ", global rows = " << getGlobalNumRows()
999 << ", global cols = " << getGlobalNumCols()
1000 << ", global num entries = " << getGlobalNumEntries()
1001 << "}";
1002 } else {
1003 oss << "{status = fill not complete"
1004 << ", global rows = " << getGlobalNumRows()
1005 << "}";
1006 }
1007 return oss.str();
1008 }
1009
1012 XPETRA_MONITOR("EpetraCrsMatrixT::describe");
1013
1014 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1015 using std::endl;
1016 using std::setw;
1019 using Teuchos::VERB_HIGH;
1020 using Teuchos::VERB_LOW;
1022 using Teuchos::VERB_NONE;
1023 Teuchos::EVerbosityLevel vl = verbLevel;
1024 if (vl == VERB_DEFAULT) vl = VERB_LOW;
1025 RCP<const Comm<int> > comm = this->getComm();
1026 const int myImageID = comm->getRank(),
1027 numImages = comm->getSize();
1028 size_t width = 1;
1029 for (size_t dec = 10; dec < getGlobalNumRows(); dec *= 10) {
1030 ++width;
1031 }
1032 width = std::max<size_t>(width, 11) + 2;
1033 Teuchos::OSTab tab(out);
1034 // none: print nothing
1035 // low: print O(1) info from node 0
1036 // medium: print O(P) info, num entries per node
1037 // high: print O(N) info, num entries per row
1038 // extreme: print O(NNZ) info: print indices and values
1039 //
1040 // for medium and higher, print constituent objects at specified verbLevel
1041 if (vl != VERB_NONE) {
1042 if (myImageID == 0) out << this->description() << std::endl;
1043 // O(1) globals, minus what was already printed by description()
1044 if (isFillComplete() && myImageID == 0) {
1045 out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1046 }
1047 // constituent objects
1048 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1049 if (myImageID == 0) out << "\nRow map: " << std::endl;
1050 getRowMap()->describe(out, vl);
1051 //
1052 if (getColMap() != null) {
1053 if (getColMap() == getRowMap()) {
1054 if (myImageID == 0) out << "\nColumn map is row map.";
1055 } else {
1056 if (myImageID == 0) out << "\nColumn map: " << std::endl;
1057 getColMap()->describe(out, vl);
1058 }
1059 }
1060 if (getDomainMap() != null) {
1061 if (getDomainMap() == getRowMap()) {
1062 if (myImageID == 0) out << "\nDomain map is row map.";
1063 } else if (getDomainMap() == getColMap()) {
1064 if (myImageID == 0) out << "\nDomain map is row map.";
1065 } else {
1066 if (myImageID == 0) out << "\nDomain map: " << std::endl;
1067 getDomainMap()->describe(out, vl);
1068 }
1069 }
1070 if (getRangeMap() != null) {
1071 if (getRangeMap() == getDomainMap()) {
1072 if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1073 } else if (getRangeMap() == getRowMap()) {
1074 if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1075 } else {
1076 if (myImageID == 0) out << "\nRange map: " << std::endl;
1077 getRangeMap()->describe(out, vl);
1078 }
1079 }
1080 if (myImageID == 0) out << std::endl;
1081 }
1082 // O(P) data
1083 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1084 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1085 if (myImageID == imageCtr) {
1086 out << "Node ID = " << imageCtr << std::endl;
1087 // TODO: need a graph
1088 // if (staticGraph_->indicesAreAllocated() == false) {
1089 // out << "Node not allocated" << std::endl;
1090 // }
1091 // else {
1092 // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
1093 // }
1094
1095 // TMP:
1096 // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1097 // End of TMP
1098
1099 out << "Node number of entries = " << getLocalNumEntries() << std::endl;
1100 out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
1101 }
1102 comm->barrier();
1103 comm->barrier();
1104 comm->barrier();
1105 }
1106 }
1107 // O(N) and O(NNZ) data
1108 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1109 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1110 if (myImageID == imageCtr) {
1111 out << std::setw(width) << "Node ID"
1112 << std::setw(width) << "Global Row"
1113 << std::setw(width) << "Num Entries";
1114 if (vl == VERB_EXTREME) {
1115 out << std::setw(width) << "(Index,Value)";
1116 }
1117 out << std::endl;
1118 for (size_t r = 0; r < getLocalNumRows(); ++r) {
1119 const size_t nE = getNumEntriesInLocalRow(r);
1120 GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1121 out << std::setw(width) << myImageID
1122 << std::setw(width) << gid
1123 << std::setw(width) << nE;
1124 if (vl == VERB_EXTREME) {
1125 if (isGloballyIndexed()) {
1128 getGlobalRowView(gid, rowinds, rowvals);
1129 for (size_t j = 0; j < nE; ++j) {
1130 out << " (" << rowinds[j]
1131 << ", " << rowvals[j]
1132 << ") ";
1133 }
1134 } else if (isLocallyIndexed()) {
1137 getLocalRowView(r, rowinds, rowvals);
1138 for (size_t j = 0; j < nE; ++j) {
1139 out << " (" << getColMap()->getGlobalElement(rowinds[j])
1140 << ", " << rowvals[j]
1141 << ") ";
1142 }
1143 }
1144 }
1145 out << std::endl;
1146 }
1147 }
1148 comm->barrier();
1149 comm->barrier();
1150 comm->barrier();
1151 }
1152 }
1153 }
1154 }
1155
1156 void setObjectLabel(const std::string &objectLabel) {
1158 mtx_->SetLabel(objectLabel.c_str());
1159 }
1160
1161
1164 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_))))
1165 , isFillResumed_(false) {}
1166
1168 //{@
1169
1172 XPETRA_MONITOR("EpetraCrsMatrixT::getMap");
1173 return toXpetra<GlobalOrdinal, Node>(mtx_->Map());
1174 }
1175
1179 XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1180
1181 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1182 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1183
1184 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1185 int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1186 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1187 }
1188
1192 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1193
1194 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1195 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1196
1197 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1198 int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1199 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
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 EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "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, *tExporter.getEpetra_Export(), 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 EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "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, *tExporter.getEpetra_Export(), toEpetra(CM));
1225 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1226 }
1227
1229 XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
1230 const Epetra_Map *newMapEpetra = (!newMap.is_null()) ? &toEpetra<GlobalOrdinal, Node>(newMap) : 0;
1231 int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
1232 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1233 }
1234
1236
1238
1239
1241 bool hasMatrix() const { return !mtx_.is_null(); }
1242
1245 : mtx_(mtx)
1246 , isFillResumed_(false) {}
1247
1250
1252 RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } // TODO: remove
1253
1254#ifdef HAVE_XPETRA_TPETRA
1256
1258#if 0
1260 "Xpetra::EpetraCrsMatrx only available on host for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
1262#endif
1263 return getLocalMatrixHost();
1264 }
1265
1266 typename local_matrix_type::HostMirror getLocalMatrixHost() const {
1268
1269 const int numRows = matrix->NumMyRows();
1270 const int numCols = matrix->NumMyCols();
1271 const int nnz = matrix->NumMyNonzeros();
1272
1273 int *rowptr;
1274 int *colind;
1275 double *vals;
1276 int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1277 TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1278
1279 // Transform int* rowptr array to size_type* array
1280 typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows + 1);
1281 for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1283
1284 // create Kokkos::Views
1285 typename local_matrix_type::index_type kokkosColind(colind, nnz);
1286 typename local_matrix_type::values_type kokkosVals(vals, nnz);
1287
1288 local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1289
1290 return localMatrix;
1291 }
1292
1293 void setAllValues(const typename local_matrix_type::row_map_type &ptr,
1294 const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
1295 const typename local_matrix_type::values_type &val) {
1296 // Check sizes
1298 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1300 "An exception is thrown to let you know that you mismatched your pointers.");
1301
1302 // Check pointers
1303 if (val.size() > 0) {
1304 std::cout << ind.data() << " " << mtx_->ExpertExtractIndices().Values() << std::endl;
1305 TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1306 "An exception is thrown to let you know that you mismatched your pointers.");
1307 TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1308 "An exception is thrown to let you know that you mismatched your pointers.");
1309 }
1310
1311 // We have to make a copy here, it is unavoidable
1312 // See comments in allocateAllValues
1313 const size_t N = getLocalNumRows();
1314
1315 Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1316 myRowptr.Resize(N + 1);
1317 for (size_t i = 0; i < N + 1; i++)
1318 myRowptr[i] = Teuchos::as<int>(ptr(i));
1319 }
1320
1321 LocalOrdinal GetStorageBlockSize() const { return 1; }
1322
1323 private:
1324#else
1325#ifdef __GNUC__
1326#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."
1327#endif
1328#endif
1330
1339
1340 private:
1343
1351
1352}; // EpetraCrsMatrixT class
1353
1354#endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1355
1356#ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1357template <>
1359 : public CrsMatrix<double, int, long long, EpetraNode> {
1360 typedef long long GlobalOrdinal;
1364
1365 // The following typedefs are used by the Kokkos interface
1366#ifdef HAVE_XPETRA_TPETRA
1369#endif
1370
1371 public:
1373
1374
1376 EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1377 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), maxNumEntriesPerRow, true)))
1378 , isFillResumed_(false) {}
1379
1381 EpetraCrsMatrixT(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap, const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc, const Teuchos::RCP<Teuchos::ParameterList> & /* plist */ = Teuchos::null)
1382 : isFillResumed_(false) {
1383 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1384 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1385 }
1386
1388 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)
1389 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), maxNumEntriesPerRow, true)))
1390 , isFillResumed_(false) {}
1391
1393 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)
1394 : isFillResumed_(false) {
1395 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1396 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1397 }
1398
1403
1407 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1408 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1409 const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
1410 : isFillResumed_(false) {
1411 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1412 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1413
1414 const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1415 const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1416
1417 // Follows the Tpetra parameters
1418 bool restrictComm = false;
1419 if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1420 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), myDomainMap, myRangeMap, restrictComm));
1421 if (restrictComm && mtx_->NumMyRows() == 0)
1422 mtx_ = Teuchos::null;
1423 }
1424
1428 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1429 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1430 const Teuchos::RCP<Teuchos::ParameterList> &params = Teuchos::null)
1431 : isFillResumed_(false) {
1432 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1433 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1434
1435 const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1436 const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1437
1438 // Follows the Tpetra parameters
1439 bool restrictComm = false;
1440 if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1441
1442 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), myDomainMap, myRangeMap, restrictComm));
1443 }
1444
1447 const Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > DomainImporter,
1451 : isFillResumed_(false) {
1452 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1453 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1454 XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1455
1456 const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1457 const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1458
1459 // Follows the Tpetra parameters
1460 bool restrictComm = false;
1461 if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1462 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tImporter.getEpetra_Import(), tdImporter->getEpetra_Import().get(), myDomainMap, myRangeMap, restrictComm));
1463 if (restrictComm && mtx_->NumMyRows() == 0)
1464 mtx_ = Teuchos::null;
1465 }
1466
1469 const Teuchos::RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > DomainExporter,
1473 : isFillResumed_(false) {
1474 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1475 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1476 XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1477
1478 const Epetra_Map *myDomainMap = (domainMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(domainMap) : 0;
1479 const Epetra_Map *myRangeMap = (rangeMap != Teuchos::null) ? &toEpetra<GlobalOrdinal, Node>(rangeMap) : 0;
1480
1481 // Follows the Tpetra parameters
1482 bool restrictComm = false;
1483 if (!params.is_null()) restrictComm = params->get("Restrict Communicator", restrictComm);
1484
1485 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(), *tExporter.getEpetra_Export(), tdExporter->getEpetra_Export().get(), myDomainMap, myRangeMap, restrictComm));
1486 }
1487
1488#ifdef HAVE_XPETRA_TPETRA
1511 const local_matrix_type &lclMatrix,
1512 const Teuchos::RCP<Teuchos::ParameterList> &params = null)
1513 : EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params) {}
1514
1516 const local_matrix_type &lclMatrix,
1519 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap = Teuchos::null,
1520 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap = Teuchos::null,
1521 const Teuchos::RCP<Teuchos::ParameterList> &params = null) {
1522 // local typedefs from local_matrix_type
1523 // typedef typename local_matrix_type::size_type size_type;
1524 typedef typename local_matrix_type::value_type value_type;
1525 typedef typename local_matrix_type::ordinal_type ordinal_type;
1526
1527 // The number of rows in the sparse matrix.
1528 ordinal_type lclNumRows = lclMatrix.numRows();
1529 ordinal_type lclNumCols = lclMatrix.numCols(); // do we need this?
1530
1531 // plausibility checks
1533 "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1535 "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1536
1537 Teuchos::ArrayRCP<size_t> NumEntriesPerRowToAlloc(lclNumRows);
1538 for (ordinal_type r = 0; r < lclNumRows; ++r) {
1539 // extract data from current row r
1540 auto rowview = lclMatrix.row(r);
1541 NumEntriesPerRowToAlloc[r] = rowview.length;
1542 }
1543
1544 // setup matrix
1545 isFillResumed_ = false;
1546 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1547 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal, Node>(rowMap), toEpetra<GlobalOrdinal, Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1548
1549 // loop over all rows and colums of local matrix and fill matrix
1550 for (ordinal_type r = 0; r < lclNumRows; ++r) {
1551 // extract data from current row r
1552 auto rowview = lclMatrix.row(r);
1553
1554 // arrays for current row data
1557
1558 for (ordinal_type c = 0; c < rowview.length; c++) {
1559 value_type value = rowview.value(c);
1560 ordinal_type colidx = rowview.colidx(c);
1561
1562 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!");
1563
1564 indout[c] = colidx;
1565 valout[c] = value;
1566 }
1567 insertLocalValues(r, indout.view(0, indout.size()), valout.view(0, valout.size()));
1568 }
1569
1570 // call fill complete
1571 if (!domainMap.is_null() && !rangeMap.is_null())
1572 this->fillComplete(domainMap, rowMap, params);
1573 else
1574 this->fillComplete(rowMap, rowMap, params);
1575 }
1576#endif
1577
1580
1582
1584
1585
1588 XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1589 XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1590 }
1591
1594 XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1595 XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1596 }
1597
1600 XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1601
1602 {
1603 const std::string tfecfFuncName("replaceGlobalValues");
1605 ": Fill must be active in order to call this method. If you have already "
1606 "called fillComplete(), you need to call resumeFill() before you can "
1607 "replace values.");
1608
1609 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1610 std::runtime_error, ": values.size() must equal indices.size().");
1611 }
1612
1613 XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1614 }
1615
1618 XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
1619
1620 {
1621 const std::string tfecfFuncName("replaceLocalValues");
1623 ": Fill must be active in order to call this method. If you have already "
1624 "called fillComplete(), you need to call resumeFill() before you can "
1625 "replace values.");
1626
1627 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1628 std::runtime_error, ": values.size() must equal indices.size().");
1629 }
1630
1631 XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1632 }
1633
1635 void setAllToScalar(const Scalar &alpha) {
1636 XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar");
1637 mtx_->PutScalar(alpha);
1638 }
1639
1641 void scale(const Scalar &alpha) {
1642 XPETRA_MONITOR("EpetraCrsMatrixT::scale");
1643 mtx_->Scale(alpha);
1644 }
1645
1647 //** \warning This is an expert-only routine and should not be called from user code. */
1648 void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t> &rowptr, ArrayRCP<LocalOrdinal> &colind, ArrayRCP<Scalar> &values) {
1649 XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1650
1651 // Row offsets
1652 // Unfortunately, we cannot do this in the same manner as column indices
1653 // and values (see below). The problem is that Tpetra insists on using
1654 // size_t, and Epetra uses int internally. So we only resize here, and
1655 // will need to copy in setAllValues
1656 rowptr.resize(getLocalNumRows() + 1);
1657
1658 int lowerOffset = 0;
1659 bool ownMemory = false;
1660
1661 // Column indices
1662 // Extract, resize, set colind
1663 Epetra_IntSerialDenseVector &myColind = mtx_->ExpertExtractIndices();
1664 myColind.Resize(numNonZeros);
1665 colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1666
1667 // Values
1668 // Extract, reallocate, set values
1669 double *&myValues = mtx_->ExpertExtractValues();
1670 delete[] myValues;
1671 myValues = new double[numNonZeros];
1672 values = Teuchos::arcp(myValues, lowerOffset, numNonZeros, ownMemory);
1673 }
1674
1676 void setAllValues(const ArrayRCP<size_t> &rowptr, const ArrayRCP<LocalOrdinal> &colind, const ArrayRCP<Scalar> &values) {
1677 XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1678
1679 // Check sizes
1681 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1683 "An exception is thrown to let you know that you mismatched your pointers.");
1684
1685 // Check pointers
1686 if (values.size() > 0) {
1687 TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1688 "An exception is thrown to let you know that you mismatched your pointers.");
1690 "An exception is thrown to let you know that you mismatched your pointers.");
1691 }
1692
1693 // We have to make a copy here, it is unavoidable
1694 // See comments in allocateAllValues
1695 const size_t N = getLocalNumRows();
1696
1697 Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1698 myRowptr.Resize(N + 1);
1699 for (size_t i = 0; i < N + 1; i++)
1700 myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1701 }
1702
1705 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1706
1707 int lowerOffset = 0;
1708 bool ownMemory = false;
1709
1710 const size_t n = getLocalNumRows();
1711 const size_t nnz = getLocalNumEntries();
1712
1713 // Row offsets
1714 // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1715 Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
1716 rowptr.resize(n + 1);
1717 for (size_t i = 0; i < n + 1; i++)
1718 (*const_cast<size_t *>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1719
1720 // Column indices
1721 colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1722
1723 // Values
1724 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1725 }
1726
1729 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1730
1731 int lowerOffset = 0;
1732 bool ownMemory = false;
1733
1734 const size_t nnz = getLocalNumEntries();
1735 // Values
1736 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1737 }
1738
1739 // Epetra always has global constants
1740 bool haveGlobalConstants() const { return true; }
1741
1743 //** \warning This is an expert-only routine and should not be called from user code. */
1745 const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap,
1746 const RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > &importer = Teuchos::null,
1747 const RCP<const Export<LocalOrdinal, GlobalOrdinal, Node> > &exporter = Teuchos::null,
1748 const RCP<ParameterList> & /* params */ = Teuchos::null) {
1749 XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1750
1751 // For Epetra matrices, resumeFill() is a fictive operation.
1752 isFillResumed_ = false;
1753
1754 int rv = 0;
1755 const Epetra_Import *myimport = 0;
1756 const Epetra_Export *myexport = 0;
1757
1758 if (!importer.is_null()) {
1759 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1760 myimport = eImporter.getEpetra_Import().getRawPtr();
1761 }
1762 if (!exporter.is_null()) {
1763 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1764 myexport = eExporter.getEpetra_Export().getRawPtr();
1765 }
1766
1767 rv = mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), myimport, myexport);
1768
1769 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1770 }
1771
1772
1774
1775
1777 void resumeFill(const RCP<ParameterList> & /* params */ = Teuchos::null) {
1778 XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1779
1780 // According to Tpetra documentation, resumeFill() may be called repeatedly.
1781 isFillResumed_ = true;
1782 }
1783
1785 void fillComplete(const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &domainMap, const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rangeMap, const RCP<ParameterList> &params = Teuchos::null) {
1786 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1787
1788 // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1789 if (isFillResumed_ == true) {
1790 isFillResumed_ = false;
1791 return;
1792 }
1793
1794 bool doOptimizeStorage = true;
1795 if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
1796 mtx_->FillComplete(toEpetra<GlobalOrdinal, Node>(domainMap), toEpetra<GlobalOrdinal, Node>(rangeMap), doOptimizeStorage);
1797 }
1798
1800 void fillComplete(const RCP<ParameterList> &params = Teuchos::null) {
1801 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1802
1803 // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1804 if (isFillResumed_ == true) {
1805 isFillResumed_ = false;
1806 return;
1807 }
1808
1809 bool doOptimizeStorage = true;
1810 if (params != null && params->get("Optimize Storage", true) == false) doOptimizeStorage = false;
1811 mtx_->FillComplete(doOptimizeStorage);
1812 }
1813
1816 XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1817 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1818
1819 const RCP<const Epetra_Import> &myImport = eImporter.getEpetra_Import();
1820 int rv = 0;
1821 if (myImport == Teuchos::null)
1822 rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), 0);
1823 else
1824 rv = mtx_->ReplaceDomainMapAndImporter(toEpetra<GlobalOrdinal, Node>(newDomainMap), &*myImport);
1825 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1826 }
1827
1829
1831
1832
1835 XPETRA_MONITOR("EpetraCrsMatrixT::getComm");
1836 return toXpetra(mtx_->Comm());
1837 }
1838
1841 XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap");
1842 return toXpetra<GlobalOrdinal, Node>(mtx_->RowMap());
1843 }
1844
1847 XPETRA_MONITOR("EpetraCrsMatrixT::getColMap");
1848 return toXpetra<GlobalOrdinal, Node>(mtx_->ColMap());
1849 }
1850
1853 XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph");
1854 return toXpetra<GlobalOrdinal, Node>(mtx_->Graph());
1855 }
1856
1859 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows");
1860 return mtx_->NumGlobalRows64();
1861 }
1862
1865 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols");
1866 return mtx_->NumGlobalCols64();
1867 }
1868
1870 size_t getLocalNumRows() const {
1871 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows");
1872 return mtx_->NumMyRows();
1873 }
1874
1876 size_t getLocalNumCols() const {
1877 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols");
1878 return mtx_->NumMyCols();
1879 }
1880
1883 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries");
1884 return mtx_->NumGlobalNonzeros64();
1885 }
1886
1888 size_t getLocalNumEntries() const {
1889 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries");
1890 return mtx_->NumMyNonzeros();
1891 }
1892
1894 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
1895 XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow");
1896 return mtx_->NumMyEntries(localRow);
1897 }
1898
1900 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
1901 XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow");
1902 return mtx_->NumGlobalEntries(globalRow);
1903 }
1904
1907 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries");
1908 return mtx_->GlobalMaxNumEntries();
1909 }
1910
1913 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries");
1914 return mtx_->MaxNumEntries();
1915 }
1916
1918 bool isLocallyIndexed() const {
1919 XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed");
1920 return mtx_->IndicesAreLocal();
1921 }
1922
1924 bool isGloballyIndexed() const {
1925 XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed");
1926 return mtx_->IndicesAreGlobal();
1927 }
1928
1930 bool isFillComplete() const {
1931 XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete");
1932 if (isFillResumed_)
1933 return false;
1934 else
1935 return mtx_->Filled();
1936 }
1937
1939 bool isFillActive() const {
1940 XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive");
1941 return !isFillComplete();
1942 }
1943
1946 XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm");
1947 return mtx_->NormFrobenius();
1948 }
1949
1951 bool supportsRowViews() const {
1952 XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews");
1953 return true;
1954 }
1955
1957 void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1958 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1959
1960 int numEntries = -1;
1961 XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1962 NumEntries = numEntries;
1963 }
1964
1966 void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1967 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
1968
1969 int numEntries = -1;
1970 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1971 NumEntries = numEntries;
1972 }
1973
1976 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
1977
1978 int numEntries;
1979 double *eValues;
1980 GlobalOrdinal *eIndices;
1981
1982 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
1983 if (numEntries == 0) {
1984 eValues = NULL;
1985 eIndices = NULL;
1986 } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1987
1988 indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
1989 values = ArrayView<const double>(eValues, numEntries);
1990 }
1991
1994 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
1995
1996 int numEntries;
1997 double *eValues;
1998 int *eIndices;
1999
2000 XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
2001 if (numEntries == 0) {
2002 eValues = NULL;
2003 eIndices = NULL;
2004 } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
2005
2006 indices = ArrayView<const int>(eIndices, numEntries);
2007 values = ArrayView<const double>(eValues, numEntries);
2008 }
2009
2012 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
2013 mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal, Node>(diag));
2014 }
2015
2018 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
2019 }
2020
2023 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
2024 }
2025
2027 void getLocalDiagCopy(Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & /* diag */, const Kokkos::View<const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged> & /* offsets */) const {
2028 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
2029 }
2030
2033 mtx_->ReplaceDiagonalValues(toEpetra<GlobalOrdinal, Node>(diag));
2034 }
2035
2042
2044
2046
2047
2050 XPETRA_MONITOR("EpetraCrsMatrixT::apply");
2051
2052 // TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
2053
2054 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
2055 XPETRA_DYNAMIC_CAST(EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
2056
2057 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");
2058 bool eTrans = toEpetra(mode);
2059
2060 // /!\ UseTranspose value
2061 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.");
2062
2063 RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
2064
2065 // helper vector: tmp = A*x
2067 tmp->PutScalar(0.0);
2068 XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
2069
2070 // calculate alpha * A * x + beta * y
2071 XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha, *tmp, beta));
2072 }
2073
2075 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
2076 }
2077
2080 XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap");
2081 return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap());
2082 }
2083
2086 XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap");
2087 return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap());
2088 }
2089
2091
2093
2094
2096 std::string description() const {
2097 XPETRA_MONITOR("EpetraCrsMatrixT::description");
2098
2099 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2100 std::ostringstream oss;
2101 // TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
2102 if (isFillComplete()) {
2103 oss << "{status = fill complete"
2104 << ", global rows = " << getGlobalNumRows()
2105 << ", global cols = " << getGlobalNumCols()
2106 << ", global num entries = " << getGlobalNumEntries()
2107 << "}";
2108 } else {
2109 oss << "{status = fill not complete"
2110 << ", global rows = " << getGlobalNumRows()
2111 << "}";
2112 }
2113 return oss.str();
2114 }
2115
2118 XPETRA_MONITOR("EpetraCrsMatrixT::describe");
2119
2120 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2121 using std::endl;
2122 using std::setw;
2125 using Teuchos::VERB_HIGH;
2126 using Teuchos::VERB_LOW;
2128 using Teuchos::VERB_NONE;
2129 Teuchos::EVerbosityLevel vl = verbLevel;
2130 if (vl == VERB_DEFAULT) vl = VERB_LOW;
2131 RCP<const Comm<int> > comm = this->getComm();
2132 const int myImageID = comm->getRank(),
2133 numImages = comm->getSize();
2134 size_t width = 1;
2135 for (size_t dec = 10; dec < getGlobalNumRows(); dec *= 10) {
2136 ++width;
2137 }
2138 width = std::max<size_t>(width, 11) + 2;
2139 Teuchos::OSTab tab(out);
2140 // none: print nothing
2141 // low: print O(1) info from node 0
2142 // medium: print O(P) info, num entries per node
2143 // high: print O(N) info, num entries per row
2144 // extreme: print O(NNZ) info: print indices and values
2145 //
2146 // for medium and higher, print constituent objects at specified verbLevel
2147 if (vl != VERB_NONE) {
2148 if (myImageID == 0) out << this->description() << std::endl;
2149 // O(1) globals, minus what was already printed by description()
2150 if (isFillComplete() && myImageID == 0) {
2151 out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
2152 }
2153 // constituent objects
2154 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2155 if (myImageID == 0) out << "\nRow map: " << std::endl;
2156 getRowMap()->describe(out, vl);
2157 //
2158 if (getColMap() != null) {
2159 if (getColMap() == getRowMap()) {
2160 if (myImageID == 0) out << "\nColumn map is row map.";
2161 } else {
2162 if (myImageID == 0) out << "\nColumn map: " << std::endl;
2163 getColMap()->describe(out, vl);
2164 }
2165 }
2166 if (getDomainMap() != null) {
2167 if (getDomainMap() == getRowMap()) {
2168 if (myImageID == 0) out << "\nDomain map is row map.";
2169 } else if (getDomainMap() == getColMap()) {
2170 if (myImageID == 0) out << "\nDomain map is row map.";
2171 } else {
2172 if (myImageID == 0) out << "\nDomain map: " << std::endl;
2173 getDomainMap()->describe(out, vl);
2174 }
2175 }
2176 if (getRangeMap() != null) {
2177 if (getRangeMap() == getDomainMap()) {
2178 if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
2179 } else if (getRangeMap() == getRowMap()) {
2180 if (myImageID == 0) out << "\nRange map is row map." << std::endl;
2181 } else {
2182 if (myImageID == 0) out << "\nRange map: " << std::endl;
2183 getRangeMap()->describe(out, vl);
2184 }
2185 }
2186 if (myImageID == 0) out << std::endl;
2187 }
2188 // O(P) data
2189 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2190 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2191 if (myImageID == imageCtr) {
2192 out << "Node ID = " << imageCtr << std::endl;
2193 // TODO: need a graph
2194 // if (staticGraph_->indicesAreAllocated() == false) {
2195 // out << "Node not allocated" << std::endl;
2196 // }
2197 // else {
2198 // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
2199 // }
2200
2201 // TMP:
2202 // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2203 // End of TMP
2204
2205 out << "Node number of entries = " << getLocalNumEntries() << std::endl;
2206 out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
2207 }
2208 comm->barrier();
2209 comm->barrier();
2210 comm->barrier();
2211 }
2212 }
2213 // O(N) and O(NNZ) data
2214 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2215 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2216 if (myImageID == imageCtr) {
2217 out << std::setw(width) << "Node ID"
2218 << std::setw(width) << "Global Row"
2219 << std::setw(width) << "Num Entries";
2220 if (vl == VERB_EXTREME) {
2221 out << std::setw(width) << "(Index,Value)";
2222 }
2223 out << std::endl;
2224 for (size_t r = 0; r < getLocalNumRows(); ++r) {
2225 const size_t nE = getNumEntriesInLocalRow(r);
2226 GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2227 out << std::setw(width) << myImageID
2228 << std::setw(width) << gid
2229 << std::setw(width) << nE;
2230 if (vl == VERB_EXTREME) {
2231 if (isGloballyIndexed()) {
2234 getGlobalRowView(gid, rowinds, rowvals);
2235 for (size_t j = 0; j < nE; ++j) {
2236 out << " (" << rowinds[j]
2237 << ", " << rowvals[j]
2238 << ") ";
2239 }
2240 } else if (isLocallyIndexed()) {
2243 getLocalRowView(r, rowinds, rowvals);
2244 for (size_t j = 0; j < nE; ++j) {
2245 out << " (" << getColMap()->getGlobalElement(rowinds[j])
2246 << ", " << rowvals[j]
2247 << ") ";
2248 }
2249 }
2250 }
2251 out << std::endl;
2252 }
2253 }
2254 comm->barrier();
2255 comm->barrier();
2256 comm->barrier();
2257 }
2258 }
2259 }
2260 }
2261
2262 void setObjectLabel(const std::string &objectLabel) {
2264 mtx_->SetLabel(objectLabel.c_str());
2265 }
2266
2267
2270 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_))))
2271 , isFillResumed_(false) {}
2272
2274 //{@
2275
2278 XPETRA_MONITOR("EpetraCrsMatrixT::getMap");
2279 return toXpetra<GlobalOrdinal, Node>(mtx_->Map());
2280 }
2281
2285 XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2286
2287 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2288 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2289
2290 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2291 int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2292 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2293 }
2294
2298 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2299
2300 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2301 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2302
2303 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2304 int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2305 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
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 EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "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, *tExporter.getEpetra_Export(), 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 EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "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, *tExporter.getEpetra_Export(), toEpetra(CM));
2331 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2332 }
2333
2335 XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
2336 const Epetra_Map *newMapEpetra = (!newMap.is_null()) ? &toEpetra<GlobalOrdinal, Node>(newMap) : 0;
2337 int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
2338 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
2339 }
2340
2342
2344
2345
2347 bool hasMatrix() const { return !mtx_.is_null(); }
2348
2351 : mtx_(mtx)
2352 , isFillResumed_(false) {}
2353
2356
2358 RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } // TODO: remove
2359
2360#ifdef HAVE_XPETRA_TPETRA
2364
2365 const int numRows = matrix->NumMyRows();
2366 const int numCols = matrix->NumMyCols();
2367 const int nnz = matrix->NumMyNonzeros();
2368
2369 int *rowptr;
2370 int *colind;
2371 double *vals;
2372 int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2373 TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2374
2375 // Transform int* rowptr array to size_type* array
2376 typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows + 1);
2377 for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2379
2380 // create Kokkos::Views
2381 typename local_matrix_type::index_type kokkosColind(colind, nnz);
2382 typename local_matrix_type::values_type kokkosVals(vals, nnz);
2383
2384 local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2385
2386 return localMatrix;
2387 }
2388
2389 void setAllValues(const typename local_matrix_type::row_map_type &ptr,
2390 const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type &ind,
2391 const typename local_matrix_type::values_type &val) {
2392 // Check sizes
2394 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
2396 "An exception is thrown to let you know that you mismatched your pointers.");
2397
2398 // Check pointers
2399 if (val.size() > 0) {
2400 TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
2401 "An exception is thrown to let you know that you mismatched your pointers.");
2402 TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
2403 "An exception is thrown to let you know that you mismatched your pointers.");
2404 }
2405
2406 // We have to make a copy here, it is unavoidable
2407 // See comments in allocateAllValues
2408 const size_t N = getLocalNumRows();
2409
2410 Epetra_IntSerialDenseVector &myRowptr = mtx_->ExpertExtractIndexOffset();
2411 myRowptr.Resize(N + 1);
2412 for (size_t i = 0; i < N + 1; i++)
2413 myRowptr[i] = Teuchos::as<int>(ptr(i));
2414 }
2415
2416 LocalOrdinal GetStorageBlockSize() const { return 1; }
2417
2418 private:
2419#else
2420#ifdef __GNUC__
2421#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."
2422#endif
2423#endif
2424
2426
2434
2435 private:
2437
2438 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.
2439
2440}; // EpetraCrsMatrixT class
2441
2442#endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2443
2444} // namespace Xpetra
2445
2446#define XPETRA_EPETRACRSMATRIX_SHORT
2447#endif // XPETRA_EPETRACRSMATRIX_HPP
Copy
#define XPETRA_MONITOR(funcName)
#define XPETRA_ERR_CHECK(arg)
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
#define XPETRA_RCP_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
int Resize(int Length_in)
size_type size() const
T * getRawPtr() const
ArrayView< T > view(size_type lowerOffset, size_type size) const
void resize(const size_type n, const T &val=T())
iterator begin() const
iterator end() const
size_type size() const
T * getRawPtr() const
static const EVerbosityLevel verbLevel_default
virtual void setObjectLabel(const std::string &objectLabel)
bool is_null() const
T * get() const
LocalOrdinal local_ordinal_type
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...
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
size_t getLocalNumRows() const
Returns the number of matrix rows owned on the calling node.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
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.
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::node_type node_type
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
Get the underlying Epetra matrix.
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
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)
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
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.
void fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
size_t getLocalNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix.
bool isFillResumed_
Flag to keep track of fill status.
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 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.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
void replaceDiag(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag)
Replace the diagonal entries of the matrix.
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< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
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 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 isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
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 getLocalNumEntries() const
Returns the local number of entries in this matrix.
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 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...
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_type local_matrix_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.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
RCP< Epetra_CrsMatrix > mtx_
The underlying actual matrix object.
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 getAllValues(ArrayRCP< Scalar > &values)
Gets the 1D pointer arrays of the graph.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
void setObjectLabel(const std::string &objectLabel)
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
Gets the 1D pointer arrays of the graph.
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...
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
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.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using local IDs.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
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)
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 setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
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....
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 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.
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.
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
local_matrix_type getLocalMatrixDevice() const
Compatibility layer for accessing the matrix data through a Kokkos interface.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap)
Constructor for empty DynamicProfile matrix (no space is preallocated).
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
bool isFillActive() const
Returns true if the matrix is in edit mode.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using global IDs.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &) const
Get offsets of the diagonal entries in the matrix.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
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.
std::string description() const
A simple one-line description of this object.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
void resumeFill(const RCP< ParameterList > &=Teuchos::null)
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
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 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.
local_matrix_type::HostMirror getLocalMatrixHost() const
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 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 doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
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, 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.
size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
bool hasMatrix() const
Does this have an underlying matrix.
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &) const
Get offsets of the diagonal entries in the matrix.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
size_t getLocalNumRows() const
Returns the number of matrix rows owned on the calling node.
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
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.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
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.
bool hasMatrix() const
Does this have an underlying matrix.
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 insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
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 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.
size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
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)
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified (locally owned) global row.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using local IDs.
void getAllValues(ArrayRCP< Scalar > &values)
Gets the 1D pointer arrays of the graph.
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.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
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 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
void fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
size_t getLocalNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
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)
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() 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 column Map and number of entries in each row.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using global IDs.
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_type local_matrix_type
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)
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 resumeFill(const RCP< ParameterList > &=Teuchos::null)
local_matrix_type getLocalMatrix() const
Compatibility layer for accessing the matrix data through a Kokkos interface.
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
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.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
const RCP< const Comm< int > > getComm() const
Returns the communicator.
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.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
bool isFillActive() const
Returns true if the matrix is in edit mode.
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::node_type node_type
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 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.
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
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 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...
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
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 replaceDiag(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag)
Replace the diagonal entries of the matrix.
LocalOrdinal GetStorageBlockSize() const
Returns the block size of the storage mechanism, which is usually 1, except for Tpetra::BlockCrsMatri...
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.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
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 doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
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.
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...
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.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying a previously constructed graph.
std::string description() const
A simple one-line description of this object.
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.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
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.
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.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
size_t getLocalNumCols() const
Returns the number of matrix columns owned on the calling node.
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries in the specified global row.
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)
void fillComplete(const RCP< ParameterList > &params=null)
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
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 getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
void resumeFill(const RCP< ParameterList > &params=null)
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)
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null)
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
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...
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
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 allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
void setAllToScalar(const Scalar &alpha)
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)
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)
LocalOrdinal GetStorageBlockSize() const
Returns the block size of the storage mechanism, which is usually 1, except for Tpetra::BlockCrsMatri...
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
local_matrix_type getLocalMatrixDevice() const
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
const RCP< const Comm< int > > getComm() const
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_matrix_type local_matrix_type
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
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=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
void getAllValues(ArrayRCP< Scalar > &values)
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
size_t getLocalNumRows() const
Returns the number of matrix rows owned on the calling node.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
The Map describing the parallel distribution of this object.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Kokkos::View< const size_t *, typename Node::device_type, Kokkos::MemoryUnmanaged > &offsets) const
bool isFillActive() const
Returns true if the matrix is in edit mode.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
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 doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
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)
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
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 describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
local_matrix_type::HostMirror getLocalMatrixHost() const
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
bool hasMatrix() const
Does this have an underlying matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void replaceDiag(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
std::string description() const
A simple one-line description of this object.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
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)
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >::node_type node_type
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)
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Exception throws when you call an unimplemented method of Xpetra.
Exception throws to report errors in the internal logical of the program.
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.
#define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TypeTo as(const TypeFrom &t)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
TypeTo asSafe(const TypeFrom &t)
basic_FancyOStream< char > FancyOStream
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
size_t global_size_t
Global size_t object.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
CombineMode
Xpetra::Combine Mode enumerable type.
static magnitudeType magnitude(T a)