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 getGlobalMaxNumRowEntries() const { return 0; }
193  size_t getNodeMaxNumRowEntries() const { return 0; }
194  bool isLocallyIndexed() const { return false; }
195  bool isGloballyIndexed() const { return false; }
196  bool isFillComplete() const { return false; }
197  bool isFillActive() const { return false; }
199  bool supportsRowViews() const { return false; }
200  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
201  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
210 
212  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { return Teuchos::null; }
213  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { return Teuchos::null; }
214 
215  std::string description() const { return std::string(""); }
217  void setObjectLabel( const std::string &objectLabel ) { }
218 
221  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
222  }
223 
230 
231  bool hasMatrix() const { return false; }
234  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
235  }
236  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
237  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } //TODO: remove
238 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
239 #ifdef HAVE_XPETRA_TPETRA
240  local_matrix_type getLocalMatrix () const {
242  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
243  }
244 
245  void setAllValues (const typename local_matrix_type::row_map_type& ptr,
246  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& ind,
247  const typename local_matrix_type::values_type& val)
248  {
250  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
251  }
252 #else
253 #ifdef __GNUC__
254 #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."
255 #endif
256 #endif
257 #endif
258 
259 }; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
260 
261 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
262 template<>
264 : public CrsMatrix <double, int, int, EpetraNode>
265 {
266  typedef int GlobalOrdinal;
267  typedef EpetraNode Node;
270 
271 
272  // The following typedefs are used by the Kokkos interface
273 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
274 #ifdef HAVE_XPETRA_TPETRA
277 #endif
278 #endif
279 
280 public:
281 
283 
284 
286  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */ = Teuchos::null)
287 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
288 { }
289 
290 
292  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)
293  : isFillResumed_(false)
294  {
295  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
296  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
297  }
298 
299 
301  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)
302  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
303  { }
304 
305 
308  : isFillResumed_(false)
309  {
310  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
311  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
312  }
313 
314 
317  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
318  { }
319 
320 
324  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
325  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
326  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
327  isFillResumed_(false)
328  {
329  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
330  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
331 
332  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
333  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
334 
335  // Follows the Tpetra parameters
336  bool restrictComm=false;
337  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
338  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
339  if(restrictComm && mtx_->NumMyRows()==0)
340  mtx_=Teuchos::null;
341  }
342 
343 
344 
348  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
349  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
350  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
351  isFillResumed_(false)
352  {
353  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
354  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
355 
356  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
357  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
358 
359  // Follows the Tpetra parameters
360  bool restrictComm=false;
361  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
362 
363  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
364  }
365 
367  const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
368  const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
369  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
370  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
371  const Teuchos::RCP<Teuchos::ParameterList>& params) :
372  isFillResumed_(false)
373  {
374  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
375  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
376  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
377 
378  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
379  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
380 
381  // Follows the Tpetra parameters
382  bool restrictComm=false;
383  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
384  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
385  if(restrictComm && mtx_->NumMyRows()==0)
386  mtx_=Teuchos::null;
387  }
388 
390  const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
391  const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
392  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
393  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
394  const Teuchos::RCP<Teuchos::ParameterList>& params) :
395  isFillResumed_(false)
396  {
397  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
398  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
399  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
400 
401  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
402  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
403 
404  // Follows the Tpetra parameters
405  bool restrictComm=false;
406  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
407 
408  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
409  }
410 
411 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
412 #ifdef HAVE_XPETRA_TPETRA
413  // NOTE: TPETRA means we can use C++11 here
414 
438  const local_matrix_type& lclMatrix,
439  const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
440  EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
441  { }
442 
444  const local_matrix_type& lclMatrix,
445  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
446  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
447  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
448  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
449  const Teuchos::RCP<Teuchos::ParameterList>& params = null)
450  {
451  // local typedefs from local_matrix_type
452  //typedef typename local_matrix_type::size_type size_type;
453  typedef typename local_matrix_type::value_type value_type;
454  typedef typename local_matrix_type::ordinal_type ordinal_type;
455 
456  // The number of rows in the sparse matrix.
457  ordinal_type lclNumRows = lclMatrix.numRows ();
458  ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
459 
460  // plausibility checks
461  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
462  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
463  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
464  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
465 
466  Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
467  for (ordinal_type r = 0; r < lclNumRows; ++r) {
468  // extract data from current row r
469  auto rowview = lclMatrix.row (r);
470  NumEntriesPerRowToAlloc[r] = rowview.length;
471  }
472 
473  // setup matrix
474  isFillResumed_ = false;
475  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
476  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(DynamicProfile)));
477 
478  // loop over all rows and colums of local matrix and fill matrix
479  for (ordinal_type r = 0; r < lclNumRows; ++r) {
480  // extract data from current row r
481  auto rowview = lclMatrix.row (r);
482 
483  // arrays for current row data
486 
487  for(ordinal_type c = 0; c < rowview.length; c++) {
488  value_type value = rowview.value (c);
489  ordinal_type colidx = rowview.colidx (c);
490 
491  TEUCHOS_TEST_FOR_EXCEPTION(colMap->isNodeLocalElement(colidx) == false, Xpetra::Exceptions::RuntimeError,
492  "Xpetra::EpetraCrsMatrixT: local matrix contains column elements which are not in the provided column map!");
493 
494  indout [c] = colidx;
495  valout [c] = value;
496  }
497  insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
498  }
499 
500  // call fill complete
501  if (!domainMap.is_null() && !rangeMap.is_null())
502  this->fillComplete(domainMap, rowMap, params);
503  else
504  this->fillComplete(rowMap, rowMap, params);
505 
506  // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
507  isInitializedLocalMatrix_ = false;
508  }
509 #endif
510 #endif
511 
513  virtual ~EpetraCrsMatrixT() { }
514 
516 
518 
519 
522  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
523  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
524  }
525 
526 
529  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
530  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
531  }
532 
535  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
536 
537  {
538  const std::string tfecfFuncName("replaceGlobalValues");
539  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
540  ": Fill must be active in order to call this method. If you have already "
541  "called fillComplete(), you need to call resumeFill() before you can "
542  "replace values.");
543 
544  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
545  std::runtime_error, ": values.size() must equal indices.size().");
546  }
547 
548  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
549 
550  }
551 
554  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
555 
556  {
557  const std::string tfecfFuncName("replaceLocalValues");
558  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
559  ": Fill must be active in order to call this method. If you have already "
560  "called fillComplete(), you need to call resumeFill() before you can "
561  "replace values.");
562 
563  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
564  std::runtime_error, ": values.size() must equal indices.size().");
565  }
566 
567  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
568 
569  }
570 
571 
573  void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
574 
576  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
577 
579  //** \warning This is an expert-only routine and should not be called from user code. */
580  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
581  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
582 
583  // Row offsets
584  // Unfortunately, we cannot do this in the same manner as column indices
585  // and values (see below). The problem is that Tpetra insists on using
586  // size_t, and Epetra uses int internally. So we only resize here, and
587  // will need to copy in setAllValues
588  rowptr.resize(getNodeNumRows()+1);
589 
590  int lowerOffset = 0;
591  bool ownMemory = false;
592 
593  // Column indices
594  // Extract, resize, set colind
595  Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
596  myColind.Resize(numNonZeros);
597  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
598 
599  // Values
600  // Extract, reallocate, set values
601  double *& myValues = mtx_->ExpertExtractValues();
602  delete [] myValues;
603  myValues = new double[numNonZeros];
604  values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
605  }
606 
608  void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
609  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
610 
611  // Check sizes
613  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
615  "An exception is thrown to let you know that you mismatched your pointers.");
616 
617  // Check pointers
618  if (values.size() > 0) {
619  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
620  "An exception is thrown to let you know that you mismatched your pointers.");
621  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
622  "An exception is thrown to let you know that you mismatched your pointers.");
623  }
624 
625  // We have to make a copy here, it is unavoidable
626  // See comments in allocateAllValues
627  const size_t N = getNodeNumRows();
628 
629  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
630  myRowptr.Resize(N+1);
631  for (size_t i = 0; i < N+1; i++)
632  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
633  }
634 
635 
638  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
639 
640  int lowerOffset = 0;
641  bool ownMemory = false;
642 
643  const size_t n = getNodeNumRows();
644  const size_t nnz = getNodeNumEntries();
645 
646  // Row offsets
647  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
648  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
649  rowptr.resize(n+1);
650  for (size_t i = 0; i < n+1; i++)
651  (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
652 
653  // Column indices
654  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
655 
656  // Values
657  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
658  }
659 
660  // Epetra always has global constants
661  bool haveGlobalConstants() const { return true; }
663  //** \warning This is an expert-only routine and should not be called from user code. */
665  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
666  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
667  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
668  const RCP<ParameterList> & /* params */=Teuchos::null) {
669  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
670 
671  // For Epetra matrices, resumeFill() is a fictive operation.
672  isFillResumed_ = false;
673 
674  int rv=0;
675  const Epetra_Import * myimport =0;
676  const Epetra_Export * myexport =0;
677 
678  if(!importer.is_null()) {
679  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
680  myimport = eImporter.getEpetra_Import().getRawPtr();
681  }
682  if(!exporter.is_null()) {
683  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
684  myexport = eExporter.getEpetra_Export().getRawPtr();
685  }
686 
687  rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
688 
689  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
690  }
692 
694 
695 
697  void resumeFill(const RCP< ParameterList > &/* params */=Teuchos::null) {
698  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
699 
700  // According to Tpetra documentation, resumeFill() may be called repeatedly.
701  isFillResumed_ = true;
702  }
703 
705  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
706  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
707 
708  // For Epetra matrices, resumeFill() is a fictive operation.
709  isFillResumed_ = false;
710 
711  bool doOptimizeStorage = true;
712  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
713  mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
714  }
715 
716 
718  void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
719  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
720 
721  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
722  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
723 
724  bool doOptimizeStorage = true;
725  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
726  mtx_->FillComplete(doOptimizeStorage);
727  }
728 
729 
732  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
733  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
734 
735  const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
736  int rv=0;
737  if(myImport==Teuchos::null)
738  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
739  else
740  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
741  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
742  }
743 
745 
747 
748 
750  const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
751 
753  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
754 
756  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
757 
759  RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
760 
762  global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
763 
765  global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
766 
768  size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
769 
771  size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
772 
774  global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
775 
777  size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
778 
780  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
781 
783  size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
784 
786  size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
787 
789  bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
790 
792  bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
793 
795  bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
796 
798  bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
799 
801  ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
802 
804  bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
805 
807  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
808  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
809 
810  int numEntries = -1;
811  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
812  NumEntries = numEntries;
813  }
814 
816  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
817  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
818 
819  int numEntries = -1;
820  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
821  NumEntries = numEntries;
822  }
823 
826  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
827 
828  int numEntries;
829  double * eValues;
830  GlobalOrdinal * eIndices;
831 
832  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
833  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
834 
835  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
836  values = ArrayView<const double>(eValues, numEntries);
837  }
838 
841  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
842 
843  int numEntries;
844  double * eValues;
845  int * eIndices;
846 
847  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
848  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
849 
850  indices = ArrayView<const int>(eIndices, numEntries);
851  values = ArrayView<const double>(eValues, numEntries);
852  }
853 
856  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy");
857  XPETRA_ERR_CHECK(mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)));
858  }
859 
861  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &/* offsets */) const {
862  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
863  }
864 
867  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
868  }
869 
872  mtx_->ReplaceDiagonalValues (toEpetra<GlobalOrdinal,Node>(diag));
873  }
874 
876  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
877  };
879  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
880  };
881 
883 
885 
886 
889  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
890 
891  //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
892 
893  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
894  XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
895 
896  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");
897  bool eTrans = toEpetra(mode);
898 
899  // /!\ UseTranspose value
900  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.");
901 
902  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
903 
904  // helper vector: tmp = A*x
906  tmp->PutScalar(0.0);
907  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
908 
909  // calculate alpha * A * x + beta * y
910  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
911  }
912 
914  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
915 
917  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
918 
920 
922 
923 
925  std::string description() const {
926  XPETRA_MONITOR("EpetraCrsMatrixT::description");
927 
928  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
929  std::ostringstream oss;
930  //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
931  if (isFillComplete()) {
932  oss << "{status = fill complete"
933  << ", global rows = " << getGlobalNumRows()
934  << ", global cols = " << getGlobalNumCols()
935  << ", global num entries = " << getGlobalNumEntries()
936  << "}";
937  }
938  else {
939  oss << "{status = fill not complete"
940  << ", global rows = " << getGlobalNumRows()
941  << "}";
942  }
943  return oss.str();
944 
945  }
946 
947 
950  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
951 
952  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
953  using std::endl;
954  using std::setw;
955  using Teuchos::VERB_DEFAULT;
956  using Teuchos::VERB_NONE;
957  using Teuchos::VERB_LOW;
958  using Teuchos::VERB_MEDIUM;
959  using Teuchos::VERB_HIGH;
960  using Teuchos::VERB_EXTREME;
961  Teuchos::EVerbosityLevel vl = verbLevel;
962  if (vl == VERB_DEFAULT) vl = VERB_LOW;
963  RCP<const Comm<int> > comm = this->getComm();
964  const int myImageID = comm->getRank(),
965  numImages = comm->getSize();
966  size_t width = 1;
967  for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
968  ++width;
969  }
970  width = std::max<size_t>(width,11) + 2;
971  Teuchos::OSTab tab(out);
972  // none: print nothing
973  // low: print O(1) info from node 0
974  // medium: print O(P) info, num entries per node
975  // high: print O(N) info, num entries per row
976  // extreme: print O(NNZ) info: print indices and values
977  //
978  // for medium and higher, print constituent objects at specified verbLevel
979  if (vl != VERB_NONE) {
980  if (myImageID == 0) out << this->description() << std::endl;
981  // O(1) globals, minus what was already printed by description()
982  if (isFillComplete() && myImageID == 0) {
983  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
984  }
985  // constituent objects
986  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
987  if (myImageID == 0) out << "\nRow map: " << std::endl;
988  getRowMap()->describe(out,vl);
989  //
990  if (getColMap() != null) {
991  if (getColMap() == getRowMap()) {
992  if (myImageID == 0) out << "\nColumn map is row map.";
993  }
994  else {
995  if (myImageID == 0) out << "\nColumn map: " << std::endl;
996  getColMap()->describe(out,vl);
997  }
998  }
999  if (getDomainMap() != null) {
1000  if (getDomainMap() == getRowMap()) {
1001  if (myImageID == 0) out << "\nDomain map is row map.";
1002  }
1003  else if (getDomainMap() == getColMap()) {
1004  if (myImageID == 0) out << "\nDomain map is row map.";
1005  }
1006  else {
1007  if (myImageID == 0) out << "\nDomain map: " << std::endl;
1008  getDomainMap()->describe(out,vl);
1009  }
1010  }
1011  if (getRangeMap() != null) {
1012  if (getRangeMap() == getDomainMap()) {
1013  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1014  }
1015  else if (getRangeMap() == getRowMap()) {
1016  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1017  }
1018  else {
1019  if (myImageID == 0) out << "\nRange map: " << std::endl;
1020  getRangeMap()->describe(out,vl);
1021  }
1022  }
1023  if (myImageID == 0) out << std::endl;
1024  }
1025  // O(P) data
1026  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1027  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1028  if (myImageID == imageCtr) {
1029  out << "Node ID = " << imageCtr << std::endl;
1030  // TODO: need a graph
1031  // if (staticGraph_->indicesAreAllocated() == false) {
1032  // out << "Node not allocated" << std::endl;
1033  // }
1034  // else {
1035  // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
1036  // }
1037 
1038  // TMP:
1039  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1040  // End of TMP
1041 
1042  out << "Node number of entries = " << getNodeNumEntries() << std::endl;
1043  out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
1044  }
1045  comm->barrier();
1046  comm->barrier();
1047  comm->barrier();
1048  }
1049  }
1050  // O(N) and O(NNZ) data
1051  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1052  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1053  if (myImageID == imageCtr) {
1054  out << std::setw(width) << "Node ID"
1055  << std::setw(width) << "Global Row"
1056  << std::setw(width) << "Num Entries";
1057  if (vl == VERB_EXTREME) {
1058  out << std::setw(width) << "(Index,Value)";
1059  }
1060  out << std::endl;
1061  for (size_t r=0; r < getNodeNumRows(); ++r) {
1062  const size_t nE = getNumEntriesInLocalRow(r);
1063  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1064  out << std::setw(width) << myImageID
1065  << std::setw(width) << gid
1066  << std::setw(width) << nE;
1067  if (vl == VERB_EXTREME) {
1068  if (isGloballyIndexed()) {
1070  ArrayView<const Scalar> rowvals;
1071  getGlobalRowView(gid,rowinds,rowvals);
1072  for (size_t j=0; j < nE; ++j) {
1073  out << " (" << rowinds[j]
1074  << ", " << rowvals[j]
1075  << ") ";
1076  }
1077  }
1078  else if (isLocallyIndexed()) {
1080  ArrayView<const Scalar> rowvals;
1081  getLocalRowView(r,rowinds,rowvals);
1082  for (size_t j=0; j < nE; ++j) {
1083  out << " (" << getColMap()->getGlobalElement(rowinds[j])
1084  << ", " << rowvals[j]
1085  << ") ";
1086  }
1087  }
1088  }
1089  out << std::endl;
1090  }
1091  }
1092  comm->barrier();
1093  comm->barrier();
1094  comm->barrier();
1095  }
1096  }
1097  }
1098 
1099  }
1100 
1101  void setObjectLabel( const std::string &objectLabel ) {
1102  Teuchos::LabeledObject::setObjectLabel(objectLabel);
1103  mtx_->SetLabel(objectLabel.c_str());
1104  }
1106 
1109  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
1110  { }
1111 
1112 
1114  //{@
1115 
1117  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
1118 
1122  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1123 
1124  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1125  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1126 
1127  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1128  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1129  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1130  }
1131 
1135  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1136 
1137  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1138  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1139 
1140  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1141  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1142  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1143  }
1144 
1148  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1149 
1150  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1151  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1152 
1153  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1154  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1155  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1156 
1157  }
1158 
1162  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1163 
1164  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1165  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1166 
1167  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1168  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1169  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1170  }
1171 
1173 
1175 
1177 
1178 
1180  bool hasMatrix() const { return !mtx_.is_null();}
1181 
1183  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
1184 
1187 
1189  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
1190 
1191 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1192 #ifdef HAVE_XPETRA_TPETRA
1193  local_matrix_type getLocalMatrix () const {
1195  if (isInitializedLocalMatrix_)
1196  return localMatrix_;
1197 
1199 
1200  const int numRows = matrix->NumMyRows();
1201  const int numCols = matrix->NumMyCols();
1202  const int nnz = matrix->NumMyNonzeros();
1203 
1204  int* rowptr;
1205  int* colind;
1206  double* vals;
1207  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1208  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1209 
1210  // Transform int* rowptr array to size_type* array
1211  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
1212  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1213  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
1214 
1215  // create Kokkos::Views
1216  typename local_matrix_type::index_type kokkosColind(colind, nnz);
1217  typename local_matrix_type::values_type kokkosVals (vals, nnz);
1218 
1219  localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1220  isInitializedLocalMatrix_ = true;
1221 
1222  return localMatrix_;
1223  }
1224 
1225  void setAllValues (const typename local_matrix_type::row_map_type& /* ptr */,
1226  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& /* ind */,
1227  const typename local_matrix_type::values_type& /* val */)
1228  {
1230  "Xpetra::EpetraCrsMatrix::setAllValues is not implemented");
1231  }
1232 
1233 private:
1234  mutable local_matrix_type localMatrix_;
1235  mutable bool isInitializedLocalMatrix_ = false; // It's OK to use C++11 when Tpetra is enabled
1236 #else
1237 #ifdef __GNUC__
1238 #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."
1239 #endif
1240 #endif
1241 #endif
1242 
1243 
1244 private:
1247 
1255 
1256 }; // EpetraCrsMatrixT class
1257 
1258 #endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1259 
1260 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1261 template<>
1262 class EpetraCrsMatrixT <long long, EpetraNode>
1263 : public CrsMatrix <double, int, long long, EpetraNode>
1264 {
1265  typedef long long GlobalOrdinal;
1266  typedef EpetraNode Node;
1269 
1270 
1271  // The following typedefs are used by the Kokkos interface
1272 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1273 #ifdef HAVE_XPETRA_TPETRA
1276 #endif
1277 #endif
1278 
1279 public:
1280 
1282 
1283 
1285  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &/* plist */ = Teuchos::null)
1286 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
1287 { }
1288 
1289 
1291  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)
1292  : isFillResumed_(false)
1293  {
1294  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1295  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
1296  }
1297 
1298 
1300  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)
1301  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
1302  { }
1303 
1304 
1307  : isFillResumed_(false)
1308  {
1309  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1310  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
1311  }
1312 
1313 
1316  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
1317  { }
1318 
1319 
1323  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1324  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1325  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
1326  isFillResumed_(false)
1327  {
1328  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1329  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1330 
1331  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1332  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1333 
1334  // Follows the Tpetra parameters
1335  bool restrictComm=false;
1336  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1337  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
1338  if(restrictComm && mtx_->NumMyRows()==0)
1339  mtx_=Teuchos::null;
1340  }
1341 
1342 
1343 
1347  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1348  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1349  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
1350  isFillResumed_(false)
1351  {
1352  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1353  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1354 
1355  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1356  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1357 
1358  // Follows the Tpetra parameters
1359  bool restrictComm=false;
1360  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1361 
1362  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
1363  }
1364 
1366  const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
1367  const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
1368  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1369  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1370  const Teuchos::RCP<Teuchos::ParameterList>& params) :
1371  isFillResumed_(false)
1372  {
1373  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1374  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1375  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1376 
1377  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1378  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1379 
1380  // Follows the Tpetra parameters
1381  bool restrictComm=false;
1382  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1383  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
1384  if(restrictComm && mtx_->NumMyRows()==0)
1385  mtx_=Teuchos::null;
1386  }
1387 
1389  const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
1390  const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
1391  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1392  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1393  const Teuchos::RCP<Teuchos::ParameterList>& params) :
1394  isFillResumed_(false)
1395  {
1396  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1397  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1398  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1399 
1400  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1401  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1402 
1403  // Follows the Tpetra parameters
1404  bool restrictComm=false;
1405  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1406 
1407  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
1408  }
1409 
1410 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1411 #ifdef HAVE_XPETRA_TPETRA
1433  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
1434  const local_matrix_type& lclMatrix,
1435  const Teuchos::RCP<Teuchos::ParameterList>& params = null) :
1436  EpetraCrsMatrixT(lclMatrix, rowMap, colMap, Teuchos::null, Teuchos::null, params)
1437 { }
1438 
1440  const local_matrix_type& lclMatrix,
1441  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rowMap,
1442  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
1443  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& domainMap = Teuchos::null,
1444  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& rangeMap = Teuchos::null,
1445  const Teuchos::RCP<Teuchos::ParameterList>& params = null)
1446  {
1447  // local typedefs from local_matrix_type
1448  //typedef typename local_matrix_type::size_type size_type;
1449  typedef typename local_matrix_type::value_type value_type;
1450  typedef typename local_matrix_type::ordinal_type ordinal_type;
1451 
1452  // The number of rows in the sparse matrix.
1453  ordinal_type lclNumRows = lclMatrix.numRows ();
1454  ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
1455 
1456  // plausibility checks
1457  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
1458  "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1459  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError,
1460  "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1461 
1462  Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
1463  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1464  // extract data from current row r
1465  auto rowview = lclMatrix.row (r);
1466  NumEntriesPerRowToAlloc[r] = rowview.length;
1467  }
1468 
1469  // setup matrix
1470  isFillResumed_ = false;
1471  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1472  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(DynamicProfile)));
1473 
1474  // loop over all rows and colums of local matrix and fill matrix
1475  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1476  // extract data from current row r
1477  auto rowview = lclMatrix.row (r);
1478 
1479  // arrays for current row data
1482 
1483  for(ordinal_type c = 0; c < rowview.length; c++) {
1484  value_type value = rowview.value (c);
1485  ordinal_type colidx = rowview.colidx (c);
1486 
1487  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!");
1488 
1489  indout [c] = colidx;
1490  valout [c] = value;
1491  }
1492  insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
1493  }
1494 
1495  // call fill complete
1496  if (!domainMap.is_null() && !rangeMap.is_null())
1497  this->fillComplete(domainMap, rowMap, params);
1498  else
1499  this->fillComplete(rowMap, rowMap, params);
1500 
1501  // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
1502  isInitializedLocalMatrix_ = false;
1503  }
1504 #endif
1505 #endif
1506 
1508  virtual ~EpetraCrsMatrixT() { }
1509 
1511 
1513 
1514 
1517  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1518  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1519  }
1520 
1521 
1524  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1525  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1526  }
1527 
1530  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1531 
1532  {
1533  const std::string tfecfFuncName("replaceGlobalValues");
1534  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
1535  ": Fill must be active in order to call this method. If you have already "
1536  "called fillComplete(), you need to call resumeFill() before you can "
1537  "replace values.");
1538 
1539  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1540  std::runtime_error, ": values.size() must equal indices.size().");
1541  }
1542 
1543  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1544 
1545  }
1546 
1549  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
1550 
1551  {
1552  const std::string tfecfFuncName("replaceLocalValues");
1553  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
1554  ": Fill must be active in order to call this method. If you have already "
1555  "called fillComplete(), you need to call resumeFill() before you can "
1556  "replace values.");
1557 
1558  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1559  std::runtime_error, ": values.size() must equal indices.size().");
1560  }
1561 
1562  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1563 
1564  }
1565 
1566 
1568  void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
1569 
1571  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
1572 
1574  //** \warning This is an expert-only routine and should not be called from user code. */
1575  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
1576  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1577 
1578  // Row offsets
1579  // Unfortunately, we cannot do this in the same manner as column indices
1580  // and values (see below). The problem is that Tpetra insists on using
1581  // size_t, and Epetra uses int internally. So we only resize here, and
1582  // will need to copy in setAllValues
1583  rowptr.resize(getNodeNumRows()+1);
1584 
1585  int lowerOffset = 0;
1586  bool ownMemory = false;
1587 
1588  // Column indices
1589  // Extract, resize, set colind
1590  Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
1591  myColind.Resize(numNonZeros);
1592  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1593 
1594  // Values
1595  // Extract, reallocate, set values
1596  double *& myValues = mtx_->ExpertExtractValues();
1597  delete [] myValues;
1598  myValues = new double[numNonZeros];
1599  values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
1600  }
1601 
1603  void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
1604  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1605 
1606  // Check sizes
1608  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1610  "An exception is thrown to let you know that you mismatched your pointers.");
1611 
1612  // Check pointers
1613  if (values.size() > 0) {
1614  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1615  "An exception is thrown to let you know that you mismatched your pointers.");
1616  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1617  "An exception is thrown to let you know that you mismatched your pointers.");
1618  }
1619 
1620  // We have to make a copy here, it is unavoidable
1621  // See comments in allocateAllValues
1622  const size_t N = getNodeNumRows();
1623 
1624  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1625  myRowptr.Resize(N+1);
1626  for (size_t i = 0; i < N+1; i++)
1627  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1628  }
1629 
1630 
1633  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1634 
1635  int lowerOffset = 0;
1636  bool ownMemory = false;
1637 
1638  const size_t n = getNodeNumRows();
1639  const size_t nnz = getNodeNumEntries();
1640 
1641  // Row offsets
1642  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1643  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1644  rowptr.resize(n+1);
1645  for (size_t i = 0; i < n+1; i++)
1646  (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1647 
1648  // Column indices
1649  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1650 
1651  // Values
1652  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1653  }
1654 
1655  // Epetra always has global constants
1656  bool haveGlobalConstants() const { return true;}
1657 
1659  //** \warning This is an expert-only routine and should not be called from user code. */
1661  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1662  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
1663  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
1664  const RCP<ParameterList> & /* params */=Teuchos::null) {
1665  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1666 
1667  // For Epetra matrices, resumeFill() is a fictive operation.
1668  isFillResumed_ = false;
1669 
1670  int rv=0;
1671  const Epetra_Import * myimport =0;
1672  const Epetra_Export * myexport =0;
1673 
1674  if(!importer.is_null()) {
1675  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1676  myimport = eImporter.getEpetra_Import().getRawPtr();
1677  }
1678  if(!exporter.is_null()) {
1679  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1680  myexport = eExporter.getEpetra_Export().getRawPtr();
1681  }
1682 
1683  rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
1684 
1685  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1686  }
1688 
1690 
1691 
1693  void resumeFill(const RCP< ParameterList > &/* params */=Teuchos::null) {
1694  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1695 
1696  // According to Tpetra documentation, resumeFill() may be called repeatedly.
1697  isFillResumed_ = true;
1698  }
1699 
1701  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
1702  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1703 
1704  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1705  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1706 
1707  bool doOptimizeStorage = true;
1708  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1709  mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
1710  }
1711 
1712 
1714  void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
1715  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1716 
1717  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1718  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1719 
1720  bool doOptimizeStorage = true;
1721  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1722  mtx_->FillComplete(doOptimizeStorage);
1723  }
1724 
1725 
1728  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1729  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1730 
1731  const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
1732  int rv=0;
1733  if(myImport==Teuchos::null)
1734  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
1735  else
1736  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
1737  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1738  }
1739 
1741 
1743 
1744 
1746  const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
1747 
1749  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
1750 
1752  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
1753 
1755  RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
1756 
1758  global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
1759 
1761  global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
1762 
1764  size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
1765 
1767  size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
1768 
1770  global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
1771 
1773  size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
1774 
1776  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
1777 
1779  size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
1780 
1782  size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
1783 
1785  bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
1786 
1788  bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
1789 
1791  bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
1792 
1794  bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
1795 
1797  typename ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
1798 
1800  bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
1801 
1803  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1804  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1805 
1806  int numEntries = -1;
1807  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1808  NumEntries = numEntries;
1809  }
1810 
1812  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1813  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
1814 
1815  int numEntries = -1;
1816  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1817  NumEntries = numEntries;
1818  }
1819 
1822  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
1823 
1824  int numEntries;
1825  double * eValues;
1826  GlobalOrdinal * eIndices;
1827 
1828  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
1829  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1830 
1831  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
1832  values = ArrayView<const double>(eValues, numEntries);
1833  }
1834 
1837  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
1838 
1839  int numEntries;
1840  double * eValues;
1841  int * eIndices;
1842 
1843  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
1844  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1845 
1846  indices = ArrayView<const int>(eIndices, numEntries);
1847  values = ArrayView<const double>(eValues, numEntries);
1848  }
1849 
1851  void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy"); mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)); }
1852 
1854  void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t> &/* offsets */) const {
1855  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
1856  }
1857 
1860  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
1861  }
1862 
1865  mtx_->ReplaceDiagonalValues (toEpetra<GlobalOrdinal,Node>(diag));
1866  }
1867 
1869  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
1870  };
1872  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
1873  };
1874 
1876 
1878 
1879 
1882  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
1883 
1884  //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
1885 
1886  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1887  XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1888 
1889  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");
1890  bool eTrans = toEpetra(mode);
1891 
1892  // /!\ UseTranspose value
1893  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.");
1894 
1895  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
1896 
1897  // helper vector: tmp = A*x
1899  tmp->PutScalar(0.0);
1900  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
1901 
1902  // calculate alpha * A * x + beta * y
1903  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
1904  }
1905 
1907  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
1908 
1910  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
1911 
1913 
1915 
1916 
1918  std::string description() const {
1919  XPETRA_MONITOR("EpetraCrsMatrixT::description");
1920 
1921  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1922  std::ostringstream oss;
1923  //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
1924  if (isFillComplete()) {
1925  oss << "{status = fill complete"
1926  << ", global rows = " << getGlobalNumRows()
1927  << ", global cols = " << getGlobalNumCols()
1928  << ", global num entries = " << getGlobalNumEntries()
1929  << "}";
1930  }
1931  else {
1932  oss << "{status = fill not complete"
1933  << ", global rows = " << getGlobalNumRows()
1934  << "}";
1935  }
1936  return oss.str();
1937 
1938  }
1939 
1940 
1943  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
1944 
1945  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1946  using std::endl;
1947  using std::setw;
1948  using Teuchos::VERB_DEFAULT;
1949  using Teuchos::VERB_NONE;
1950  using Teuchos::VERB_LOW;
1951  using Teuchos::VERB_MEDIUM;
1952  using Teuchos::VERB_HIGH;
1953  using Teuchos::VERB_EXTREME;
1954  Teuchos::EVerbosityLevel vl = verbLevel;
1955  if (vl == VERB_DEFAULT) vl = VERB_LOW;
1956  RCP<const Comm<int> > comm = this->getComm();
1957  const int myImageID = comm->getRank(),
1958  numImages = comm->getSize();
1959  size_t width = 1;
1960  for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
1961  ++width;
1962  }
1963  width = std::max<size_t>(width,11) + 2;
1964  Teuchos::OSTab tab(out);
1965  // none: print nothing
1966  // low: print O(1) info from node 0
1967  // medium: print O(P) info, num entries per node
1968  // high: print O(N) info, num entries per row
1969  // extreme: print O(NNZ) info: print indices and values
1970  //
1971  // for medium and higher, print constituent objects at specified verbLevel
1972  if (vl != VERB_NONE) {
1973  if (myImageID == 0) out << this->description() << std::endl;
1974  // O(1) globals, minus what was already printed by description()
1975  if (isFillComplete() && myImageID == 0) {
1976  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1977  }
1978  // constituent objects
1979  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1980  if (myImageID == 0) out << "\nRow map: " << std::endl;
1981  getRowMap()->describe(out,vl);
1982  //
1983  if (getColMap() != null) {
1984  if (getColMap() == getRowMap()) {
1985  if (myImageID == 0) out << "\nColumn map is row map.";
1986  }
1987  else {
1988  if (myImageID == 0) out << "\nColumn map: " << std::endl;
1989  getColMap()->describe(out,vl);
1990  }
1991  }
1992  if (getDomainMap() != null) {
1993  if (getDomainMap() == getRowMap()) {
1994  if (myImageID == 0) out << "\nDomain map is row map.";
1995  }
1996  else if (getDomainMap() == getColMap()) {
1997  if (myImageID == 0) out << "\nDomain map is row map.";
1998  }
1999  else {
2000  if (myImageID == 0) out << "\nDomain map: " << std::endl;
2001  getDomainMap()->describe(out,vl);
2002  }
2003  }
2004  if (getRangeMap() != null) {
2005  if (getRangeMap() == getDomainMap()) {
2006  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
2007  }
2008  else if (getRangeMap() == getRowMap()) {
2009  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
2010  }
2011  else {
2012  if (myImageID == 0) out << "\nRange map: " << std::endl;
2013  getRangeMap()->describe(out,vl);
2014  }
2015  }
2016  if (myImageID == 0) out << std::endl;
2017  }
2018  // O(P) data
2019  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2020  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2021  if (myImageID == imageCtr) {
2022  out << "Node ID = " << imageCtr << std::endl;
2023  // TODO: need a graph
2024  // if (staticGraph_->indicesAreAllocated() == false) {
2025  // out << "Node not allocated" << std::endl;
2026  // }
2027  // else {
2028  // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
2029  // }
2030 
2031  // TMP:
2032  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2033  // End of TMP
2034 
2035  out << "Node number of entries = " << getNodeNumEntries() << std::endl;
2036  out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
2037  }
2038  comm->barrier();
2039  comm->barrier();
2040  comm->barrier();
2041  }
2042  }
2043  // O(N) and O(NNZ) data
2044  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2045  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2046  if (myImageID == imageCtr) {
2047  out << std::setw(width) << "Node ID"
2048  << std::setw(width) << "Global Row"
2049  << std::setw(width) << "Num Entries";
2050  if (vl == VERB_EXTREME) {
2051  out << std::setw(width) << "(Index,Value)";
2052  }
2053  out << std::endl;
2054  for (size_t r=0; r < getNodeNumRows(); ++r) {
2055  const size_t nE = getNumEntriesInLocalRow(r);
2056  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2057  out << std::setw(width) << myImageID
2058  << std::setw(width) << gid
2059  << std::setw(width) << nE;
2060  if (vl == VERB_EXTREME) {
2061  if (isGloballyIndexed()) {
2063  ArrayView<const Scalar> rowvals;
2064  getGlobalRowView(gid,rowinds,rowvals);
2065  for (size_t j=0; j < nE; ++j) {
2066  out << " (" << rowinds[j]
2067  << ", " << rowvals[j]
2068  << ") ";
2069  }
2070  }
2071  else if (isLocallyIndexed()) {
2073  ArrayView<const Scalar> rowvals;
2074  getLocalRowView(r,rowinds,rowvals);
2075  for (size_t j=0; j < nE; ++j) {
2076  out << " (" << getColMap()->getGlobalElement(rowinds[j])
2077  << ", " << rowvals[j]
2078  << ") ";
2079  }
2080  }
2081  }
2082  out << std::endl;
2083  }
2084  }
2085  comm->barrier();
2086  comm->barrier();
2087  comm->barrier();
2088  }
2089  }
2090  }
2091 
2092  }
2093 
2094  void setObjectLabel( const std::string &objectLabel ) {
2095  Teuchos::LabeledObject::setObjectLabel(objectLabel);
2096  mtx_->SetLabel(objectLabel.c_str());
2097  }
2099 
2102  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
2103  { }
2104 
2105 
2107  //{@
2108 
2110  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
2111 
2115  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2116 
2117  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2118  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2119 
2120  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2121  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2122  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2123  }
2124 
2128  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2129 
2130  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2131  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2132 
2133  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2134  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2135  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2136  }
2137 
2141  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2142 
2143  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2144  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2145 
2146  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2147  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2148  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2149 
2150  }
2151 
2155  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2156 
2157  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2158  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2159 
2160  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2161  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2162  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2163  }
2164 
2166 
2168 
2170 
2171 
2173  bool hasMatrix() const { return !mtx_.is_null();}
2174 
2176  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
2177 
2180 
2182  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
2183 
2184 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
2185 #ifdef HAVE_XPETRA_TPETRA
2186  local_matrix_type getLocalMatrix () const {
2188  if (isInitializedLocalMatrix_)
2189  return localMatrix_;
2190 
2192 
2193  const int numRows = matrix->NumMyRows();
2194  const int numCols = matrix->NumMyCols();
2195  const int nnz = matrix->NumMyNonzeros();
2196 
2197  int* rowptr;
2198  int* colind;
2199  double* vals;
2200  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2201  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2202 
2203  // Transform int* rowptr array to size_type* array
2204  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
2205  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2206  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
2207 
2208  // create Kokkos::Views
2209  typename local_matrix_type::index_type kokkosColind(colind, nnz);
2210  typename local_matrix_type::values_type kokkosVals (vals, nnz);
2211 
2212  localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2213  isInitializedLocalMatrix_ = true;
2214 
2215  return localMatrix_;
2216  }
2217 
2218  void setAllValues (const typename local_matrix_type::row_map_type& /* ptr */,
2219  const typename local_matrix_type::StaticCrsGraphType::entries_type::non_const_type& /* ind */,
2220  const typename local_matrix_type::values_type& /* val */)
2221  {
2223  "Xpetra::EpetraCrsMatrix::setAllValues is not implemented");
2224  }
2225 
2226 private:
2227  mutable local_matrix_type localMatrix_;
2228  mutable bool isInitializedLocalMatrix_ = false;
2229 #else
2230 #ifdef __GNUC__
2231 #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."
2232 #endif
2233 #endif
2234 #endif
2235 
2236 
2237 private:
2239 
2240  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.
2241 
2242 }; // EpetraCrsMatrixT class
2243 
2244 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2245 
2246 } // Xpetra namespace
2247 
2248 #define XPETRA_EPETRACRSMATRIX_SHORT
2249 #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 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.
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...
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)