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