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, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) {
95  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
96  }
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, ProfileType pftype=DynamicProfile, 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, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Kokkos::Compat::KokkosSerialWrapperNode."); }
103  EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node> > &graph, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with Node=Kokkos::Compat::KokkosSerialWrapperNode."); }
106  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
107  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
108  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
110  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
111  }
114  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
115  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
116  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
118  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
119  }
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) {
127  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
128  }
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) {
136  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
137  }
138 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
139 #ifdef HAVE_XPETRA_TPETRA
142  const local_matrix_type& lclMatrix,
143  const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
145  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
146  }
148  const local_matrix_type& lclMatrix,
151  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
152  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
153  const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
155  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
156  }
157 #endif
158 #endif
159  virtual ~EpetraCrsMatrixT() { }
160 
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) { }
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) { }
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; }
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 getGlobalMaxNumRowEntries() const { return 0; }
193  size_t getNodeMaxNumRowEntries() const { return 0; }
194  bool isLocallyIndexed() const { return false; }
195  bool isGloballyIndexed() const { return false; }
196  bool isFillComplete() const { return false; }
197  bool isFillActive() const { return false; }
199  bool supportsRowViews() const { return false; }
200  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
201  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
202  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const { }
203  void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const { }
209 
211  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { return Teuchos::null; }
212  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { return Teuchos::null; }
213 
214  std::string description() const { return std::string(""); }
216 
219  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
220  }
221 
228 
229  bool hasMatrix() const { return false; }
232  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
233  }
234  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
235  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } //TODO: remove
236 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
237 #ifdef HAVE_XPETRA_TPETRA
238  local_matrix_type getLocalMatrix () const {
240  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
241  }
242 
243  void setAllValues (const typename local_matrix_type::row_map_type& ptr,
244  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& ind,
245  const typename local_matrix_type::values_type& val)
246  {
248  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
249  }
250 #else
251 #ifdef __GNUC__
252 #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."
253 #endif
254 #endif
255 #endif
256 
257 }; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
258 
259 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
260 template<>
262 : public CrsMatrix <double, int, int, EpetraNode>
263 {
264  typedef int GlobalOrdinal;
265  typedef EpetraNode Node;
268 
269 
270  // The following typedefs are used by the Kokkos interface
271 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
272 #ifdef HAVE_XPETRA_TPETRA
275 #endif
276 #endif
277 
278 public:
279 
281 
282 
284  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist = Teuchos::null)
285 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
286 { }
287 
288 
291  : isFillResumed_(false)
292  {
293  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
294  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
295  }
296 
297 
300  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
301  { }
302 
303 
306  : isFillResumed_(false)
307  {
308  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
309  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
310  }
311 
312 
315  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
316  { }
317 
318 
322  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
323  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
324  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
325  isFillResumed_(false)
326  {
327  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
328  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
329 
330  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
331  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
332 
333  // Follows the Tpetra parameters
334  bool restrictComm=false;
335  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
336  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
337  if(restrictComm && mtx_->NumMyRows()==0)
338  mtx_=Teuchos::null;
339  }
340 
341 
342 
346  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
347  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
348  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
349  isFillResumed_(false)
350  {
351  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
352  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
353 
354  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
355  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
356 
357  // Follows the Tpetra parameters
358  bool restrictComm=false;
359  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
360 
361  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
362  }
363 
365  const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
366  const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
367  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
368  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
369  const Teuchos::RCP<Teuchos::ParameterList>& params) :
370  isFillResumed_(false)
371  {
372  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
373  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
374  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
375 
376  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
377  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
378 
379  // Follows the Tpetra parameters
380  bool restrictComm=false;
381  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
382  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
383  if(restrictComm && mtx_->NumMyRows()==0)
384  mtx_=Teuchos::null;
385  }
386 
388  const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
389  const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
390  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
391  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
392  const Teuchos::RCP<Teuchos::ParameterList>& params) :
393  isFillResumed_(false)
394  {
395  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
396  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
397  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
398 
399  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
400  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
401 
402  // Follows the Tpetra parameters
403  bool restrictComm=false;
404  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
405 
406  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
407  }
408 
409 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
410 #ifdef HAVE_XPETRA_TPETRA
411  // NOTE: TPETRA means we can use C++11 here
412 
436  const local_matrix_type& lclMatrix,
437  const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
438  EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
439  { }
440 
442  const local_matrix_type& lclMatrix,
445  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
446  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
447  const Teuchos::RCP<Teuchos::ParameterList>& params = null)
448  {
449  // local typedefs from local_matrix_type
450  //typedef typename local_matrix_type::size_type size_type;
451  typedef typename local_matrix_type::value_type value_type;
452  typedef typename local_matrix_type::ordinal_type ordinal_type;
453 
454  // The number of rows in the sparse matrix.
455  ordinal_type lclNumRows = lclMatrix.numRows ();
456  ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
457 
458  // plausibility checks
459  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
460  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
461  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
462  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
463 
464  Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
465  for (ordinal_type r = 0; r < lclNumRows; ++r) {
466  // extract data from current row r
467  auto rowview = lclMatrix.row (r);
468  NumEntriesPerRowToAlloc[r] = rowview.length;
469  }
470 
471  // setup matrix
472  isFillResumed_ = false;
473  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
474  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(DynamicProfile)));
475 
476  // loop over all rows and colums of local matrix and fill matrix
477  for (ordinal_type r = 0; r < lclNumRows; ++r) {
478  // extract data from current row r
479  auto rowview = lclMatrix.row (r);
480 
481  // arrays for current row data
484 
485  for(ordinal_type c = 0; c < rowview.length; c++) {
486  value_type value = rowview.value (c);
487  ordinal_type colidx = rowview.colidx (c);
488 
489  TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError,
490  "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
491 
492  indout [c] = colidx;
493  valout [c] = value;
494  }
495  insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
496  }
497 
498  // call fill complete
499  if (!domainMap.is_null() && !rangeMap.is_null())
500  this->fillComplete(domainMap, rowMap, params);
501  else
502  this->fillComplete(rowMap, rowMap, params);
503 
504  // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
505  isInitializedLocalMatrix_ = false;
506  }
507 #endif
508 #endif
509 
511  virtual ~EpetraCrsMatrixT() { }
512 
514 
516 
517 
519  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
520  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
521  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
522  }
523 
524 
526  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
527  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
528  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
529  }
530 
532  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values) {
533  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
534 
535  {
536  const std::string tfecfFuncName("replaceGlobalValues");
537  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
538  ": Fill must be active in order to call this method. If you have already "
539  "called fillComplete(), you need to call resumeFill() before you can "
540  "replace values.");
541 
542  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
543  std::runtime_error, ": values.size() must equal indices.size().");
544  }
545 
546  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
547 
548  }
549 
551  void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values) {
552  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
553 
554  {
555  const std::string tfecfFuncName("replaceLocalValues");
556  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
557  ": Fill must be active in order to call this method. If you have already "
558  "called fillComplete(), you need to call resumeFill() before you can "
559  "replace values.");
560 
561  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
562  std::runtime_error, ": values.size() must equal indices.size().");
563  }
564 
565  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
566 
567  }
568 
569 
571  void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
572 
574  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
575 
577  //** \warning This is an expert-only routine and should not be called from user code. */
578  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
579  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
580 
581  // Row offsets
582  // Unfortunately, we cannot do this in the same manner as column indices
583  // and values (see below). The problem is that Tpetra insists on using
584  // size_t, and Epetra uses int internally. So we only resize here, and
585  // will need to copy in setAllValues
586  rowptr.resize(getNodeNumRows()+1);
587 
588  int lowerOffset = 0;
589  bool ownMemory = false;
590 
591  // Column indices
592  // Extract, resize, set colind
593  Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
594  myColind.Resize(numNonZeros);
595  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
596 
597  // Values
598  // Extract, reallocate, set values
599  double *& myValues = mtx_->ExpertExtractValues();
600  delete [] myValues;
601  myValues = new double[numNonZeros];
602  values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
603  }
604 
606  void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
607  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
608 
609  // Check sizes
611  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
613  "An exception is thrown to let you know that you mismatched your pointers.");
614 
615  // Check pointers
616  if (values.size() > 0) {
617  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
618  "An exception is thrown to let you know that you mismatched your pointers.");
619  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
620  "An exception is thrown to let you know that you mismatched your pointers.");
621  }
622 
623  // We have to make a copy here, it is unavoidable
624  // See comments in allocateAllValues
625  const size_t N = getNodeNumRows();
626 
627  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
628  myRowptr.Resize(N+1);
629  for (size_t i = 0; i < N+1; i++)
630  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
631  }
632 
633 
636  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
637 
638  int lowerOffset = 0;
639  bool ownMemory = false;
640 
641  const size_t n = getNodeNumRows();
642  const size_t nnz = getNodeNumEntries();
643 
644  // Row offsets
645  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
646  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
647  rowptr.resize(n+1);
648  for (size_t i = 0; i < n+1; i++)
649  (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
650 
651  // Column indices
652  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
653 
654  // Values
655  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
656  }
657 
658  // Epetra always has global constants
659  bool haveGlobalConstants() const { return true; }
661  //** \warning This is an expert-only routine and should not be called from user code. */
663  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
664  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
665  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
666  const RCP<ParameterList> & params=Teuchos::null) {
667  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
668 
669  // For Epetra matrices, resumeFill() is a fictive operation.
670  isFillResumed_ = false;
671 
672  int rv=0;
673  const Epetra_Import * myimport =0;
674  const Epetra_Export * myexport =0;
675 
676  if(!importer.is_null()) {
677  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
678  myimport = eImporter.getEpetra_Import().getRawPtr();
679  }
680  if(!exporter.is_null()) {
681  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
682  myexport = eExporter.getEpetra_Export().getRawPtr();
683  }
684 
685  rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
686 
687  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
688  }
690 
692 
693 
695  void resumeFill(const RCP< ParameterList > &params=Teuchos::null) {
696  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
697 
698  // According to Tpetra documentation, resumeFill() may be called repeatedly.
699  isFillResumed_ = true;
700  }
701 
703  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
704  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
705 
706  // For Epetra matrices, resumeFill() is a fictive operation.
707  isFillResumed_ = false;
708 
709  bool doOptimizeStorage = true;
710  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
711  mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
712  }
713 
714 
716  void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
717  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
718 
719  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
720  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
721 
722  bool doOptimizeStorage = true;
723  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
724  mtx_->FillComplete(doOptimizeStorage);
725  }
726 
727 
730  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
731  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
732 
733  const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
734  int rv=0;
735  if(myImport==Teuchos::null)
736  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
737  else
738  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
739  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
740  }
741 
743 
745 
746 
748  const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
749 
751  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
752 
754  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
755 
757  RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
758 
760  global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
761 
763  global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
764 
766  size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
767 
769  size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
770 
772  global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
773 
775  size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
776 
778  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
779 
781  size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
782 
784  size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
785 
787  bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
788 
790  bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
791 
793  bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
794 
796  bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
797 
799  ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
800 
802  bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
803 
805  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
806  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
807 
808  int numEntries = -1;
809  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
810  NumEntries = numEntries;
811  }
812 
814  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
815  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
816 
817  int numEntries = -1;
818  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
819  NumEntries = numEntries;
820  }
821 
823  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
824  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
825 
826  int numEntries;
827  double * eValues;
828  GlobalOrdinal * eIndices;
829 
830  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
831  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
832 
833  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
834  values = ArrayView<const double>(eValues, numEntries);
835  }
836 
838  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
839  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
840 
841  int numEntries;
842  double * eValues;
843  int * eIndices;
844 
845  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
846  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
847 
848  indices = ArrayView<const int>(eIndices, numEntries);
849  values = ArrayView<const double>(eValues, numEntries);
850  }
851 
854  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
855  XPETRA_ERR_CHECK(mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)));
856  }
857 
860  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
861  }
862 
865  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
866  }
867 
869  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
870  };
872  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
873  };
874 
876 
878 
879 
882  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
883 
884  //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
885 
886  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
887  XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
888 
889  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");
890  bool eTrans = toEpetra(mode);
891 
892  // /!\ UseTranspose value
893  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.");
894 
895  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
896 
897  // helper vector: tmp = A*x
899  tmp->PutScalar(0.0);
900  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
901 
902  // calculate alpha * A * x + beta * y
903  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
904  }
905 
907  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
908 
910  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
911 
913 
915 
916 
918  std::string description() const {
919  XPETRA_MONITOR("EpetraCrsMatrixT::description");
920 
921  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
922  std::ostringstream oss;
923  //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
924  if (isFillComplete()) {
925  oss << "{status = fill complete"
926  << ", global rows = " << getGlobalNumRows()
927  << ", global cols = " << getGlobalNumCols()
928  << ", global num entries = " << getGlobalNumEntries()
929  << "}";
930  }
931  else {
932  oss << "{status = fill not complete"
933  << ", global rows = " << getGlobalNumRows()
934  << "}";
935  }
936  return oss.str();
937 
938  }
939 
940 
943  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
944 
945  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
946  using std::endl;
947  using std::setw;
948  using Teuchos::VERB_DEFAULT;
949  using Teuchos::VERB_NONE;
950  using Teuchos::VERB_LOW;
951  using Teuchos::VERB_MEDIUM;
952  using Teuchos::VERB_HIGH;
953  using Teuchos::VERB_EXTREME;
954  Teuchos::EVerbosityLevel vl = verbLevel;
955  if (vl == VERB_DEFAULT) vl = VERB_LOW;
956  RCP<const Comm<int> > comm = this->getComm();
957  const int myImageID = comm->getRank(),
958  numImages = comm->getSize();
959  size_t width = 1;
960  for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
961  ++width;
962  }
963  width = std::max<size_t>(width,11) + 2;
964  Teuchos::OSTab tab(out);
965  // none: print nothing
966  // low: print O(1) info from node 0
967  // medium: print O(P) info, num entries per node
968  // high: print O(N) info, num entries per row
969  // extreme: print O(NNZ) info: print indices and values
970  //
971  // for medium and higher, print constituent objects at specified verbLevel
972  if (vl != VERB_NONE) {
973  if (myImageID == 0) out << this->description() << std::endl;
974  // O(1) globals, minus what was already printed by description()
975  if (isFillComplete() && myImageID == 0) {
976  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
977  }
978  // constituent objects
979  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
980  if (myImageID == 0) out << "\nRow map: " << std::endl;
981  getRowMap()->describe(out,vl);
982  //
983  if (getColMap() != null) {
984  if (getColMap() == getRowMap()) {
985  if (myImageID == 0) out << "\nColumn map is row map.";
986  }
987  else {
988  if (myImageID == 0) out << "\nColumn map: " << std::endl;
989  getColMap()->describe(out,vl);
990  }
991  }
992  if (getDomainMap() != null) {
993  if (getDomainMap() == getRowMap()) {
994  if (myImageID == 0) out << "\nDomain map is row map.";
995  }
996  else if (getDomainMap() == getColMap()) {
997  if (myImageID == 0) out << "\nDomain map is row map.";
998  }
999  else {
1000  if (myImageID == 0) out << "\nDomain map: " << std::endl;
1001  getDomainMap()->describe(out,vl);
1002  }
1003  }
1004  if (getRangeMap() != null) {
1005  if (getRangeMap() == getDomainMap()) {
1006  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1007  }
1008  else if (getRangeMap() == getRowMap()) {
1009  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1010  }
1011  else {
1012  if (myImageID == 0) out << "\nRange map: " << std::endl;
1013  getRangeMap()->describe(out,vl);
1014  }
1015  }
1016  if (myImageID == 0) out << std::endl;
1017  }
1018  // O(P) data
1019  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1020  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1021  if (myImageID == imageCtr) {
1022  out << "Node ID = " << imageCtr << std::endl;
1023  // TODO: need a graph
1024  // if (staticGraph_->indicesAreAllocated() == false) {
1025  // out << "Node not allocated" << std::endl;
1026  // }
1027  // else {
1028  // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
1029  // }
1030 
1031  // TMP:
1032  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1033  // End of TMP
1034 
1035  out << "Node number of entries = " << getNodeNumEntries() << std::endl;
1036  out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
1037  }
1038  comm->barrier();
1039  comm->barrier();
1040  comm->barrier();
1041  }
1042  }
1043  // O(N) and O(NNZ) data
1044  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1045  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1046  if (myImageID == imageCtr) {
1047  out << std::setw(width) << "Node ID"
1048  << std::setw(width) << "Global Row"
1049  << std::setw(width) << "Num Entries";
1050  if (vl == VERB_EXTREME) {
1051  out << std::setw(width) << "(Index,Value)";
1052  }
1053  out << std::endl;
1054  for (size_t r=0; r < getNodeNumRows(); ++r) {
1055  const size_t nE = getNumEntriesInLocalRow(r);
1056  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1057  out << std::setw(width) << myImageID
1058  << std::setw(width) << gid
1059  << std::setw(width) << nE;
1060  if (vl == VERB_EXTREME) {
1061  if (isGloballyIndexed()) {
1063  ArrayView<const Scalar> rowvals;
1064  getGlobalRowView(gid,rowinds,rowvals);
1065  for (size_t j=0; j < nE; ++j) {
1066  out << " (" << rowinds[j]
1067  << ", " << rowvals[j]
1068  << ") ";
1069  }
1070  }
1071  else if (isLocallyIndexed()) {
1073  ArrayView<const Scalar> rowvals;
1074  getLocalRowView(r,rowinds,rowvals);
1075  for (size_t j=0; j < nE; ++j) {
1076  out << " (" << getColMap()->getGlobalElement(rowinds[j])
1077  << ", " << rowvals[j]
1078  << ") ";
1079  }
1080  }
1081  }
1082  out << std::endl;
1083  }
1084  }
1085  comm->barrier();
1086  comm->barrier();
1087  comm->barrier();
1088  }
1089  }
1090  }
1091 
1092  }
1093 
1094 
1096 
1099  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
1100  { }
1101 
1102 
1104  //{@
1105 
1107  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
1108 
1112  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1113 
1114  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1115  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1116 
1117  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1118  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1119  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1120  }
1121 
1125  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1126 
1127  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1128  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1129 
1130  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1131  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1132  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1133  }
1134 
1138  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1139 
1140  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1141  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1142 
1143  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1144  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1145  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1146 
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 EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "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, *tExporter.getEpetra_Export(), toEpetra(CM));
1159  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1160  }
1161 
1163 
1165 
1167 
1168 
1170  bool hasMatrix() const { return !mtx_.is_null();}
1171 
1173  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
1174 
1177 
1179  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
1180 
1181 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1182 #ifdef HAVE_XPETRA_TPETRA
1183  local_matrix_type getLocalMatrix () const {
1185  if (isInitializedLocalMatrix_)
1186  return localMatrix_;
1187 
1189 
1190  const int numRows = matrix->NumMyRows();
1191  const int numCols = matrix->NumMyCols();
1192  const int nnz = matrix->NumMyNonzeros();
1193 
1194  int* rowptr;
1195  int* colind;
1196  double* vals;
1197  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1198  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1199 
1200  // Transform int* rowptr array to size_type* array
1201  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
1202  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1203  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
1204 
1205  // create Kokkos::Views
1206  typename local_matrix_type::index_type kokkosColind(colind, nnz);
1207  typename local_matrix_type::values_type kokkosVals (vals, nnz);
1208 
1209  localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1210  isInitializedLocalMatrix_ = true;
1211 
1212  return localMatrix_;
1213  }
1214 
1215  void setAllValues (const typename local_matrix_type::row_map_type& ptr,
1216  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& ind,
1217  const typename local_matrix_type::values_type& val)
1218  {
1220  "Xpetra::EpetraCrsMatrix::setAllValues is not implemented");
1221  }
1222 
1223 private:
1224  mutable local_matrix_type localMatrix_;
1225  mutable bool isInitializedLocalMatrix_ = false; // It's OK to use C++11 when Tpetra is enabled
1226 #else
1227 #ifdef __GNUC__
1228 #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."
1229 #endif
1230 #endif
1231 #endif
1232 
1233 
1234 private:
1236 
1237  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.
1238 
1239 }; // EpetraCrsMatrixT class
1240 
1241 #endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1242 
1243 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1244 template<>
1245 class EpetraCrsMatrixT <long long, EpetraNode>
1246 : public CrsMatrix <double, int, long long, EpetraNode>
1247 {
1248  typedef long long GlobalOrdinal;
1249  typedef EpetraNode Node;
1252 
1253 
1254  // The following typedefs are used by the Kokkos interface
1255 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1256 #ifdef HAVE_XPETRA_TPETRA
1259 #endif
1260 #endif
1261 
1262 public:
1263 
1265 
1266 
1268  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist = Teuchos::null)
1269 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
1270 { }
1271 
1272 
1275  : isFillResumed_(false)
1276  {
1277  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1278  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
1279  }
1280 
1281 
1284  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
1285  { }
1286 
1287 
1290  : isFillResumed_(false)
1291  {
1292  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1293  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
1294  }
1295 
1296 
1299  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
1300  { }
1301 
1302 
1306  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1307  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1308  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
1309  isFillResumed_(false)
1310  {
1311  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1312  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1313 
1314  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1315  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1316 
1317  // Follows the Tpetra parameters
1318  bool restrictComm=false;
1319  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1320  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
1321  if(restrictComm && mtx_->NumMyRows()==0)
1322  mtx_=Teuchos::null;
1323  }
1324 
1325 
1326 
1330  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1331  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1332  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
1333  isFillResumed_(false)
1334  {
1335  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1336  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1337 
1338  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1339  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1340 
1341  // Follows the Tpetra parameters
1342  bool restrictComm=false;
1343  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1344 
1345  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
1346  }
1347 
1349  const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
1350  const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
1351  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1352  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1353  const Teuchos::RCP<Teuchos::ParameterList>& params) :
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>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1358  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1359 
1360  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1361  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1362 
1363  // Follows the Tpetra parameters
1364  bool restrictComm=false;
1365  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1366  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
1367  if(restrictComm && mtx_->NumMyRows()==0)
1368  mtx_=Teuchos::null;
1369  }
1370 
1372  const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
1373  const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
1374  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1375  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1376  const Teuchos::RCP<Teuchos::ParameterList>& params) :
1377  isFillResumed_(false)
1378  {
1379  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1380  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1381  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "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(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
1391  }
1392 
1393 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1394 #ifdef HAVE_XPETRA_TPETRA
1416  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
1417  const local_matrix_type& lclMatrix,
1418  const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
1419  EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
1420 { }
1421 
1423  const local_matrix_type& lclMatrix,
1424  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
1425  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
1426  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
1427  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
1428  const Teuchos::RCP<Teuchos::ParameterList>& params = null)
1429  {
1430  // local typedefs from local_matrix_type
1431  //typedef typename local_matrix_type::size_type size_type;
1432  typedef typename local_matrix_type::value_type value_type;
1433  typedef typename local_matrix_type::ordinal_type ordinal_type;
1434 
1435  // The number of rows in the sparse matrix.
1436  ordinal_type lclNumRows = lclMatrix.numRows ();
1437  ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
1438 
1439  // plausibility checks
1440  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
1441  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1442  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
1443  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1444 
1445  Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
1446  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1447  // extract data from current row r
1448  auto rowview = lclMatrix.row (r);
1449  NumEntriesPerRowToAlloc[r] = rowview.length;
1450  }
1451 
1452  // setup matrix
1453  isFillResumed_ = false;
1454  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1455  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(DynamicProfile)));
1456 
1457  // loop over all rows and colums of local matrix and fill matrix
1458  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1459  // extract data from current row r
1460  auto rowview = lclMatrix.row (r);
1461 
1462  // arrays for current row data
1465 
1466  for(ordinal_type c = 0; c < rowview.length; c++) {
1467  value_type value = rowview.value (c);
1468  ordinal_type colidx = rowview.colidx (c);
1469 
1470  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!");
1471 
1472  indout [c] = colidx;
1473  valout [c] = value;
1474  }
1475  insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
1476  }
1477 
1478  // call fill complete
1479  if (!domainMap.is_null() && !rangeMap.is_null())
1480  this->fillComplete(domainMap, rowMap, params);
1481  else
1482  this->fillComplete(rowMap, rowMap, params);
1483 
1484  // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
1485  isInitializedLocalMatrix_ = false;
1486  }
1487 #endif
1488 #endif
1489 
1491  virtual ~EpetraCrsMatrixT() { }
1492 
1494 
1496 
1497 
1499  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1500  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1501  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1502  }
1503 
1504 
1506  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1507  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1508  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1509  }
1510 
1512  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values) {
1513  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1514 
1515  {
1516  const std::string tfecfFuncName("replaceGlobalValues");
1517  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
1518  ": Fill must be active in order to call this method. If you have already "
1519  "called fillComplete(), you need to call resumeFill() before you can "
1520  "replace values.");
1521 
1522  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1523  std::runtime_error, ": values.size() must equal indices.size().");
1524  }
1525 
1526  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1527 
1528  }
1529 
1531  void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values) {
1532  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
1533 
1534  {
1535  const std::string tfecfFuncName("replaceLocalValues");
1536  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
1537  ": Fill must be active in order to call this method. If you have already "
1538  "called fillComplete(), you need to call resumeFill() before you can "
1539  "replace values.");
1540 
1541  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1542  std::runtime_error, ": values.size() must equal indices.size().");
1543  }
1544 
1545  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1546 
1547  }
1548 
1549 
1551  void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
1552 
1554  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
1555 
1557  //** \warning This is an expert-only routine and should not be called from user code. */
1558  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
1559  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1560 
1561  // Row offsets
1562  // Unfortunately, we cannot do this in the same manner as column indices
1563  // and values (see below). The problem is that Tpetra insists on using
1564  // size_t, and Epetra uses int internally. So we only resize here, and
1565  // will need to copy in setAllValues
1566  rowptr.resize(getNodeNumRows()+1);
1567 
1568  int lowerOffset = 0;
1569  bool ownMemory = false;
1570 
1571  // Column indices
1572  // Extract, resize, set colind
1573  Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
1574  myColind.Resize(numNonZeros);
1575  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1576 
1577  // Values
1578  // Extract, reallocate, set values
1579  double *& myValues = mtx_->ExpertExtractValues();
1580  delete [] myValues;
1581  myValues = new double[numNonZeros];
1582  values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
1583  }
1584 
1586  void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
1587  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1588 
1589  // Check sizes
1591  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1593  "An exception is thrown to let you know that you mismatched your pointers.");
1594 
1595  // Check pointers
1596  if (values.size() > 0) {
1597  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1598  "An exception is thrown to let you know that you mismatched your pointers.");
1599  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1600  "An exception is thrown to let you know that you mismatched your pointers.");
1601  }
1602 
1603  // We have to make a copy here, it is unavoidable
1604  // See comments in allocateAllValues
1605  const size_t N = getNodeNumRows();
1606 
1607  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1608  myRowptr.Resize(N+1);
1609  for (size_t i = 0; i < N+1; i++)
1610  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1611  }
1612 
1613 
1616  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1617 
1618  int lowerOffset = 0;
1619  bool ownMemory = false;
1620 
1621  const size_t n = getNodeNumRows();
1622  const size_t nnz = getNodeNumEntries();
1623 
1624  // Row offsets
1625  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1626  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1627  rowptr.resize(n+1);
1628  for (size_t i = 0; i < n+1; i++)
1629  (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1630 
1631  // Column indices
1632  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1633 
1634  // Values
1635  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1636  }
1637 
1638  // Epetra always has global constants
1639  bool haveGlobalConstants() const { return true;}
1640 
1642  //** \warning This is an expert-only routine and should not be called from user code. */
1644  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1645  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
1646  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
1647  const RCP<ParameterList> & params=Teuchos::null) {
1648  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1649 
1650  // For Epetra matrices, resumeFill() is a fictive operation.
1651  isFillResumed_ = false;
1652 
1653  int rv=0;
1654  const Epetra_Import * myimport =0;
1655  const Epetra_Export * myexport =0;
1656 
1657  if(!importer.is_null()) {
1658  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1659  myimport = eImporter.getEpetra_Import().getRawPtr();
1660  }
1661  if(!exporter.is_null()) {
1662  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1663  myexport = eExporter.getEpetra_Export().getRawPtr();
1664  }
1665 
1666  rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
1667 
1668  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1669  }
1671 
1673 
1674 
1676  void resumeFill(const RCP< ParameterList > &params=Teuchos::null) {
1677  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1678 
1679  // According to Tpetra documentation, resumeFill() may be called repeatedly.
1680  isFillResumed_ = true;
1681  }
1682 
1684  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
1685  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1686 
1687  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1688  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1689 
1690  bool doOptimizeStorage = true;
1691  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1692  mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
1693  }
1694 
1695 
1697  void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
1698  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1699 
1700  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1701  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1702 
1703  bool doOptimizeStorage = true;
1704  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1705  mtx_->FillComplete(doOptimizeStorage);
1706  }
1707 
1708 
1711  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1712  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1713 
1714  const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
1715  int rv=0;
1716  if(myImport==Teuchos::null)
1717  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
1718  else
1719  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
1720  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1721  }
1722 
1724 
1726 
1727 
1729  const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
1730 
1732  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
1733 
1735  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
1736 
1738  RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
1739 
1741  global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
1742 
1744  global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
1745 
1747  size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
1748 
1750  size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
1751 
1753  global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
1754 
1756  size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
1757 
1759  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
1760 
1762  size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
1763 
1765  size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
1766 
1768  bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
1769 
1771  bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
1772 
1774  bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
1775 
1777  bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
1778 
1780  typename ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
1781 
1783  bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
1784 
1786  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1787  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1788 
1789  int numEntries = -1;
1790  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1791  NumEntries = numEntries;
1792  }
1793 
1795  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1796  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
1797 
1798  int numEntries = -1;
1799  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1800  NumEntries = numEntries;
1801  }
1802 
1804  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
1805  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
1806 
1807  int numEntries;
1808  double * eValues;
1809  GlobalOrdinal * eIndices;
1810 
1811  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
1812  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1813 
1814  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
1815  values = ArrayView<const double>(eValues, numEntries);
1816  }
1817 
1819  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
1820  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
1821 
1822  int numEntries;
1823  double * eValues;
1824  int * eIndices;
1825 
1826  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
1827  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1828 
1829  indices = ArrayView<const int>(eIndices, numEntries);
1830  values = ArrayView<const double>(eValues, numEntries);
1831  }
1832 
1834  void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy"); mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)); }
1835 
1838  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
1839  }
1840 
1843  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
1844  }
1845 
1847  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
1848  };
1850  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
1851  };
1852 
1854 
1856 
1857 
1860  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
1861 
1862  //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
1863 
1864  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1865  XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1866 
1867  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");
1868  bool eTrans = toEpetra(mode);
1869 
1870  // /!\ UseTranspose value
1871  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.");
1872 
1873  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
1874 
1875  // helper vector: tmp = A*x
1877  tmp->PutScalar(0.0);
1878  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
1879 
1880  // calculate alpha * A * x + beta * y
1881  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
1882  }
1883 
1885  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
1886 
1888  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
1889 
1891 
1893 
1894 
1896  std::string description() const {
1897  XPETRA_MONITOR("EpetraCrsMatrixT::description");
1898 
1899  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1900  std::ostringstream oss;
1901  //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
1902  if (isFillComplete()) {
1903  oss << "{status = fill complete"
1904  << ", global rows = " << getGlobalNumRows()
1905  << ", global cols = " << getGlobalNumCols()
1906  << ", global num entries = " << getGlobalNumEntries()
1907  << "}";
1908  }
1909  else {
1910  oss << "{status = fill not complete"
1911  << ", global rows = " << getGlobalNumRows()
1912  << "}";
1913  }
1914  return oss.str();
1915 
1916  }
1917 
1918 
1921  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
1922 
1923  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1924  using std::endl;
1925  using std::setw;
1926  using Teuchos::VERB_DEFAULT;
1927  using Teuchos::VERB_NONE;
1928  using Teuchos::VERB_LOW;
1929  using Teuchos::VERB_MEDIUM;
1930  using Teuchos::VERB_HIGH;
1931  using Teuchos::VERB_EXTREME;
1932  Teuchos::EVerbosityLevel vl = verbLevel;
1933  if (vl == VERB_DEFAULT) vl = VERB_LOW;
1934  RCP<const Comm<int> > comm = this->getComm();
1935  const int myImageID = comm->getRank(),
1936  numImages = comm->getSize();
1937  size_t width = 1;
1938  for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
1939  ++width;
1940  }
1941  width = std::max<size_t>(width,11) + 2;
1942  Teuchos::OSTab tab(out);
1943  // none: print nothing
1944  // low: print O(1) info from node 0
1945  // medium: print O(P) info, num entries per node
1946  // high: print O(N) info, num entries per row
1947  // extreme: print O(NNZ) info: print indices and values
1948  //
1949  // for medium and higher, print constituent objects at specified verbLevel
1950  if (vl != VERB_NONE) {
1951  if (myImageID == 0) out << this->description() << std::endl;
1952  // O(1) globals, minus what was already printed by description()
1953  if (isFillComplete() && myImageID == 0) {
1954  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1955  }
1956  // constituent objects
1957  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1958  if (myImageID == 0) out << "\nRow map: " << std::endl;
1959  getRowMap()->describe(out,vl);
1960  //
1961  if (getColMap() != null) {
1962  if (getColMap() == getRowMap()) {
1963  if (myImageID == 0) out << "\nColumn map is row map.";
1964  }
1965  else {
1966  if (myImageID == 0) out << "\nColumn map: " << std::endl;
1967  getColMap()->describe(out,vl);
1968  }
1969  }
1970  if (getDomainMap() != null) {
1971  if (getDomainMap() == getRowMap()) {
1972  if (myImageID == 0) out << "\nDomain map is row map.";
1973  }
1974  else if (getDomainMap() == getColMap()) {
1975  if (myImageID == 0) out << "\nDomain map is row map.";
1976  }
1977  else {
1978  if (myImageID == 0) out << "\nDomain map: " << std::endl;
1979  getDomainMap()->describe(out,vl);
1980  }
1981  }
1982  if (getRangeMap() != null) {
1983  if (getRangeMap() == getDomainMap()) {
1984  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1985  }
1986  else if (getRangeMap() == getRowMap()) {
1987  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1988  }
1989  else {
1990  if (myImageID == 0) out << "\nRange map: " << std::endl;
1991  getRangeMap()->describe(out,vl);
1992  }
1993  }
1994  if (myImageID == 0) out << std::endl;
1995  }
1996  // O(P) data
1997  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1998  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1999  if (myImageID == imageCtr) {
2000  out << "Node ID = " << imageCtr << std::endl;
2001  // TODO: need a graph
2002  // if (staticGraph_->indicesAreAllocated() == false) {
2003  // out << "Node not allocated" << std::endl;
2004  // }
2005  // else {
2006  // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
2007  // }
2008 
2009  // TMP:
2010  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2011  // End of TMP
2012 
2013  out << "Node number of entries = " << getNodeNumEntries() << std::endl;
2014  out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
2015  }
2016  comm->barrier();
2017  comm->barrier();
2018  comm->barrier();
2019  }
2020  }
2021  // O(N) and O(NNZ) data
2022  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2023  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2024  if (myImageID == imageCtr) {
2025  out << std::setw(width) << "Node ID"
2026  << std::setw(width) << "Global Row"
2027  << std::setw(width) << "Num Entries";
2028  if (vl == VERB_EXTREME) {
2029  out << std::setw(width) << "(Index,Value)";
2030  }
2031  out << std::endl;
2032  for (size_t r=0; r < getNodeNumRows(); ++r) {
2033  const size_t nE = getNumEntriesInLocalRow(r);
2034  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2035  out << std::setw(width) << myImageID
2036  << std::setw(width) << gid
2037  << std::setw(width) << nE;
2038  if (vl == VERB_EXTREME) {
2039  if (isGloballyIndexed()) {
2041  ArrayView<const Scalar> rowvals;
2042  getGlobalRowView(gid,rowinds,rowvals);
2043  for (size_t j=0; j < nE; ++j) {
2044  out << " (" << rowinds[j]
2045  << ", " << rowvals[j]
2046  << ") ";
2047  }
2048  }
2049  else if (isLocallyIndexed()) {
2051  ArrayView<const Scalar> rowvals;
2052  getLocalRowView(r,rowinds,rowvals);
2053  for (size_t j=0; j < nE; ++j) {
2054  out << " (" << getColMap()->getGlobalElement(rowinds[j])
2055  << ", " << rowvals[j]
2056  << ") ";
2057  }
2058  }
2059  }
2060  out << std::endl;
2061  }
2062  }
2063  comm->barrier();
2064  comm->barrier();
2065  comm->barrier();
2066  }
2067  }
2068  }
2069 
2070  }
2071 
2072 
2074 
2077  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
2078  { }
2079 
2080 
2082  //{@
2083 
2085  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
2086 
2090  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2091 
2092  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2093  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2094 
2095  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2096  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2097  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2098  }
2099 
2103  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2104 
2105  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2106  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2107 
2108  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2109  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2110  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2111  }
2112 
2116  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2117 
2118  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2119  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2120 
2121  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2122  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2123  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2124 
2125  }
2126 
2130  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2131 
2132  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2133  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2134 
2135  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2136  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2137  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2138  }
2139 
2141 
2143 
2145 
2146 
2148  bool hasMatrix() const { return !mtx_.is_null();}
2149 
2151  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
2152 
2155 
2157  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
2158 
2159 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
2160 #ifdef HAVE_XPETRA_TPETRA
2161  local_matrix_type getLocalMatrix () const {
2163  if (isInitializedLocalMatrix_)
2164  return localMatrix_;
2165 
2167 
2168  const int numRows = matrix->NumMyRows();
2169  const int numCols = matrix->NumMyCols();
2170  const int nnz = matrix->NumMyNonzeros();
2171 
2172  int* rowptr;
2173  int* colind;
2174  double* vals;
2175  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2176  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2177 
2178  // Transform int* rowptr array to size_type* array
2179  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
2180  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2181  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
2182 
2183  // create Kokkos::Views
2184  typename local_matrix_type::index_type kokkosColind(colind, nnz);
2185  typename local_matrix_type::values_type kokkosVals (vals, nnz);
2186 
2187  localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2188  isInitializedLocalMatrix_ = true;
2189 
2190  return localMatrix_;
2191  }
2192 
2193  void setAllValues (const typename local_matrix_type::row_map_type& ptr,
2194  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& ind,
2195  const typename local_matrix_type::values_type& val)
2196  {
2198  "Xpetra::EpetraCrsMatrix::setAllValues is not implemented");
2199  }
2200 
2201 private:
2202  mutable local_matrix_type localMatrix_;
2203  mutable bool isInitializedLocalMatrix_ = false;
2204 #else
2205 #ifdef __GNUC__
2206 #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."
2207 #endif
2208 #endif
2209 #endif
2210 
2211 
2212 private:
2214 
2215  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.
2216 
2217 }; // EpetraCrsMatrixT class
2218 
2219 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2220 
2221 } // Xpetra namespace
2222 
2223 #define XPETRA_EPETRACRSMATRIX_SHORT
2224 #endif // XPETRA_EPETRACRSMATRIX_HPP
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 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).
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...
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)
bool isFillActive() const
Returns true if the matrix is in edit mode.
bool isFillActive() const
Returns true if the matrix is in edit mode.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
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.
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this 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 getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
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)
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
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)
int Resize(int Length_in)
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, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and number of entries in each row.
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)
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
const RCP< const Comm< int > > getComm() const
Returns the communicator.
int ExtractCrsDataPointers(int *&IndexOffset, int *&Indices, double *&Values_in) const
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
void resumeFill(const RCP< ParameterList > &params=null)
size_type size() const
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
void resumeFill(const RCP< ParameterList > &params=Teuchos::null)
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)
int NumMyRows() const
T & get(const std::string &name, T def_value)
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
void fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
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 getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
#define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg)
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
int NumMyCols() const
int PutScalar(double ScalarConstant)
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
bool hasMatrix() const
Does this have an underlying 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 isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
Xpetra namespace
void resumeFill(const RCP< ParameterList > &params=Teuchos::null)
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
Gets the 1D pointer arrays of the graph.
Exception throws to report errors in the internal logical of the program.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
size_type size() const
LocalOrdinal local_ordinal_type
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 removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
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.
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.
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.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) 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, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
bool hasMatrix() const
Does this have an underlying matrix.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
bool is_null() const
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 fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
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 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 rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
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.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
void resize(const size_type n, const T &val=T())
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 getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying a previously constructed graph.
size_t getNodeNumCols() const
Returns the number of matrix columns owned on the calling node.
void setAllToScalar(const Scalar &alpha)
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 isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying fixed number of entries for each row.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const RCP< const Comm< int > > getComm() const
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
const RCP< const Comm< int > > getComm() const
Returns the communicator.
#define XPETRA_ERR_CHECK(arg)
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...
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
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)
Expert static fill complete.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
bool hasMatrix() const
Does this have an underlying matrix.
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix. ...
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
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 getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
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)
std::string description() const
A simple one-line description of this object.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const 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.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Exception throws when you call an unimplemented method of Xpetra.
iterator end() const
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
size_t global_size_t
Global size_t object.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
static const EVerbosityLevel verbLevel_default
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying (possibly different) number of entries in each row.
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &params=Teuchos::null)
iterator begin() const
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
static magnitudeType magnitude(T a)
void fillComplete(const RCP< ParameterList > &params=null)
Signal that data entry is complete.
int NumMyNonzeros() const
#define XPETRA_RCP_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
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.
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 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.
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
Get the underlying Epetra matrix.
void scale(const Scalar &alpha)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying (possibly different) number of entries in each row.
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)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying a previously constructed graph.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
T * getRawPtr() const
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
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
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.
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)
Expert static fill complete.
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
ArrayView< T > view(size_type lowerOffset, size_type size) const
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
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, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and number of entries in each row.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Copy
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
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)
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and fixed number of entries for each row.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
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...
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
std::string description() const
A simple one-line description of this object.
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)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, 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, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and fixed number of entries for each row.
T * getRawPtr() const
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
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 getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with 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.
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 getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void 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.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
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...
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
The Map describing the parallel distribution of this object.
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.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying fixed number of entries for each row.
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using local IDs.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)