Xpetra Version of the Day
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_KOKKOS_REFACTOR
52#ifdef HAVE_XPETRA_TPETRA
53#include <Kokkos_View.hpp>
54#endif
55#endif
56
58
59#include "Xpetra_CrsMatrix.hpp"
60
61#include <Epetra_CrsMatrix.h>
62#include <Epetra_Map.h>
63
64#include "Xpetra_EpetraMap.hpp"
68
69#include "Xpetra_MapFactory.hpp"
70
71#include "Xpetra_Utils.hpp"
72#include "Xpetra_Exceptions.hpp"
73
74namespace Xpetra {
75
76// general implementation: empty stub
77template<class EpetraGlobalOrdinal, class Node>
79 : public CrsMatrix<double, int, EpetraGlobalOrdinal, Node>
80{
81 typedef EpetraGlobalOrdinal GlobalOrdinal;
84
85#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
86#ifdef HAVE_XPETRA_TPETRA
89#endif
90#endif
91
92public:
93 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, 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 ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) {
99 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
100 }
101 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."); }
102 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."); }
103 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."); }
106 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
107 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
108 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
110 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
111 }
114 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
115 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
116 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
118 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
119 }
122 const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
123 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
124 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
127 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
128 }
131 const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
132 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
133 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
136 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
137 }
138#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
139#ifdef HAVE_XPETRA_TPETRA
142 const local_matrix_type& lclMatrix,
143 const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
145 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
146 }
148 const local_matrix_type& lclMatrix,
149 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
150 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
151 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
152 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
153 const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
155 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
156 }
157#endif
158#endif
159 virtual ~EpetraCrsMatrixT() { }
160
165 void setAllToScalar(const Scalar &alpha) { }
166 void scale(const Scalar &alpha) { }
167 void allocateAllValues(size_t numNonZeros,ArrayRCP<size_t> & rowptr, ArrayRCP<LocalOrdinal> & colind, ArrayRCP<Scalar> & values) { }
168 void setAllValues(const ArrayRCP<size_t> & rowptr, const ArrayRCP<LocalOrdinal> & colind, const ArrayRCP<Scalar> & values) { }
171 bool haveGlobalConstants() const { return true;}
173 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
174 const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
175 const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
176 const RCP<ParameterList> &params=Teuchos::null) { }
177
178 void resumeFill(const RCP< ParameterList > &params=null) { }
179 void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null) { }
180 void fillComplete(const RCP< ParameterList > &params=null) { }
182 const RCP< const Comm< int > > getComm() const { return Teuchos::null; }
183 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { return Teuchos::null; }
184 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { return Teuchos::null; }
186 global_size_t getGlobalNumRows() const { return 0; }
187 global_size_t getGlobalNumCols() const { return 0; }
188 size_t getNodeNumRows() const { return 0; }
189 size_t getNodeNumCols() const { return 0; }
190 global_size_t getGlobalNumEntries() const { return 0; }
191 size_t getNodeNumEntries() const { return 0; }
192 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { return 0; }
193 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { return 0; }
194 size_t getGlobalMaxNumRowEntries() const { return 0; }
195 size_t getNodeMaxNumRowEntries() const { return 0; }
196 bool isLocallyIndexed() const { return false; }
197 bool isGloballyIndexed() const { return false; }
198 bool isFillComplete() const { return false; }
199 bool isFillActive() const { return false; }
201 bool supportsRowViews() const { return false; }
202 void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
203 void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
212
216 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { return Teuchos::null; }
217
218 std::string description() const { return std::string(""); }
220 void setObjectLabel( const std::string &objectLabel ) { }
221
224 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
225 }
226
233
234 bool hasMatrix() const { return false; }
237 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
238 }
239 RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
240 RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } //TODO: remove
241#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
242#ifdef HAVE_XPETRA_TPETRA
243#ifdef TPETRA_ENABLE_DEPRECATED_CODE
244 local_matrix_type getLocalMatrix () const {
246 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
247 }
248#endif
249local_matrix_type getLocalMatrixDevice () const {
251 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
252 }
253 typename local_matrix_type::HostMirror getLocalMatrixHost () const {
255 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
256 }
257
258
259
260 void setAllValues (const typename local_matrix_type::row_map_type& ptr,
261 const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& ind,
262 const typename local_matrix_type::values_type& val)
263 {
265 "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
266 }
267#else
268#ifdef __GNUC__
269#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."
270#endif
271#endif
272#endif
273
277 Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
278 apply(X,R);
279 R.update(one,B,negone);
280 }
281
282}; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
283
284#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
285template<>
287: public CrsMatrix <double, int, int, EpetraNode>
288{
289 typedef int GlobalOrdinal;
293
294
295 // The following typedefs are used by the Kokkos interface
296#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
297#ifdef HAVE_XPETRA_TPETRA
300#endif
301#endif
302
303public:
304
306
307
310: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), 0, false))), isFillResumed_(false)
311{ }
312
314 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */ = Teuchos::null)
315: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
316{ }
317
318
320 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
321 : isFillResumed_(false)
322 {
323 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
324 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
325 }
326
327
329 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)
330 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
331 { }
332
333
336 : isFillResumed_(false)
337 {
338 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
339 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
340 }
341
342
345 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
346 { }
347
348
352 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
353 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
354 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
355 isFillResumed_(false)
356 {
357 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
358 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
359
360 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
361 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
362
363 // Follows the Tpetra parameters
364 bool restrictComm=false;
365 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
366 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
367 if(restrictComm && mtx_->NumMyRows()==0)
368 mtx_=Teuchos::null;
369 }
370
371
372
376 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
377 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
378 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
379 isFillResumed_(false)
380 {
381 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
382 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
383
384 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
385 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
386
387 // Follows the Tpetra parameters
388 bool restrictComm=false;
389 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
390
391 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
392 }
393
396 const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
397 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
398 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
400 isFillResumed_(false)
401 {
402 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
403 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
404 XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
405
406 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
407 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
408
409 // Follows the Tpetra parameters
410 bool restrictComm=false;
411 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
412 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
413 if(restrictComm && mtx_->NumMyRows()==0)
414 mtx_=Teuchos::null;
415 }
416
419 const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
420 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
421 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
423 isFillResumed_(false)
424 {
425 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
426 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
427 XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
428
429 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
430 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
431
432 // Follows the Tpetra parameters
433 bool restrictComm=false;
434 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
435
436 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
437 }
438
439#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
440#ifdef HAVE_XPETRA_TPETRA
441 // NOTE: TPETRA means we can use C++11 here
442
466 const local_matrix_type& lclMatrix,
467 const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
468 EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
469 { }
470
472 const local_matrix_type& lclMatrix,
473 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
474 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
475 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
476 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
477 const Teuchos::RCP<Teuchos::ParameterList>& params = null)
478 {
479 // local typedefs from local_matrix_type
480 //typedef typename local_matrix_type::size_type size_type;
481 typedef typename local_matrix_type::value_type value_type;
482 typedef typename local_matrix_type::ordinal_type ordinal_type;
483
484 // The number of rows in the sparse matrix.
485 ordinal_type lclNumRows = lclMatrix.numRows ();
486 ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
487
488 // plausibility checks
489 TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
490 "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
491 TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
492 "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
493
494 Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
495 for (ordinal_type r = 0; r < lclNumRows; ++r) {
496 // extract data from current row r
497 auto rowview = lclMatrix.row (r);
498 NumEntriesPerRowToAlloc[r] = rowview.length;
499 }
500
501 // setup matrix
502 isFillResumed_ = false;
503 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
504 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
505
506 // loop over all rows and colums of local matrix and fill matrix
507 for (ordinal_type r = 0; r < lclNumRows; ++r) {
508 // extract data from current row r
509 auto rowview = lclMatrix.row (r);
510
511 // arrays for current row data
514
515 for(ordinal_type c = 0; c < rowview.length; c++) {
516 value_type value = rowview.value (c);
517 ordinal_type colidx = rowview.colidx (c);
518
519 TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError,
520 "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
521
522 indout [c] = colidx;
523 valout [c] = value;
524 }
525 insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
526 }
527
528 // call fill complete
529 if (!domainMap.is_null() && !rangeMap.is_null())
530 this->fillComplete(domainMap, rowMap, params);
531 else
532 this->fillComplete(rowMap, rowMap, params);
533
534 // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
535 isInitializedLocalMatrix_ = false;
536 }
537#endif
538#endif
539
541 virtual ~EpetraCrsMatrixT() { }
542
544
546
547
550 XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
551 XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
552 }
553
554
557 XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
558 XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
559 }
560
563 XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
564
565 {
566 const std::string tfecfFuncName("replaceGlobalValues");
568 ": Fill must be active in order to call this method. If you have already "
569 "called fillComplete(), you need to call resumeFill() before you can "
570 "replace values.");
571
572 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
573 std::runtime_error, ": values.size() must equal indices.size().");
574 }
575
576 XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
577
578 }
579
582 XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
583
584 {
585 const std::string tfecfFuncName("replaceLocalValues");
587 ": Fill must be active in order to call this method. If you have already "
588 "called fillComplete(), you need to call resumeFill() before you can "
589 "replace values.");
590
591 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
592 std::runtime_error, ": values.size() must equal indices.size().");
593 }
594
595 XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
596
597 }
598
599
601 void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
602
604 void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
605
607 //** \warning This is an expert-only routine and should not be called from user code. */
608 void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
609 XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
610
611 // Row offsets
612 // Unfortunately, we cannot do this in the same manner as column indices
613 // and values (see below). The problem is that Tpetra insists on using
614 // size_t, and Epetra uses int internally. So we only resize here, and
615 // will need to copy in setAllValues
616 rowptr.resize(getNodeNumRows()+1);
617
618 int lowerOffset = 0;
619 bool ownMemory = false;
620
621 // Column indices
622 // Extract, resize, set colind
623 Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
624 myColind.Resize(numNonZeros);
625 colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
626
627 // Values
628 // Extract, reallocate, set values
629 double *& myValues = mtx_->ExpertExtractValues();
630 delete [] myValues;
631 myValues = new double[numNonZeros];
632 values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
633 }
634
636 void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
637 XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
638
639 // Check sizes
641 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
643 "An exception is thrown to let you know that you mismatched your pointers.");
644
645 // Check pointers
646 if (values.size() > 0) {
647 TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
648 "An exception is thrown to let you know that you mismatched your pointers.");
649 TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
650 "An exception is thrown to let you know that you mismatched your pointers.");
651 }
652
653 // We have to make a copy here, it is unavoidable
654 // See comments in allocateAllValues
655 const size_t N = getNodeNumRows();
656
657 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
658 myRowptr.Resize(N+1);
659 for (size_t i = 0; i < N+1; i++)
660 myRowptr[i] = Teuchos::as<int>(rowptr[i]);
661 }
662
663
666 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
667
668 int lowerOffset = 0;
669 bool ownMemory = false;
670
671 const size_t n = getNodeNumRows();
672 const size_t nnz = getNodeNumEntries();
673
674 // Row offsets
675 // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
676 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
677 rowptr.resize(n+1);
678 for (size_t i = 0; i < n+1; i++)
679 (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
680
681 // Column indices
682 colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
683
684 // Values
685 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
686 }
687
690 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
691
692 int lowerOffset = 0;
693 bool ownMemory = false;
694
695 const size_t nnz = getNodeNumEntries();
696 // Values
697 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
698 }
699
700 // Epetra always has global constants
701 bool haveGlobalConstants() const { return true; }
703 //** \warning This is an expert-only routine and should not be called from user code. */
705 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
706 const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
707 const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
708 const RCP<ParameterList> & /* params */=Teuchos::null) {
709 XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
710
711 // For Epetra matrices, resumeFill() is a fictive operation.
712 isFillResumed_ = false;
713
714 int rv=0;
715 const Epetra_Import * myimport =0;
716 const Epetra_Export * myexport =0;
717
718 if(!importer.is_null()) {
719 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
720 myimport = eImporter.getEpetra_Import().getRawPtr();
721 }
722 if(!exporter.is_null()) {
723 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
724 myexport = eExporter.getEpetra_Export().getRawPtr();
725 }
726
727 rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
728
729 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
730 }
732
734
735
737 void resumeFill(const RCP< ParameterList > &/* params */=Teuchos::null) {
738 XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
739
740 // According to Tpetra documentation, resumeFill() may be called repeatedly.
741 isFillResumed_ = true;
742 }
743
745 void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
746 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
747
748 // For Epetra matrices, resumeFill() is a fictive operation.
749 isFillResumed_ = false;
750
751 bool doOptimizeStorage = true;
752 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
753 mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
754 }
755
756
758 void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
759 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
760
761 // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
762 if (isFillResumed_ == true) { isFillResumed_ = false; return; }
763
764 bool doOptimizeStorage = true;
765 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
766 mtx_->FillComplete(doOptimizeStorage);
767 }
768
769
772 XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
773 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
774
775 const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
776 int rv=0;
777 if(myImport==Teuchos::null)
778 rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
779 else
780 rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
781 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
782 }
783
785
787
788
790 const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
791
793 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
794
796 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
797
799 RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
800
802 global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
803
805 global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
806
808 size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
809
811 size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
812
814 global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
815
817 size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
818
820 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
821
823 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow"); return mtx_->NumGlobalEntries(globalRow); }
824
826 size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
827
829 size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
830
832 bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
833
835 bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
836
838 bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
839
841 bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
842
844 ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
845
847 bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
848
850 void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
851 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
852
853 int numEntries = -1;
854 XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
855 NumEntries = numEntries;
856 }
857
859 void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
860 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
861
862 int numEntries = -1;
863 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
864 NumEntries = numEntries;
865 }
866
869 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
870
871 int numEntries;
872 double * eValues;
873 GlobalOrdinal * eIndices;
874
875 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
876 if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
877
878 indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
879 values = ArrayView<const double>(eValues, numEntries);
880 }
881
884 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
885
886 int numEntries;
887 double * eValues;
888 int * eIndices;
889
890 XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
891 if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
892
893 indices = ArrayView<const int>(eIndices, numEntries);
894 values = ArrayView<const double>(eValues, numEntries);
895 }
896
899 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
900 XPETRA_ERR_CHECK(mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)));
901 }
902
905 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
906 }
907
910 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
911 }
912
915 mtx_->ReplaceDiagonalValues (toEpetra<GlobalOrdinal,Node>(diag));
916 }
917
919 XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
920 };
922 XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
923 };
924
926
928
929
932 XPETRA_MONITOR("EpetraCrsMatrixT::apply");
933
934 //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
935
936 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
937 XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
938
939 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");
940 bool eTrans = toEpetra(mode);
941
942 // /!\ UseTranspose value
943 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.");
944
945 RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
946
947 // helper vector: tmp = A*x
949 tmp->PutScalar(0.0);
950 XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
951
952 // calculate alpha * A * x + beta * y
953 XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
954 }
955
958 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
959 }
960
962 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
963
965 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
966
968
970
971
973 std::string description() const {
974 XPETRA_MONITOR("EpetraCrsMatrixT::description");
975
976 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
977 std::ostringstream oss;
978 //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
979 if (isFillComplete()) {
980 oss << "{status = fill complete"
981 << ", global rows = " << getGlobalNumRows()
982 << ", global cols = " << getGlobalNumCols()
983 << ", global num entries = " << getGlobalNumEntries()
984 << "}";
985 }
986 else {
987 oss << "{status = fill not complete"
988 << ", global rows = " << getGlobalNumRows()
989 << "}";
990 }
991 return oss.str();
992
993 }
994
995
998 XPETRA_MONITOR("EpetraCrsMatrixT::describe");
999
1000 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1001 using std::endl;
1002 using std::setw;
1004 using Teuchos::VERB_NONE;
1005 using Teuchos::VERB_LOW;
1007 using Teuchos::VERB_HIGH;
1009 Teuchos::EVerbosityLevel vl = verbLevel;
1010 if (vl == VERB_DEFAULT) vl = VERB_LOW;
1011 RCP<const Comm<int> > comm = this->getComm();
1012 const int myImageID = comm->getRank(),
1013 numImages = comm->getSize();
1014 size_t width = 1;
1015 for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
1016 ++width;
1017 }
1018 width = std::max<size_t>(width,11) + 2;
1019 Teuchos::OSTab tab(out);
1020 // none: print nothing
1021 // low: print O(1) info from node 0
1022 // medium: print O(P) info, num entries per node
1023 // high: print O(N) info, num entries per row
1024 // extreme: print O(NNZ) info: print indices and values
1025 //
1026 // for medium and higher, print constituent objects at specified verbLevel
1027 if (vl != VERB_NONE) {
1028 if (myImageID == 0) out << this->description() << std::endl;
1029 // O(1) globals, minus what was already printed by description()
1030 if (isFillComplete() && myImageID == 0) {
1031 out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1032 }
1033 // constituent objects
1034 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1035 if (myImageID == 0) out << "\nRow map: " << std::endl;
1036 getRowMap()->describe(out,vl);
1037 //
1038 if (getColMap() != null) {
1039 if (getColMap() == getRowMap()) {
1040 if (myImageID == 0) out << "\nColumn map is row map.";
1041 }
1042 else {
1043 if (myImageID == 0) out << "\nColumn map: " << std::endl;
1044 getColMap()->describe(out,vl);
1045 }
1046 }
1047 if (getDomainMap() != null) {
1048 if (getDomainMap() == getRowMap()) {
1049 if (myImageID == 0) out << "\nDomain map is row map.";
1050 }
1051 else if (getDomainMap() == getColMap()) {
1052 if (myImageID == 0) out << "\nDomain map is row map.";
1053 }
1054 else {
1055 if (myImageID == 0) out << "\nDomain map: " << std::endl;
1056 getDomainMap()->describe(out,vl);
1057 }
1058 }
1059 if (getRangeMap() != null) {
1060 if (getRangeMap() == getDomainMap()) {
1061 if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1062 }
1063 else if (getRangeMap() == getRowMap()) {
1064 if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1065 }
1066 else {
1067 if (myImageID == 0) out << "\nRange map: " << std::endl;
1068 getRangeMap()->describe(out,vl);
1069 }
1070 }
1071 if (myImageID == 0) out << std::endl;
1072 }
1073 // O(P) data
1074 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1075 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1076 if (myImageID == imageCtr) {
1077 out << "Node ID = " << imageCtr << std::endl;
1078 // TODO: need a graph
1079 // if (staticGraph_->indicesAreAllocated() == false) {
1080 // out << "Node not allocated" << std::endl;
1081 // }
1082 // else {
1083 // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
1084 // }
1085
1086 // TMP:
1087 // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1088 // End of TMP
1089
1090 out << "Node number of entries = " << getNodeNumEntries() << std::endl;
1091 out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
1092 }
1093 comm->barrier();
1094 comm->barrier();
1095 comm->barrier();
1096 }
1097 }
1098 // O(N) and O(NNZ) data
1099 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1100 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1101 if (myImageID == imageCtr) {
1102 out << std::setw(width) << "Node ID"
1103 << std::setw(width) << "Global Row"
1104 << std::setw(width) << "Num Entries";
1105 if (vl == VERB_EXTREME) {
1106 out << std::setw(width) << "(Index,Value)";
1107 }
1108 out << std::endl;
1109 for (size_t r=0; r < getNodeNumRows(); ++r) {
1110 const size_t nE = getNumEntriesInLocalRow(r);
1111 GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1112 out << std::setw(width) << myImageID
1113 << std::setw(width) << gid
1114 << std::setw(width) << nE;
1115 if (vl == VERB_EXTREME) {
1116 if (isGloballyIndexed()) {
1119 getGlobalRowView(gid,rowinds,rowvals);
1120 for (size_t j=0; j < nE; ++j) {
1121 out << " (" << rowinds[j]
1122 << ", " << rowvals[j]
1123 << ") ";
1124 }
1125 }
1126 else if (isLocallyIndexed()) {
1129 getLocalRowView(r,rowinds,rowvals);
1130 for (size_t j=0; j < nE; ++j) {
1131 out << " (" << getColMap()->getGlobalElement(rowinds[j])
1132 << ", " << rowvals[j]
1133 << ") ";
1134 }
1135 }
1136 }
1137 out << std::endl;
1138 }
1139 }
1140 comm->barrier();
1141 comm->barrier();
1142 comm->barrier();
1143 }
1144 }
1145 }
1146
1147 }
1148
1149 void setObjectLabel( const std::string &objectLabel ) {
1151 mtx_->SetLabel(objectLabel.c_str());
1152 }
1154
1157 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
1158 { }
1159
1160
1162 //{@
1163
1165 Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
1166
1170 XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1171
1172 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1173 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1174
1175 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1176 int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1177 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1178 }
1179
1183 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1184
1185 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1186 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1187
1188 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1189 int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1190 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1191 }
1192
1196 XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1197
1198 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1199 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1200
1201 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1202 int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1203 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1204
1205 }
1206
1210 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1211
1212 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1213 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1214
1215 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1216 int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1217 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1218 }
1219
1221 XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
1222 const Epetra_Map* newMapEpetra = (!newMap.is_null())? &toEpetra<GlobalOrdinal,Node>(newMap) : 0;
1223 int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
1224 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1225 }
1226
1228
1230
1231
1233 bool hasMatrix() const { return !mtx_.is_null();}
1234
1236 EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
1237
1240
1242 RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
1243
1244#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1245#ifdef HAVE_XPETRA_TPETRA
1247#ifdef TPETRA_ENABLE_DEPRECATED_CODE
1248
1249local_matrix_type getLocalMatrix () const {
1250 return getLocalMatrixDevice();
1251}
1252#endif
1253
1254local_matrix_type getLocalMatrixDevice () const {
1255#if 0
1257 "Xpetra::EpetraCrsMatrx only available on host for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
1258 TEUCHOS_UNREACHABLE_RETURN((local_matrix_type()));
1259#endif
1260 return getLocalMatrixHost();
1261}
1262
1263
1264typename local_matrix_type::HostMirror getLocalMatrixHost () const {
1265 if (isInitializedLocalMatrix_)
1266 return localMatrix_;
1267
1268 RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
1269
1270 const int numRows = matrix->NumMyRows();
1271 const int numCols = matrix->NumMyCols();
1272 const int nnz = matrix->NumMyNonzeros();
1273
1274 int* rowptr;
1275 int* colind;
1276 double* vals;
1277 int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1278 TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1279
1280 // Transform int* rowptr array to size_type* array
1281 typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
1282 for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1283 kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
1284
1285 // create Kokkos::Views
1286 typename local_matrix_type::index_type kokkosColind(colind, nnz);
1287 typename local_matrix_type::values_type kokkosVals (vals, nnz);
1288
1289 localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1290 isInitializedLocalMatrix_ = true;
1291
1292 return localMatrix_;
1293 }
1294
1295 void setAllValues (const typename local_matrix_type::row_map_type& /* ptr */,
1296 const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& /* ind */,
1297 const typename local_matrix_type::values_type& /* val */)
1298 {
1300 "Xpetra::EpetraCrsMatrix::setAllValues is not implemented");
1301 }
1302
1303
1304
1305private:
1306 mutable local_matrix_type localMatrix_;
1307 mutable bool isInitializedLocalMatrix_ = false; // It's OK to use C++11 when Tpetra is enabled
1308#else
1309#ifdef __GNUC__
1310#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."
1311#endif
1312#endif
1313#endif
1315
1319 Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
1320
1321 apply(X,R);
1322 R.update(one,B,negone);
1323 }
1324
1325private:
1328
1336
1337}; // EpetraCrsMatrixT class
1338
1339#endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1340
1341#ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1342template<>
1344: public CrsMatrix <double, int, long long, EpetraNode>
1345{
1346 typedef long long GlobalOrdinal;
1350
1351
1352 // The following typedefs are used by the Kokkos interface
1353#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1354#ifdef HAVE_XPETRA_TPETRA
1357#endif
1358#endif
1359
1360public:
1361
1363
1364
1366 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */ = Teuchos::null)
1367: mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
1368{ }
1369
1370
1372 EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
1373 : isFillResumed_(false)
1374 {
1375 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1376 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1377 }
1378
1379
1381 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)
1382 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
1383 { }
1384
1385
1388 : isFillResumed_(false)
1389 {
1390 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1391 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1392 }
1393
1394
1397 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
1398 { }
1399
1400
1404 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1405 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1406 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
1407 isFillResumed_(false)
1408 {
1409 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1410 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1411
1412 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1413 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1414
1415 // Follows the Tpetra parameters
1416 bool restrictComm=false;
1417 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1418 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
1419 if(restrictComm && mtx_->NumMyRows()==0)
1420 mtx_=Teuchos::null;
1421 }
1422
1423
1424
1428 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1429 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1430 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
1431 isFillResumed_(false)
1432 {
1433 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1434 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1435
1436 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1437 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1438
1439 // Follows the Tpetra parameters
1440 bool restrictComm=false;
1441 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1442
1443 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
1444 }
1445
1447 const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
1448 const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
1449 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1450 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1452 isFillResumed_(false)
1453 {
1454 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1455 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1456 XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1457
1458 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1459 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1460
1461 // Follows the Tpetra parameters
1462 bool restrictComm=false;
1463 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1464 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
1465 if(restrictComm && mtx_->NumMyRows()==0)
1466 mtx_=Teuchos::null;
1467 }
1468
1470 const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
1471 const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
1472 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1473 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1475 isFillResumed_(false)
1476 {
1477 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1478 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1479 XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1480
1481 const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1482 const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1483
1484 // Follows the Tpetra parameters
1485 bool restrictComm=false;
1486 if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1487
1488 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
1489 }
1490
1491#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1492#ifdef HAVE_XPETRA_TPETRA
1515 const local_matrix_type& lclMatrix,
1516 const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
1517 EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
1518{ }
1519
1521 const local_matrix_type& lclMatrix,
1522 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
1523 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
1524 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
1525 const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
1526 const Teuchos::RCP<Teuchos::ParameterList>& params = null)
1527 {
1528 // local typedefs from local_matrix_type
1529 //typedef typename local_matrix_type::size_type size_type;
1530 typedef typename local_matrix_type::value_type value_type;
1531 typedef typename local_matrix_type::ordinal_type ordinal_type;
1532
1533 // The number of rows in the sparse matrix.
1534 ordinal_type lclNumRows = lclMatrix.numRows ();
1535 ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
1536
1537 // plausibility checks
1538 TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
1539 "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1540 TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
1541 "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1542
1543 Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
1544 for (ordinal_type r = 0; r < lclNumRows; ++r) {
1545 // extract data from current row r
1546 auto rowview = lclMatrix.row (r);
1547 NumEntriesPerRowToAlloc[r] = rowview.length;
1548 }
1549
1550 // setup matrix
1551 isFillResumed_ = false;
1552 Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1553 mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1554
1555 // loop over all rows and colums of local matrix and fill matrix
1556 for (ordinal_type r = 0; r < lclNumRows; ++r) {
1557 // extract data from current row r
1558 auto rowview = lclMatrix.row (r);
1559
1560 // arrays for current row data
1563
1564 for(ordinal_type c = 0; c < rowview.length; c++) {
1565 value_type value = rowview.value (c);
1566 ordinal_type colidx = rowview.colidx (c);
1567
1568 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!");
1569
1570 indout [c] = colidx;
1571 valout [c] = value;
1572 }
1573 insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
1574 }
1575
1576 // call fill complete
1577 if (!domainMap.is_null() && !rangeMap.is_null())
1578 this->fillComplete(domainMap, rowMap, params);
1579 else
1580 this->fillComplete(rowMap, rowMap, params);
1581
1582 // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
1583 isInitializedLocalMatrix_ = false;
1584 }
1585#endif
1586#endif
1587
1589 virtual ~EpetraCrsMatrixT() { }
1590
1592
1594
1595
1598 XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1599 XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1600 }
1601
1602
1605 XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1606 XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1607 }
1608
1611 XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1612
1613 {
1614 const std::string tfecfFuncName("replaceGlobalValues");
1616 ": Fill must be active in order to call this method. If you have already "
1617 "called fillComplete(), you need to call resumeFill() before you can "
1618 "replace values.");
1619
1620 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1621 std::runtime_error, ": values.size() must equal indices.size().");
1622 }
1623
1624 XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1625
1626 }
1627
1630 XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
1631
1632 {
1633 const std::string tfecfFuncName("replaceLocalValues");
1635 ": Fill must be active in order to call this method. If you have already "
1636 "called fillComplete(), you need to call resumeFill() before you can "
1637 "replace values.");
1638
1639 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1640 std::runtime_error, ": values.size() must equal indices.size().");
1641 }
1642
1643 XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1644
1645 }
1646
1647
1649 void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
1650
1652 void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
1653
1655 //** \warning This is an expert-only routine and should not be called from user code. */
1656 void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
1657 XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1658
1659 // Row offsets
1660 // Unfortunately, we cannot do this in the same manner as column indices
1661 // and values (see below). The problem is that Tpetra insists on using
1662 // size_t, and Epetra uses int internally. So we only resize here, and
1663 // will need to copy in setAllValues
1664 rowptr.resize(getNodeNumRows()+1);
1665
1666 int lowerOffset = 0;
1667 bool ownMemory = false;
1668
1669 // Column indices
1670 // Extract, resize, set colind
1671 Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
1672 myColind.Resize(numNonZeros);
1673 colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1674
1675 // Values
1676 // Extract, reallocate, set values
1677 double *& myValues = mtx_->ExpertExtractValues();
1678 delete [] myValues;
1679 myValues = new double[numNonZeros];
1680 values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
1681 }
1682
1684 void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
1685 XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1686
1687 // Check sizes
1689 "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1691 "An exception is thrown to let you know that you mismatched your pointers.");
1692
1693 // Check pointers
1694 if (values.size() > 0) {
1695 TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1696 "An exception is thrown to let you know that you mismatched your pointers.");
1697 TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1698 "An exception is thrown to let you know that you mismatched your pointers.");
1699 }
1700
1701 // We have to make a copy here, it is unavoidable
1702 // See comments in allocateAllValues
1703 const size_t N = getNodeNumRows();
1704
1705 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1706 myRowptr.Resize(N+1);
1707 for (size_t i = 0; i < N+1; i++)
1708 myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1709 }
1710
1711
1714 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1715
1716 int lowerOffset = 0;
1717 bool ownMemory = false;
1718
1719 const size_t n = getNodeNumRows();
1720 const size_t nnz = getNodeNumEntries();
1721
1722 // Row offsets
1723 // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1724 Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1725 rowptr.resize(n+1);
1726 for (size_t i = 0; i < n+1; i++)
1727 (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1728
1729 // Column indices
1730 colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1731
1732 // Values
1733 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1734 }
1735
1736
1739 XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1740
1741 int lowerOffset = 0;
1742 bool ownMemory = false;
1743
1744 const size_t nnz = getNodeNumEntries();
1745 // Values
1746 values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1747 }
1748
1749
1750 // Epetra always has global constants
1751 bool haveGlobalConstants() const { return true;}
1752
1754 //** \warning This is an expert-only routine and should not be called from user code. */
1756 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1757 const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
1758 const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
1759 const RCP<ParameterList> & /* params */=Teuchos::null) {
1760 XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1761
1762 // For Epetra matrices, resumeFill() is a fictive operation.
1763 isFillResumed_ = false;
1764
1765 int rv=0;
1766 const Epetra_Import * myimport =0;
1767 const Epetra_Export * myexport =0;
1768
1769 if(!importer.is_null()) {
1770 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1771 myimport = eImporter.getEpetra_Import().getRawPtr();
1772 }
1773 if(!exporter.is_null()) {
1774 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1775 myexport = eExporter.getEpetra_Export().getRawPtr();
1776 }
1777
1778 rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
1779
1780 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1781 }
1783
1785
1786
1788 void resumeFill(const RCP< ParameterList > &/* params */=Teuchos::null) {
1789 XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1790
1791 // According to Tpetra documentation, resumeFill() may be called repeatedly.
1792 isFillResumed_ = true;
1793 }
1794
1796 void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
1797 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1798
1799 // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1800 if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1801
1802 bool doOptimizeStorage = true;
1803 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1804 mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
1805 }
1806
1807
1809 void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
1810 XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1811
1812 // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1813 if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1814
1815 bool doOptimizeStorage = true;
1816 if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1817 mtx_->FillComplete(doOptimizeStorage);
1818 }
1819
1820
1823 XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1824 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1825
1826 const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
1827 int rv=0;
1828 if(myImport==Teuchos::null)
1829 rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
1830 else
1831 rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
1832 TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1833 }
1834
1836
1838
1839
1841 const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
1842
1844 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
1845
1847 const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
1848
1850 RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
1851
1853 global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
1854
1856 global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
1857
1859 size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
1860
1862 size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
1863
1865 global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
1866
1868 size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
1869
1871 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
1872
1874 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow"); return mtx_->NumGlobalEntries(globalRow); }
1875
1877 size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
1878
1880 size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
1881
1883 bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
1884
1886 bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
1887
1889 bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
1890
1892 bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
1893
1895 typename ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
1896
1898 bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
1899
1901 void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1902 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1903
1904 int numEntries = -1;
1905 XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1906 NumEntries = numEntries;
1907 }
1908
1910 void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1911 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
1912
1913 int numEntries = -1;
1914 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1915 NumEntries = numEntries;
1916 }
1917
1920 XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
1921
1922 int numEntries;
1923 double * eValues;
1924 GlobalOrdinal * eIndices;
1925
1926 XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
1927 if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1928
1929 indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
1930 values = ArrayView<const double>(eValues, numEntries);
1931 }
1932
1935 XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
1936
1937 int numEntries;
1938 double * eValues;
1939 int * eIndices;
1940
1941 XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
1942 if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1943
1944 indices = ArrayView<const int>(eIndices, numEntries);
1945 values = ArrayView<const double>(eValues, numEntries);
1946 }
1947
1949 void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy"); mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)); }
1950
1953 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
1954 }
1955
1958 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
1959 }
1960
1963 mtx_->ReplaceDiagonalValues (toEpetra<GlobalOrdinal,Node>(diag));
1964 }
1965
1967 XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
1968 };
1970 XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
1971 };
1972
1974
1976
1977
1980 XPETRA_MONITOR("EpetraCrsMatrixT::apply");
1981
1982 //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
1983
1984 XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1985 XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1986
1987 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");
1988 bool eTrans = toEpetra(mode);
1989
1990 // /!\ UseTranspose value
1991 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.");
1992
1993 RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
1994
1995 // helper vector: tmp = A*x
1997 tmp->PutScalar(0.0);
1998 XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
1999
2000 // calculate alpha * A * x + beta * y
2001 XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
2002 }
2003
2005 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.apply() is not implemented for region matricies.");
2006 }
2007
2009 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
2010
2012 const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
2013
2015
2017
2018
2020 std::string description() const {
2021 XPETRA_MONITOR("EpetraCrsMatrixT::description");
2022
2023 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2024 std::ostringstream oss;
2025 //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
2026 if (isFillComplete()) {
2027 oss << "{status = fill complete"
2028 << ", global rows = " << getGlobalNumRows()
2029 << ", global cols = " << getGlobalNumCols()
2030 << ", global num entries = " << getGlobalNumEntries()
2031 << "}";
2032 }
2033 else {
2034 oss << "{status = fill not complete"
2035 << ", global rows = " << getGlobalNumRows()
2036 << "}";
2037 }
2038 return oss.str();
2039
2040 }
2041
2042
2045 XPETRA_MONITOR("EpetraCrsMatrixT::describe");
2046
2047 // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2048 using std::endl;
2049 using std::setw;
2051 using Teuchos::VERB_NONE;
2052 using Teuchos::VERB_LOW;
2054 using Teuchos::VERB_HIGH;
2056 Teuchos::EVerbosityLevel vl = verbLevel;
2057 if (vl == VERB_DEFAULT) vl = VERB_LOW;
2058 RCP<const Comm<int> > comm = this->getComm();
2059 const int myImageID = comm->getRank(),
2060 numImages = comm->getSize();
2061 size_t width = 1;
2062 for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
2063 ++width;
2064 }
2065 width = std::max<size_t>(width,11) + 2;
2066 Teuchos::OSTab tab(out);
2067 // none: print nothing
2068 // low: print O(1) info from node 0
2069 // medium: print O(P) info, num entries per node
2070 // high: print O(N) info, num entries per row
2071 // extreme: print O(NNZ) info: print indices and values
2072 //
2073 // for medium and higher, print constituent objects at specified verbLevel
2074 if (vl != VERB_NONE) {
2075 if (myImageID == 0) out << this->description() << std::endl;
2076 // O(1) globals, minus what was already printed by description()
2077 if (isFillComplete() && myImageID == 0) {
2078 out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
2079 }
2080 // constituent objects
2081 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2082 if (myImageID == 0) out << "\nRow map: " << std::endl;
2083 getRowMap()->describe(out,vl);
2084 //
2085 if (getColMap() != null) {
2086 if (getColMap() == getRowMap()) {
2087 if (myImageID == 0) out << "\nColumn map is row map.";
2088 }
2089 else {
2090 if (myImageID == 0) out << "\nColumn map: " << std::endl;
2091 getColMap()->describe(out,vl);
2092 }
2093 }
2094 if (getDomainMap() != null) {
2095 if (getDomainMap() == getRowMap()) {
2096 if (myImageID == 0) out << "\nDomain map is row map.";
2097 }
2098 else if (getDomainMap() == getColMap()) {
2099 if (myImageID == 0) out << "\nDomain map is row map.";
2100 }
2101 else {
2102 if (myImageID == 0) out << "\nDomain map: " << std::endl;
2103 getDomainMap()->describe(out,vl);
2104 }
2105 }
2106 if (getRangeMap() != null) {
2107 if (getRangeMap() == getDomainMap()) {
2108 if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
2109 }
2110 else if (getRangeMap() == getRowMap()) {
2111 if (myImageID == 0) out << "\nRange map is row map." << std::endl;
2112 }
2113 else {
2114 if (myImageID == 0) out << "\nRange map: " << std::endl;
2115 getRangeMap()->describe(out,vl);
2116 }
2117 }
2118 if (myImageID == 0) out << std::endl;
2119 }
2120 // O(P) data
2121 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2122 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2123 if (myImageID == imageCtr) {
2124 out << "Node ID = " << imageCtr << std::endl;
2125 // TODO: need a graph
2126 // if (staticGraph_->indicesAreAllocated() == false) {
2127 // out << "Node not allocated" << std::endl;
2128 // }
2129 // else {
2130 // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
2131 // }
2132
2133 // TMP:
2134 // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2135 // End of TMP
2136
2137 out << "Node number of entries = " << getNodeNumEntries() << std::endl;
2138 out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
2139 }
2140 comm->barrier();
2141 comm->barrier();
2142 comm->barrier();
2143 }
2144 }
2145 // O(N) and O(NNZ) data
2146 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2147 for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2148 if (myImageID == imageCtr) {
2149 out << std::setw(width) << "Node ID"
2150 << std::setw(width) << "Global Row"
2151 << std::setw(width) << "Num Entries";
2152 if (vl == VERB_EXTREME) {
2153 out << std::setw(width) << "(Index,Value)";
2154 }
2155 out << std::endl;
2156 for (size_t r=0; r < getNodeNumRows(); ++r) {
2157 const size_t nE = getNumEntriesInLocalRow(r);
2158 GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2159 out << std::setw(width) << myImageID
2160 << std::setw(width) << gid
2161 << std::setw(width) << nE;
2162 if (vl == VERB_EXTREME) {
2163 if (isGloballyIndexed()) {
2166 getGlobalRowView(gid,rowinds,rowvals);
2167 for (size_t j=0; j < nE; ++j) {
2168 out << " (" << rowinds[j]
2169 << ", " << rowvals[j]
2170 << ") ";
2171 }
2172 }
2173 else if (isLocallyIndexed()) {
2176 getLocalRowView(r,rowinds,rowvals);
2177 for (size_t j=0; j < nE; ++j) {
2178 out << " (" << getColMap()->getGlobalElement(rowinds[j])
2179 << ", " << rowvals[j]
2180 << ") ";
2181 }
2182 }
2183 }
2184 out << std::endl;
2185 }
2186 }
2187 comm->barrier();
2188 comm->barrier();
2189 comm->barrier();
2190 }
2191 }
2192 }
2193
2194 }
2195
2196 void setObjectLabel( const std::string &objectLabel ) {
2198 mtx_->SetLabel(objectLabel.c_str());
2199 }
2201
2204 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
2205 { }
2206
2207
2209 //{@
2210
2212 Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
2213
2217 XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2218
2219 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2220 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2221
2222 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2223 int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2224 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2225 }
2226
2230 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2231
2232 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2233 XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2234
2235 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2236 int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2237 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2238 }
2239
2243 XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2244
2245 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2246 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2247
2248 RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2249 int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2250 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2251
2252 }
2253
2257 XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2258
2259 XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2260 XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2261
2262 RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2263 int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2264 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2265 }
2266
2268 XPETRA_MONITOR("EpetraCrsMatrixT::removeEmptyProcessesInPlace");
2269 const Epetra_Map* newMapEpetra = (!newMap.is_null())? &toEpetra<GlobalOrdinal,Node>(newMap) : 0;
2270 int err = mtx_->RemoveEmptyProcessesInPlace(newMapEpetra);
2271 TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
2272 }
2273
2275
2277
2278
2280 bool hasMatrix() const { return !mtx_.is_null();}
2281
2283 EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
2284
2287
2289 RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
2290
2291#ifdef HAVE_XPETRA_KOKKOS_REFACTOR
2292#ifdef HAVE_XPETRA_TPETRA
2294 local_matrix_type getLocalMatrix () const {
2295 if (isInitializedLocalMatrix_)
2296 return localMatrix_;
2297
2299
2300 const int numRows = matrix->NumMyRows();
2301 const int numCols = matrix->NumMyCols();
2302 const int nnz = matrix->NumMyNonzeros();
2303
2304 int* rowptr;
2305 int* colind;
2306 double* vals;
2307 int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2308 TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2309
2310 // Transform int* rowptr array to size_type* array
2311 typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
2312 for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2313 kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
2314
2315 // create Kokkos::Views
2316 typename local_matrix_type::index_type kokkosColind(colind, nnz);
2317 typename local_matrix_type::values_type kokkosVals (vals, nnz);
2318
2319 localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2320 isInitializedLocalMatrix_ = true;
2321
2322 return localMatrix_;
2323 }
2324
2325 void setAllValues (const typename local_matrix_type::row_map_type& /* ptr */,
2326 const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& /* ind */,
2327 const typename local_matrix_type::values_type& /* val */)
2328 {
2330 "Xpetra::EpetraCrsMatrix::setAllValues is not implemented");
2331 }
2332
2333
2334private:
2335 mutable local_matrix_type localMatrix_;
2336 mutable bool isInitializedLocalMatrix_ = false;
2337#else
2338#ifdef __GNUC__
2339#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."
2340#endif
2341#endif
2342#endif
2344
2348 Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
2349 apply(X,R);
2350 R.update(one,B,negone);
2351 }
2352
2353private:
2355
2356 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.
2357
2358}; // EpetraCrsMatrixT class
2359
2360#endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2361
2362} // Xpetra namespace
2363
2364#define XPETRA_EPETRACRSMATRIX_SHORT
2365#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
void resize(const size_type n, const T &val=T())
iterator begin() const
iterator end() const
size_type size() const
T * getRawPtr() const
static const EVerbosityLevel verbLevel_default
virtual void setObjectLabel(const std::string &objectLabel)
bool is_null() const
T * get() const
LocalOrdinal local_ordinal_type
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
void 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.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
Get the underlying Epetra matrix.
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
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.
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
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...
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.
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.
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...
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
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)
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
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.
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
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)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
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 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.
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.
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)
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix.
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.
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
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.
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.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
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.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
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...
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries in the specified global row.
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.
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)
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
const RCP< const Comm< int > > getComm() const
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
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 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)
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...
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
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.
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)
size_t getNodeNumCols() const
Returns the number of matrix columns owned on the calling node.
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)
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
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)