Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_EpetraCrsMatrix.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_EPETRACRSMATRIX_HPP
47 #define XPETRA_EPETRACRSMATRIX_HPP
48 
49 /* this file is automatically generated - do not edit (see script/epetra.py) */
50 
51 #ifdef HAVE_XPETRA_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"
65 #include "Xpetra_EpetraVector.hpp"
68 
69 #include "Xpetra_MapFactory.hpp"
70 
71 #include "Xpetra_Utils.hpp"
72 #include "Xpetra_Exceptions.hpp"
73 
74 namespace Xpetra {
75 
76 // general implementation: empty stub
77 template<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 
92 public:
93  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) {
94  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
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) {
98  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
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."); }
104  EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
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) {
109  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
110  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
111  }
112  EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
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) {
117  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
118  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
119  }
120  EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
121  const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
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,
125  const Teuchos::RCP<Teuchos::ParameterList>& params) {
126  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
127  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
128  }
129  EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
130  const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
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,
134  const Teuchos::RCP<Teuchos::ParameterList>& params) {
135  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
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
140  EpetraCrsMatrixT (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
141  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
142  const local_matrix_type& lclMatrix,
143  const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
144  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
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) {
154  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
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 
161  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals) {}
162  void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals) { }
163  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals) { }
164  void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals) { }
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) { }
169  void getAllValues(ArrayRCP<const size_t>& rowptr, ArrayRCP<const LocalOrdinal>& colind, ArrayRCP<const Scalar>& values) const { }
170  bool haveGlobalConstants() const { return true;}
172  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
173  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
174  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
175  const RCP<ParameterList> &params=Teuchos::null) { }
176 
177  void resumeFill(const RCP< ParameterList > &params=null) { }
178  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null) { }
179  void fillComplete(const RCP< ParameterList > &params=null) { }
180  void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > >& newDomainMap, Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > & newImporter) { }
181  const RCP< const Comm< int > > getComm() const { return Teuchos::null; }
182  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { return Teuchos::null; }
183  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { return Teuchos::null; }
184  RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { return Teuchos::null; }
185  global_size_t getGlobalNumRows() const { return 0; }
186  global_size_t getGlobalNumCols() const { return 0; }
187  size_t getNodeNumRows() const { return 0; }
188  size_t getNodeNumCols() const { return 0; }
189  global_size_t getGlobalNumEntries() const { return 0; }
190  size_t getNodeNumEntries() const { return 0; }
191  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { return 0; }
192  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { return 0; }
193  size_t getGlobalMaxNumRowEntries() const { return 0; }
194  size_t getNodeMaxNumRowEntries() const { return 0; }
195  bool isLocallyIndexed() const { return false; }
196  bool isGloballyIndexed() const { return false; }
197  bool isFillComplete() const { return false; }
198  bool isFillActive() const { return false; }
199  typename ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { return ScalarTraits< Scalar >::magnitude(ScalarTraits< Scalar >::zero()); }
200  bool supportsRowViews() const { return false; }
201  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
202  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
203  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const { }
204  void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const { }
206  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &offsets) const { }
207  void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView<const size_t> &offsets) const { }
211 
212  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 { }
213  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { return Teuchos::null; }
214  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { return Teuchos::null; }
215 
216  std::string description() const { return std::string(""); }
217  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const { }
218  void setObjectLabel( const std::string &objectLabel ) { }
219 
221  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
222  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
223  }
224 
225  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { return Teuchos::null; }
230  void removeEmptyProcessesInPlace (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& newMap) { }
231 
232  bool hasMatrix() const { return false; }
233  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) {
234  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
235  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
236  }
237  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
238  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } //TODO: remove
239 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
240 #ifdef HAVE_XPETRA_TPETRA
241  local_matrix_type getLocalMatrix () const {
242  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
243  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
244  }
245 
246  void setAllValues (const typename local_matrix_type::row_map_type& ptr,
247  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& ind,
248  const typename local_matrix_type::values_type& val)
249  {
250  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
251  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
252  }
253 #else
254 #ifdef __GNUC__
255 #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."
256 #endif
257 #endif
258 #endif
259 
263  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
264  apply(X,R);
265  R.update(one,B,negone);
266  }
267 
268 }; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
269 
270 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
271 template<>
273 : public CrsMatrix <double, int, int, EpetraNode>
274 {
275  typedef int GlobalOrdinal;
276  typedef EpetraNode Node;
279 
280 
281  // The following typedefs are used by the Kokkos interface
282 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
283 #ifdef HAVE_XPETRA_TPETRA
286 #endif
287 #endif
288 
289 public:
290 
292 
293 
295  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap)
296 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), 0, false))), isFillResumed_(false)
297 { }
298 
300  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */ = Teuchos::null)
301 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
302 { }
303 
304 
306  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
307  : isFillResumed_(false)
308  {
309  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
310  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
311  }
312 
313 
315  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
316  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
317  { }
318 
319 
321  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
322  : isFillResumed_(false)
323  {
324  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
325  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
326  }
327 
328 
330  EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
331  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
332  { }
333 
334 
336  EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
338  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
339  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
340  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
341  isFillResumed_(false)
342  {
343  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
344  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
345 
346  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
347  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
348 
349  // Follows the Tpetra parameters
350  bool restrictComm=false;
351  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
352  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
353  if(restrictComm && mtx_->NumMyRows()==0)
354  mtx_=Teuchos::null;
355  }
356 
357 
358 
360  EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
362  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
363  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
364  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
365  isFillResumed_(false)
366  {
367  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
368  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
369 
370  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
371  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
372 
373  // Follows the Tpetra parameters
374  bool restrictComm=false;
375  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
376 
377  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
378  }
379 
380  EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
381  const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
382  const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
383  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
384  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
385  const Teuchos::RCP<Teuchos::ParameterList>& params) :
386  isFillResumed_(false)
387  {
388  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
389  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
390  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
391 
392  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
393  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
394 
395  // Follows the Tpetra parameters
396  bool restrictComm=false;
397  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
398  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
399  if(restrictComm && mtx_->NumMyRows()==0)
400  mtx_=Teuchos::null;
401  }
402 
403  EpetraCrsMatrixT(const Teuchos::RCP<const CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& sourceMatrix,
404  const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
405  const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
406  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
407  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
408  const Teuchos::RCP<Teuchos::ParameterList>& params) :
409  isFillResumed_(false)
410  {
411  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
412  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
413  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
414 
415  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
416  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
417 
418  // Follows the Tpetra parameters
419  bool restrictComm=false;
420  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
421 
422  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
423  }
424 
425 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
426 #ifdef HAVE_XPETRA_TPETRA
427  // NOTE: TPETRA means we can use C++11 here
428 
450  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
451  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
452  const local_matrix_type& lclMatrix,
453  const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
454  EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
455  { }
456 
458  const local_matrix_type& lclMatrix,
459  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
460  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
461  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
462  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
463  const Teuchos::RCP<Teuchos::ParameterList>& params = null)
464  {
465  // local typedefs from local_matrix_type
466  //typedef typename local_matrix_type::size_type size_type;
467  typedef typename local_matrix_type::value_type value_type;
468  typedef typename local_matrix_type::ordinal_type ordinal_type;
469 
470  // The number of rows in the sparse matrix.
471  ordinal_type lclNumRows = lclMatrix.numRows ();
472  ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
473 
474  // plausibility checks
475  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
476  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
477  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
478  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
479 
480  Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
481  for (ordinal_type r = 0; r < lclNumRows; ++r) {
482  // extract data from current row r
483  auto rowview = lclMatrix.row (r);
484  NumEntriesPerRowToAlloc[r] = rowview.length;
485  }
486 
487  // setup matrix
488  isFillResumed_ = false;
489  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
490  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
491 
492  // loop over all rows and colums of local matrix and fill matrix
493  for (ordinal_type r = 0; r < lclNumRows; ++r) {
494  // extract data from current row r
495  auto rowview = lclMatrix.row (r);
496 
497  // arrays for current row data
498  Teuchos::ArrayRCP<ordinal_type> indout(rowview.length,Teuchos::ScalarTraits<ordinal_type>::zero());
499  Teuchos::ArrayRCP<value_type> valout(rowview.length,Teuchos::ScalarTraits<value_type>::zero());
500 
501  for(ordinal_type c = 0; c < rowview.length; c++) {
502  value_type value = rowview.value (c);
503  ordinal_type colidx = rowview.colidx (c);
504 
505  TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError,
506  "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
507 
508  indout [c] = colidx;
509  valout [c] = value;
510  }
511  insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
512  }
513 
514  // call fill complete
515  if (!domainMap.is_null() && !rangeMap.is_null())
516  this->fillComplete(domainMap, rowMap, params);
517  else
518  this->fillComplete(rowMap, rowMap, params);
519 
520  // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
521  isInitializedLocalMatrix_ = false;
522  }
523 #endif
524 #endif
525 
527  virtual ~EpetraCrsMatrixT() { }
528 
530 
532 
533 
535  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
536  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
537  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
538  }
539 
540 
542  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
543  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
544  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
545  }
546 
548  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values) {
549  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
550 
551  {
552  const std::string tfecfFuncName("replaceGlobalValues");
553  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
554  ": Fill must be active in order to call this method. If you have already "
555  "called fillComplete(), you need to call resumeFill() before you can "
556  "replace values.");
557 
558  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
559  std::runtime_error, ": values.size() must equal indices.size().");
560  }
561 
562  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
563 
564  }
565 
567  void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values) {
568  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
569 
570  {
571  const std::string tfecfFuncName("replaceLocalValues");
572  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
573  ": Fill must be active in order to call this method. If you have already "
574  "called fillComplete(), you need to call resumeFill() before you can "
575  "replace values.");
576 
577  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
578  std::runtime_error, ": values.size() must equal indices.size().");
579  }
580 
581  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
582 
583  }
584 
585 
587  void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
588 
590  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
591 
593  //** \warning This is an expert-only routine and should not be called from user code. */
594  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
595  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
596 
597  // Row offsets
598  // Unfortunately, we cannot do this in the same manner as column indices
599  // and values (see below). The problem is that Tpetra insists on using
600  // size_t, and Epetra uses int internally. So we only resize here, and
601  // will need to copy in setAllValues
602  rowptr.resize(getNodeNumRows()+1);
603 
604  int lowerOffset = 0;
605  bool ownMemory = false;
606 
607  // Column indices
608  // Extract, resize, set colind
609  Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
610  myColind.Resize(numNonZeros);
611  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
612 
613  // Values
614  // Extract, reallocate, set values
615  double *& myValues = mtx_->ExpertExtractValues();
616  delete [] myValues;
617  myValues = new double[numNonZeros];
618  values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
619  }
620 
622  void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
623  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
624 
625  // Check sizes
626  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getNodeNumRows()+1, Xpetra::Exceptions::RuntimeError,
627  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
628  TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
629  "An exception is thrown to let you know that you mismatched your pointers.");
630 
631  // Check pointers
632  if (values.size() > 0) {
633  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
634  "An exception is thrown to let you know that you mismatched your pointers.");
635  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
636  "An exception is thrown to let you know that you mismatched your pointers.");
637  }
638 
639  // We have to make a copy here, it is unavoidable
640  // See comments in allocateAllValues
641  const size_t N = getNodeNumRows();
642 
643  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
644  myRowptr.Resize(N+1);
645  for (size_t i = 0; i < N+1; i++)
646  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
647  }
648 
649 
651  void getAllValues(ArrayRCP<const size_t>& rowptr, ArrayRCP<const LocalOrdinal>& colind, ArrayRCP<const Scalar>& values) const {
652  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
653 
654  int lowerOffset = 0;
655  bool ownMemory = false;
656 
657  const size_t n = getNodeNumRows();
658  const size_t nnz = getNodeNumEntries();
659 
660  // Row offsets
661  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
662  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
663  rowptr.resize(n+1);
664  for (size_t i = 0; i < n+1; i++)
665  (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
666 
667  // Column indices
668  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
669 
670  // Values
671  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
672  }
673 
674  // Epetra always has global constants
675  bool haveGlobalConstants() const { return true; }
677  //** \warning This is an expert-only routine and should not be called from user code. */
679  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
680  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
681  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
682  const RCP<ParameterList> & /* params */=Teuchos::null) {
683  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
684 
685  // For Epetra matrices, resumeFill() is a fictive operation.
686  isFillResumed_ = false;
687 
688  int rv=0;
689  const Epetra_Import * myimport =0;
690  const Epetra_Export * myexport =0;
691 
692  if(!importer.is_null()) {
693  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
694  myimport = eImporter.getEpetra_Import().getRawPtr();
695  }
696  if(!exporter.is_null()) {
697  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
698  myexport = eExporter.getEpetra_Export().getRawPtr();
699  }
700 
701  rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
702 
703  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
704  }
706 
708 
709 
711  void resumeFill(const RCP< ParameterList > &/* params */=Teuchos::null) {
712  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
713 
714  // According to Tpetra documentation, resumeFill() may be called repeatedly.
715  isFillResumed_ = true;
716  }
717 
719  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
720  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
721 
722  // For Epetra matrices, resumeFill() is a fictive operation.
723  isFillResumed_ = false;
724 
725  bool doOptimizeStorage = true;
726  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
727  mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
728  }
729 
730 
732  void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
733  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
734 
735  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
736  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
737 
738  bool doOptimizeStorage = true;
739  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
740  mtx_->FillComplete(doOptimizeStorage);
741  }
742 
743 
745  void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > >& newDomainMap, Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > & newImporter) {
746  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
747  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
748 
749  const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
750  int rv=0;
751  if(myImport==Teuchos::null)
752  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
753  else
754  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
755  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
756  }
757 
759 
761 
762 
764  const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
765 
767  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
768 
770  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
771 
773  RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
774 
776  global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
777 
779  global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
780 
782  size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
783 
785  size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
786 
788  global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
789 
791  size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
792 
794  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
795 
797  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow"); return mtx_->NumGlobalEntries(globalRow); }
798 
800  size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
801 
803  size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
804 
806  bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
807 
809  bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
810 
812  bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
813 
815  bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
816 
818  ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
819 
821  bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
822 
824  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
825  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
826 
827  int numEntries = -1;
828  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
829  NumEntries = numEntries;
830  }
831 
833  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
834  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
835 
836  int numEntries = -1;
837  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
838  NumEntries = numEntries;
839  }
840 
842  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
843  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
844 
845  int numEntries;
846  double * eValues;
847  GlobalOrdinal * eIndices;
848 
849  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
850  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
851 
852  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
853  values = ArrayView<const double>(eValues, numEntries);
854  }
855 
857  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
858  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
859 
860  int numEntries;
861  double * eValues;
862  int * eIndices;
863 
864  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
865  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
866 
867  indices = ArrayView<const int>(eIndices, numEntries);
868  values = ArrayView<const double>(eValues, numEntries);
869  }
870 
873  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
874  XPETRA_ERR_CHECK(mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)));
875  }
876 
878  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &/* offsets */) const {
879  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
880  }
881 
883  void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &/* diag */, const Teuchos::ArrayView<const size_t> &/* offsets */) const {
884  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
885  }
886 
889  mtx_->ReplaceDiagonalValues (toEpetra<GlobalOrdinal,Node>(diag));
890  }
891 
893  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
894  };
896  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
897  };
898 
900 
902 
903 
905  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 {
906  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
907 
908  //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
909 
910  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
911  XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
912 
913  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");
914  bool eTrans = toEpetra(mode);
915 
916  // /!\ UseTranspose value
917  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.");
918 
919  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
920 
921  // helper vector: tmp = A*x
922  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
923  tmp->PutScalar(0.0);
924  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
925 
926  // calculate alpha * A * x + beta * y
927  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
928  }
929 
931  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
932 
934  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
935 
937 
939 
940 
942  std::string description() const {
943  XPETRA_MONITOR("EpetraCrsMatrixT::description");
944 
945  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
946  std::ostringstream oss;
947  //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
948  if (isFillComplete()) {
949  oss << "{status = fill complete"
950  << ", global rows = " << getGlobalNumRows()
951  << ", global cols = " << getGlobalNumCols()
952  << ", global num entries = " << getGlobalNumEntries()
953  << "}";
954  }
955  else {
956  oss << "{status = fill not complete"
957  << ", global rows = " << getGlobalNumRows()
958  << "}";
959  }
960  return oss.str();
961 
962  }
963 
964 
966  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const {
967  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
968 
969  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
970  using std::endl;
971  using std::setw;
972  using Teuchos::VERB_DEFAULT;
973  using Teuchos::VERB_NONE;
974  using Teuchos::VERB_LOW;
975  using Teuchos::VERB_MEDIUM;
976  using Teuchos::VERB_HIGH;
977  using Teuchos::VERB_EXTREME;
978  Teuchos::EVerbosityLevel vl = verbLevel;
979  if (vl == VERB_DEFAULT) vl = VERB_LOW;
980  RCP<const Comm<int> > comm = this->getComm();
981  const int myImageID = comm->getRank(),
982  numImages = comm->getSize();
983  size_t width = 1;
984  for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
985  ++width;
986  }
987  width = std::max<size_t>(width,11) + 2;
988  Teuchos::OSTab tab(out);
989  // none: print nothing
990  // low: print O(1) info from node 0
991  // medium: print O(P) info, num entries per node
992  // high: print O(N) info, num entries per row
993  // extreme: print O(NNZ) info: print indices and values
994  //
995  // for medium and higher, print constituent objects at specified verbLevel
996  if (vl != VERB_NONE) {
997  if (myImageID == 0) out << this->description() << std::endl;
998  // O(1) globals, minus what was already printed by description()
999  if (isFillComplete() && myImageID == 0) {
1000  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1001  }
1002  // constituent objects
1003  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1004  if (myImageID == 0) out << "\nRow map: " << std::endl;
1005  getRowMap()->describe(out,vl);
1006  //
1007  if (getColMap() != null) {
1008  if (getColMap() == getRowMap()) {
1009  if (myImageID == 0) out << "\nColumn map is row map.";
1010  }
1011  else {
1012  if (myImageID == 0) out << "\nColumn map: " << std::endl;
1013  getColMap()->describe(out,vl);
1014  }
1015  }
1016  if (getDomainMap() != null) {
1017  if (getDomainMap() == getRowMap()) {
1018  if (myImageID == 0) out << "\nDomain map is row map.";
1019  }
1020  else if (getDomainMap() == getColMap()) {
1021  if (myImageID == 0) out << "\nDomain map is row map.";
1022  }
1023  else {
1024  if (myImageID == 0) out << "\nDomain map: " << std::endl;
1025  getDomainMap()->describe(out,vl);
1026  }
1027  }
1028  if (getRangeMap() != null) {
1029  if (getRangeMap() == getDomainMap()) {
1030  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1031  }
1032  else if (getRangeMap() == getRowMap()) {
1033  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1034  }
1035  else {
1036  if (myImageID == 0) out << "\nRange map: " << std::endl;
1037  getRangeMap()->describe(out,vl);
1038  }
1039  }
1040  if (myImageID == 0) out << std::endl;
1041  }
1042  // O(P) data
1043  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1044  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1045  if (myImageID == imageCtr) {
1046  out << "Node ID = " << imageCtr << std::endl;
1047  // TODO: need a graph
1048  // if (staticGraph_->indicesAreAllocated() == false) {
1049  // out << "Node not allocated" << std::endl;
1050  // }
1051  // else {
1052  // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
1053  // }
1054 
1055  // TMP:
1056  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1057  // End of TMP
1058 
1059  out << "Node number of entries = " << getNodeNumEntries() << std::endl;
1060  out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
1061  }
1062  comm->barrier();
1063  comm->barrier();
1064  comm->barrier();
1065  }
1066  }
1067  // O(N) and O(NNZ) data
1068  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1069  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1070  if (myImageID == imageCtr) {
1071  out << std::setw(width) << "Node ID"
1072  << std::setw(width) << "Global Row"
1073  << std::setw(width) << "Num Entries";
1074  if (vl == VERB_EXTREME) {
1075  out << std::setw(width) << "(Index,Value)";
1076  }
1077  out << std::endl;
1078  for (size_t r=0; r < getNodeNumRows(); ++r) {
1079  const size_t nE = getNumEntriesInLocalRow(r);
1080  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1081  out << std::setw(width) << myImageID
1082  << std::setw(width) << gid
1083  << std::setw(width) << nE;
1084  if (vl == VERB_EXTREME) {
1085  if (isGloballyIndexed()) {
1086  ArrayView<const GlobalOrdinal> rowinds;
1087  ArrayView<const Scalar> rowvals;
1088  getGlobalRowView(gid,rowinds,rowvals);
1089  for (size_t j=0; j < nE; ++j) {
1090  out << " (" << rowinds[j]
1091  << ", " << rowvals[j]
1092  << ") ";
1093  }
1094  }
1095  else if (isLocallyIndexed()) {
1096  ArrayView<const LocalOrdinal> rowinds;
1097  ArrayView<const Scalar> rowvals;
1098  getLocalRowView(r,rowinds,rowvals);
1099  for (size_t j=0; j < nE; ++j) {
1100  out << " (" << getColMap()->getGlobalElement(rowinds[j])
1101  << ", " << rowvals[j]
1102  << ") ";
1103  }
1104  }
1105  }
1106  out << std::endl;
1107  }
1108  }
1109  comm->barrier();
1110  comm->barrier();
1111  comm->barrier();
1112  }
1113  }
1114  }
1115 
1116  }
1117 
1118  void setObjectLabel( const std::string &objectLabel ) {
1119  Teuchos::LabeledObject::setObjectLabel(objectLabel);
1120  mtx_->SetLabel(objectLabel.c_str());
1121  }
1123 
1126  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
1127  { }
1128 
1129 
1131  //{@
1132 
1134  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
1135 
1139  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1140 
1141  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1142  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1143 
1144  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1145  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1146  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1147  }
1148 
1152  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1153 
1154  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1155  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1156 
1157  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1158  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1159  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1160  }
1161 
1165  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1166 
1167  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1168  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1169 
1170  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1171  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1172  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1173 
1174  }
1175 
1179  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1180 
1181  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1182  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1183 
1184  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1185  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1186  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Caught nonzero error code " + std::to_string(err) + " returned by Epetra.");
1187  }
1188 
1189  void removeEmptyProcessesInPlace (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& /* newMap */) { }
1190 
1192 
1194 
1195 
1197  bool hasMatrix() const { return !mtx_.is_null();}
1198 
1200  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
1201 
1203  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
1204 
1206  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
1207 
1208 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1209 #ifdef HAVE_XPETRA_TPETRA
1210  local_matrix_type getLocalMatrix () const {
1212  if (isInitializedLocalMatrix_)
1213  return localMatrix_;
1214 
1215  RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
1216 
1217  const int numRows = matrix->NumMyRows();
1218  const int numCols = matrix->NumMyCols();
1219  const int nnz = matrix->NumMyNonzeros();
1220 
1221  int* rowptr;
1222  int* colind;
1223  double* vals;
1224  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1225  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1226 
1227  // Transform int* rowptr array to size_type* array
1228  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
1229  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1230  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
1231 
1232  // create Kokkos::Views
1233  typename local_matrix_type::index_type kokkosColind(colind, nnz);
1234  typename local_matrix_type::values_type kokkosVals (vals, nnz);
1235 
1236  localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1237  isInitializedLocalMatrix_ = true;
1238 
1239  return localMatrix_;
1240  }
1241 
1242  void setAllValues (const typename local_matrix_type::row_map_type& /* ptr */,
1243  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& /* ind */,
1244  const typename local_matrix_type::values_type& /* val */)
1245  {
1246  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
1247  "Xpetra::EpetraCrsMatrix::setAllValues is not implemented");
1248  }
1249 
1250 
1251 
1252 private:
1253  mutable local_matrix_type localMatrix_;
1254  mutable bool isInitializedLocalMatrix_ = false; // It's OK to use C++11 when Tpetra is enabled
1255 #else
1256 #ifdef __GNUC__
1257 #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."
1258 #endif
1259 #endif
1260 #endif
1261 
1262 
1266  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
1267 
1268  apply(X,R);
1269  R.update(one,B,negone);
1270  }
1271 
1272 private:
1274  RCP<Epetra_CrsMatrix> mtx_;
1275 
1283 
1284 }; // EpetraCrsMatrixT class
1285 
1286 #endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1287 
1288 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1289 template<>
1290 class EpetraCrsMatrixT <long long, EpetraNode>
1291 : public CrsMatrix <double, int, long long, EpetraNode>
1292 {
1293  typedef long long GlobalOrdinal;
1294  typedef EpetraNode Node;
1297 
1298 
1299  // The following typedefs are used by the Kokkos interface
1300 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1301 #ifdef HAVE_XPETRA_TPETRA
1304 #endif
1305 #endif
1306 
1307 public:
1308 
1310 
1311 
1313  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */ = Teuchos::null)
1314 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
1315 { }
1316 
1317 
1319  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
1320  : isFillResumed_(false)
1321  {
1322  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1323  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1324  }
1325 
1326 
1328  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)
1329  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, true))), isFillResumed_(false)
1330  { }
1331 
1332 
1334  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
1335  : isFillResumed_(false)
1336  {
1337  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1338  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1339  }
1340 
1341 
1343  EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */=Teuchos::null)
1344  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
1345  { }
1346 
1347 
1351  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1352  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1353  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
1354  isFillResumed_(false)
1355  {
1356  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1357  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1358 
1359  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1360  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1361 
1362  // Follows the Tpetra parameters
1363  bool restrictComm=false;
1364  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1365  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
1366  if(restrictComm && mtx_->NumMyRows()==0)
1367  mtx_=Teuchos::null;
1368  }
1369 
1370 
1371 
1375  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1376  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1377  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
1378  isFillResumed_(false)
1379  {
1380  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1381  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1382 
1383  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1384  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1385 
1386  // Follows the Tpetra parameters
1387  bool restrictComm=false;
1388  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1389 
1390  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
1391  }
1392 
1394  const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
1395  const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
1396  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1397  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1398  const Teuchos::RCP<Teuchos::ParameterList>& params) :
1399  isFillResumed_(false)
1400  {
1401  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1402  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1403  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1404 
1405  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1406  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1407 
1408  // Follows the Tpetra parameters
1409  bool restrictComm=false;
1410  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1411  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
1412  if(restrictComm && mtx_->NumMyRows()==0)
1413  mtx_=Teuchos::null;
1414  }
1415 
1417  const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
1418  const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
1419  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1420  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1421  const Teuchos::RCP<Teuchos::ParameterList>& params) :
1422  isFillResumed_(false)
1423  {
1424  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1425  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1426  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1427 
1428  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1429  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1430 
1431  // Follows the Tpetra parameters
1432  bool restrictComm=false;
1433  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1434 
1435  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
1436  }
1437 
1438 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1439 #ifdef HAVE_XPETRA_TPETRA
1440  EpetraCrsMatrixT (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
1461  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
1462  const local_matrix_type& lclMatrix,
1463  const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
1464  EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
1465 { }
1466 
1468  const local_matrix_type& lclMatrix,
1469  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
1470  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
1471  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
1472  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
1473  const Teuchos::RCP<Teuchos::ParameterList>& params = null)
1474  {
1475  // local typedefs from local_matrix_type
1476  //typedef typename local_matrix_type::size_type size_type;
1477  typedef typename local_matrix_type::value_type value_type;
1478  typedef typename local_matrix_type::ordinal_type ordinal_type;
1479 
1480  // The number of rows in the sparse matrix.
1481  ordinal_type lclNumRows = lclMatrix.numRows ();
1482  ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
1483 
1484  // plausibility checks
1485  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
1486  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1487  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
1488  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1489 
1490  Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
1491  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1492  // extract data from current row r
1493  auto rowview = lclMatrix.row (r);
1494  NumEntriesPerRowToAlloc[r] = rowview.length;
1495  }
1496 
1497  // setup matrix
1498  isFillResumed_ = false;
1499  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1500  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), true));
1501 
1502  // loop over all rows and colums of local matrix and fill matrix
1503  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1504  // extract data from current row r
1505  auto rowview = lclMatrix.row (r);
1506 
1507  // arrays for current row data
1508  Teuchos::ArrayRCP<ordinal_type> indout(rowview.length,Teuchos::ScalarTraits<ordinal_type>::zero());
1509  Teuchos::ArrayRCP<value_type> valout(rowview.length,Teuchos::ScalarTraits<value_type>::zero());
1510 
1511  for(ordinal_type c = 0; c < rowview.length; c++) {
1512  value_type value = rowview.value (c);
1513  ordinal_type colidx = rowview.colidx (c);
1514 
1515  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!");
1516 
1517  indout [c] = colidx;
1518  valout [c] = value;
1519  }
1520  insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
1521  }
1522 
1523  // call fill complete
1524  if (!domainMap.is_null() && !rangeMap.is_null())
1525  this->fillComplete(domainMap, rowMap, params);
1526  else
1527  this->fillComplete(rowMap, rowMap, params);
1528 
1529  // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
1530  isInitializedLocalMatrix_ = false;
1531  }
1532 #endif
1533 #endif
1534 
1536  virtual ~EpetraCrsMatrixT() { }
1537 
1539 
1541 
1542 
1544  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1545  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1546  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1547  }
1548 
1549 
1551  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1552  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1553  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1554  }
1555 
1557  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values) {
1558  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1559 
1560  {
1561  const std::string tfecfFuncName("replaceGlobalValues");
1562  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
1563  ": Fill must be active in order to call this method. If you have already "
1564  "called fillComplete(), you need to call resumeFill() before you can "
1565  "replace values.");
1566 
1567  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1568  std::runtime_error, ": values.size() must equal indices.size().");
1569  }
1570 
1571  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1572 
1573  }
1574 
1576  void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values) {
1577  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
1578 
1579  {
1580  const std::string tfecfFuncName("replaceLocalValues");
1581  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
1582  ": Fill must be active in order to call this method. If you have already "
1583  "called fillComplete(), you need to call resumeFill() before you can "
1584  "replace values.");
1585 
1586  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1587  std::runtime_error, ": values.size() must equal indices.size().");
1588  }
1589 
1590  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1591 
1592  }
1593 
1594 
1596  void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
1597 
1599  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
1600 
1602  //** \warning This is an expert-only routine and should not be called from user code. */
1603  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
1604  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1605 
1606  // Row offsets
1607  // Unfortunately, we cannot do this in the same manner as column indices
1608  // and values (see below). The problem is that Tpetra insists on using
1609  // size_t, and Epetra uses int internally. So we only resize here, and
1610  // will need to copy in setAllValues
1611  rowptr.resize(getNodeNumRows()+1);
1612 
1613  int lowerOffset = 0;
1614  bool ownMemory = false;
1615 
1616  // Column indices
1617  // Extract, resize, set colind
1618  Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
1619  myColind.Resize(numNonZeros);
1620  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1621 
1622  // Values
1623  // Extract, reallocate, set values
1624  double *& myValues = mtx_->ExpertExtractValues();
1625  delete [] myValues;
1626  myValues = new double[numNonZeros];
1627  values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
1628  }
1629 
1631  void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
1632  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1633 
1634  // Check sizes
1635  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getNodeNumRows()+1, Xpetra::Exceptions::RuntimeError,
1636  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1637  TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError,
1638  "An exception is thrown to let you know that you mismatched your pointers.");
1639 
1640  // Check pointers
1641  if (values.size() > 0) {
1642  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1643  "An exception is thrown to let you know that you mismatched your pointers.");
1644  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1645  "An exception is thrown to let you know that you mismatched your pointers.");
1646  }
1647 
1648  // We have to make a copy here, it is unavoidable
1649  // See comments in allocateAllValues
1650  const size_t N = getNodeNumRows();
1651 
1652  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1653  myRowptr.Resize(N+1);
1654  for (size_t i = 0; i < N+1; i++)
1655  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1656  }
1657 
1658 
1660  void getAllValues(ArrayRCP<const size_t>& rowptr, ArrayRCP<const LocalOrdinal>& colind, ArrayRCP<const Scalar>& values) const {
1661  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1662 
1663  int lowerOffset = 0;
1664  bool ownMemory = false;
1665 
1666  const size_t n = getNodeNumRows();
1667  const size_t nnz = getNodeNumEntries();
1668 
1669  // Row offsets
1670  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1671  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1672  rowptr.resize(n+1);
1673  for (size_t i = 0; i < n+1; i++)
1674  (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1675 
1676  // Column indices
1677  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1678 
1679  // Values
1680  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1681  }
1682 
1683  // Epetra always has global constants
1684  bool haveGlobalConstants() const { return true;}
1685 
1687  //** \warning This is an expert-only routine and should not be called from user code. */
1689  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1690  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
1691  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
1692  const RCP<ParameterList> & /* params */=Teuchos::null) {
1693  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1694 
1695  // For Epetra matrices, resumeFill() is a fictive operation.
1696  isFillResumed_ = false;
1697 
1698  int rv=0;
1699  const Epetra_Import * myimport =0;
1700  const Epetra_Export * myexport =0;
1701 
1702  if(!importer.is_null()) {
1703  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1704  myimport = eImporter.getEpetra_Import().getRawPtr();
1705  }
1706  if(!exporter.is_null()) {
1707  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1708  myexport = eExporter.getEpetra_Export().getRawPtr();
1709  }
1710 
1711  rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
1712 
1713  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1714  }
1716 
1718 
1719 
1721  void resumeFill(const RCP< ParameterList > &/* params */=Teuchos::null) {
1722  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1723 
1724  // According to Tpetra documentation, resumeFill() may be called repeatedly.
1725  isFillResumed_ = true;
1726  }
1727 
1729  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
1730  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1731 
1732  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1733  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1734 
1735  bool doOptimizeStorage = true;
1736  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1737  mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
1738  }
1739 
1740 
1742  void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
1743  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1744 
1745  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1746  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1747 
1748  bool doOptimizeStorage = true;
1749  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1750  mtx_->FillComplete(doOptimizeStorage);
1751  }
1752 
1753 
1755  void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > >& newDomainMap, Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > & newImporter) {
1756  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1757  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1758 
1759  const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
1760  int rv=0;
1761  if(myImport==Teuchos::null)
1762  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
1763  else
1764  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
1765  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1766  }
1767 
1769 
1771 
1772 
1774  const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
1775 
1777  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
1778 
1780  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
1781 
1783  RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
1784 
1786  global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
1787 
1789  global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
1790 
1792  size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
1793 
1795  size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
1796 
1798  global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
1799 
1801  size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
1802 
1804  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
1805 
1807  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInGlobalRow"); return mtx_->NumGlobalEntries(globalRow); }
1808 
1810  size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
1811 
1813  size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
1814 
1816  bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
1817 
1819  bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
1820 
1822  bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
1823 
1825  bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
1826 
1828  typename ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
1829 
1831  bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
1832 
1834  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1835  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1836 
1837  int numEntries = -1;
1838  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1839  NumEntries = numEntries;
1840  }
1841 
1843  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1844  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
1845 
1846  int numEntries = -1;
1847  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1848  NumEntries = numEntries;
1849  }
1850 
1852  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
1853  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
1854 
1855  int numEntries;
1856  double * eValues;
1857  GlobalOrdinal * eIndices;
1858 
1859  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
1860  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1861 
1862  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
1863  values = ArrayView<const double>(eValues, numEntries);
1864  }
1865 
1867  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
1868  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
1869 
1870  int numEntries;
1871  double * eValues;
1872  int * eIndices;
1873 
1874  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
1875  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1876 
1877  indices = ArrayView<const int>(eIndices, numEntries);
1878  values = ArrayView<const double>(eValues, numEntries);
1879  }
1880 
1882  void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy"); mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)); }
1883 
1885  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &/* offsets */) const {
1886  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
1887  }
1888 
1890  void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &/* diag */, const Teuchos::ArrayView<const size_t> &/* offsets */) const {
1891  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
1892  }
1893 
1896  mtx_->ReplaceDiagonalValues (toEpetra<GlobalOrdinal,Node>(diag));
1897  }
1898 
1900  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
1901  };
1903  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
1904  };
1905 
1907 
1909 
1910 
1912  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 {
1913  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
1914 
1915  //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
1916 
1917  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1918  XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1919 
1920  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");
1921  bool eTrans = toEpetra(mode);
1922 
1923  // /!\ UseTranspose value
1924  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.");
1925 
1926  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
1927 
1928  // helper vector: tmp = A*x
1929  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
1930  tmp->PutScalar(0.0);
1931  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
1932 
1933  // calculate alpha * A * x + beta * y
1934  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
1935  }
1936 
1938  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
1939 
1941  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
1942 
1944 
1946 
1947 
1949  std::string description() const {
1950  XPETRA_MONITOR("EpetraCrsMatrixT::description");
1951 
1952  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1953  std::ostringstream oss;
1954  //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
1955  if (isFillComplete()) {
1956  oss << "{status = fill complete"
1957  << ", global rows = " << getGlobalNumRows()
1958  << ", global cols = " << getGlobalNumCols()
1959  << ", global num entries = " << getGlobalNumEntries()
1960  << "}";
1961  }
1962  else {
1963  oss << "{status = fill not complete"
1964  << ", global rows = " << getGlobalNumRows()
1965  << "}";
1966  }
1967  return oss.str();
1968 
1969  }
1970 
1971 
1973  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const {
1974  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
1975 
1976  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1977  using std::endl;
1978  using std::setw;
1979  using Teuchos::VERB_DEFAULT;
1980  using Teuchos::VERB_NONE;
1981  using Teuchos::VERB_LOW;
1982  using Teuchos::VERB_MEDIUM;
1983  using Teuchos::VERB_HIGH;
1984  using Teuchos::VERB_EXTREME;
1985  Teuchos::EVerbosityLevel vl = verbLevel;
1986  if (vl == VERB_DEFAULT) vl = VERB_LOW;
1987  RCP<const Comm<int> > comm = this->getComm();
1988  const int myImageID = comm->getRank(),
1989  numImages = comm->getSize();
1990  size_t width = 1;
1991  for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
1992  ++width;
1993  }
1994  width = std::max<size_t>(width,11) + 2;
1995  Teuchos::OSTab tab(out);
1996  // none: print nothing
1997  // low: print O(1) info from node 0
1998  // medium: print O(P) info, num entries per node
1999  // high: print O(N) info, num entries per row
2000  // extreme: print O(NNZ) info: print indices and values
2001  //
2002  // for medium and higher, print constituent objects at specified verbLevel
2003  if (vl != VERB_NONE) {
2004  if (myImageID == 0) out << this->description() << std::endl;
2005  // O(1) globals, minus what was already printed by description()
2006  if (isFillComplete() && myImageID == 0) {
2007  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
2008  }
2009  // constituent objects
2010  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2011  if (myImageID == 0) out << "\nRow map: " << std::endl;
2012  getRowMap()->describe(out,vl);
2013  //
2014  if (getColMap() != null) {
2015  if (getColMap() == getRowMap()) {
2016  if (myImageID == 0) out << "\nColumn map is row map.";
2017  }
2018  else {
2019  if (myImageID == 0) out << "\nColumn map: " << std::endl;
2020  getColMap()->describe(out,vl);
2021  }
2022  }
2023  if (getDomainMap() != null) {
2024  if (getDomainMap() == getRowMap()) {
2025  if (myImageID == 0) out << "\nDomain map is row map.";
2026  }
2027  else if (getDomainMap() == getColMap()) {
2028  if (myImageID == 0) out << "\nDomain map is row map.";
2029  }
2030  else {
2031  if (myImageID == 0) out << "\nDomain map: " << std::endl;
2032  getDomainMap()->describe(out,vl);
2033  }
2034  }
2035  if (getRangeMap() != null) {
2036  if (getRangeMap() == getDomainMap()) {
2037  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
2038  }
2039  else if (getRangeMap() == getRowMap()) {
2040  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
2041  }
2042  else {
2043  if (myImageID == 0) out << "\nRange map: " << std::endl;
2044  getRangeMap()->describe(out,vl);
2045  }
2046  }
2047  if (myImageID == 0) out << std::endl;
2048  }
2049  // O(P) data
2050  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2051  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2052  if (myImageID == imageCtr) {
2053  out << "Node ID = " << imageCtr << std::endl;
2054  // TODO: need a graph
2055  // if (staticGraph_->indicesAreAllocated() == false) {
2056  // out << "Node not allocated" << std::endl;
2057  // }
2058  // else {
2059  // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
2060  // }
2061 
2062  // TMP:
2063  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2064  // End of TMP
2065 
2066  out << "Node number of entries = " << getNodeNumEntries() << std::endl;
2067  out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
2068  }
2069  comm->barrier();
2070  comm->barrier();
2071  comm->barrier();
2072  }
2073  }
2074  // O(N) and O(NNZ) data
2075  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2076  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2077  if (myImageID == imageCtr) {
2078  out << std::setw(width) << "Node ID"
2079  << std::setw(width) << "Global Row"
2080  << std::setw(width) << "Num Entries";
2081  if (vl == VERB_EXTREME) {
2082  out << std::setw(width) << "(Index,Value)";
2083  }
2084  out << std::endl;
2085  for (size_t r=0; r < getNodeNumRows(); ++r) {
2086  const size_t nE = getNumEntriesInLocalRow(r);
2087  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2088  out << std::setw(width) << myImageID
2089  << std::setw(width) << gid
2090  << std::setw(width) << nE;
2091  if (vl == VERB_EXTREME) {
2092  if (isGloballyIndexed()) {
2093  ArrayView<const GlobalOrdinal> rowinds;
2094  ArrayView<const Scalar> rowvals;
2095  getGlobalRowView(gid,rowinds,rowvals);
2096  for (size_t j=0; j < nE; ++j) {
2097  out << " (" << rowinds[j]
2098  << ", " << rowvals[j]
2099  << ") ";
2100  }
2101  }
2102  else if (isLocallyIndexed()) {
2103  ArrayView<const LocalOrdinal> rowinds;
2104  ArrayView<const Scalar> rowvals;
2105  getLocalRowView(r,rowinds,rowvals);
2106  for (size_t j=0; j < nE; ++j) {
2107  out << " (" << getColMap()->getGlobalElement(rowinds[j])
2108  << ", " << rowvals[j]
2109  << ") ";
2110  }
2111  }
2112  }
2113  out << std::endl;
2114  }
2115  }
2116  comm->barrier();
2117  comm->barrier();
2118  comm->barrier();
2119  }
2120  }
2121  }
2122 
2123  }
2124 
2125  void setObjectLabel( const std::string &objectLabel ) {
2126  Teuchos::LabeledObject::setObjectLabel(objectLabel);
2127  mtx_->SetLabel(objectLabel.c_str());
2128  }
2130 
2133  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
2134  { }
2135 
2136 
2138  //{@
2139 
2141  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
2142 
2146  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2147 
2148  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2149  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2150 
2151  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2152  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2153  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2154  }
2155 
2159  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2160 
2161  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2162  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2163 
2164  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2165  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2166  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2167  }
2168 
2172  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2173 
2174  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2175  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2176 
2177  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2178  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2179  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2180 
2181  }
2182 
2186  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2187 
2188  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2189  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2190 
2191  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2192  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2193  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2194  }
2195 
2196  void removeEmptyProcessesInPlace (const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& /* newMap */) { }
2197 
2199 
2201 
2202 
2204  bool hasMatrix() const { return !mtx_.is_null();}
2205 
2207  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
2208 
2210  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return mtx_; }
2211 
2213  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
2214 
2215 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
2216 #ifdef HAVE_XPETRA_TPETRA
2217  local_matrix_type getLocalMatrix () const {
2219  if (isInitializedLocalMatrix_)
2220  return localMatrix_;
2221 
2222  RCP<Epetra_CrsMatrix> matrix = getEpetra_CrsMatrixNonConst();
2223 
2224  const int numRows = matrix->NumMyRows();
2225  const int numCols = matrix->NumMyCols();
2226  const int nnz = matrix->NumMyNonzeros();
2227 
2228  int* rowptr;
2229  int* colind;
2230  double* vals;
2231  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2232  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2233 
2234  // Transform int* rowptr array to size_type* array
2235  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
2236  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2237  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
2238 
2239  // create Kokkos::Views
2240  typename local_matrix_type::index_type kokkosColind(colind, nnz);
2241  typename local_matrix_type::values_type kokkosVals (vals, nnz);
2242 
2243  localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2244  isInitializedLocalMatrix_ = true;
2245 
2246  return localMatrix_;
2247  }
2248 
2249  void setAllValues (const typename local_matrix_type::row_map_type& /* ptr */,
2250  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& /* ind */,
2251  const typename local_matrix_type::values_type& /* val */)
2252  {
2253  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError,
2254  "Xpetra::EpetraCrsMatrix::setAllValues is not implemented");
2255  }
2256 
2257 
2258 private:
2259  mutable local_matrix_type localMatrix_;
2260  mutable bool isInitializedLocalMatrix_ = false;
2261 #else
2262 #ifdef __GNUC__
2263 #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."
2264 #endif
2265 #endif
2266 #endif
2267 
2268 
2272  Scalar one = Teuchos::ScalarTraits<Scalar>::one(), negone = -one;
2273  apply(X,R);
2274  R.update(one,B,negone);
2275  }
2276 
2277 private:
2278  RCP<Epetra_CrsMatrix> mtx_;
2279 
2280  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.
2281 
2282 }; // EpetraCrsMatrixT class
2283 
2284 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2285 
2286 } // Xpetra namespace
2287 
2288 #define XPETRA_EPETRACRSMATRIX_SHORT
2289 #endif // XPETRA_EPETRACRSMATRIX_HPP
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void setObjectLabel(const std::string &objectLabel)
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying row and column Maps and number of entries in each row.
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused import.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
size_t getNodeNumEntries() const
Returns the local number of entries in this 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.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
Allocates and returns ArrayRCPs of the Crs arrays — This is an Xpetra-only routine.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying column Map and number of entries in each row.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
void resumeFill(const RCP< ParameterList > &params=null)
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...
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &=Teuchos::null)
Expert static fill complete.
const RCP< const Comm< int > > getComm() const
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
void replaceDiag(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag)
bool hasMatrix() const
Does this have an underlying matrix.
RCP< Epetra_CrsMatrix > mtx_
The underlying actual matrix object.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused export.
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
std::string description() const
A simple one-line description of this 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...
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified (locally owned) global row...
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
Exception throws to report errors in the internal logical of the program.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
LocalOrdinal local_ordinal_type
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
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...
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix. ...
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replaces the current domainMap and importer with the user-specified objects.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying fixed number of entries for each row.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
std::string description() const
A simple one-line description of this object.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Teuchos::ArrayView< const size_t > &) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
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.
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
void fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using local IDs.
void resumeFill(const RCP< ParameterList > &=Teuchos::null)
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using global IDs.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replaces the current domainMap and importer with the user-specified objects.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
Get the underlying Epetra matrix.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
void setAllToScalar(const Scalar &alpha)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying (possibly different) number of entries in each row.
bool hasMatrix() const
Does this have an underlying matrix.
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &=Teuchos::null)
Expert static fill complete.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
std::string description() const
A simple one-line description of this object.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
#define XPETRA_ERR_CHECK(arg)
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with 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.
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.
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 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...
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &) const
Get offsets of the diagonal entries in the matrix.
size_t getNodeNumCols() const
Returns the number of matrix columns owned on the calling node.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
bool isFillActive() const
Returns true if the matrix is in edit mode.
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
Get the underlying Epetra matrix.
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
void replaceDiag(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag)
Replace the diagonal entries of the matrix.
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.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying (possibly different) number of entries in each row.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
Allocates and returns ArrayRCPs of the Crs arrays — This is an Xpetra-only routine.
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
Gets the 1D pointer arrays of the graph.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
void replaceDiag(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag)
Replace the diagonal entries of the matrix.
Exception throws when you call an unimplemented method of Xpetra.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
const RCP< const Comm< int > > getComm() const
Returns the communicator.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
size_t global_size_t
Global size_t object.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &params=Teuchos::null)
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
void fillComplete(const RCP< ParameterList > &params=null)
Signal that data entry is complete.
#define XPETRA_RCP_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
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 CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused import.
void setObjectLabel(const std::string &objectLabel)
void scale(const Scalar &alpha)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using global IDs.
const RCP< const Comm< int > > getComm() const
Returns the communicator.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
bool hasMatrix() const
Does this have an underlying matrix.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
bool isFillActive() const
Returns true if the matrix is in edit mode.
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &)
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null)
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying a previously constructed graph.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying a previously constructed graph.
bool isFillActive() const
Returns true if the matrix is in edit mode.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
CombineMode
Xpetra::Combine Mode enumerable type.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
#define XPETRA_MONITOR(funcName)
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &) const
Get offsets of the diagonal entries in the matrix.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &)
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap)
Constructor for empty DynamicProfile matrix (no space is preallocated).
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &, const Teuchos::ArrayView< const size_t > &) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
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...
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries in the specified global row.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete, specifying domain and range maps.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying column Map and fixed number of entries for each row.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete, specifying domain and range maps.
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, const Teuchos::RCP< Teuchos::ParameterList > &=Teuchos::null)
Constructor specifying column Map and fixed number of entries for each row.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
bool isFillResumed_
Flag to keep track of fill status.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused export.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this 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
The Map describing the parallel distribution 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 > &params=Teuchos::null)
void resumeFill(const RCP< ParameterList > &=Teuchos::null)
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)