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