Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_EpetraCrsMatrix.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// Xpetra: A linear algebra interface package
6// Copyright 2012 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact
39// Jonathan Hu (jhu@sandia.gov)
40// Andrey Prokopenko (aprokop@sandia.gov)
41// Ray Tuminaro (rstumin@sandia.gov)
42//
43// ***********************************************************************
44//
45// @HEADER
46#ifndef XPETRA_EPETRACRSMATRIX_HPP
47#define XPETRA_EPETRACRSMATRIX_HPP
48
49/* this file is automatically generated - do not edit (see script/epetra.py) */
50
51#ifdef HAVE_XPETRA_TPETRA
52#include <Kokkos_Core.hpp>
53#endif
54
56
57#include "Xpetra_CrsMatrix.hpp"
58
59#include <Epetra_CrsMatrix.h>
60#include <Epetra_Map.h>
61
62#include "Xpetra_EpetraMap.hpp"
66
67#include "Xpetra_MapFactory.hpp"
68
69#include "Xpetra_Utils.hpp"
70#include "Xpetra_Exceptions.hpp"
71
72namespace Xpetra {
73
74// general implementation: empty stub
75template<class EpetraGlobalOrdinal, class Node>
77 : public CrsMatrix<double, int, EpetraGlobalOrdinal, Node>
78{
79 typedef EpetraGlobalOrdinal GlobalOrdinal;
82
83#ifdef HAVE_XPETRA_TPETRA
86#endif
87
88public:
89 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) {
91 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
92 }
93 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) {
95 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
96 }
97 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=Kokkos::Compat::KokkosSerialWrapperNode."); }
98 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=Kokkos::Compat::KokkosSerialWrapperNode."); }
99 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=Kokkos::Compat::KokkosSerialWrapperNode."); }
102 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
103 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
104 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
106 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
107 }
110 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
111 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
112 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
114 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
115 }
118 const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
119 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
120 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
123 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
124 }
127 const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
128 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
129 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
132 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
133 }
134#ifdef HAVE_XPETRA_TPETRA
137 const local_matrix_type& lclMatrix,
138 const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
140 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
141 }
143 const local_matrix_type& lclMatrix,
146 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
147 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
148 const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
150 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
151 }
152#endif
153 virtual ~EpetraCrsMatrixT() { }
154
159 void setAllToScalar(const Scalar &alpha) { }
160 void scale(const Scalar &alpha) { }
161 void allocateAllValues(size_t numNonZeros,ArrayRCP<size_t> & rowptr, ArrayRCP<LocalOrdinal> & colind, ArrayRCP<Scalar> & values) { }
162 void setAllValues(const ArrayRCP<size_t> & rowptr, const ArrayRCP<LocalOrdinal> & colind, const ArrayRCP<Scalar> & values) { }
165 bool haveGlobalConstants() const { return true;}
167 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
168 const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
169 const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
170 const RCP<ParameterList> &params=Teuchos::null) { }
171
172 void resumeFill(const RCP< ParameterList > &params=null) { }
173 void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null) { }
174 void fillComplete(const RCP< ParameterList > &params=null) { }
176 const RCP< const Comm< int > > getComm() const { return Teuchos::null; }
177 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { return Teuchos::null; }
178 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { return Teuchos::null; }
180 global_size_t getGlobalNumRows() const { return 0; }
181 global_size_t getGlobalNumCols() const { return 0; }
182 size_t getLocalNumRows() const { return 0; }
183 size_t getLocalNumCols() const { return 0; }
184 global_size_t getGlobalNumEntries() const { return 0; }
185 size_t getLocalNumEntries() const { return 0; }
186 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { return 0; }
187 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { return 0; }
188 size_t getGlobalMaxNumRowEntries() const { return 0; }
189 size_t getLocalMaxNumRowEntries() const { return 0; }
190 bool isLocallyIndexed() const { return false; }
191 bool isGloballyIndexed() const { return false; }
192 bool isFillComplete() const { return false; }
193 bool isFillActive() const { return false; }
195 bool supportsRowViews() const { return false; }
196 void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
197 void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
206
210 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { return Teuchos::null; }
211
212 std::string description() const { return std::string(""); }
214 void setObjectLabel( const std::string &objectLabel ) { }
215
218 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
219 }
220
227
228 bool hasMatrix() const { return false; }
231 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
232 }
233 RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
234 RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } //TODO: remove
235#ifdef HAVE_XPETRA_TPETRA
238 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
239 }
240 typename local_matrix_type::HostMirror getLocalMatrixHost () const {
242 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
243 }
244
245
246
247 void setAllValues (const typename local_matrix_type::row_map_type& ptr,
248 const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& ind,
249 const typename local_matrix_type::values_type& val)
250 {
252 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
253 }
254
256
257#else
258#ifdef __GNUC__
259#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."
260#endif
261#endif
262
263
267 Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
268 apply(X,R);
269 R.update(one,B,negone);
270 }
271
272}; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
273
274#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
275template<>
277: public CrsMatrix <double, int, int, EpetraNode>
278{
279 typedef int GlobalOrdinal;
283
284
285 // The following typedefs are used by the Kokkos interface
286#ifdef HAVE_XPETRA_TPETRA
289#endif
290
291public:
292
294
295
298: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), 0, false))), isFillResumed_(false)
299{ }
300
302 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */ = Teuchos::null)
303: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
304{ }
305
306
308 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
309 : isFillResumed_(false)
310 {
311 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
312 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
313 }
314
315
317 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)
318 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
319 { }
320
321
324 : isFillResumed_(false)
325 {
326 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
327 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
328 }
329
330
333 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
334 { }
335
336
340 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
341 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
342 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
343 isFillResumed_(false)
344 {
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>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
347
348 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
349 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
350
351 // Follows the Tpetra parameters
352 bool restrictComm=false;
353 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
354 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
355 if(restrictComm && mtx_->NumMyRows()==0)
356 mtx_=Teuchos::null;
357 }
358
359
360
364 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
365 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
366 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
367 isFillResumed_(false)
368 {
369 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
370 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
371
372 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
373 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
374
375 // Follows the Tpetra parameters
376 bool restrictComm=false;
377 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
378
379 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
380 }
381
384 const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
385 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
386 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
388 isFillResumed_(false)
389 {
390 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
391 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
392 XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
393
394 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
395 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
396
397 // Follows the Tpetra parameters
398 bool restrictComm=false;
399 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
400 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
401 if(restrictComm && mtx_->NumMyRows()==0)
402 mtx_=Teuchos::null;
403 }
404
407 const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
408 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
409 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
411 isFillResumed_(false)
412 {
413 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
414 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
415 XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
416
417 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
418 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
419
420 // Follows the Tpetra parameters
421 bool restrictComm=false;
422 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
423
424 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
425 }
426
427#ifdef HAVE_XPETRA_TPETRA
428 // NOTE: TPETRA means we can use C++11 here
429
453 const local_matrix_type& lclMatrix,
454 const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
455 EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
456 { }
457
459 const local_matrix_type& lclMatrix,
462 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
463 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
464 const Teuchos::RCP<Teuchos::ParameterList>& params = null)
465 {
466 // local typedefs from local_matrix_type
467 //typedef typename local_matrix_type::size_type size_type;
468 typedef typename local_matrix_type::value_type value_type;
469 typedef typename local_matrix_type::ordinal_type ordinal_type;
470
471 // The number of rows in the sparse matrix.
472 ordinal_type lclNumRows = lclMatrix.numRows ();
473 ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
474
475 // plausibility checks
476 TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
477 "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
478 TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
479 "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
480
481 Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
482 for (ordinal_type r = 0; r < lclNumRows; ++r) {
483 // extract data from current row r
484 auto rowview = lclMatrix.row (r);
485 NumEntriesPerRowToAlloc[r] = rowview.length;
486 }
487
488 // setup matrix
489 isFillResumed_ = false;
490 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
491 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
492
493 // loop over all rows and colums of local matrix and fill matrix
494 for (ordinal_type r = 0; r < lclNumRows; ++r) {
495 // extract data from current row r
496 auto rowview = lclMatrix.row (r);
497
498 // arrays for current row data
501
502 for(ordinal_type c = 0; c < rowview.length; c++) {
503 value_type value = rowview.value (c);
504 ordinal_type colidx = rowview.colidx (c);
505
506 TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError,
507 "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
508
509 indout [c] = colidx;
510 valout [c] = value;
511 }
512 insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
513 }
514
515 // call fill complete
516 if (!domainMap.is_null() && !rangeMap.is_null())
517 this->fillComplete(domainMap, rowMap, params);
518 else
519 this->fillComplete(rowMap, rowMap, params);
520 }
521#endif
522
524 virtual ~EpetraCrsMatrixT() { }
525
527
529
530
533 XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
534 XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
535 }
536
537
540 XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
541 XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
542 }
543
546 XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
547
548 {
549 const std::string tfecfFuncName("replaceGlobalValues");
551 ": Fill must be active in order to call this method. If you have already "
552 "called fillComplete(), you need to call resumeFill() before you can "
553 "replace values.");
554
555 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
556 std::runtime_error, ": values.size() must equal indices.size().");
557 }
558
559 XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
560
561 }
562
565 XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
566
567 {
568 const std::string tfecfFuncName("replaceLocalValues");
570 ": Fill must be active in order to call this method. If you have already "
571 "called fillComplete(), you need to call resumeFill() before you can "
572 "replace values.");
573
574 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
575 std::runtime_error, ": values.size() must equal indices.size().");
576 }
577
578 XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
579
580 }
581
582
584 void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
585
587 void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
588
590 //** \warning This is an expert-only routine and should not be called from user code. */
591 void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
592 XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
593
594 // Row offsets
595 // Unfortunately, we cannot do this in the same manner as column indices
596 // and values (see below). The problem is that Tpetra insists on using
597 // size_t, and Epetra uses int internally. So we only resize here, and
598 // will need to copy in setAllValues
599 rowptr.resize(getLocalNumRows()+1);
600
601 int lowerOffset = 0;
602 bool ownMemory = false;
603
604 // Column indices
605 // Extract, resize, set colind
606 Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
607 myColind.Resize(numNonZeros);
608 colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
609
610 // Values
611 // Extract, reallocate, set values
612 double *& myValues = mtx_->ExpertExtractValues();
613 delete [] myValues;
614 myValues = new double[numNonZeros];
615 values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
616 }
617
619 void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
620 XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
621
622 // Check sizes
624 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
626 "An exception is thrown to let you know that you mismatched your pointers.");
627
628 // Check pointers
629 if (values.size() > 0) {
630 TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
631 "An exception is thrown to let you know that you mismatched your pointers.");
632 TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
633 "An exception is thrown to let you know that you mismatched your pointers.");
634 }
635
636 // We have to make a copy here, it is unavoidable
637 // See comments in allocateAllValues
638 const size_t N = getLocalNumRows();
639
640 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
641 myRowptr.Resize(N+1);
642 for (size_t i = 0; i < N+1; i++)
643 myRowptr[i] = Teuchos::as<int>(rowptr[i]);
644 }
645
646
649 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
650
651 int lowerOffset = 0;
652 bool ownMemory = false;
653
654 const size_t n = getLocalNumRows();
655 const size_t nnz = getLocalNumEntries();
656
657 // Row offsets
658 // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
659 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
660 rowptr.resize(n+1);
661 for (size_t i = 0; i < n+1; i++)
662 (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
663
664 // Column indices
665 colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
666
667 // Values
668 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
669 }
670
673 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
674
675 int lowerOffset = 0;
676 bool ownMemory = false;
677
678 const size_t nnz = getLocalNumEntries();
679 // Values
680 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
681 }
682
683 // Epetra always has global constants
684 bool haveGlobalConstants() const { return true; }
686 //** \warning This is an expert-only routine and should not be called from user code. */
688 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
689 const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
690 const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
691 const RCP<ParameterList> & /* params */=Teuchos::null) {
692 XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
693
694 // For Epetra matrices, resumeFill() is a fictive operation.
695 isFillResumed_ = false;
696
697 int rv=0;
698 const Epetra_Import * myimport =0;
699 const Epetra_Export * myexport =0;
700
701 if(!importer.is_null()) {
702 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
703 myimport = eImporter.getEpetra_Import().getRawPtr();
704 }
705 if(!exporter.is_null()) {
706 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
707 myexport = eExporter.getEpetra_Export().getRawPtr();
708 }
709
710 rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
711
712 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
713 }
715
717
718
720 void resumeFill(const RCP< ParameterList > &/* params */=Teuchos::null) {
721 XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
722
723 // According to Tpetra documentation, resumeFill() may be called repeatedly.
724 isFillResumed_ = true;
725 }
726
728 void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
729 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
730
731 // For Epetra matrices, resumeFill() is a fictive operation.
732 isFillResumed_ = false;
733
734 bool doOptimizeStorage = true;
735 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
736 mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
737 }
738
739
741 void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
742 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
743
744 // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
745 if (isFillResumed_ == true) { isFillResumed_ = false; return; }
746
747 bool doOptimizeStorage = true;
748 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
749 mtx_->FillComplete(doOptimizeStorage);
750 }
751
752
755 XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
756 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
757
758 const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
759 int rv=0;
760 if(myImport==Teuchos::null)
761 rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
762 else
763 rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
764 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
765 }
766
768
770
771
773 const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
774
776 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
777
779 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
780
782 RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
783
785 global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
786
788 global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
789
791 size_t getLocalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows"); return mtx_->NumMyRows(); }
792
794 size_t getLocalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols"); return mtx_->NumMyCols(); }
795
797 global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
798
800 size_t getLocalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries"); return mtx_->NumMyNonzeros(); }
801
803 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
804
806 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow"); return mtx_->NumGlobalEntries(globalRow); }
807
809 size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
810
812 size_t getLocalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
813
815 bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
816
818 bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
819
821 bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
822
824 bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
825
827 ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
828
830 bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
831
833 void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
834 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
835
836 int numEntries = -1;
837 XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
838 NumEntries = numEntries;
839 }
840
842 void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
843 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
844
845 int numEntries = -1;
846 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
847 NumEntries = numEntries;
848 }
849
852 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
853
854 int numEntries;
855 double * eValues;
856 GlobalOrdinal * eIndices;
857
858 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
859 if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
860
861 indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
862 values = ArrayView<const double>(eValues, numEntries);
863 }
864
867 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
868
869 int numEntries;
870 double * eValues;
871 int * eIndices;
872
873 XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
874 if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
875
876 indices = ArrayView<const int>(eIndices, numEntries);
877 values = ArrayView<const double>(eValues, numEntries);
878 }
879
882 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
883 XPETRA_ERR_CHECK(mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)));
884 }
885
888 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
889 }
890
893 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
894 }
895
898 mtx_->ReplaceDiagonalValues (toEpetra<GlobalOrdinal,Node>(diag));
899 }
900
902 XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
903 };
905 XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
906 };
907
909
911
912
915 XPETRA_MONITOR("EpetraCrsMatrixT::apply");
916
917 //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
918
919 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
920 XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
921
922 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");
923 bool eTrans = toEpetra(mode);
924
925 // /!\ UseTranspose value
926 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.");
927
928 RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
929
930 // helper vector: tmp = A*x
932 tmp->PutScalar(0.0);
933 XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
934
935 // calculate alpha * A * x + beta * y
936 XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
937 }
938
941 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
942 }
943
945 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
946
948 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
949
951
953
954
956 std::string description() const {
957 XPETRA_MONITOR("EpetraCrsMatrixT::description");
958
959 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
960 std::ostringstream oss;
961 //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
962 if (isFillComplete()) {
963 oss << "{status = fill complete"
964 << ", global rows = " << getGlobalNumRows()
965 << ", global cols = " << getGlobalNumCols()
966 << ", global num entries = " << getGlobalNumEntries()
967 << "}";
968 }
969 else {
970 oss << "{status = fill not complete"
971 << ", global rows = " << getGlobalNumRows()
972 << "}";
973 }
974 return oss.str();
975
976 }
977
978
981 XPETRA_MONITOR("EpetraCrsMatrixT::describe");
982
983 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
984 using std::endl;
985 using std::setw;
987 using Teuchos::VERB_NONE;
988 using Teuchos::VERB_LOW;
990 using Teuchos::VERB_HIGH;
992 Teuchos::EVerbosityLevel vl = verbLevel;
993 if (vl == VERB_DEFAULT) vl = VERB_LOW;
994 RCP<const Comm<int> > comm = this->getComm();
995 const int myImageID = comm->getRank(),
996 numImages = comm->getSize();
997 size_t width = 1;
998 for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
999 ++width;
1000 }
1001 width = std::max<size_t>(width,11) + 2;
1002 Teuchos::OSTab tab(out);
1003 // none: print nothing
1004 // low: print O(1) info from node 0
1005 // medium: print O(P) info, num entries per node
1006 // high: print O(N) info, num entries per row
1007 // extreme: print O(NNZ) info: print indices and values
1008 //
1009 // for medium and higher, print constituent objects at specified verbLevel
1010 if (vl != VERB_NONE) {
1011 if (myImageID == 0) out << this->description() << std::endl;
1012 // O(1) globals, minus what was already printed by description()
1013 if (isFillComplete() && myImageID == 0) {
1014 out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1015 }
1016 // constituent objects
1017 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1018 if (myImageID == 0) out << "\nRow map: " << std::endl;
1019 getRowMap()->describe(out,vl);
1020 //
1021 if (getColMap() != null) {
1022 if (getColMap() == getRowMap()) {
1023 if (myImageID == 0) out << "\nColumn map is row map.";
1024 }
1025 else {
1026 if (myImageID == 0) out << "\nColumn map: " << std::endl;
1027 getColMap()->describe(out,vl);
1028 }
1029 }
1030 if (getDomainMap() != null) {
1031 if (getDomainMap() == getRowMap()) {
1032 if (myImageID == 0) out << "\nDomain map is row map.";
1033 }
1034 else if (getDomainMap() == getColMap()) {
1035 if (myImageID == 0) out << "\nDomain map is row map.";
1036 }
1037 else {
1038 if (myImageID == 0) out << "\nDomain map: " << std::endl;
1039 getDomainMap()->describe(out,vl);
1040 }
1041 }
1042 if (getRangeMap() != null) {
1043 if (getRangeMap() == getDomainMap()) {
1044 if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1045 }
1046 else if (getRangeMap() == getRowMap()) {
1047 if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1048 }
1049 else {
1050 if (myImageID == 0) out << "\nRange map: " << std::endl;
1051 getRangeMap()->describe(out,vl);
1052 }
1053 }
1054 if (myImageID == 0) out << std::endl;
1055 }
1056 // O(P) data
1057 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1058 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1059 if (myImageID == imageCtr) {
1060 out << "Node ID = " << imageCtr << std::endl;
1061 // TODO: need a graph
1062 // if (staticGraph_->indicesAreAllocated() == false) {
1063 // out << "Node not allocated" << std::endl;
1064 // }
1065 // else {
1066 // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
1067 // }
1068
1069 // TMP:
1070 // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1071 // End of TMP
1072
1073 out << "Node number of entries = " << getLocalNumEntries() << std::endl;
1074 out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
1075 }
1076 comm->barrier();
1077 comm->barrier();
1078 comm->barrier();
1079 }
1080 }
1081 // O(N) and O(NNZ) data
1082 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1083 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1084 if (myImageID == imageCtr) {
1085 out << std::setw(width) << "Node ID"
1086 << std::setw(width) << "Global Row"
1087 << std::setw(width) << "Num Entries";
1088 if (vl == VERB_EXTREME) {
1089 out << std::setw(width) << "(Index,Value)";
1090 }
1091 out << std::endl;
1092 for (size_t r=0; r < getLocalNumRows(); ++r) {
1093 const size_t nE = getNumEntriesInLocalRow(r);
1094 GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1095 out << std::setw(width) << myImageID
1096 << std::setw(width) << gid
1097 << std::setw(width) << nE;
1098 if (vl == VERB_EXTREME) {
1099 if (isGloballyIndexed()) {
1102 getGlobalRowView(gid,rowinds,rowvals);
1103 for (size_t j=0; j < nE; ++j) {
1104 out << " (" << rowinds[j]
1105 << ", " << rowvals[j]
1106 << ") ";
1107 }
1108 }
1109 else if (isLocallyIndexed()) {
1112 getLocalRowView(r,rowinds,rowvals);
1113 for (size_t j=0; j < nE; ++j) {
1114 out << " (" << getColMap()->getGlobalElement(rowinds[j])
1115 << ", " << rowvals[j]
1116 << ") ";
1117 }
1118 }
1119 }
1120 out << std::endl;
1121 }
1122 }
1123 comm->barrier();
1124 comm->barrier();
1125 comm->barrier();
1126 }
1127 }
1128 }
1129
1130 }
1131
1132 void setObjectLabel( const std::string &objectLabel ) {
1134 mtx_->SetLabel(objectLabel.c_str());
1135 }
1137
1140 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
1141 { }
1142
1143
1145 //{@
1146
1148 Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
1149
1153 XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1154
1155 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1156 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1157
1158 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1159 int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1160 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1161 }
1162
1166 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1167
1168 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1169 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1170
1171 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1172 int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1173 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
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 EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "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, *tExporter.getEpetra_Export(), toEpetra(CM));
1186 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1187
1188 }
1189
1193 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1194
1195 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1196 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1197
1198 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1199 int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1200 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1201 }
1202
1204 XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
1205 const Epetra_Map* newMapEpetra = (!newMap.is_null())? &toEpetra<GlobalOrdinal,Node>(newMap) : 0;
1206 int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
1207 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1208 }
1209
1211
1213
1214
1216 bool hasMatrix() const { return !mtx_.is_null();}
1217
1219 EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
1220
1223
1225 RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
1226
1227#ifdef HAVE_XPETRA_TPETRA
1229
1231#if 0
1233 "Xpetra::EpetraCrsMatrx only available on host for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
1235#endif
1236 return getLocalMatrixHost();
1237}
1238
1239
1240typename local_matrix_type::HostMirror getLocalMatrixHost () const {
1242
1243 const int numRows = matrix->NumMyRows();
1244 const int numCols = matrix->NumMyCols();
1245 const int nnz = matrix->NumMyNonzeros();
1246
1247 int* rowptr;
1248 int* colind;
1249 double* vals;
1250 int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1251 TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1252
1253 // Transform int* rowptr array to size_type* array
1254 typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows+1);
1255 for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1256 kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
1257
1258 // create Kokkos::Views
1259 typename local_matrix_type::index_type kokkosColind(colind, nnz);
1260 typename local_matrix_type::values_type kokkosVals (vals, nnz);
1261
1262 local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1263
1264 return localMatrix;
1265 }
1266
1267 void setAllValues (const typename local_matrix_type::row_map_type& ptr,
1268 const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& ind,
1269 const typename local_matrix_type::values_type& val)
1270 {
1271
1272 // Check sizes
1273 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(ptr.size()) != getLocalNumRows()+1, Xpetra::Exceptions::RuntimeError,
1274 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1276 "An exception is thrown to let you know that you mismatched your pointers.");
1277
1278 // Check pointers
1279 if (val.size() > 0) {
1280 std::cout << ind.data() << " " << mtx_->ExpertExtractIndices().Values() << std::endl;
1281 TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1282 "An exception is thrown to let you know that you mismatched your pointers.");
1283 TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1284 "An exception is thrown to let you know that you mismatched your pointers.");
1285 }
1286
1287 // We have to make a copy here, it is unavoidable
1288 // See comments in allocateAllValues
1289 const size_t N = getLocalNumRows();
1290
1291 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1292 myRowptr.Resize(N+1);
1293 for (size_t i = 0; i < N+1; i++)
1294 myRowptr[i] = Teuchos::as<int>(ptr(i));
1295
1296 }
1297
1298
1300
1301private:
1302#else
1303#ifdef __GNUC__
1304#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."
1305#endif
1306#endif
1308
1309
1310
1314 Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
1315
1316 apply(X,R);
1317 R.update(one,B,negone);
1318 }
1319
1320private:
1323
1331
1332}; // EpetraCrsMatrixT class
1333
1334#endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1335
1336#ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1337template<>
1339: public CrsMatrix <double, int, long long, EpetraNode>
1340{
1341 typedef long long GlobalOrdinal;
1345
1346
1347 // The following typedefs are used by the Kokkos interface
1348#ifdef HAVE_XPETRA_TPETRA
1351#endif
1352
1353public:
1354
1356
1357
1359 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */ = Teuchos::null)
1360: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
1361{ }
1362
1363
1365 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
1366 : isFillResumed_(false)
1367 {
1368 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1369 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1370 }
1371
1372
1374 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)
1375 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
1376 { }
1377
1378
1381 : isFillResumed_(false)
1382 {
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), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1385 }
1386
1387
1390 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
1391 { }
1392
1393
1397 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1398 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1399 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
1400 isFillResumed_(false)
1401 {
1402 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1403 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1404
1405 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1406 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1407
1408 // Follows the Tpetra parameters
1409 bool restrictComm=false;
1410 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1411 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
1412 if(restrictComm && mtx_->NumMyRows()==0)
1413 mtx_=Teuchos::null;
1414 }
1415
1416
1417
1421 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1422 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1423 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
1424 isFillResumed_(false)
1425 {
1426 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1427 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1428
1429 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1430 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1431
1432 // Follows the Tpetra parameters
1433 bool restrictComm=false;
1434 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1435
1436 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
1437 }
1438
1440 const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
1441 const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
1442 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1443 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1445 isFillResumed_(false)
1446 {
1447 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1448 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1449 XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1450
1451 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1452 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1453
1454 // Follows the Tpetra parameters
1455 bool restrictComm=false;
1456 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1457 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
1458 if(restrictComm && mtx_->NumMyRows()==0)
1459 mtx_=Teuchos::null;
1460 }
1461
1463 const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
1464 const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
1465 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1466 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1468 isFillResumed_(false)
1469 {
1470 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1471 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1472 XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1473
1474 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1475 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1476
1477 // Follows the Tpetra parameters
1478 bool restrictComm=false;
1479 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1480
1481 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
1482 }
1483
1484#ifdef HAVE_XPETRA_TPETRA
1507 const local_matrix_type& lclMatrix,
1508 const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
1509 EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
1510{ }
1511
1513 const local_matrix_type& lclMatrix,
1516 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
1517 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
1518 const Teuchos::RCP<Teuchos::ParameterList>& params = null)
1519 {
1520 // local typedefs from local_matrix_type
1521 //typedef typename local_matrix_type::size_type size_type;
1522 typedef typename local_matrix_type::value_type value_type;
1523 typedef typename local_matrix_type::ordinal_type ordinal_type;
1524
1525 // The number of rows in the sparse matrix.
1526 ordinal_type lclNumRows = lclMatrix.numRows ();
1527 ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
1528
1529 // plausibility checks
1530 TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
1531 "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1532 TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getLocalNumElements()), Xpetra::Exceptions::RuntimeError,
1533 "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1534
1535 Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
1536 for (ordinal_type r = 0; r < lclNumRows; ++r) {
1537 // extract data from current row r
1538 auto rowview = lclMatrix.row (r);
1539 NumEntriesPerRowToAlloc[r] = rowview.length;
1540 }
1541
1542 // setup matrix
1543 isFillResumed_ = false;
1544 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1545 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1546
1547 // loop over all rows and colums of local matrix and fill matrix
1548 for (ordinal_type r = 0; r < lclNumRows; ++r) {
1549 // extract data from current row r
1550 auto rowview = lclMatrix.row (r);
1551
1552 // arrays for current row data
1555
1556 for(ordinal_type c = 0; c < rowview.length; c++) {
1557 value_type value = rowview.value (c);
1558 ordinal_type colidx = rowview.colidx (c);
1559
1560 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!");
1561
1562 indout [c] = colidx;
1563 valout [c] = value;
1564 }
1565 insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
1566 }
1567
1568 // call fill complete
1569 if (!domainMap.is_null() && !rangeMap.is_null())
1570 this->fillComplete(domainMap, rowMap, params);
1571 else
1572 this->fillComplete(rowMap, rowMap, params);
1573 }
1574#endif
1575
1577 virtual ~EpetraCrsMatrixT() { }
1578
1580
1582
1583
1586 XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1587 XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1588 }
1589
1590
1593 XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1594 XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1595 }
1596
1599 XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1600
1601 {
1602 const std::string tfecfFuncName("replaceGlobalValues");
1604 ": Fill must be active in order to call this method. If you have already "
1605 "called fillComplete(), you need to call resumeFill() before you can "
1606 "replace values.");
1607
1608 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1609 std::runtime_error, ": values.size() must equal indices.size().");
1610 }
1611
1612 XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1613
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 }
1634
1635
1637 void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
1638
1640 void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
1641
1643 //** \warning This is an expert-only routine and should not be called from user code. */
1644 void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
1645 XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1646
1647 // Row offsets
1648 // Unfortunately, we cannot do this in the same manner as column indices
1649 // and values (see below). The problem is that Tpetra insists on using
1650 // size_t, and Epetra uses int internally. So we only resize here, and
1651 // will need to copy in setAllValues
1652 rowptr.resize(getLocalNumRows()+1);
1653
1654 int lowerOffset = 0;
1655 bool ownMemory = false;
1656
1657 // Column indices
1658 // Extract, resize, set colind
1659 Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
1660 myColind.Resize(numNonZeros);
1661 colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1662
1663 // Values
1664 // Extract, reallocate, set values
1665 double *& myValues = mtx_->ExpertExtractValues();
1666 delete [] myValues;
1667 myValues = new double[numNonZeros];
1668 values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
1669 }
1670
1672 void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
1673 XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1674
1675 // Check sizes
1677 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1679 "An exception is thrown to let you know that you mismatched your pointers.");
1680
1681 // Check pointers
1682 if (values.size() > 0) {
1683 TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1684 "An exception is thrown to let you know that you mismatched your pointers.");
1685 TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1686 "An exception is thrown to let you know that you mismatched your pointers.");
1687 }
1688
1689 // We have to make a copy here, it is unavoidable
1690 // See comments in allocateAllValues
1691 const size_t N = getLocalNumRows();
1692
1693 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1694 myRowptr.Resize(N+1);
1695 for (size_t i = 0; i < N+1; i++)
1696 myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1697 }
1698
1699
1702 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1703
1704 int lowerOffset = 0;
1705 bool ownMemory = false;
1706
1707 const size_t n = getLocalNumRows();
1708 const size_t nnz = getLocalNumEntries();
1709
1710 // Row offsets
1711 // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1712 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1713 rowptr.resize(n+1);
1714 for (size_t i = 0; i < n+1; i++)
1715 (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1716
1717 // Column indices
1718 colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1719
1720 // Values
1721 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1722 }
1723
1724
1727 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1728
1729 int lowerOffset = 0;
1730 bool ownMemory = false;
1731
1732 const size_t nnz = getLocalNumEntries();
1733 // Values
1734 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1735 }
1736
1737
1738 // Epetra always has global constants
1739 bool haveGlobalConstants() const { return true;}
1740
1742 //** \warning This is an expert-only routine and should not be called from user code. */
1744 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1745 const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
1746 const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
1747 const RCP<ParameterList> & /* params */=Teuchos::null) {
1748 XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1749
1750 // For Epetra matrices, resumeFill() is a fictive operation.
1751 isFillResumed_ = false;
1752
1753 int rv=0;
1754 const Epetra_Import * myimport =0;
1755 const Epetra_Export * myexport =0;
1756
1757 if(!importer.is_null()) {
1758 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1759 myimport = eImporter.getEpetra_Import().getRawPtr();
1760 }
1761 if(!exporter.is_null()) {
1762 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1763 myexport = eExporter.getEpetra_Export().getRawPtr();
1764 }
1765
1766 rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
1767
1768 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1769 }
1771
1773
1774
1776 void resumeFill(const RCP< ParameterList > &/* params */=Teuchos::null) {
1777 XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1778
1779 // According to Tpetra documentation, resumeFill() may be called repeatedly.
1780 isFillResumed_ = true;
1781 }
1782
1784 void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
1785 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1786
1787 // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1788 if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1789
1790 bool doOptimizeStorage = true;
1791 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1792 mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
1793 }
1794
1795
1797 void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
1798 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1799
1800 // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1801 if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1802
1803 bool doOptimizeStorage = true;
1804 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1805 mtx_->FillComplete(doOptimizeStorage);
1806 }
1807
1808
1811 XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1812 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1813
1814 const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
1815 int rv=0;
1816 if(myImport==Teuchos::null)
1817 rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
1818 else
1819 rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
1820 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1821 }
1822
1824
1826
1827
1829 const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
1830
1832 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
1833
1835 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
1836
1838 RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
1839
1841 global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
1842
1844 global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
1845
1847 size_t getLocalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumRows"); return mtx_->NumMyRows(); }
1848
1850 size_t getLocalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumCols"); return mtx_->NumMyCols(); }
1851
1853 global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
1854
1856 size_t getLocalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalNumEntries"); return mtx_->NumMyNonzeros(); }
1857
1859 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
1860
1862 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow"); return mtx_->NumGlobalEntries(globalRow); }
1863
1865 size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
1866
1868 size_t getLocalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
1869
1871 bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
1872
1874 bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
1875
1877 bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
1878
1880 bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
1881
1883 typename ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
1884
1886 bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
1887
1889 void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1890 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1891
1892 int numEntries = -1;
1893 XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1894 NumEntries = numEntries;
1895 }
1896
1898 void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1899 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
1900
1901 int numEntries = -1;
1902 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1903 NumEntries = numEntries;
1904 }
1905
1908 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
1909
1910 int numEntries;
1911 double * eValues;
1912 GlobalOrdinal * eIndices;
1913
1914 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
1915 if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1916
1917 indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
1918 values = ArrayView<const double>(eValues, numEntries);
1919 }
1920
1923 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
1924
1925 int numEntries;
1926 double * eValues;
1927 int * eIndices;
1928
1929 XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
1930 if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1931
1932 indices = ArrayView<const int>(eIndices, numEntries);
1933 values = ArrayView<const double>(eValues, numEntries);
1934 }
1935
1937 void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy"); mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)); }
1938
1941 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
1942 }
1943
1946 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
1947 }
1948
1951 mtx_->ReplaceDiagonalValues (toEpetra<GlobalOrdinal,Node>(diag));
1952 }
1953
1955 XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
1956 };
1958 XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
1959 };
1960
1962
1964
1965
1968 XPETRA_MONITOR("EpetraCrsMatrixT::apply");
1969
1970 //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
1971
1972 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1973 XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1974
1975 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");
1976 bool eTrans = toEpetra(mode);
1977
1978 // /!\ UseTranspose value
1979 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.");
1980
1981 RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
1982
1983 // helper vector: tmp = A*x
1985 tmp->PutScalar(0.0);
1986 XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
1987
1988 // calculate alpha * A * x + beta * y
1989 XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
1990 }
1991
1993 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
1994 }
1995
1997 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
1998
2000 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
2001
2003
2005
2006
2008 std::string description() const {
2009 XPETRA_MONITOR("EpetraCrsMatrixT::description");
2010
2011 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2012 std::ostringstream oss;
2013 //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
2014 if (isFillComplete()) {
2015 oss << "{status = fill complete"
2016 << ", global rows = " << getGlobalNumRows()
2017 << ", global cols = " << getGlobalNumCols()
2018 << ", global num entries = " << getGlobalNumEntries()
2019 << "}";
2020 }
2021 else {
2022 oss << "{status = fill not complete"
2023 << ", global rows = " << getGlobalNumRows()
2024 << "}";
2025 }
2026 return oss.str();
2027
2028 }
2029
2030
2033 XPETRA_MONITOR("EpetraCrsMatrixT::describe");
2034
2035 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2036 using std::endl;
2037 using std::setw;
2039 using Teuchos::VERB_NONE;
2040 using Teuchos::VERB_LOW;
2042 using Teuchos::VERB_HIGH;
2044 Teuchos::EVerbosityLevel vl = verbLevel;
2045 if (vl == VERB_DEFAULT) vl = VERB_LOW;
2046 RCP<const Comm<int> > comm = this->getComm();
2047 const int myImageID = comm->getRank(),
2048 numImages = comm->getSize();
2049 size_t width = 1;
2050 for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
2051 ++width;
2052 }
2053 width = std::max<size_t>(width,11) + 2;
2054 Teuchos::OSTab tab(out);
2055 // none: print nothing
2056 // low: print O(1) info from node 0
2057 // medium: print O(P) info, num entries per node
2058 // high: print O(N) info, num entries per row
2059 // extreme: print O(NNZ) info: print indices and values
2060 //
2061 // for medium and higher, print constituent objects at specified verbLevel
2062 if (vl != VERB_NONE) {
2063 if (myImageID == 0) out << this->description() << std::endl;
2064 // O(1) globals, minus what was already printed by description()
2065 if (isFillComplete() && myImageID == 0) {
2066 out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
2067 }
2068 // constituent objects
2069 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2070 if (myImageID == 0) out << "\nRow map: " << std::endl;
2071 getRowMap()->describe(out,vl);
2072 //
2073 if (getColMap() != null) {
2074 if (getColMap() == getRowMap()) {
2075 if (myImageID == 0) out << "\nColumn map is row map.";
2076 }
2077 else {
2078 if (myImageID == 0) out << "\nColumn map: " << std::endl;
2079 getColMap()->describe(out,vl);
2080 }
2081 }
2082 if (getDomainMap() != null) {
2083 if (getDomainMap() == getRowMap()) {
2084 if (myImageID == 0) out << "\nDomain map is row map.";
2085 }
2086 else if (getDomainMap() == getColMap()) {
2087 if (myImageID == 0) out << "\nDomain map is row map.";
2088 }
2089 else {
2090 if (myImageID == 0) out << "\nDomain map: " << std::endl;
2091 getDomainMap()->describe(out,vl);
2092 }
2093 }
2094 if (getRangeMap() != null) {
2095 if (getRangeMap() == getDomainMap()) {
2096 if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
2097 }
2098 else if (getRangeMap() == getRowMap()) {
2099 if (myImageID == 0) out << "\nRange map is row map." << std::endl;
2100 }
2101 else {
2102 if (myImageID == 0) out << "\nRange map: " << std::endl;
2103 getRangeMap()->describe(out,vl);
2104 }
2105 }
2106 if (myImageID == 0) out << std::endl;
2107 }
2108 // O(P) data
2109 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2110 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2111 if (myImageID == imageCtr) {
2112 out << "Node ID = " << imageCtr << std::endl;
2113 // TODO: need a graph
2114 // if (staticGraph_->indicesAreAllocated() == false) {
2115 // out << "Node not allocated" << std::endl;
2116 // }
2117 // else {
2118 // out << "Node number of allocated entries = " << staticGraph_->getLocalAllocationSize() << std::endl;
2119 // }
2120
2121 // TMP:
2122 // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2123 // End of TMP
2124
2125 out << "Node number of entries = " << getLocalNumEntries() << std::endl;
2126 out << "Node max number of entries = " << getLocalMaxNumRowEntries() << std::endl;
2127 }
2128 comm->barrier();
2129 comm->barrier();
2130 comm->barrier();
2131 }
2132 }
2133 // O(N) and O(NNZ) data
2134 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2135 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2136 if (myImageID == imageCtr) {
2137 out << std::setw(width) << "Node ID"
2138 << std::setw(width) << "Global Row"
2139 << std::setw(width) << "Num Entries";
2140 if (vl == VERB_EXTREME) {
2141 out << std::setw(width) << "(Index,Value)";
2142 }
2143 out << std::endl;
2144 for (size_t r=0; r < getLocalNumRows(); ++r) {
2145 const size_t nE = getNumEntriesInLocalRow(r);
2146 GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2147 out << std::setw(width) << myImageID
2148 << std::setw(width) << gid
2149 << std::setw(width) << nE;
2150 if (vl == VERB_EXTREME) {
2151 if (isGloballyIndexed()) {
2154 getGlobalRowView(gid,rowinds,rowvals);
2155 for (size_t j=0; j < nE; ++j) {
2156 out << " (" << rowinds[j]
2157 << ", " << rowvals[j]
2158 << ") ";
2159 }
2160 }
2161 else if (isLocallyIndexed()) {
2164 getLocalRowView(r,rowinds,rowvals);
2165 for (size_t j=0; j < nE; ++j) {
2166 out << " (" << getColMap()->getGlobalElement(rowinds[j])
2167 << ", " << rowvals[j]
2168 << ") ";
2169 }
2170 }
2171 }
2172 out << std::endl;
2173 }
2174 }
2175 comm->barrier();
2176 comm->barrier();
2177 comm->barrier();
2178 }
2179 }
2180 }
2181
2182 }
2183
2184 void setObjectLabel( const std::string &objectLabel ) {
2186 mtx_->SetLabel(objectLabel.c_str());
2187 }
2189
2192 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
2193 { }
2194
2195
2197 //{@
2198
2200 Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
2201
2205 XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2206
2207 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2208 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2209
2210 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2211 int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2212 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2213 }
2214
2218 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2219
2220 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2221 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2222
2223 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2224 int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2225 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2226 }
2227
2231 XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2232
2233 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2234 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2235
2236 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2237 int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2238 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2239
2240 }
2241
2245 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2246
2247 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2248 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2249
2250 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2251 int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2252 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2253 }
2254
2256 XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
2257 const Epetra_Map* newMapEpetra = (!newMap.is_null())? &toEpetra<GlobalOrdinal,Node>(newMap) : 0;
2258 int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
2259 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
2260 }
2261
2263
2265
2266
2268 bool hasMatrix() const { return !mtx_.is_null();}
2269
2271 EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
2272
2275
2277 RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
2278
2279#ifdef HAVE_XPETRA_TPETRA
2282
2284
2285 const int numRows = matrix->NumMyRows();
2286 const int numCols = matrix->NumMyCols();
2287 const int nnz = matrix->NumMyNonzeros();
2288
2289 int* rowptr;
2290 int* colind;
2291 double* vals;
2292 int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2293 TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2294
2295 // Transform int* rowptr array to size_type* array
2296 typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr(Kokkos::ViewAllocateWithoutInitializing("local row map"), numRows+1);
2297 for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2298 kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
2299
2300 // create Kokkos::Views
2301 typename local_matrix_type::index_type kokkosColind(colind, nnz);
2302 typename local_matrix_type::values_type kokkosVals (vals, nnz);
2303
2304 local_matrix_type localMatrix = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2305
2306 return localMatrix;
2307 }
2308
2309 void setAllValues (const typename local_matrix_type::row_map_type& ptr,
2310 const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& ind,
2311 const typename local_matrix_type::values_type& val)
2312 {
2313
2314 // Check sizes
2315 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(ptr.size()) != getLocalNumRows()+1, Xpetra::Exceptions::RuntimeError,
2316 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
2318 "An exception is thrown to let you know that you mismatched your pointers.");
2319
2320 // Check pointers
2321 if (val.size() > 0) {
2322 TEUCHOS_TEST_FOR_EXCEPTION(ind.data() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
2323 "An exception is thrown to let you know that you mismatched your pointers.");
2324 TEUCHOS_TEST_FOR_EXCEPTION(val.data() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
2325 "An exception is thrown to let you know that you mismatched your pointers.");
2326 }
2327
2328 // We have to make a copy here, it is unavoidable
2329 // See comments in allocateAllValues
2330 const size_t N = getLocalNumRows();
2331
2332 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
2333 myRowptr.Resize(N+1);
2334 for (size_t i = 0; i < N+1; i++)
2335 myRowptr[i] = Teuchos::as<int>(ptr(i));
2336
2337 }
2338
2339
2341
2342private:
2343#else
2344#ifdef __GNUC__
2345#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."
2346#endif
2347#endif
2348
2349
2351
2355 Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
2356 apply(X,R);
2357 R.update(one,B,negone);
2358 }
2359
2360private:
2362
2363 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.
2364
2365}; // EpetraCrsMatrixT class
2366
2367#endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2368
2369} // Xpetra namespace
2370
2371#define XPETRA_EPETRACRSMATRIX_SHORT
2372#endif // XPETRA_EPETRACRSMATRIX_HPP
#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
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...
LocalOrdinal local_ordinal_type
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 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.
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)
Signal that data entry is complete.
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)
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)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Copy
Xpetra namespace
size_t global_size_t
Global size_t object.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
CombineMode
Xpetra::Combine Mode enumerable type.
static magnitudeType magnitude(T a)