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  }
147 #endif
148 #endif
149  virtual ~EpetraCrsMatrixT() { }
150 
151  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals) {}
152  void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals) { }
153  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals) { }
154  void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals) { }
155  void setAllToScalar(const Scalar &alpha) { }
156  void scale(const Scalar &alpha) { }
157  void allocateAllValues(size_t numNonZeros,ArrayRCP<size_t> & rowptr, ArrayRCP<LocalOrdinal> & colind, ArrayRCP<Scalar> & values) { }
158  void setAllValues(const ArrayRCP<size_t> & rowptr, const ArrayRCP<LocalOrdinal> & colind, const ArrayRCP<Scalar> & values) { }
160  bool haveGlobalConstants() const { return true;}
162  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
163  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
164  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
165  const RCP<ParameterList> &params=Teuchos::null) { }
166 
167  void resumeFill(const RCP< ParameterList > &params=null) { }
168  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null) { }
169  void fillComplete(const RCP< ParameterList > &params=null) { }
171  const RCP< const Comm< int > > getComm() const { return Teuchos::null; }
172  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { return Teuchos::null; }
173  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { return Teuchos::null; }
175  global_size_t getGlobalNumRows() const { return 0; }
176  global_size_t getGlobalNumCols() const { return 0; }
177  size_t getNodeNumRows() const { return 0; }
178  size_t getNodeNumCols() const { return 0; }
179  global_size_t getGlobalNumEntries() const { return 0; }
180  size_t getNodeNumEntries() const { return 0; }
181  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { return 0; }
182  global_size_t getGlobalNumDiags() const { return 0; }
183  size_t getNodeNumDiags() const { return 0; }
184  size_t getGlobalMaxNumRowEntries() const { return 0; }
185  size_t getNodeMaxNumRowEntries() const { return 0; }
186  bool isLocallyIndexed() const { return false; }
187  bool isGloballyIndexed() const { return false; }
188  bool isFillComplete() const { return false; }
189  bool isFillActive() const { return false; }
191  bool supportsRowViews() const { return false; }
192  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
193  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const { }
194  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const { }
195  void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const { }
201 
203  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { return Teuchos::null; }
204  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { return Teuchos::null; }
205 
206  std::string description() const { return std::string(""); }
208 
211  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
212  }
213 
220 
221  bool hasMatrix() const { return false; }
224  "Xpetra::EpetraCrsMatrix only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)");
225  }
226  RCP<const Epetra_CrsMatrix> getEpetra_CrsMatrix() const { return Teuchos::null; }
227  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return Teuchos::null; } //TODO: remove
228 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
229 #ifdef HAVE_XPETRA_TPETRA
230  local_matrix_type getLocalMatrix () const {
231  TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete() == false, std::runtime_error,
232  "Xpetra::EpetraCrsMatrix::getLocalMatrix: matrix must be filled and completed before you can access the data through the Kokkos interface!");
233  return localMatrix_;
234  }
235 private:
236  mutable
237  local_matrix_type localMatrix_;
238 #else
239 #ifdef __GNUC__
240 #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."
241 #endif
242 #endif
243 #endif
244 
245 }; // EpetraCrsMatrixT class (specialization on GO=long, empty stub implementation)
246 
247 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
248 template<>
250 : public CrsMatrix <double, int, int, EpetraNode>
251 {
252  typedef int GlobalOrdinal;
253  typedef EpetraNode Node;
256 
257 
258  // The following typedefs are used by the Kokkos interface
259 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
260 #ifdef HAVE_XPETRA_TPETRA
263 #endif
264 #endif
265 
266 public:
267 
269 
270 
272  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist = Teuchos::null)
273 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
274 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
275 #ifdef HAVE_XPETRA_TPETRA
276 , isInitializedLocalMatrix_(false)
277 #endif
278 #endif
279 { }
280 
281 
284  : isFillResumed_(false)
285 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
286 #ifdef HAVE_XPETRA_TPETRA
287  , isInitializedLocalMatrix_(false)
288 #endif
289 #endif
290  {
291  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
292  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
293  }
294 
295 
298  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
299 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
300 #ifdef HAVE_XPETRA_TPETRA
301  , isInitializedLocalMatrix_(false)
302 #endif
303 #endif
304  { }
305 
306 
309  : isFillResumed_(false)
310 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
311 #ifdef HAVE_XPETRA_TPETRA
312  , isInitializedLocalMatrix_(false)
313 #endif
314 #endif
315  {
316  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
317  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
318  }
319 
320 
323  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
324 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
325 #ifdef HAVE_XPETRA_TPETRA
326  , isInitializedLocalMatrix_(false)
327 #endif
328 #endif
329  { }
330 
331 
335  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
336  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
337  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
338  isFillResumed_(false)
339 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
340 #ifdef HAVE_XPETRA_TPETRA
341  , isInitializedLocalMatrix_(false)
342 #endif
343 #endif
344  {
345  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
346  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
347 
348  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
349  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
350 
351  // Follows the Tpetra parameters
352  bool restrictComm=false;
353  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
354  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
355  if(restrictComm && mtx_->NumMyRows()==0)
356  mtx_=Teuchos::null;
357  }
358 
359 
360 
364  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
365  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
366  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
367  isFillResumed_(false)
368 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
369 #ifdef HAVE_XPETRA_TPETRA
370  , isInitializedLocalMatrix_(false)
371 #endif
372 #endif
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 EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
376 
377  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
378  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
379 
380  // Follows the Tpetra parameters
381  bool restrictComm=false;
382  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
383 
384  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
385  }
386 
388  const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
389  const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
390  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
391  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
392  const Teuchos::RCP<Teuchos::ParameterList>& params) :
393  isFillResumed_(false)
394 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
395 #ifdef HAVE_XPETRA_TPETRA
396  , isInitializedLocalMatrix_(false)
397 #endif
398 #endif
399  {
400  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
401  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
402  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
403 
404  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
405  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
406 
407  // Follows the Tpetra parameters
408  bool restrictComm=false;
409  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
410  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
411  if(restrictComm && mtx_->NumMyRows()==0)
412  mtx_=Teuchos::null;
413  }
414 
416  const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
417  const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
418  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
419  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
420  const Teuchos::RCP<Teuchos::ParameterList>& params) :
421  isFillResumed_(false)
422 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
423 #ifdef HAVE_XPETRA_TPETRA
424  , isInitializedLocalMatrix_(false)
425 #endif
426 #endif
427  {
428  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
429  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
430  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
431 
432  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
433  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
434 
435  // Follows the Tpetra parameters
436  bool restrictComm=false;
437  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
438 
439  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
440  }
441 
442 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
443 #ifdef HAVE_XPETRA_TPETRA
466  const local_matrix_type& lclMatrix,
467  const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
468  // local typedefs from local_matrix_type
469  //typedef typename local_matrix_type::size_type size_type;
470  typedef typename local_matrix_type::value_type value_type;
471  typedef typename local_matrix_type::ordinal_type ordinal_type;
472 
473  // The number of rows in the sparse matrix.
474  ordinal_type lclNumRows = lclMatrix.numRows ();
475  ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
476 
477  // plausibility checks
478  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
479  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
480 
481  std::vector<GlobalOrdinal> domainMapGids; // vector for collecting domain map GIDs
482 
483  Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
484  for (ordinal_type r = 0; r < lclNumRows; ++r) {
485  // extract data from current row r
486  auto rowview = lclMatrix.row (r);
487  NumEntriesPerRowToAlloc[r] = rowview.length;
488  }
489 
490  // setup matrix
491  isFillResumed_ = false;
492  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
493  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(DynamicProfile)));
494 
495  // loop over all rows and colums of local matrix and fill matrix
496  for (ordinal_type r = 0; r < lclNumRows; ++r) {
497  // extract data from current row r
498  auto rowview = lclMatrix.row (r);
499 
500  // arrays for current row data
503 
504  for(ordinal_type c = 0; c < rowview.length; c++) {
505  value_type value = rowview.value (c);
506  ordinal_type colidx = rowview.colidx (c);
507 
508  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!");
509 
510  indout [c] = colidx;
511  valout [c] = value;
512 
513  // collect GIDs for domain map
514  GlobalOrdinal gcid = colMap->getGlobalElement(c);
515  if(rowMap->isNodeGlobalElement(gcid)) domainMapGids.push_back(gcid);
516  }
517  insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
518  }
519 
520  // sort entries in domainMapGids and remove duplicates
521  const GlobalOrdinal INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
522  std::sort(domainMapGids.begin(), domainMapGids.end());
523  domainMapGids.erase(std::unique(domainMapGids.begin(), domainMapGids.end()), domainMapGids.end());
524  Teuchos::ArrayView<GlobalOrdinal> domainMapGidsView(&domainMapGids[0], domainMapGids.size());
526  Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(colMap->lib(), INVALID, domainMapGidsView, colMap->getIndexBase(), colMap->getComm());
527 
528  // call fill complete
529  this->fillComplete(domainMap, rowMap, params);
530 
531  // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
532  isInitializedLocalMatrix_ = false;
533  }
534 #endif
535 #endif
536 
538  virtual ~EpetraCrsMatrixT() { }
539 
541 
543 
544 
546  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
547  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
548  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
549  }
550 
551 
553  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
554  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
555  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
556  }
557 
559  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values) {
560  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
561 
562  {
563  const std::string tfecfFuncName("replaceGlobalValues");
564  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
565  ": Fill must be active in order to call this method. If you have already "
566  "called fillComplete(), you need to call resumeFill() before you can "
567  "replace values.");
568 
569  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
570  std::runtime_error, ": values.size() must equal indices.size().");
571  }
572 
573  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
574 
575  }
576 
578  void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values) {
579  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
580 
581  {
582  const std::string tfecfFuncName("replaceLocalValues");
583  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
584  ": Fill must be active in order to call this method. If you have already "
585  "called fillComplete(), you need to call resumeFill() before you can "
586  "replace values.");
587 
588  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
589  std::runtime_error, ": values.size() must equal indices.size().");
590  }
591 
592  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
593 
594  }
595 
596 
598  void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
599 
601  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
602 
604  //** \warning This is an expert-only routine and should not be called from user code. */
605  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
606  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
607 
608  // Row offsets
609  // Unfortunately, we cannot do this in the same manner as column indices
610  // and values (see below). The problem is that Tpetra insists on using
611  // size_t, and Epetra uses int internally. So we only resize here, and
612  // will need to copy in setAllValues
613  rowptr.resize(getNodeNumRows()+1);
614 
615  int lowerOffset = 0;
616  bool ownMemory = false;
617 
618  // Column indices
619  // Extract, resize, set colind
620  Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
621  myColind.Resize(numNonZeros);
622  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
623 
624  // Values
625  // Extract, reallocate, set values
626  double *& myValues = mtx_->ExpertExtractValues();
627  delete [] myValues;
628  myValues = new double[numNonZeros];
629  values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
630  }
631 
633  void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
634  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
635 
636  // Check sizes
638  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
640  "An exception is thrown to let you know that you mismatched your pointers.");
641 
642  // Check pointers
643  if (values.size() > 0) {
644  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
645  "An exception is thrown to let you know that you mismatched your pointers.");
646  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
647  "An exception is thrown to let you know that you mismatched your pointers.");
648  }
649 
650  // We have to make a copy here, it is unavoidable
651  // See comments in allocateAllValues
652  const size_t N = getNodeNumRows();
653 
654  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
655  myRowptr.Resize(N+1);
656  for (size_t i = 0; i < N+1; i++)
657  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
658  }
659 
660 
663  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
664 
665  int lowerOffset = 0;
666  bool ownMemory = false;
667 
668  const size_t n = getNodeNumRows();
669  const size_t nnz = getNodeNumEntries();
670 
671  // Row offsets
672  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
673  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
674  rowptr.resize(n+1);
675  for (size_t i = 0; i < n+1; i++)
676  (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
677 
678  // Column indices
679  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
680 
681  // Values
682  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
683  }
684 
685  // Epetra always has global constants
686  bool haveGlobalConstants() const { return true; }
688  //** \warning This is an expert-only routine and should not be called from user code. */
690  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
691  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
692  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
693  const RCP<ParameterList> & params=Teuchos::null) {
694  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
695  int rv=0;
696  const Epetra_Import * myimport =0;
697  const Epetra_Export * myexport =0;
698 
699  if(!importer.is_null()) {
700  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
701  myimport = eImporter.getEpetra_Import().getRawPtr();
702  }
703  if(!exporter.is_null()) {
704  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
705  myexport = eExporter.getEpetra_Export().getRawPtr();
706  }
707 
708  rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
709 
710  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
711  }
713 
715 
716 
718  void resumeFill(const RCP< ParameterList > &params=Teuchos::null) {
719  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
720 
721  // According to Tpetra documentation, resumeFill() may be called repeatedly.
722  isFillResumed_ = true;
723  }
724 
726  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
727  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
728 
729  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
730  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
731 
732  bool doOptimizeStorage = true;
733  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
734  mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
735  }
736 
737 
739  void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
740  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
741 
742  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
743  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
744 
745  bool doOptimizeStorage = true;
746  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
747  mtx_->FillComplete(doOptimizeStorage);
748  }
749 
750 
753  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
754  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
755 
756  const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
757  int rv=0;
758  if(myImport==Teuchos::null)
759  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
760  else
761  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
762  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
763  }
764 
766 
768 
769 
771  const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
772 
774  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
775 
777  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
778 
780  RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
781 
783  global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
784 
786  global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
787 
789  size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
790 
792  size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
793 
795  global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
796 
798  size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
799 
801  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
802 
804  global_size_t getGlobalNumDiags() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumDiags"); return mtx_->NumGlobalDiagonals64(); }
805 
807  size_t getNodeNumDiags() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumDiags"); return mtx_->NumMyDiagonals(); }
808 
810  size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
811 
813  size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
814 
816  bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
817 
819  bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
820 
822  bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
823 
825  bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
826 
828  ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
829 
831  bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
832 
834  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
835  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
836 
837  int numEntries = -1;
838  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
839  NumEntries = numEntries;
840  }
841 
843  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
844  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
845 
846  int numEntries = -1;
847  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
848  NumEntries = numEntries;
849  }
850 
852  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
853  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
854 
855  int numEntries;
856  double * eValues;
857  GlobalOrdinal * eIndices;
858 
859  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
860  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
861 
862  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
863  values = ArrayView<const double>(eValues, numEntries);
864  }
865 
867  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
868  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
869 
870  int numEntries;
871  double * eValues;
872  int * eIndices;
873 
874  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
875  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
876 
877  indices = ArrayView<const int>(eIndices, numEntries);
878  values = ArrayView<const double>(eValues, numEntries);
879  }
880 
882  void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy"); mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)); }
883 
886  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
887  }
888 
891  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
892  }
893 
895  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
896  };
898  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
899  };
900 
902 
904 
905 
908  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
909 
910  //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
911 
912  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
913  XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
914 
915  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");
916  bool eTrans = toEpetra(mode);
917 
918  // /!\ UseTranspose value
919  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.");
920 
921  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
922 
923  // helper vector: tmp = A*x
924  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
925  tmp->PutScalar(0.0);
926  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
927 
928  // calculate alpha * A * x + beta * y
929  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
930  }
931 
933  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
934 
936  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
937 
939 
941 
942 
944  std::string description() const {
945  XPETRA_MONITOR("EpetraCrsMatrixT::description");
946 
947  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
948  std::ostringstream oss;
949  //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
950  if (isFillComplete()) {
951  oss << "{status = fill complete"
952  << ", global rows = " << getGlobalNumRows()
953  << ", global cols = " << getGlobalNumCols()
954  << ", global num entries = " << getGlobalNumEntries()
955  << "}";
956  }
957  else {
958  oss << "{status = fill not complete"
959  << ", global rows = " << getGlobalNumRows()
960  << "}";
961  }
962  return oss.str();
963 
964  }
965 
966 
969  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
970 
971  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
972  using std::endl;
973  using std::setw;
974  using Teuchos::VERB_DEFAULT;
975  using Teuchos::VERB_NONE;
976  using Teuchos::VERB_LOW;
977  using Teuchos::VERB_MEDIUM;
978  using Teuchos::VERB_HIGH;
979  using Teuchos::VERB_EXTREME;
980  Teuchos::EVerbosityLevel vl = verbLevel;
981  if (vl == VERB_DEFAULT) vl = VERB_LOW;
982  RCP<const Comm<int> > comm = this->getComm();
983  const int myImageID = comm->getRank(),
984  numImages = comm->getSize();
985  size_t width = 1;
986  for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
987  ++width;
988  }
989  width = std::max<size_t>(width,11) + 2;
990  Teuchos::OSTab tab(out);
991  // none: print nothing
992  // low: print O(1) info from node 0
993  // medium: print O(P) info, num entries per node
994  // high: print O(N) info, num entries per row
995  // extreme: print O(NNZ) info: print indices and values
996  //
997  // for medium and higher, print constituent objects at specified verbLevel
998  if (vl != VERB_NONE) {
999  if (myImageID == 0) out << this->description() << std::endl;
1000  // O(1) globals, minus what was already printed by description()
1001  if (isFillComplete() && myImageID == 0) {
1002  out << "Global number of diagonals = " << getGlobalNumDiags() << std::endl;
1003  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
1004  }
1005  // constituent objects
1006  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1007  if (myImageID == 0) out << "\nRow map: " << std::endl;
1008  getRowMap()->describe(out,vl);
1009  //
1010  if (getColMap() != null) {
1011  if (getColMap() == getRowMap()) {
1012  if (myImageID == 0) out << "\nColumn map is row map.";
1013  }
1014  else {
1015  if (myImageID == 0) out << "\nColumn map: " << std::endl;
1016  getColMap()->describe(out,vl);
1017  }
1018  }
1019  if (getDomainMap() != null) {
1020  if (getDomainMap() == getRowMap()) {
1021  if (myImageID == 0) out << "\nDomain map is row map.";
1022  }
1023  else if (getDomainMap() == getColMap()) {
1024  if (myImageID == 0) out << "\nDomain map is row map.";
1025  }
1026  else {
1027  if (myImageID == 0) out << "\nDomain map: " << std::endl;
1028  getDomainMap()->describe(out,vl);
1029  }
1030  }
1031  if (getRangeMap() != null) {
1032  if (getRangeMap() == getDomainMap()) {
1033  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
1034  }
1035  else if (getRangeMap() == getRowMap()) {
1036  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
1037  }
1038  else {
1039  if (myImageID == 0) out << "\nRange map: " << std::endl;
1040  getRangeMap()->describe(out,vl);
1041  }
1042  }
1043  if (myImageID == 0) out << std::endl;
1044  }
1045  // O(P) data
1046  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
1047  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1048  if (myImageID == imageCtr) {
1049  out << "Node ID = " << imageCtr << std::endl;
1050  // TODO: need a graph
1051  // if (staticGraph_->indicesAreAllocated() == false) {
1052  // out << "Node not allocated" << std::endl;
1053  // }
1054  // else {
1055  // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
1056  // }
1057 
1058  // TMP:
1059  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
1060  // End of TMP
1061 
1062  out << "Node number of entries = " << getNodeNumEntries() << std::endl;
1063  if (isFillComplete()) {
1064  out << "Node number of diagonals = " << getNodeNumDiags() << std::endl;
1065  }
1066  out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
1067  }
1068  comm->barrier();
1069  comm->barrier();
1070  comm->barrier();
1071  }
1072  }
1073  // O(N) and O(NNZ) data
1074  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
1075  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
1076  if (myImageID == imageCtr) {
1077  out << std::setw(width) << "Node ID"
1078  << std::setw(width) << "Global Row"
1079  << std::setw(width) << "Num Entries";
1080  if (vl == VERB_EXTREME) {
1081  out << std::setw(width) << "(Index,Value)";
1082  }
1083  out << std::endl;
1084  for (size_t r=0; r < getNodeNumRows(); ++r) {
1085  const size_t nE = getNumEntriesInLocalRow(r);
1086  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
1087  out << std::setw(width) << myImageID
1088  << std::setw(width) << gid
1089  << std::setw(width) << nE;
1090  if (vl == VERB_EXTREME) {
1091  if (isGloballyIndexed()) {
1093  ArrayView<const Scalar> rowvals;
1094  getGlobalRowView(gid,rowinds,rowvals);
1095  for (size_t j=0; j < nE; ++j) {
1096  out << " (" << rowinds[j]
1097  << ", " << rowvals[j]
1098  << ") ";
1099  }
1100  }
1101  else if (isLocallyIndexed()) {
1103  ArrayView<const Scalar> rowvals;
1104  getLocalRowView(r,rowinds,rowvals);
1105  for (size_t j=0; j < nE; ++j) {
1106  out << " (" << getColMap()->getGlobalElement(rowinds[j])
1107  << ", " << rowvals[j]
1108  << ") ";
1109  }
1110  }
1111  }
1112  out << std::endl;
1113  }
1114  }
1115  comm->barrier();
1116  comm->barrier();
1117  comm->barrier();
1118  }
1119  }
1120  }
1121 
1122  }
1123 
1124 
1126 
1129  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
1130 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1131 #ifdef HAVE_XPETRA_TPETRA
1132  , isInitializedLocalMatrix_(false)
1133 #endif
1134 #endif
1135  { }
1136 
1137 
1139  //{@
1140 
1142  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
1143 
1147  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1148 
1149  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1150  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1151 
1152  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1153  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1154  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1155  }
1156 
1160  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1161 
1162  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1163  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1164 
1165  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1166  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
1167  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1168  }
1169 
1173  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
1174 
1175  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1176  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1177 
1178  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
1179  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1180  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1181 
1182  }
1183 
1187  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
1188 
1189  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
1190  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
1191 
1192  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
1193  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
1194  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
1195  }
1196 
1198 
1200 
1202 
1203 
1205  bool hasMatrix() const { return !mtx_.is_null();}
1206 
1208  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
1209 
1212 
1214  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
1215 
1216 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1217 #ifdef HAVE_XPETRA_TPETRA
1218  local_matrix_type getLocalMatrix () const {
1220  TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete() == false, std::runtime_error,
1221  "Xpetra::EpetraCrsMatrix::getLocalMatrix: matrix must be filled and completed before you can access the data through the Kokkos interface!");
1222  if (isInitializedLocalMatrix_)
1223  return localMatrix_;
1224 
1226 
1227  const int numRows = matrix->NumMyRows();
1228  const int numCols = matrix->NumMyCols();
1229  const int nnz = matrix->NumMyNonzeros();
1230 
1231  int* rowptr;
1232  int* colind;
1233  double* vals;
1234  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
1235  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
1236 
1237  // Transform int* rowptr array to size_type* array
1238  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
1239  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
1240  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
1241 
1242  // create Kokkos::Views
1243  typename local_matrix_type::index_type kokkosColind(colind, nnz);
1244  typename local_matrix_type::values_type kokkosVals (vals, nnz);
1245 
1246  localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
1247  isInitializedLocalMatrix_ = true;
1248 
1249  return localMatrix_;
1250  }
1251 #else
1252 #ifdef __GNUC__
1253 #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."
1254 #endif
1255 #endif
1256 #endif
1257 
1258 
1259 private:
1261 
1262  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.
1263 
1264 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1265 #ifdef HAVE_XPETRA_TPETRA
1266  mutable
1267  local_matrix_type localMatrix_;
1268  mutable
1269  bool isInitializedLocalMatrix_;
1270 #else
1271 #ifdef __GNUC__
1272 #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."
1273 #endif
1274 #endif
1275 #endif
1276 
1277 }; // EpetraCrsMatrixT class
1278 
1279 #endif //#ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1280 
1281 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1282 template<>
1283 class EpetraCrsMatrixT <long long, EpetraNode>
1284 : public CrsMatrix <double, int, long long, EpetraNode>
1285 {
1286  typedef long long GlobalOrdinal;
1287  typedef EpetraNode Node;
1290 
1291 
1292  // The following typedefs are used by the Kokkos interface
1293 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1294 #ifdef HAVE_XPETRA_TPETRA
1297 #endif
1298 #endif
1299 
1300 public:
1301 
1303 
1304 
1306  EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist = Teuchos::null)
1307 : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
1308 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1309 #ifdef HAVE_XPETRA_TPETRA
1310 , isInitializedLocalMatrix_(false)
1311 #endif
1312 #endif
1313 { }
1314 
1315 
1318  : isFillResumed_(false)
1319 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1320 #ifdef HAVE_XPETRA_TPETRA
1321  , isInitializedLocalMatrix_(false)
1322 #endif
1323 #endif
1324  {
1325  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1326  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
1327  }
1328 
1329 
1332  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), maxNumEntriesPerRow, toEpetra(pftype)))), isFillResumed_(false)
1333 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1334 #ifdef HAVE_XPETRA_TPETRA
1335  , isInitializedLocalMatrix_(false)
1336 #endif
1337 #endif
1338  { }
1339 
1340 
1343  : isFillResumed_(false)
1344 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1345 #ifdef HAVE_XPETRA_TPETRA
1346  , isInitializedLocalMatrix_(false)
1347 #endif
1348 #endif
1349  {
1350  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1351  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(pftype)));
1352  }
1353 
1354 
1357  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(graph)))), isFillResumed_(false)
1358 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1359 #ifdef HAVE_XPETRA_TPETRA
1360  , isInitializedLocalMatrix_(false)
1361 #endif
1362 #endif
1363  { }
1364 
1365 
1369  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1370  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1371  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null):
1372  isFillResumed_(false)
1373 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1374 #ifdef HAVE_XPETRA_TPETRA
1375  , isInitializedLocalMatrix_(false)
1376 #endif
1377 #endif
1378  {
1379  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1380  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1381 
1382  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1383  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1384 
1385  // Follows the Tpetra parameters
1386  bool restrictComm=false;
1387  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1388  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),myDomainMap,myRangeMap,restrictComm));
1389  if(restrictComm && mtx_->NumMyRows()==0)
1390  mtx_=Teuchos::null;
1391  }
1392 
1393 
1394 
1398  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap = Teuchos::null,
1399  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap = Teuchos::null,
1400  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) :
1401  isFillResumed_(false)
1402 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1403 #ifdef HAVE_XPETRA_TPETRA
1404  , isInitializedLocalMatrix_(false)
1405 #endif
1406 #endif
1407  {
1408  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1409  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1410 
1411  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1412  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1413 
1414  // Follows the Tpetra parameters
1415  bool restrictComm=false;
1416  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1417 
1418  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),myDomainMap,myRangeMap,restrictComm));
1419  }
1420 
1422  const Import<LocalOrdinal,GlobalOrdinal,Node> &RowImporter,
1423  const Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > DomainImporter,
1424  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1425  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1426  const Teuchos::RCP<Teuchos::ParameterList>& params) :
1427  isFillResumed_(false)
1428 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1429 #ifdef HAVE_XPETRA_TPETRA
1430  , isInitializedLocalMatrix_(false)
1431 #endif
1432 #endif
1433  {
1434  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1435  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, RowImporter, tImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1436  XPETRA_RCP_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, DomainImporter, tdImporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraImportT as an input argument.");
1437 
1438  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1439  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1440 
1441  // Follows the Tpetra parameters
1442  bool restrictComm=false;
1443  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1444  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tImporter.getEpetra_Import(),tdImporter->getEpetra_Import().get(),myDomainMap,myRangeMap,restrictComm));
1445  if(restrictComm && mtx_->NumMyRows()==0)
1446  mtx_=Teuchos::null;
1447  }
1448 
1450  const Export<LocalOrdinal,GlobalOrdinal,Node> &RowExporter,
1451  const Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > DomainExporter,
1452  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & domainMap,
1453  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1454  const Teuchos::RCP<Teuchos::ParameterList>& params) :
1455  isFillResumed_(false)
1456 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1457 #ifdef HAVE_XPETRA_TPETRA
1458  , isInitializedLocalMatrix_(false)
1459 #endif
1460 #endif
1461  {
1462  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, *sourceMatrix, tSourceMatrix, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraCrsMatrixT as an input argument.");
1463  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, RowExporter, tExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1464  XPETRA_RCP_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, DomainExporter, tdExporter, "Xpetra::EpetraCrsMatrixT constructor only accepts Xpetra::EpetraExportT as an input argument.");
1465 
1466  const Epetra_Map* myDomainMap = (domainMap!=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(domainMap): 0;
1467  const Epetra_Map* myRangeMap = (rangeMap !=Teuchos::null)? &toEpetra<GlobalOrdinal,Node>(rangeMap) : 0;
1468 
1469  // Follows the Tpetra parameters
1470  bool restrictComm=false;
1471  if(!params.is_null()) restrictComm = params->get("Restrict Communicator",restrictComm);
1472 
1473  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(*tSourceMatrix.getEpetra_CrsMatrix(),*tExporter.getEpetra_Export(),tdExporter->getEpetra_Export().get(),myDomainMap,myRangeMap,restrictComm));
1474  }
1475 
1476 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
1477 #ifdef HAVE_XPETRA_TPETRA
1499  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& colMap,
1500  const local_matrix_type& lclMatrix,
1501  const Teuchos::RCP<Teuchos::ParameterList>& params = null) {
1502  // local typedefs from local_matrix_type
1503  //typedef typename local_matrix_type::size_type size_type;
1504  typedef typename local_matrix_type::value_type value_type;
1505  typedef typename local_matrix_type::ordinal_type ordinal_type;
1506 
1507  // The number of rows in the sparse matrix.
1508  ordinal_type lclNumRows = lclMatrix.numRows ();
1509  ordinal_type lclNumCols = lclMatrix.numCols (); // do we need this?
1510 
1511  // plausibility checks
1512  TEUCHOS_TEST_FOR_EXCEPTION(lclNumRows != Teuchos::as<ordinal_type>(rowMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: number of rows in local matrix and number of local entries in row map do not match!");
1513  TEUCHOS_TEST_FOR_EXCEPTION(lclNumCols != Teuchos::as<ordinal_type>(colMap->getNodeNumElements()), Xpetra::Exceptions::RuntimeError, "Xpetra::EpetraCrsMatrixT: number of columns in local matrix and number of local entries in column map do not match!");
1514 
1515  std::vector<GlobalOrdinal> domainMapGids; // vector for collecting domain map GIDs
1516 
1517  Teuchos::ArrayRCP< size_t > NumEntriesPerRowToAlloc(lclNumRows);
1518  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1519  // extract data from current row r
1520  auto rowview = lclMatrix.row (r);
1521  NumEntriesPerRowToAlloc[r] = rowview.length;
1522  }
1523 
1524  // setup matrix
1525  isFillResumed_ = false;
1526  Teuchos::Array<int> numEntriesPerRowToAlloc(NumEntriesPerRowToAlloc.begin(), NumEntriesPerRowToAlloc.end()); // convert array of "size_t" to array of "int"
1527  mtx_ = Teuchos::rcp(new Epetra_CrsMatrix(Copy, toEpetra<GlobalOrdinal,Node>(rowMap), toEpetra<GlobalOrdinal,Node>(colMap), numEntriesPerRowToAlloc.getRawPtr(), toEpetra(DynamicProfile)));
1528 
1529  // loop over all rows and colums of local matrix and fill matrix
1530  for (ordinal_type r = 0; r < lclNumRows; ++r) {
1531  // extract data from current row r
1532  auto rowview = lclMatrix.row (r);
1533 
1534  // arrays for current row data
1537 
1538  for(ordinal_type c = 0; c < rowview.length; c++) {
1539  value_type value = rowview.value (c);
1540  ordinal_type colidx = rowview.colidx (c);
1541 
1542  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!");
1543 
1544  indout [c] = colidx;
1545  valout [c] = value;
1546 
1547  // collect GIDs for domain map
1548  GlobalOrdinal gcid = colMap->getGlobalElement(c);
1549  if(rowMap->isNodeGlobalElement(gcid)) domainMapGids.push_back(gcid);
1550  }
1551  insertLocalValues(r, indout.view(0,indout.size()), valout.view(0,valout.size()));
1552  }
1553 
1554  // sort entries in domainMapGids and remove duplicates
1555  const GlobalOrdinal INVALID = Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid();
1556  std::sort(domainMapGids.begin(), domainMapGids.end());
1557  domainMapGids.erase(std::unique(domainMapGids.begin(), domainMapGids.end()), domainMapGids.end());
1558  Teuchos::ArrayView<GlobalOrdinal> domainMapGidsView(&domainMapGids[0], domainMapGids.size());
1560  Xpetra::MapFactory<LocalOrdinal,GlobalOrdinal,Node>::Build(colMap->lib(), INVALID, domainMapGidsView, colMap->getIndexBase(), colMap->getComm());
1561 
1562  // call fill complete
1563  this->fillComplete(domainMap, rowMap, params);
1564 
1565  // AP (2015/10/22): Could probably be optimized using provided lclMatrix, but lets not worry about that
1566  isInitializedLocalMatrix_ = false;
1567  }
1568 #endif
1569 #endif
1570 
1572  virtual ~EpetraCrsMatrixT() { }
1573 
1575 
1577 
1578 
1580  void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView<const GlobalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1581  XPETRA_MONITOR("EpetraCrsMatrixT::insertGlobalValues");
1582  XPETRA_ERR_CHECK(mtx_->InsertGlobalValues(globalRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1583  }
1584 
1585 
1587  void insertLocalValues(LocalOrdinal localRow, const ArrayView<const LocalOrdinal> &cols, const ArrayView<const Scalar> &vals) {
1588  XPETRA_MONITOR("EpetraCrsMatrixT::insertLocalValues");
1589  XPETRA_ERR_CHECK(mtx_->InsertMyValues(localRow, vals.size(), vals.getRawPtr(), cols.getRawPtr()));
1590  }
1591 
1593  void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values) {
1594  XPETRA_MONITOR("EpetraCrsMatrixT::replaceGlobalValues");
1595 
1596  {
1597  const std::string tfecfFuncName("replaceGlobalValues");
1598  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
1599  ": Fill must be active in order to call this method. If you have already "
1600  "called fillComplete(), you need to call resumeFill() before you can "
1601  "replace values.");
1602 
1603  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1604  std::runtime_error, ": values.size() must equal indices.size().");
1605  }
1606 
1607  XPETRA_ERR_CHECK(mtx_->ReplaceGlobalValues(globalRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1608 
1609  }
1610 
1612  void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values) {
1613  XPETRA_MONITOR("EpetraCrsMatrixT::replaceLocalValues");
1614 
1615  {
1616  const std::string tfecfFuncName("replaceLocalValues");
1617  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! isFillActive(), std::runtime_error,
1618  ": Fill must be active in order to call this method. If you have already "
1619  "called fillComplete(), you need to call resumeFill() before you can "
1620  "replace values.");
1621 
1622  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(values.size() != indices.size(),
1623  std::runtime_error, ": values.size() must equal indices.size().");
1624  }
1625 
1626  XPETRA_ERR_CHECK(mtx_->ReplaceMyValues(localRow, indices.size(), values.getRawPtr(), indices.getRawPtr()));
1627 
1628  }
1629 
1630 
1632  void setAllToScalar(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllToScalar"); mtx_->PutScalar(alpha); }
1633 
1635  void scale(const Scalar &alpha) { XPETRA_MONITOR("EpetraCrsMatrixT::scale"); mtx_->Scale(alpha); }
1636 
1638  //** \warning This is an expert-only routine and should not be called from user code. */
1639  void allocateAllValues(size_t numNonZeros, ArrayRCP<size_t>& rowptr, ArrayRCP<LocalOrdinal>& colind, ArrayRCP<Scalar>& values) {
1640  XPETRA_MONITOR("EpetraCrsMatrixT::allocateAllValues");
1641 
1642  // Row offsets
1643  // Unfortunately, we cannot do this in the same manner as column indices
1644  // and values (see below). The problem is that Tpetra insists on using
1645  // size_t, and Epetra uses int internally. So we only resize here, and
1646  // will need to copy in setAllValues
1647  rowptr.resize(getNodeNumRows()+1);
1648 
1649  int lowerOffset = 0;
1650  bool ownMemory = false;
1651 
1652  // Column indices
1653  // Extract, resize, set colind
1654  Epetra_IntSerialDenseVector& myColind = mtx_->ExpertExtractIndices();
1655  myColind.Resize(numNonZeros);
1656  colind = Teuchos::arcp(myColind.Values(), lowerOffset, numNonZeros, ownMemory);
1657 
1658  // Values
1659  // Extract, reallocate, set values
1660  double *& myValues = mtx_->ExpertExtractValues();
1661  delete [] myValues;
1662  myValues = new double[numNonZeros];
1663  values = Teuchos::arcp(myValues,lowerOffset,numNonZeros,ownMemory);
1664  }
1665 
1667  void setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) {
1668  XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues");
1669 
1670  // Check sizes
1672  "An exception is thrown to let you know that the size of your rowptr array is incorrect.");
1674  "An exception is thrown to let you know that you mismatched your pointers.");
1675 
1676  // Check pointers
1677  if (values.size() > 0) {
1678  TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError,
1679  "An exception is thrown to let you know that you mismatched your pointers.");
1680  TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError,
1681  "An exception is thrown to let you know that you mismatched your pointers.");
1682  }
1683 
1684  // We have to make a copy here, it is unavoidable
1685  // See comments in allocateAllValues
1686  const size_t N = getNodeNumRows();
1687 
1688  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1689  myRowptr.Resize(N+1);
1690  for (size_t i = 0; i < N+1; i++)
1691  myRowptr[i] = Teuchos::as<int>(rowptr[i]);
1692  }
1693 
1694 
1697  XPETRA_MONITOR("EpetraCrsMatrixT::getAllValues");
1698 
1699  int lowerOffset = 0;
1700  bool ownMemory = false;
1701 
1702  const size_t n = getNodeNumRows();
1703  const size_t nnz = getNodeNumEntries();
1704 
1705  // Row offsets
1706  // We have to make a copy here, it is unavoidable (see comments in allocateAllValues)
1707  Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset();
1708  rowptr.resize(n+1);
1709  for (size_t i = 0; i < n+1; i++)
1710  (*const_cast<size_t*>(&rowptr[i])) = Teuchos::as<size_t>(myRowptr[i]);
1711 
1712  // Column indices
1713  colind = Teuchos::arcp(mtx_->ExpertExtractIndices().Values(), lowerOffset, nnz, ownMemory);
1714 
1715  // Values
1716  values = Teuchos::arcp(mtx_->ExpertExtractValues(), lowerOffset, nnz, ownMemory);
1717  }
1718 
1719  // Epetra always has global constants
1720  bool haveGlobalConstants() const { return true;}
1721 
1723  //** \warning This is an expert-only routine and should not be called from user code. */
1725  const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & rangeMap,
1726  const RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > &importer=Teuchos::null,
1727  const RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > &exporter=Teuchos::null,
1728  const RCP<ParameterList> & params=Teuchos::null) {
1729  XPETRA_MONITOR("EpetraCrsMatrixT::expertStaticFillComplete");
1730  int rv=0;
1731  const Epetra_Import * myimport =0;
1732  const Epetra_Export * myexport =0;
1733 
1734  if(!importer.is_null()) {
1735  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *importer, eImporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1736  myimport = eImporter.getEpetra_Import().getRawPtr();
1737  }
1738  if(!exporter.is_null()) {
1739  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, *exporter, eExporter, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete only accepts Xpetra::EpetraImportT.");
1740  myexport = eExporter.getEpetra_Export().getRawPtr();
1741  }
1742 
1743  rv=mtx_->ExpertStaticFillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), myimport, myexport);
1744 
1745  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::expertStaticFillComplete FAILED!");
1746  }
1748 
1750 
1751 
1753  void resumeFill(const RCP< ParameterList > &params=Teuchos::null) {
1754  XPETRA_MONITOR("EpetraCrsMatrixT::resumeFill");
1755 
1756  // According to Tpetra documentation, resumeFill() may be called repeatedly.
1757  isFillResumed_ = true;
1758  }
1759 
1761  void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null) {
1762  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1763 
1764  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1765  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1766 
1767  bool doOptimizeStorage = true;
1768  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1769  mtx_->FillComplete(toEpetra<GlobalOrdinal,Node>(domainMap), toEpetra<GlobalOrdinal,Node>(rangeMap), doOptimizeStorage);
1770  }
1771 
1772 
1774  void fillComplete(const RCP< ParameterList > &params=Teuchos::null) {
1775  XPETRA_MONITOR("EpetraCrsMatrixT::fillComplete");
1776 
1777  // For Epetra matrices, resumeFill() is a fictive operation. There is no need for a fillComplete after some resumeFill() operations.
1778  if (isFillResumed_ == true) { isFillResumed_ = false; return; }
1779 
1780  bool doOptimizeStorage = true;
1781  if (params != null && params->get("Optimize Storage",true) == false) doOptimizeStorage = false;
1782  mtx_->FillComplete(doOptimizeStorage);
1783  }
1784 
1785 
1788  XPETRA_MONITOR("EpetraCrsMatrixT::replaceDomainMapAndImporter");
1789  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, *newImporter, eImporter, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter only accepts Xpetra::EpetraImportT.");
1790 
1791  const RCP<const Epetra_Import> & myImport = eImporter.getEpetra_Import();
1792  int rv=0;
1793  if(myImport==Teuchos::null)
1794  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),0);
1795  else
1796  rv=mtx_->ReplaceDomainMapAndImporter( toEpetra<GlobalOrdinal,Node>(newDomainMap),&*myImport);
1797  TEUCHOS_TEST_FOR_EXCEPTION(rv != 0, std::runtime_error, "Xpetra::EpetraCrsMatrixT::replaceDomainMapAndImporter FAILED!");
1798  }
1799 
1801 
1803 
1804 
1806  const RCP< const Comm< int > > getComm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getComm"); return toXpetra(mtx_->Comm()); }
1807 
1809  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRowMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->RowMap()); }
1810 
1812  const RCP< const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getColMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->ColMap()); }
1813 
1815  RCP< const CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > getCrsGraph() const { XPETRA_MONITOR("EpetraCrsMatrixT::getCrsGraph"); return toXpetra<GlobalOrdinal,Node>(mtx_->Graph()); }
1816 
1818  global_size_t getGlobalNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumRows"); return mtx_->NumGlobalRows64(); }
1819 
1821  global_size_t getGlobalNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumCols"); return mtx_->NumGlobalCols64(); }
1822 
1824  size_t getNodeNumRows() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumRows"); return mtx_->NumMyRows(); }
1825 
1827  size_t getNodeNumCols() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumCols"); return mtx_->NumMyCols(); }
1828 
1830  global_size_t getGlobalNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumEntries"); return mtx_->NumGlobalNonzeros64(); }
1831 
1833  size_t getNodeNumEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumEntries"); return mtx_->NumMyNonzeros(); }
1834 
1836  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const { XPETRA_MONITOR("EpetraCrsMatrixT::getNumEntriesInLocalRow"); return mtx_->NumMyEntries(localRow); }
1837 
1839  global_size_t getGlobalNumDiags() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalNumDiags"); return mtx_->NumGlobalDiagonals64(); }
1840 
1842  size_t getNodeNumDiags() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeNumDiags"); return mtx_->NumMyDiagonals(); }
1843 
1845  size_t getGlobalMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalMaxNumRowEntries"); return mtx_->GlobalMaxNumEntries(); }
1846 
1848  size_t getNodeMaxNumRowEntries() const { XPETRA_MONITOR("EpetraCrsMatrixT::getNodeMaxNumRowEntries"); return mtx_->MaxNumEntries(); }
1849 
1851  bool isLocallyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isLocallyIndexed"); return mtx_->IndicesAreLocal(); }
1852 
1854  bool isGloballyIndexed() const { XPETRA_MONITOR("EpetraCrsMatrixT::isGloballyIndexed"); return mtx_->IndicesAreGlobal(); }
1855 
1857  bool isFillComplete() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillComplete"); if (isFillResumed_) return false; else return mtx_->Filled(); }
1858 
1860  bool isFillActive() const { XPETRA_MONITOR("EpetraCrsMatrixT::isFillActive"); return !isFillComplete(); }
1861 
1863  typename ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const { XPETRA_MONITOR("EpetraCrsMatrixT::getFrobeniusNorm"); return mtx_->NormFrobenius(); }
1864 
1866  bool supportsRowViews() const { XPETRA_MONITOR("EpetraCrsMatrixT::supportsRowViews"); return true; }
1867 
1869  void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1870  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");
1871 
1872  int numEntries = -1;
1873  XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1874  NumEntries = numEntries;
1875  }
1876 
1878  void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView<GlobalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
1879  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowCopy");
1880 
1881  int numEntries = -1;
1882  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowCopy(GlobalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
1883  NumEntries = numEntries;
1884  }
1885 
1887  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
1888  XPETRA_MONITOR("EpetraCrsMatrixT::getGlobalRowView");
1889 
1890  int numEntries;
1891  double * eValues;
1892  GlobalOrdinal * eIndices;
1893 
1894  XPETRA_ERR_CHECK(mtx_->ExtractGlobalRowView(GlobalRow, numEntries, eValues, eIndices));
1895  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1896 
1897  indices = ArrayView<const GlobalOrdinal>(eIndices, numEntries);
1898  values = ArrayView<const double>(eValues, numEntries);
1899  }
1900 
1902  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
1903  XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowView");
1904 
1905  int numEntries;
1906  double * eValues;
1907  int * eIndices;
1908 
1909  XPETRA_ERR_CHECK(mtx_->ExtractMyRowView(LocalRow, numEntries, eValues, eIndices));
1910  if (numEntries == 0) { eValues = NULL; eIndices = NULL; } // Cf. TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ) in Teuchos ArrayView constructor.
1911 
1912  indices = ArrayView<const int>(eIndices, numEntries);
1913  values = ArrayView<const double>(eValues, numEntries);
1914  }
1915 
1917  void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const { XPETRA_MONITOR("EpetraCrsMatrixT::getLocalDiagCopy"); mtx_->ExtractDiagonalCopy(toEpetra<GlobalOrdinal,Node>(diag)); }
1918 
1921  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagOffsets() is not implemented or supported.");
1922  }
1923 
1926  TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.getLocalDiagCopy using offsets is not implemented or supported.");
1927  }
1928 
1930  XPETRA_ERR_CHECK(mtx_->LeftScale(toEpetra<GlobalOrdinal,Node>(x)));
1931  };
1933  XPETRA_ERR_CHECK(mtx_->RightScale(toEpetra<GlobalOrdinal,Node>(x)));
1934  };
1935 
1937 
1939 
1940 
1943  XPETRA_MONITOR("EpetraCrsMatrixT::apply");
1944 
1945  //TEUCHOS_TEST_FOR_EXCEPTION((alpha != 1) || (beta != 0), Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsMatrixT.multiply() only accept alpha==1 and beta==0");
1946 
1947  XPETRA_DYNAMIC_CAST(const EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, X, eX, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1948  XPETRA_DYNAMIC_CAST( EpetraMultiVectorT<GlobalOrdinal XPETRA_COMMA Node>, Y, eY, "Xpetra::EpetraCrsMatrixT->apply() only accept Xpetra::EpetraMultiVectorT as input arguments.");
1949 
1950  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");
1951  bool eTrans = toEpetra(mode);
1952 
1953  // /!\ UseTranspose value
1954  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.");
1955 
1956  RCP<Epetra_MultiVector> epY = eY.getEpetra_MultiVector();
1957 
1958  // helper vector: tmp = A*x
1959  RCP<Epetra_MultiVector> tmp = Teuchos::rcp(new Epetra_MultiVector(*epY));
1960  tmp->PutScalar(0.0);
1961  XPETRA_ERR_CHECK(mtx_->Multiply(eTrans, *eX.getEpetra_MultiVector(), *tmp));
1962 
1963  // calculate alpha * A * x + beta * y
1964  XPETRA_ERR_CHECK(eY.getEpetra_MultiVector()->Update(alpha,*tmp,beta));
1965  }
1966 
1968  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getDomainMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->DomainMap()); }
1969 
1971  const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getRangeMap"); return toXpetra<GlobalOrdinal, Node>(mtx_->RangeMap()); }
1972 
1974 
1976 
1977 
1979  std::string description() const {
1980  XPETRA_MONITOR("EpetraCrsMatrixT::description");
1981 
1982  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
1983  std::ostringstream oss;
1984  //TODO: oss << DistObject<char, LocalOrdinal,GlobalOrdinal>::description();
1985  if (isFillComplete()) {
1986  oss << "{status = fill complete"
1987  << ", global rows = " << getGlobalNumRows()
1988  << ", global cols = " << getGlobalNumCols()
1989  << ", global num entries = " << getGlobalNumEntries()
1990  << "}";
1991  }
1992  else {
1993  oss << "{status = fill not complete"
1994  << ", global rows = " << getGlobalNumRows()
1995  << "}";
1996  }
1997  return oss.str();
1998 
1999  }
2000 
2001 
2004  XPETRA_MONITOR("EpetraCrsMatrixT::describe");
2005 
2006  // This implementation come from Tpetra_CrsMatrix_def.hpp (without modification)
2007  using std::endl;
2008  using std::setw;
2009  using Teuchos::VERB_DEFAULT;
2010  using Teuchos::VERB_NONE;
2011  using Teuchos::VERB_LOW;
2012  using Teuchos::VERB_MEDIUM;
2013  using Teuchos::VERB_HIGH;
2014  using Teuchos::VERB_EXTREME;
2015  Teuchos::EVerbosityLevel vl = verbLevel;
2016  if (vl == VERB_DEFAULT) vl = VERB_LOW;
2017  RCP<const Comm<int> > comm = this->getComm();
2018  const int myImageID = comm->getRank(),
2019  numImages = comm->getSize();
2020  size_t width = 1;
2021  for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
2022  ++width;
2023  }
2024  width = std::max<size_t>(width,11) + 2;
2025  Teuchos::OSTab tab(out);
2026  // none: print nothing
2027  // low: print O(1) info from node 0
2028  // medium: print O(P) info, num entries per node
2029  // high: print O(N) info, num entries per row
2030  // extreme: print O(NNZ) info: print indices and values
2031  //
2032  // for medium and higher, print constituent objects at specified verbLevel
2033  if (vl != VERB_NONE) {
2034  if (myImageID == 0) out << this->description() << std::endl;
2035  // O(1) globals, minus what was already printed by description()
2036  if (isFillComplete() && myImageID == 0) {
2037  out << "Global number of diagonals = " << getGlobalNumDiags() << std::endl;
2038  out << "Global max number of entries = " << getGlobalMaxNumRowEntries() << std::endl;
2039  }
2040  // constituent objects
2041  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2042  if (myImageID == 0) out << "\nRow map: " << std::endl;
2043  getRowMap()->describe(out,vl);
2044  //
2045  if (getColMap() != null) {
2046  if (getColMap() == getRowMap()) {
2047  if (myImageID == 0) out << "\nColumn map is row map.";
2048  }
2049  else {
2050  if (myImageID == 0) out << "\nColumn map: " << std::endl;
2051  getColMap()->describe(out,vl);
2052  }
2053  }
2054  if (getDomainMap() != null) {
2055  if (getDomainMap() == getRowMap()) {
2056  if (myImageID == 0) out << "\nDomain map is row map.";
2057  }
2058  else if (getDomainMap() == getColMap()) {
2059  if (myImageID == 0) out << "\nDomain map is row map.";
2060  }
2061  else {
2062  if (myImageID == 0) out << "\nDomain map: " << std::endl;
2063  getDomainMap()->describe(out,vl);
2064  }
2065  }
2066  if (getRangeMap() != null) {
2067  if (getRangeMap() == getDomainMap()) {
2068  if (myImageID == 0) out << "\nRange map is domain map." << std::endl;
2069  }
2070  else if (getRangeMap() == getRowMap()) {
2071  if (myImageID == 0) out << "\nRange map is row map." << std::endl;
2072  }
2073  else {
2074  if (myImageID == 0) out << "\nRange map: " << std::endl;
2075  getRangeMap()->describe(out,vl);
2076  }
2077  }
2078  if (myImageID == 0) out << std::endl;
2079  }
2080  // O(P) data
2081  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
2082  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2083  if (myImageID == imageCtr) {
2084  out << "Node ID = " << imageCtr << std::endl;
2085  // TODO: need a graph
2086  // if (staticGraph_->indicesAreAllocated() == false) {
2087  // out << "Node not allocated" << std::endl;
2088  // }
2089  // else {
2090  // out << "Node number of allocated entries = " << staticGraph_->getNodeAllocationSize() << std::endl;
2091  // }
2092 
2093  // TMP:
2094  // const Epetra_CrsGraph & staticGraph_ = mtx_->Graph();
2095  // End of TMP
2096 
2097  out << "Node number of entries = " << getNodeNumEntries() << std::endl;
2098  if (isFillComplete()) {
2099  out << "Node number of diagonals = " << getNodeNumDiags() << std::endl;
2100  }
2101  out << "Node max number of entries = " << getNodeMaxNumRowEntries() << std::endl;
2102  }
2103  comm->barrier();
2104  comm->barrier();
2105  comm->barrier();
2106  }
2107  }
2108  // O(N) and O(NNZ) data
2109  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
2110  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
2111  if (myImageID == imageCtr) {
2112  out << std::setw(width) << "Node ID"
2113  << std::setw(width) << "Global Row"
2114  << std::setw(width) << "Num Entries";
2115  if (vl == VERB_EXTREME) {
2116  out << std::setw(width) << "(Index,Value)";
2117  }
2118  out << std::endl;
2119  for (size_t r=0; r < getNodeNumRows(); ++r) {
2120  const size_t nE = getNumEntriesInLocalRow(r);
2121  GlobalOrdinal gid = getRowMap()->getGlobalElement(r);
2122  out << std::setw(width) << myImageID
2123  << std::setw(width) << gid
2124  << std::setw(width) << nE;
2125  if (vl == VERB_EXTREME) {
2126  if (isGloballyIndexed()) {
2128  ArrayView<const Scalar> rowvals;
2129  getGlobalRowView(gid,rowinds,rowvals);
2130  for (size_t j=0; j < nE; ++j) {
2131  out << " (" << rowinds[j]
2132  << ", " << rowvals[j]
2133  << ") ";
2134  }
2135  }
2136  else if (isLocallyIndexed()) {
2138  ArrayView<const Scalar> rowvals;
2139  getLocalRowView(r,rowinds,rowvals);
2140  for (size_t j=0; j < nE; ++j) {
2141  out << " (" << getColMap()->getGlobalElement(rowinds[j])
2142  << ", " << rowvals[j]
2143  << ") ";
2144  }
2145  }
2146  }
2147  out << std::endl;
2148  }
2149  }
2150  comm->barrier();
2151  comm->barrier();
2152  comm->barrier();
2153  }
2154  }
2155  }
2156 
2157  }
2158 
2159 
2161 
2164  : mtx_(Teuchos::rcp(new Epetra_CrsMatrix(*(matrix.mtx_)))), isFillResumed_(false)
2165 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
2166 #ifdef HAVE_XPETRA_TPETRA
2167  , isInitializedLocalMatrix_(false)
2168 #endif
2169 #endif
2170  { }
2171 
2172 
2174  //{@
2175 
2177  Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const { XPETRA_MONITOR("EpetraCrsMatrixT::getMap"); return toXpetra<GlobalOrdinal,Node>(mtx_->Map()); }
2178 
2182  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2183 
2184  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2185  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2186 
2187  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2188  int err = mtx_->Import(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2189  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2190  }
2191 
2195  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2196 
2197  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2198  XPETRA_DYNAMIC_CAST(const EpetraImportT<GlobalOrdinal XPETRA_COMMA Node>, importer, tImporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2199 
2200  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2201  int err = mtx_->Export(*v, *tImporter.getEpetra_Import(), toEpetra(CM));
2202  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2203  }
2204 
2208  XPETRA_MONITOR("EpetraCrsMatrixT::doImport");
2209 
2210  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, source, tSource, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2211  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2212 
2213  RCP<const Epetra_CrsMatrix> v = tSource.getEpetra_CrsMatrix();
2214  int err = mtx_->Import(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2215  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2216 
2217  }
2218 
2222  XPETRA_MONITOR("EpetraCrsMatrixT::doExport");
2223 
2224  XPETRA_DYNAMIC_CAST(const EpetraCrsMatrixT<GlobalOrdinal XPETRA_COMMA Node>, dest, tDest, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraCrsMatrixT as input arguments.");
2225  XPETRA_DYNAMIC_CAST(const EpetraExportT<GlobalOrdinal XPETRA_COMMA Node>, exporter, tExporter, "Xpetra::EpetraCrsMatrixT::doImport only accept Xpetra::EpetraImportT as input arguments.");
2226 
2227  RCP<const Epetra_CrsMatrix> v = tDest.getEpetra_CrsMatrix();
2228  int err = mtx_->Export(*v, *tExporter.getEpetra_Export(), toEpetra(CM));
2229  TEUCHOS_TEST_FOR_EXCEPTION(err != 0, std::runtime_error, "Catch error code returned by Epetra.");
2230  }
2231 
2233 
2235 
2237 
2238 
2240  bool hasMatrix() const { return !mtx_.is_null();}
2241 
2243  EpetraCrsMatrixT(const Teuchos::RCP<Epetra_CrsMatrix > &mtx) : mtx_(mtx), isFillResumed_(false) { }
2244 
2247 
2249  RCP<Epetra_CrsMatrix> getEpetra_CrsMatrixNonConst() const { return mtx_; } //TODO: remove
2250 
2251 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
2252 #ifdef HAVE_XPETRA_TPETRA
2253  local_matrix_type getLocalMatrix () const {
2255  TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete() == false, std::runtime_error,
2256  "Xpetra::EpetraCrsMatrix::getLocalMatrix: matrix must be filled and completed before you can access the data through the Kokkos interface!");
2257  if (isInitializedLocalMatrix_)
2258  return localMatrix_;
2259 
2261 
2262  const int numRows = matrix->NumMyRows();
2263  const int numCols = matrix->NumMyCols();
2264  const int nnz = matrix->NumMyNonzeros();
2265 
2266  int* rowptr;
2267  int* colind;
2268  double* vals;
2269  int rv = matrix->ExtractCrsDataPointers(rowptr, colind, vals);
2270  TEUCHOS_TEST_FOR_EXCEPTION(rv, std::runtime_error, "Xpetra::CrsMatrix<>::getLocalMatrix: failed in ExtractCrsDataPointers");
2271 
2272  // Transform int* rowptr array to size_type* array
2273  typename local_matrix_type::row_map_type::non_const_type kokkosRowPtr("local row map", numRows+1);
2274  for (size_t i = 0; i < kokkosRowPtr.size(); i++)
2275  kokkosRowPtr(i) = Teuchos::asSafe<typename local_matrix_type::row_map_type::value_type>(rowptr[i]);
2276 
2277  // create Kokkos::Views
2278  typename local_matrix_type::index_type kokkosColind(colind, nnz);
2279  typename local_matrix_type::values_type kokkosVals (vals, nnz);
2280 
2281  localMatrix_ = local_matrix_type("LocalMatrix", numRows, numCols, nnz, kokkosVals, kokkosRowPtr, kokkosColind);
2282  isInitializedLocalMatrix_ = true;
2283 
2284  return localMatrix_;
2285  }
2286 #else
2287 #ifdef __GNUC__
2288 #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."
2289 #endif
2290 #endif
2291 #endif
2292 
2293 
2294 private:
2296 
2297  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.
2298 
2299 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
2300 #ifdef HAVE_XPETRA_TPETRA
2301  mutable
2302  local_matrix_type localMatrix_;
2303  mutable
2304  bool isInitializedLocalMatrix_;
2305 #else
2306 #ifdef __GNUC__
2307 #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."
2308 #endif
2309 #endif
2310 #endif
2311 
2312 }; // EpetraCrsMatrixT class
2313 
2314 #endif // #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2315 
2316 } // Xpetra namespace
2317 
2318 #define XPETRA_EPETRACRSMATRIX_SHORT
2319 #endif // XPETRA_EPETRACRSMATRIX_HPP
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
Gets the 1D pointer arrays of the graph.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
std::string description() const
A simple one-line description of this object.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
bool isFillActive() const
Returns true if the matrix is in edit mode.
bool isFillActive() const
Returns true if the matrix is in edit mode.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused import.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=Xpetra::GloballyDistributed, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with Xpetra-defined contiguous uniform distribution.
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix. ...
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
Allocates and returns ArrayRCPs of the Crs arrays — This is an Xpetra-only routine.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and number of entries in each row.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
const RCP< const Comm< int > > getComm() const
Returns the communicator.
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
void resumeFill(const RCP< ParameterList > &params=null)
size_type size() const
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
void resumeFill(const RCP< ParameterList > &params=Teuchos::null)
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
T & get(const std::string &name, T def_value)
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
void fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
#define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg)
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused export.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
bool hasMatrix() const
Does this have an underlying matrix.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
Xpetra namespace
void resumeFill(const RCP< ParameterList > &params=Teuchos::null)
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
Gets the 1D pointer arrays of the graph.
Exception throws to report errors in the internal logical of the program.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
size_type size() const
LocalOrdinal local_ordinal_type
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
void getAllValues(ArrayRCP< const size_t > &rowptr, ArrayRCP< const LocalOrdinal > &colind, ArrayRCP< const Scalar > &values) const
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
bool isFillActive() const
Returns true if the matrix is in edit mode.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replaces the current domainMap and importer with the user-specified objects.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
bool hasMatrix() const
Does this have an underlying matrix.
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
bool is_null() const
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
Get the underlying Epetra matrix.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
void fillComplete(const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using local IDs.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
Get the underlying Epetra matrix.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using global IDs.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
void resize(const size_type n, const T &val=T())
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replaces the current domainMap and importer with the user-specified objects.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying a previously constructed graph.
size_t getNodeNumCols() const
Returns the number of matrix columns owned on the calling node.
void setAllToScalar(const Scalar &alpha)
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying fixed number of entries for each row.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const RCP< const Comm< int > > getComm() const
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
const RCP< const Comm< int > > getComm() const
Returns the communicator.
#define XPETRA_ERR_CHECK(arg)
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &params=Teuchos::null)
Expert static fill complete.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
bool hasMatrix() const
Does this have an underlying matrix.
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix. ...
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &RowImporter, const Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > DomainImporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
EpetraCrsMatrixT(const EpetraCrsMatrixT &matrix)
Deep copy constructor.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
std::string description() const
A simple one-line description of this object.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
void allocateAllValues(size_t numNonZeros, ArrayRCP< size_t > &rowptr, ArrayRCP< LocalOrdinal > &colind, ArrayRCP< Scalar > &values)
Allocates and returns ArrayRCPs of the Crs arrays — This is an Xpetra-only routine.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Exception throws when you call an unimplemented method of Xpetra.
iterator end() const
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
void setAllValues(const ArrayRCP< size_t > &rowptr, const ArrayRCP< LocalOrdinal > &colind, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
size_t global_size_t
Global size_t object.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
static const EVerbosityLevel verbLevel_default
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying (possibly different) number of entries in each row.
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &params=Teuchos::null)
iterator begin() const
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
static magnitudeType magnitude(T a)
void fillComplete(const RCP< ParameterList > &params=null)
Signal that data entry is complete.
#define XPETRA_RCP_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused import.
RCP< Epetra_CrsMatrix > getEpetra_CrsMatrixNonConst() const
Get the underlying Epetra matrix.
void scale(const Scalar &alpha)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying (possibly different) number of entries in each row.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &RowExporter, const Teuchos::RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > DomainExporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
EpetraCrsMatrixT(const Teuchos::RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying a previously constructed graph.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
T * getRawPtr() const
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
RCP< const Epetra_CrsMatrix > getEpetra_CrsMatrix() const
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using global IDs.
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > &params=Teuchos::null)
Expert static fill complete.
EpetraCrsMatrixT(const Teuchos::RCP< Epetra_CrsMatrix > &mtx)
EpetraCrsMatrixT constructor to wrap a Epetra_CrsMatrix object.
ArrayView< T > view(size_type lowerOffset, size_type size) const
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and number of entries in each row.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Copy
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=null)
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and fixed number of entries for each row.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
std::string description() const
A simple one-line description of this object.
CombineMode
Xpetra::Combine Mode enumerable type.
void doExport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
#define XPETRA_MONITOR(funcName)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and fixed number of entries for each row.
T * getRawPtr() const
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
void doImport(const DistObject< char, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
CrsMatrix< double, int, GlobalOrdinal, Node >::local_ordinal_type LocalOrdinal
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete, specifying domain and range maps.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag, const Teuchos::ArrayView< const size_t > &offsets) const
Get a copy of the diagonal entries owned by this node, with local row indices, using row offsets...
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > &params=Teuchos::null)
Signal that data entry is complete, specifying domain and range maps.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
The Map describing the parallel distribution of this object.
EpetraCrsMatrixT(const Teuchos::RCP< const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &sourceMatrix, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Constructor for a fused export.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
EpetraCrsMatrixT(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying fixed number of entries for each row.
CrsMatrix< double, int, GlobalOrdinal, Node >::scalar_type Scalar
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices, const ArrayView< const Scalar > &values)
Replace matrix entries, using local IDs.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)