Tpetra parallel linear algebra  Version of the Day
Tpetra_CrsMatrix_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // ************************************************************************
38 // @HEADER
39 
40 #ifndef TPETRA_CRSMATRIX_DECL_HPP
41 #define TPETRA_CRSMATRIX_DECL_HPP
42 
45 
46 #include "Tpetra_CrsMatrix_fwd.hpp"
47 #include "Tpetra_LocalCrsMatrixOperator.hpp"
48 #include "Tpetra_RowMatrix_decl.hpp"
49 #include "Tpetra_Exceptions.hpp"
50 #include "Tpetra_DistObject.hpp"
51 #include "Tpetra_CrsGraph.hpp"
52 #include "Tpetra_Vector.hpp"
53 #include "Tpetra_Details_PackTraits.hpp" // unused here, could delete
54 #include "KokkosSparse_CrsMatrix.hpp"
55 #include "Teuchos_DataAccess.hpp"
56 
57 #include <memory> // std::shared_ptr
58 
59 namespace Tpetra {
60 
61  // Forward declaration for CrsMatrix::swap() test
62  template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> class crsMatrix_Swap_Tester;
63 
115  template<class CrsMatrixType>
116  Teuchos::RCP<CrsMatrixType>
117  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
118  const Import<typename CrsMatrixType::local_ordinal_type,
119  typename CrsMatrixType::global_ordinal_type,
120  typename CrsMatrixType::node_type>& importer,
121  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
122  typename CrsMatrixType::global_ordinal_type,
123  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
124  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
125  typename CrsMatrixType::global_ordinal_type,
126  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
127  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
128 
182  template<class CrsMatrixType>
183  Teuchos::RCP<CrsMatrixType>
184  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
185  const Import<typename CrsMatrixType::local_ordinal_type,
186  typename CrsMatrixType::global_ordinal_type,
187  typename CrsMatrixType::node_type>& rowImporter,
188  const Import<typename CrsMatrixType::local_ordinal_type,
189  typename CrsMatrixType::global_ordinal_type,
190  typename CrsMatrixType::node_type>& domainImporter,
191  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
192  typename CrsMatrixType::global_ordinal_type,
193  typename CrsMatrixType::node_type> >& domainMap,
194  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
195  typename CrsMatrixType::global_ordinal_type,
196  typename CrsMatrixType::node_type> >& rangeMap,
197  const Teuchos::RCP<Teuchos::ParameterList>& params);
198 
232  template<class CrsMatrixType>
233  Teuchos::RCP<CrsMatrixType>
234  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
235  const Export<typename CrsMatrixType::local_ordinal_type,
236  typename CrsMatrixType::global_ordinal_type,
237  typename CrsMatrixType::node_type>& exporter,
238  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
239  typename CrsMatrixType::global_ordinal_type,
240  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
241  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
242  typename CrsMatrixType::global_ordinal_type,
243  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
244  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
245 
279  template<class CrsMatrixType>
280  Teuchos::RCP<CrsMatrixType>
281  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
282  const Export<typename CrsMatrixType::local_ordinal_type,
283  typename CrsMatrixType::global_ordinal_type,
284  typename CrsMatrixType::node_type>& rowExporter,
285  const Export<typename CrsMatrixType::local_ordinal_type,
286  typename CrsMatrixType::global_ordinal_type,
287  typename CrsMatrixType::node_type>& domainExporter,
288  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
289  typename CrsMatrixType::global_ordinal_type,
290  typename CrsMatrixType::node_type> >& domainMap,
291  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
292  typename CrsMatrixType::global_ordinal_type,
293  typename CrsMatrixType::node_type> >& rangeMap,
294  const Teuchos::RCP<Teuchos::ParameterList>& params);
295 
298  namespace Details {
299  template<class SC, class LO, class GO, class NO>
300  void residual(const Operator<SC,LO,GO,NO> & A,
301  const MultiVector<SC,LO,GO,NO> & X,
302  const MultiVector<SC,LO,GO,NO> & B,
304  }
305 
419  template <class Scalar,
420  class LocalOrdinal,
421  class GlobalOrdinal,
422  class Node>
423  class CrsMatrix :
424  public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
425  public DistObject<char, LocalOrdinal, GlobalOrdinal, Node>
426  {
427  public:
429 
430 
432  using scalar_type = Scalar;
434  using local_ordinal_type = LocalOrdinal;
436  using global_ordinal_type = GlobalOrdinal;
438  using device_type = typename Node::device_type;
440  using execution_space = typename device_type::execution_space;
442  using memory_space = typename device_type::memory_space;
443 
448  using node_type = Node;
449 
452 
455 
458 
461 
477  using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
478 
481 
484  using local_graph_host_type = typename crs_graph_type::local_graph_host_type;
485 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
486  using local_graph_type = local_graph_device_type;
487 #endif // TPETRA_ENABLE_DEPRECATED_CODE
488 
492  KokkosSparse::CrsMatrix<impl_scalar_type,
494  device_type,
495  void,
496  typename local_graph_device_type::size_type>;
497  using local_matrix_host_type =
498  typename local_matrix_device_type::HostMirror;
499 
500 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
501  using local_matrix_type = local_matrix_device_type;
502 #endif // TPETRA_ENABLE_DEPRECATED_CODE
503 
507  scalar_type,
508  device_type>;
509 
511 
513 
515  CrsMatrix (const CrsMatrix<Scalar, LocalOrdinal,
516  GlobalOrdinal, Node>&) = default;
517 
519  CrsMatrix (CrsMatrix<Scalar, LocalOrdinal,
520  GlobalOrdinal, Node>&&) = default;
521 
523  CrsMatrix&
524  operator= (const CrsMatrix<Scalar, LocalOrdinal,
525  GlobalOrdinal, Node>&) = default;
526 
528  CrsMatrix&
529  operator= (CrsMatrix<Scalar, LocalOrdinal,
530  GlobalOrdinal, Node>&&) = default;
531 
547  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
548  const size_t maxNumEntriesPerRow,
549  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
550  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
551 
566  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
567  const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
568  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
569  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
570 
571 
592  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
593  const Teuchos::RCP<const map_type>& colMap,
594  const size_t maxNumEntPerRow,
595  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
596  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
597 
618  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
619  const Teuchos::RCP<const map_type>& colMap,
620  const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
621  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
622  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
623 
624 
654  const Teuchos::RCP<const crs_graph_type>& graph,
655  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
656 
681  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
682  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
683 
712  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
713  const typename local_matrix_device_type::values_type& values,
714  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
715 
742  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
743  const Teuchos::RCP<const map_type>& colMap,
744  const typename local_graph_device_type::row_map_type& rowPointers,
745  const typename local_graph_device_type::entries_type::non_const_type& columnIndices,
746  const typename local_matrix_device_type::values_type& values,
747  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
748 
775  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
776  const Teuchos::RCP<const map_type>& colMap,
777  const Teuchos::ArrayRCP<size_t>& rowPointers,
778  const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
779  const Teuchos::ArrayRCP<Scalar>& values,
780  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
781 
803  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
804  const Teuchos::RCP<const map_type>& colMap,
805  const local_matrix_device_type& lclMatrix,
806  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
807 
838  CrsMatrix (const local_matrix_device_type& lclMatrix,
839  const Teuchos::RCP<const map_type>& rowMap,
840  const Teuchos::RCP<const map_type>& colMap,
841  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
842  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
843  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
844 
849  CrsMatrix (const local_matrix_device_type& lclMatrix,
850  const Teuchos::RCP<const map_type>& rowMap,
851  const Teuchos::RCP<const map_type>& colMap,
852  const Teuchos::RCP<const map_type>& domainMap,
853  const Teuchos::RCP<const map_type>& rangeMap,
854  const Teuchos::RCP<const import_type>& importer,
855  const Teuchos::RCP<const export_type>& exporter,
856  const Teuchos::RCP<Teuchos::ParameterList>& params =
857  Teuchos::null);
858 
860  // This function in 'Copy' mode is only guaranteed to work correctly for matrices
861  // which are fillComplete.
863  const Teuchos::DataAccess copyOrView);
864 
874  virtual ~CrsMatrix () = default;
875 
876  // This friend declaration makes the clone() method work.
877  template <class S2, class LO2, class GO2, class N2>
878  friend class CrsMatrix;
879 
880  // This friend declaration allows for fused residual calculation
881  template <class S2, class LO2, class GO2, class N2>
882  friend void Details::residual(const Operator<S2,LO2,GO2,N2> & A,
883  const MultiVector<S2,LO2,GO2,N2> & X,
884  const MultiVector<S2,LO2,GO2,N2> & B,
886 
887  // This friend declaration allows for batching of apply calls
888  template <class MatrixArray, class MultiVectorArray>
889  friend void batchedApply(const MatrixArray &Matrices,
890  const typename std::remove_pointer<typename MultiVectorArray::value_type>::type & X,
891  MultiVectorArray &Y,
892  typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type alpha,
893  typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type beta,
894  Teuchos::RCP<Teuchos::ParameterList> params);
895 
896  public:
898 
900 
924  //
970  void
971  insertGlobalValues (const GlobalOrdinal globalRow,
972  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
973  const Teuchos::ArrayView<const Scalar>& vals);
974 
989  void
990  insertGlobalValues (const GlobalOrdinal globalRow,
991  const LocalOrdinal numEnt,
992  const Scalar vals[],
993  const GlobalOrdinal inds[]);
994 
1035  void
1036  insertLocalValues (const LocalOrdinal localRow,
1037  const Teuchos::ArrayView<const LocalOrdinal> &cols,
1038  const Teuchos::ArrayView<const Scalar> &vals);
1039 
1054  void
1055  insertLocalValues (const LocalOrdinal localRow,
1056  const LocalOrdinal numEnt,
1057  const Scalar vals[],
1058  const LocalOrdinal cols[]);
1059 
1060  protected:
1071  virtual LocalOrdinal
1073  const crs_graph_type& graph,
1074  const RowInfo& rowInfo,
1075  const GlobalOrdinal inds[],
1076  const impl_scalar_type newVals[],
1077  const LocalOrdinal numElts);
1078 
1079  public:
1118  const global_ordinal_type globalRow,
1119  const Kokkos::View<const global_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1120  const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1121 
1124  LocalOrdinal
1125  replaceGlobalValues (const GlobalOrdinal globalRow,
1126  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1127  const Teuchos::ArrayView<const Scalar>& vals);
1128 
1143  LocalOrdinal
1144  replaceGlobalValues (const GlobalOrdinal globalRow,
1145  const LocalOrdinal numEnt,
1146  const Scalar vals[],
1147  const GlobalOrdinal cols[]);
1148 
1149  protected:
1160  virtual LocalOrdinal
1162  const crs_graph_type& graph,
1163  const RowInfo& rowInfo,
1164  const LocalOrdinal inds[],
1165  const impl_scalar_type newVals[],
1166  const LocalOrdinal numElts);
1167 
1168  public:
1206  const local_ordinal_type localRow,
1207  const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1208  const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1209 
1213  LocalOrdinal
1214  replaceLocalValues (const LocalOrdinal localRow,
1215  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1216  const Teuchos::ArrayView<const Scalar>& vals);
1217 
1235  LocalOrdinal
1236  replaceLocalValues (const LocalOrdinal localRow,
1237  const LocalOrdinal numEnt,
1238  const Scalar inputVals[],
1239  const LocalOrdinal inputCols[]);
1240 
1241  private:
1246  static const bool useAtomicUpdatesByDefault =
1247 #ifdef KOKKOS_ENABLE_SERIAL
1248  ! std::is_same<execution_space, Kokkos::Serial>::value;
1249 #else
1250  true;
1251 #endif // KOKKOS_ENABLE_SERIAL
1252 
1276  protected:
1277  virtual LocalOrdinal
1279  const crs_graph_type& graph,
1280  const RowInfo& rowInfo,
1281  const GlobalOrdinal inds[],
1282  const impl_scalar_type newVals[],
1283  const LocalOrdinal numElts,
1284  const bool atomic = useAtomicUpdatesByDefault);
1285 
1286  public:
1323  LocalOrdinal
1324  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1325  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1326  const Teuchos::ArrayView<const Scalar>& vals,
1327  const bool atomic = useAtomicUpdatesByDefault);
1328 
1351  LocalOrdinal
1352  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1353  const LocalOrdinal numEnt,
1354  const Scalar vals[],
1355  const GlobalOrdinal cols[],
1356  const bool atomic = useAtomicUpdatesByDefault);
1357 
1358  protected:
1371  virtual LocalOrdinal
1373  const crs_graph_type& graph,
1374  const RowInfo& rowInfo,
1375  const LocalOrdinal inds[],
1376  const impl_scalar_type newVals[],
1377  const LocalOrdinal numElts,
1378  const bool atomic = useAtomicUpdatesByDefault);
1379 
1380  public:
1419  const local_ordinal_type localRow,
1420  const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1421  const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals,
1422  const bool atomic = useAtomicUpdatesByDefault);
1423 
1453  LocalOrdinal
1454  sumIntoLocalValues (const LocalOrdinal localRow,
1455  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1456  const Teuchos::ArrayView<const Scalar>& vals,
1457  const bool atomic = useAtomicUpdatesByDefault);
1458 
1480  LocalOrdinal
1481  sumIntoLocalValues (const LocalOrdinal localRow,
1482  const LocalOrdinal numEnt,
1483  const Scalar vals[],
1484  const LocalOrdinal cols[],
1485  const bool atomic = useAtomicUpdatesByDefault);
1486 
1487  private:
1518  LocalOrdinal
1519  transformLocalValues (impl_scalar_type rowVals[],
1520  const crs_graph_type& graph,
1521  const RowInfo& rowInfo,
1522  const LocalOrdinal inds[],
1523  const impl_scalar_type newVals[],
1524  const LocalOrdinal numElts,
1525  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1526  const bool atomic = useAtomicUpdatesByDefault);
1527 
1558  LocalOrdinal
1559  transformGlobalValues (impl_scalar_type rowVals[],
1560  const crs_graph_type& graph,
1561  const RowInfo& rowInfo,
1562  const GlobalOrdinal inds[],
1563  const impl_scalar_type newVals[],
1564  const LocalOrdinal numElts,
1565  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1566  const bool atomic = useAtomicUpdatesByDefault);
1567 
1594  LocalOrdinal
1595  transformLocalValues (const LocalOrdinal lclRow,
1596  const LocalOrdinal numInputEnt,
1597  const impl_scalar_type inputVals[],
1598  const LocalOrdinal inputCols[],
1599  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1600  const bool atomic = useAtomicUpdatesByDefault);
1601 
1628  LocalOrdinal
1629  transformGlobalValues (const GlobalOrdinal gblRow,
1630  const LocalOrdinal numInputEnt,
1631  const impl_scalar_type inputVals[],
1632  const GlobalOrdinal inputCols[],
1633  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1634  const bool atomic = useAtomicUpdatesByDefault);
1635 
1636  public:
1680  template<class LocalIndicesViewType,
1681  class ImplScalarViewType,
1682  class BinaryFunction>
1683  LocalOrdinal
1684  transformLocalValues (const LocalOrdinal lclRow,
1685  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1686  const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1687  BinaryFunction f,
1688  const bool atomic = useAtomicUpdatesByDefault)
1689  {
1690  // We use static_assert here to check the template parameters,
1691  // rather than std::enable_if (e.g., on the return value, to
1692  // enable compilation only if the template parameters match the
1693  // desired attributes). This turns obscure link errors into
1694  // clear compilation errors. It also makes the return value a
1695  // lot easier to see.
1696  static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1697  "First template parameter LocalIndicesViewType must be "
1698  "a Kokkos::View.");
1699  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1700  "Second template parameter ImplScalarViewType must be a "
1701  "Kokkos::View.");
1702  static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1703  "First template parameter LocalIndicesViewType must "
1704  "have rank 1.");
1705  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1706  "Second template parameter ImplScalarViewType must have "
1707  "rank 1.");
1708  static_assert (std::is_same<
1709  typename LocalIndicesViewType::non_const_value_type,
1710  local_ordinal_type>::value,
1711  "First template parameter LocalIndicesViewType must "
1712  "contain values of type local_ordinal_type.");
1713  static_assert (std::is_same<
1714  typename ImplScalarViewType::non_const_value_type,
1715  impl_scalar_type>::value,
1716  "Second template parameter ImplScalarViewType must "
1717  "contain values of type impl_scalar_type.");
1718  typedef LocalOrdinal LO;
1719  const LO numInputEnt = inputInds.extent (0);
1720  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1721  return Teuchos::OrdinalTraits<LO>::invalid ();
1722  }
1723  return this->transformLocalValues (lclRow,
1724  numInputEnt,
1725  inputVals.data (),
1726  inputInds.data (),
1727  f,
1728  atomic);
1729  }
1730 
1772  template<class BinaryFunction, class InputMemorySpace>
1773  LocalOrdinal
1774  transformGlobalValues (const GlobalOrdinal gblRow,
1775  const Kokkos::View<const GlobalOrdinal*,
1776  InputMemorySpace,
1777  Kokkos::MemoryUnmanaged>& inputInds,
1778  const Kokkos::View<const impl_scalar_type*,
1779  InputMemorySpace,
1780  Kokkos::MemoryUnmanaged>& inputVals,
1781  BinaryFunction f,
1782  const bool atomic = useAtomicUpdatesByDefault)
1783  {
1784  typedef LocalOrdinal LO;
1785  const LO numInputEnt = inputInds.extent (0);
1786  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1787  return Teuchos::OrdinalTraits<LO>::invalid ();
1788  }
1789  return this->transformGlobalValues (gblRow,
1790  numInputEnt,
1791  inputVals.data (),
1792  inputInds.data (),
1793  f,
1794  atomic);
1795  }
1796 
1798  void setAllToScalar (const Scalar& alpha);
1799 
1801  void scale (const Scalar& alpha);
1802 
1827  void
1828  setAllValues (const typename local_graph_device_type::row_map_type& ptr,
1829  const typename local_graph_device_type::entries_type::non_const_type& ind,
1830  const typename local_matrix_device_type::values_type& val);
1831 
1856  void
1857  setAllValues (const Teuchos::ArrayRCP<size_t>& ptr,
1858  const Teuchos::ArrayRCP<LocalOrdinal>& ind,
1859  const Teuchos::ArrayRCP<Scalar>& val);
1860 
1861  void
1862  getAllValues (Teuchos::ArrayRCP<const size_t>& rowPointers,
1863  Teuchos::ArrayRCP<const LocalOrdinal>& columnIndices,
1864  Teuchos::ArrayRCP<const Scalar>& values) const;
1865 
1872  void getAllValues(Teuchos::ArrayRCP<Scalar>& values);
1873 
1875 
1877 
1906  void globalAssemble();
1907 
1921  void resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1922 
1980  void
1981  fillComplete (const Teuchos::RCP<const map_type>& domainMap,
1982  const Teuchos::RCP<const map_type>& rangeMap,
1983  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1984 
2011  void
2012  fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2013 
2040  void
2041  expertStaticFillComplete (const Teuchos::RCP<const map_type>& domainMap,
2042  const Teuchos::RCP<const map_type>& rangeMap,
2043  const Teuchos::RCP<const import_type>& importer = Teuchos::null,
2044  const Teuchos::RCP<const export_type>& exporter = Teuchos::null,
2045  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2046 
2064  void
2065  replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
2066 
2148  void
2149  reindexColumns (crs_graph_type* const graph,
2150  const Teuchos::RCP<const map_type>& newColMap,
2151  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
2152  const bool sortEachRow = true);
2153 
2163  void
2164  replaceDomainMap (const Teuchos::RCP<const map_type>& newDomainMap);
2165 
2179  void
2180  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
2181  Teuchos::RCP<const import_type>& newImporter);
2182 
2192  void
2193  replaceRangeMap (const Teuchos::RCP<const map_type>& newRangeMap);
2194 
2208  void
2209  replaceRangeMapAndExporter (const Teuchos::RCP<const map_type>& newRangeMap,
2210  Teuchos::RCP<const export_type>& newExporter);
2211 
2225  virtual void
2226  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
2227 
2229 
2231 
2233  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const override;
2234 
2235 
2237  Teuchos::RCP<const map_type> getRowMap () const override;
2238 
2240  Teuchos::RCP<const map_type> getColMap () const override;
2241 
2243  Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> >
2244  getGraph () const override;
2245 
2247  Teuchos::RCP<const crs_graph_type> getCrsGraph () const;
2248 
2249  private:
2260  const crs_graph_type& getCrsGraphRef () const;
2261 
2262  public:
2272 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2273  local_matrix_type getLocalMatrix () const;
2274 #endif
2276  local_matrix_host_type getLocalMatrixHost () const;
2277 
2283  std::shared_ptr<local_multiply_op_type> getLocalMultiplyOperator () const;
2284 
2304  global_size_t getGlobalNumRows() const override;
2305 
2311  global_size_t getGlobalNumCols() const override;
2312 
2319  size_t getNodeNumRows() const override;
2320 
2324  size_t getNodeNumCols() const override;
2325 
2327  GlobalOrdinal getIndexBase() const override;
2328 
2330  global_size_t getGlobalNumEntries() const override;
2331 
2333  size_t getNodeNumEntries() const override;
2334 
2341  size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const override;
2342 
2349  size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const override;
2350 
2358  size_t getGlobalMaxNumRowEntries () const override;
2359 
2367  size_t getNodeMaxNumRowEntries () const override;
2368 
2370  bool hasColMap () const override;
2371 
2372 
2393  bool isLocallyIndexed() const override;
2394 
2415  bool isGloballyIndexed() const override;
2416 
2439  bool isFillComplete() const override;
2440 
2463  bool isFillActive() const;
2464 
2466 
2472  bool isStorageOptimized () const;
2473 
2475  ProfileType getProfileType () const;
2476 
2478  bool isStaticGraph () const;
2479 
2491  mag_type getFrobeniusNorm () const override;
2492 
2495  virtual bool supportsRowViews () const override;
2496 
2497 protected:
2498  using values_dualv_type =
2499  Kokkos::DualView<impl_scalar_type*, device_type>;
2500  using values_wdv_type =
2501  Details::WrappedDualView<values_dualv_type>;
2502  values_wdv_type valuesUnpacked_wdv;
2503  mutable values_wdv_type valuesPacked_wdv;
2504 
2505  using ordinal_rowptrs_type = typename local_multiply_op_type::ordinal_view_type;
2513  mutable ordinal_rowptrs_type ordinalRowptrs;
2514 
2515 public:
2516 
2517  using row_ptrs_device_view_type =
2518  typename row_matrix_type::row_ptrs_device_view_type;
2519  using row_ptrs_host_view_type =
2520  typename row_matrix_type::row_ptrs_host_view_type;
2521 
2522 
2523  using local_inds_device_view_type =
2524  typename row_matrix_type::local_inds_device_view_type;
2525  using local_inds_host_view_type =
2526  typename row_matrix_type::local_inds_host_view_type;
2527  using nonconst_local_inds_host_view_type =
2528  typename row_matrix_type::nonconst_local_inds_host_view_type;
2529 
2530  using global_inds_device_view_type =
2531  typename row_matrix_type::global_inds_device_view_type;
2532  using global_inds_host_view_type =
2533  typename row_matrix_type::global_inds_host_view_type;
2534  using nonconst_global_inds_host_view_type =
2535  typename row_matrix_type::nonconst_global_inds_host_view_type;
2536 
2537  using values_device_view_type =
2538  typename row_matrix_type::values_device_view_type;
2539  using values_host_view_type =
2540  typename row_matrix_type::values_host_view_type;
2541  using nonconst_values_host_view_type =
2542  typename row_matrix_type::nonconst_values_host_view_type;
2543 
2544 //KDDKDD INROW using values_host_view_type =
2545 //KDDKDD INROW typename values_dualv_type::t_host::const_type;
2546 //KDDKDD INROW using values_device_view_type =
2547 //KDDKDD INROW typename values_dualv_type::t_dev::const_type;
2548 
2549 //KDDKDD INROW using local_inds_host_view_type =
2550 //KDDKDD INROW typename crs_graph_type::local_inds_host_view_type;
2551 //KDDKDD INROW using local_inds_device_view_type =
2552 //KDDKDD INROW typename crs_graph_type::local_inds_device_view_type;
2553 
2554 //KDDKDD INROW using global_inds_host_view_type =
2555 //KDDKDD INROW typename crs_graph_type::global_inds_host_view_type;
2556 //KDDKDD INROW using global_inds_device_view_type =
2557 //KDDKDD INROW typename crs_graph_type::global_inds_device_view_type;
2558 
2559 //KDDKDD INROW using row_ptrs_host_view_type =
2560 //KDDKDD INROW typename crs_graph_type::row_ptrs_host_view_type;
2561 //KDDKDD INROW using row_ptrs_device_view_type =
2562 //KDDKDD INROW typename crs_graph_type::row_ptrs_device_view_type;
2563 
2564 
2613  void
2614  getGlobalRowCopy (GlobalOrdinal GlobalRow,
2615  nonconst_global_inds_host_view_type &Indices,
2616  nonconst_values_host_view_type &Values,
2617  size_t& NumEntries) const override;
2618 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2619  void
2620  getGlobalRowCopy (GlobalOrdinal GlobalRow,
2621  const Teuchos::ArrayView<GlobalOrdinal>& Indices,
2622  const Teuchos::ArrayView<Scalar>& Values,
2623  size_t& NumEntries) const override;
2624 #endif
2640  void
2641  getLocalRowCopy (LocalOrdinal LocalRow,
2642  nonconst_local_inds_host_view_type &Indices,
2643  nonconst_values_host_view_type &Values,
2644  size_t& NumEntries) const override;
2645 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2646  void
2647  getLocalRowCopy (LocalOrdinal localRow,
2648  const Teuchos::ArrayView<LocalOrdinal>& colInds,
2649  const Teuchos::ArrayView<Scalar>& vals,
2650  size_t& NumEntries) const override;
2651 #endif
2664 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2665  void
2666  getGlobalRowView (GlobalOrdinal GlobalRow,
2667  Teuchos::ArrayView<const GlobalOrdinal>& indices,
2668  Teuchos::ArrayView<const Scalar>& values) const override;
2669 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2670  void
2671  getGlobalRowView (GlobalOrdinal GlobalRow,
2672  global_inds_host_view_type &indices,
2673  values_host_view_type &values) const override;
2674 
2687 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2688  void
2689  getLocalRowView (LocalOrdinal LocalRow,
2690  Teuchos::ArrayView<const LocalOrdinal>& indices,
2691  Teuchos::ArrayView<const Scalar>& values) const override;
2692 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2693 
2694  void
2695  getLocalRowView(LocalOrdinal LocalRow,
2696  local_inds_host_view_type &indices,
2697  values_host_view_type &values) const override;
2698 
2699 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2724  LocalOrdinal
2725  getLocalRowViewRaw (const LocalOrdinal lclRow,
2726  LocalOrdinal& numEnt,
2727  const LocalOrdinal*& lclColInds,
2728  const Scalar*& vals) const override;
2729 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2730 
2731 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2755  LocalOrdinal
2756  getLocalRowView (const LocalOrdinal lclRow,
2757  LocalOrdinal& numEnt,
2758  const impl_scalar_type*& val,
2759  const LocalOrdinal*& ind) const;
2760 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2761 
2769 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2770  template<class OutputScalarType>
2771  typename std::enable_if<! std::is_same<OutputScalarType, impl_scalar_type>::value &&
2772  std::is_convertible<impl_scalar_type, OutputScalarType>::value,
2773  LocalOrdinal>::type
2774  getLocalRowView (const LocalOrdinal lclRow,
2775  LocalOrdinal& numEnt,
2776  const OutputScalarType*& val,
2777  const LocalOrdinal*& ind) const
2778  {
2779  const impl_scalar_type* valTmp = NULL;
2780  const LocalOrdinal err = this->getLocalRowView (lclRow, numEnt, valTmp, ind);
2781  // Cast is legitimate because impl_scalar_type is convertible to
2782  // OutputScalarType.
2783  val = reinterpret_cast<const OutputScalarType*> (valTmp);
2784  return err;
2785  }
2786 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2787 
2794  void
2796 
2840  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
2841 
2863  void
2865  const Kokkos::View<const size_t*, device_type,
2866  Kokkos::MemoryUnmanaged>& offsets) const;
2867 
2890  void
2892  const Teuchos::ArrayView<const size_t>& offsets) const;
2893 
2898  void
2900 
2905  void
2907 
2909 
2911 
2973  void
2976  const Teuchos::ETransp mode = Teuchos::NO_TRANS,
2977  const Scalar& alpha = Teuchos::ScalarTraits<Scalar>::one (),
2978  const Scalar& beta = Teuchos::ScalarTraits<Scalar>::zero ()) const;
2979 
2982  template <class T>
2983  Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node> >
2984  convert () const;
2985 
2987 
2989 
3000  void
3003  Teuchos::ETransp mode = Teuchos::NO_TRANS,
3004  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
3005  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const override;
3006 
3009  bool hasTransposeApply () const override;
3010 
3017  Teuchos::RCP<const map_type> getDomainMap () const override;
3018 
3025  Teuchos::RCP<const map_type> getRangeMap () const override;
3026 
3028 
3030 
3041  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3042  add (const Scalar& alpha,
3044  const Scalar& beta,
3045  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
3046  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
3047  const Teuchos::RCP<Teuchos::ParameterList>& params) const override;
3048 
3050 
3052 
3054  std::string description () const override;
3055 
3058  void
3059  describe (Teuchos::FancyOStream& out,
3060  const Teuchos::EVerbosityLevel verbLevel =
3061  Teuchos::Describable::verbLevel_default) const override;
3062 
3064 
3066 
3071  typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
3073 
3074  virtual bool
3075  checkSizes (const SrcDistObject& source) override;
3076 
3077  void
3078  applyCrsPadding(
3079  const typename crs_graph_type::padding_type& padding,
3080  const bool verbose);
3081 
3082  private:
3083  void
3084  copyAndPermuteStaticGraph(
3086  const size_t numSameIDs,
3087  const LocalOrdinal permuteToLIDs[],
3088  const LocalOrdinal permuteFromLIDs[],
3089  const size_t numPermutes);
3090 
3091  void
3092  copyAndPermuteNonStaticGraph(
3094  const size_t numSameIDs,
3095  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs_dv,
3096  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs_dv,
3097  const size_t numPermutes);
3098 
3099  protected:
3100  virtual void
3101  copyAndPermute
3102  (const SrcDistObject& source,
3103  const size_t numSameIDs,
3104  const Kokkos::DualView<
3105  const local_ordinal_type*,
3106  buffer_device_type>& permuteToLIDs,
3107  const Kokkos::DualView<
3108  const local_ordinal_type*,
3109  buffer_device_type>& permuteFromLIDs,
3110  const CombineMode CM) override;
3111 
3112  virtual void
3113  packAndPrepare
3114  (const SrcDistObject& source,
3115  const Kokkos::DualView<
3116  const local_ordinal_type*,
3117  buffer_device_type>& exportLIDs,
3118  Kokkos::DualView<char*, buffer_device_type>& exports,
3119  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3120  size_t& constantNumPackets) override;
3121 
3122  private:
3125  void
3126  unpackAndCombineImpl(
3127  const Kokkos::DualView<const local_ordinal_type*,
3128  buffer_device_type>& importLIDs,
3129  Kokkos::DualView<char*, buffer_device_type> imports,
3130  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3131  const size_t constantNumPackets,
3132  const CombineMode combineMode,
3133  const bool verbose);
3134 
3137  void
3138  unpackAndCombineImplNonStatic(
3139  const Kokkos::DualView<const local_ordinal_type*,
3140  buffer_device_type>& importLIDs,
3141  Kokkos::DualView<char*, buffer_device_type> imports,
3142  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3143  const size_t constantNumPackets,
3144  const CombineMode combineMode);
3145 
3146  public:
3156  void
3158  (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& importLIDs,
3159  Kokkos::DualView<char*, buffer_device_type> imports,
3160  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3161  const size_t constantNumPackets,
3162  const CombineMode CM) override;
3163 
3269  void
3270  packNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3271  Kokkos::DualView<char*, buffer_device_type>& exports,
3272  const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3273  size_t& constantNumPackets) const;
3274 
3275  private:
3282  void
3283  packNonStaticNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3284  Kokkos::DualView<char*, buffer_device_type>& exports,
3285  const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3286  size_t& constantNumPackets) const;
3287 
3317  size_t
3318  packRow (char exports[],
3319  const size_t offset,
3320  const size_t numEnt,
3321  const GlobalOrdinal gidsIn[],
3322  const impl_scalar_type valsIn[],
3323  const size_t numBytesPerValue) const;
3324 
3348  bool
3349  packRowStatic (char* const numEntOut,
3350  char* const valOut,
3351  char* const indOut,
3352  const size_t numEnt,
3353  const LocalOrdinal lclRow) const;
3354 
3380  size_t
3381  unpackRow (GlobalOrdinal gidsOut[],
3382  impl_scalar_type valsOut[],
3383  const char imports[],
3384  const size_t offset,
3385  const size_t numBytes,
3386  const size_t numEnt,
3387  const size_t numBytesPerValue);
3388 
3397  void
3398  allocatePackSpaceNew (Kokkos::DualView<char*, buffer_device_type>& exports,
3399  size_t& totalNumEntries,
3400  const Kokkos::DualView<const local_ordinal_type*,
3401  buffer_device_type>& exportLIDs) const;
3403 
3404  public:
3406  typename local_matrix_device_type::values_type getLocalValuesView () const {
3407 // KDDKDD UVM SHOULD ADD ACCESS TAGS; SAFEST TO ASSUME ReadWrite FOR NOW
3408  return valuesPacked_wdv.getDeviceView(Access::ReadWrite);
3409  }
3410 
3411  private:
3412  // Friend declaration for nonmember function.
3413  template<class CrsMatrixType>
3414  friend Teuchos::RCP<CrsMatrixType>
3415  Tpetra::importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3416  const Import<typename CrsMatrixType::local_ordinal_type,
3417  typename CrsMatrixType::global_ordinal_type,
3418  typename CrsMatrixType::node_type>& importer,
3419  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3420  typename CrsMatrixType::global_ordinal_type,
3421  typename CrsMatrixType::node_type> >& domainMap,
3422  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3423  typename CrsMatrixType::global_ordinal_type,
3424  typename CrsMatrixType::node_type> >& rangeMap,
3425  const Teuchos::RCP<Teuchos::ParameterList>& params);
3426 
3427  // Friend declaration for nonmember function.
3428  template<class CrsMatrixType>
3429  friend Teuchos::RCP<CrsMatrixType>
3430  Tpetra::importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3431  const Import<typename CrsMatrixType::local_ordinal_type,
3432  typename CrsMatrixType::global_ordinal_type,
3433  typename CrsMatrixType::node_type>& rowImporter,
3434  const Import<typename CrsMatrixType::local_ordinal_type,
3435  typename CrsMatrixType::global_ordinal_type,
3436  typename CrsMatrixType::node_type>& domainImporter,
3437  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3438  typename CrsMatrixType::global_ordinal_type,
3439  typename CrsMatrixType::node_type> >& domainMap,
3440  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3441  typename CrsMatrixType::global_ordinal_type,
3442  typename CrsMatrixType::node_type> >& rangeMap,
3443  const Teuchos::RCP<Teuchos::ParameterList>& params);
3444 
3445 
3446  // Friend declaration for nonmember function.
3447  template<class CrsMatrixType>
3448  friend Teuchos::RCP<CrsMatrixType>
3449  Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3450  const Export<typename CrsMatrixType::local_ordinal_type,
3451  typename CrsMatrixType::global_ordinal_type,
3452  typename CrsMatrixType::node_type>& exporter,
3453  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3454  typename CrsMatrixType::global_ordinal_type,
3455  typename CrsMatrixType::node_type> >& domainMap,
3456  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3457  typename CrsMatrixType::global_ordinal_type,
3458  typename CrsMatrixType::node_type> >& rangeMap,
3459  const Teuchos::RCP<Teuchos::ParameterList>& params);
3460 
3461  // Friend declaration for nonmember function.
3462  template<class CrsMatrixType>
3463  friend Teuchos::RCP<CrsMatrixType>
3464  Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3465  const Export<typename CrsMatrixType::local_ordinal_type,
3466  typename CrsMatrixType::global_ordinal_type,
3467  typename CrsMatrixType::node_type>& rowExporter,
3468  const Export<typename CrsMatrixType::local_ordinal_type,
3469  typename CrsMatrixType::global_ordinal_type,
3470  typename CrsMatrixType::node_type>& domainExporter,
3471  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3472  typename CrsMatrixType::global_ordinal_type,
3473  typename CrsMatrixType::node_type> >& domainMap,
3474  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3475  typename CrsMatrixType::global_ordinal_type,
3476  typename CrsMatrixType::node_type> >& rangeMap,
3477  const Teuchos::RCP<Teuchos::ParameterList>& params);
3478 
3479  public:
3495  void
3497  const import_type& importer,
3498  const Teuchos::RCP<const map_type>& domainMap,
3499  const Teuchos::RCP<const map_type>& rangeMap,
3500  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3501 
3517  void
3519  const import_type& rowImporter,
3520  const import_type& domainImporter,
3521  const Teuchos::RCP<const map_type>& domainMap,
3522  const Teuchos::RCP<const map_type>& rangeMap,
3523  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3524 
3525 
3541  void
3543  const export_type& exporter,
3544  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3545  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3546  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3547 
3563  void
3565  const export_type& rowExporter,
3566  const export_type& domainExporter,
3567  const Teuchos::RCP<const map_type>& domainMap,
3568  const Teuchos::RCP<const map_type>& rangeMap,
3569  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3570 
3571 
3572  private:
3593  void
3594  transferAndFillComplete (Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& destMatrix,
3595  const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3596  const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > & domainTransfer,
3597  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3598  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3599  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3600 
3612  protected:
3613  virtual void
3615  RowInfo& rowInfo,
3616  const GlobalOrdinal gblColInds[],
3617  const impl_scalar_type vals[],
3618  const size_t numInputEnt);
3619 
3620  private:
3630  void
3631  insertGlobalValuesFiltered(
3632  const GlobalOrdinal globalRow,
3633  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3634  const Teuchos::ArrayView<const Scalar>& values,
3635  const bool debug);
3636 
3639  void
3640  insertGlobalValuesFilteredChecked(
3641  const GlobalOrdinal globalRow,
3642  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3643  const Teuchos::ArrayView<const Scalar>& values,
3644  const char* const prefix,
3645  const bool debug,
3646  const bool verbose);
3647 
3659  void
3660  combineGlobalValues(
3661  const GlobalOrdinal globalRowIndex,
3662  const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3663  const Teuchos::ArrayView<const Scalar>& values,
3664  const Tpetra::CombineMode combineMode,
3665  const char* const prefix,
3666  const bool debug,
3667  const bool verbose);
3668 
3690  LocalOrdinal
3691  combineGlobalValuesRaw(const LocalOrdinal lclRow,
3692  const LocalOrdinal numEnt,
3693  const impl_scalar_type vals[],
3694  const GlobalOrdinal cols[],
3695  const Tpetra::CombineMode combineMode,
3696  const char* const prefix,
3697  const bool debug,
3698  const bool verbose);
3699 
3711  template<class BinaryFunction>
3712  LocalOrdinal
3713  transformGlobalValues (const GlobalOrdinal globalRow,
3714  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3715  const Teuchos::ArrayView<const Scalar>& values,
3716  BinaryFunction f,
3717  const bool atomic = useAtomicUpdatesByDefault)
3718  {
3719  typedef impl_scalar_type IST;
3720  typedef LocalOrdinal LO;
3721  typedef GlobalOrdinal GO;
3722 
3723  const LO numInputEnt = static_cast<LO> (indices.size ());
3724  if (static_cast<LO> (values.size ()) != numInputEnt) {
3725  return Teuchos::OrdinalTraits<LO>::invalid ();
3726  }
3727 
3728  const GO* const inputCols = indices.getRawPtr ();
3729  const IST* const inputVals =
3730  reinterpret_cast<const IST*> (values.getRawPtr ());
3731  return this->transformGlobalValues (globalRow, numInputEnt, inputVals,
3732  inputCols, f, atomic);
3733  }
3734 
3741  void
3742  insertNonownedGlobalValues (const GlobalOrdinal globalRow,
3743  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3744  const Teuchos::ArrayView<const Scalar>& values);
3745 
3788  void
3789  insertIndicesAndValues (crs_graph_type& graph,
3790  RowInfo& rowInfo,
3791  const typename crs_graph_type::SLocalGlobalViews& newInds,
3792  const Teuchos::ArrayView<impl_scalar_type>& oldRowVals,
3793  const Teuchos::ArrayView<const impl_scalar_type>& newRowVals,
3794  const ELocalGlobal lg,
3795  const ELocalGlobal I);
3796 
3798  typedef DistObject<char, LocalOrdinal, GlobalOrdinal, Node> dist_object_type;
3799 
3800  protected:
3801  // useful typedefs
3802  typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
3803  typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
3804  typedef Kokkos::Details::ArithTraits<mag_type> STM;
3805  typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> MV;
3806  typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
3807  typedef crs_graph_type Graph;
3808 
3809  // Enums
3810  enum GraphAllocationStatus {
3811  GraphAlreadyAllocated,
3812  GraphNotYetAllocated
3813  };
3814 
3815  protected:
3834  void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas,
3835  const bool verbose);
3836 
3847  static size_t
3848  mergeRowIndicesAndValues (size_t rowLen, local_ordinal_type* cols, impl_scalar_type* vals);
3849 
3864  void
3865  sortAndMergeIndicesAndValues (const bool sorted,
3866  const bool merged);
3867 
3875  void clearGlobalConstants();
3876 
3884  public:
3886  void computeGlobalConstants();
3888  bool haveGlobalConstants() const;
3889  protected:
3902  mutable Teuchos::RCP<MV> importMV_;
3903 
3916  mutable Teuchos::RCP<MV> exportMV_;
3917 
3937  Teuchos::RCP<MV>
3938  getColumnMapMultiVector (const MV& X_domainMap,
3939  const bool force = false) const;
3940 
3962  Teuchos::RCP<MV>
3963  getRowMapMultiVector (const MV& Y_rangeMap,
3964  const bool force = false) const;
3965 
3967  void
3968  applyNonTranspose (const MV& X_in,
3969  MV& Y_in,
3970  Scalar alpha,
3971  Scalar beta) const;
3972 
3974  void
3975  applyTranspose (const MV& X_in,
3976  MV& Y_in,
3977  const Teuchos::ETransp mode,
3978  Scalar alpha,
3979  Scalar beta) const;
3980 
3981  // matrix data accessors
3982 
3985  typename values_dualv_type::t_host::const_type
3986  getValuesViewHost (const RowInfo& rowinfo) const;
3987 
3990  typename values_dualv_type::t_dev::const_type
3991  getValuesViewDevice (const RowInfo& rowinfo) const;
3992 
3995  typename values_dualv_type::t_host
3996  getValuesViewHostNonConst (const RowInfo& rowinfo);
3997 
4000  typename values_dualv_type::t_dev
4001  getValuesViewDeviceNonConst (const RowInfo& rowinfo);
4002 
4003 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
4011  Teuchos::ArrayView<const impl_scalar_type> getView (RowInfo rowinfo) const;
4012 #endif
4013 
4014  protected:
4015 
4016  // Friend the tester for CrsMatrix::swap
4017  friend class Tpetra::crsMatrix_Swap_Tester<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
4018 
4023 
4024 
4025  protected:
4026 
4032  void fillLocalMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4033 
4039  void fillLocalGraphAndMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4040 
4042  void checkInternalState () const;
4043 
4055 
4056  Teuchos::RCP<const Graph> staticGraph_;
4057  Teuchos::RCP< Graph> myGraph_;
4059 
4061 // KDDKDD DELETE
4062 // std::shared_ptr<local_multiply_op_type> lclMatrix_;
4063 // KDDKDD DELETE
4064 
4069 // KDDKDD DELETE
4070  typename local_matrix_device_type::values_type k_values1D_;
4071 // KDDKDD DELETE
4072 
4073 protected:
4084  Details::STORAGE_1D_UNPACKED;
4085 
4087  bool fillComplete_ = false;
4088 
4116  std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
4117  Teuchos::Array<Scalar> > > nonlocals_;
4118 
4124  mutable mag_type frobNorm_ = -STM::one();
4125 
4126  public:
4127  // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
4128  // public inner class of CrsMatrix? It looks like it doesn't
4129  // depend on any implementation details of CrsMatrix at all. It
4130  // should really be declared and defined outside of CrsMatrix.
4131  template<class DestViewType, class SrcViewType,
4132  class DestOffsetViewType, class SrcOffsetViewType>
4133  struct pack_functor {
4134  typedef typename DestViewType::execution_space execution_space;
4135  SrcViewType src_;
4136  DestViewType dst_;
4137  SrcOffsetViewType src_offset_;
4138  DestOffsetViewType dst_offset_;
4139  typedef typename DestOffsetViewType::non_const_value_type scalar_index_type;
4140 
4141  pack_functor (DestViewType dst,
4142  const SrcViewType src,
4143  DestOffsetViewType dst_offset,
4144  const SrcOffsetViewType src_offset) :
4145  src_ (src),
4146  dst_ (dst),
4147  src_offset_ (src_offset),
4148  dst_offset_ (dst_offset)
4149  {}
4150 
4151  KOKKOS_INLINE_FUNCTION
4152  void operator () (const LocalOrdinal row) const {
4153  scalar_index_type srcPos = src_offset_(row);
4154  const scalar_index_type dstEnd = dst_offset_(row+1);
4155  scalar_index_type dstPos = dst_offset_(row);
4156  for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
4157  dst_(dstPos) = src_(srcPos);
4158  }
4159  }
4160  };
4161  }; // class CrsMatrix
4162 
4167  template<class Scalar,
4168  class LocalOrdinal,
4169  class GlobalOrdinal,
4170  class Node>
4171  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
4173  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
4174  const size_t maxNumEntriesPerRow = 0,
4175  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4176  {
4177  using matrix_type =
4179  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE;
4180  return Teuchos::rcp(new matrix_type(map, maxNumEntriesPerRow,
4181  pftype, params));
4182  }
4183 
4184  template<class CrsMatrixType>
4185  Teuchos::RCP<CrsMatrixType>
4186  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4187  const Import<typename CrsMatrixType::local_ordinal_type,
4188  typename CrsMatrixType::global_ordinal_type,
4189  typename CrsMatrixType::node_type>& importer,
4190  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4191  typename CrsMatrixType::global_ordinal_type,
4192  typename CrsMatrixType::node_type> >& domainMap,
4193  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4194  typename CrsMatrixType::global_ordinal_type,
4195  typename CrsMatrixType::node_type> >& rangeMap,
4196  const Teuchos::RCP<Teuchos::ParameterList>& params)
4197  {
4198  Teuchos::RCP<CrsMatrixType> destMatrix;
4199  sourceMatrix->importAndFillComplete (destMatrix, importer, domainMap, rangeMap, params);
4200  return destMatrix;
4201  }
4202 
4203  template<class CrsMatrixType>
4204  Teuchos::RCP<CrsMatrixType>
4205  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4206  const Import<typename CrsMatrixType::local_ordinal_type,
4207  typename CrsMatrixType::global_ordinal_type,
4208  typename CrsMatrixType::node_type>& rowImporter,
4209  const Import<typename CrsMatrixType::local_ordinal_type,
4210  typename CrsMatrixType::global_ordinal_type,
4211  typename CrsMatrixType::node_type>& domainImporter,
4212  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4213  typename CrsMatrixType::global_ordinal_type,
4214  typename CrsMatrixType::node_type> >& domainMap,
4215  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4216  typename CrsMatrixType::global_ordinal_type,
4217  typename CrsMatrixType::node_type> >& rangeMap,
4218  const Teuchos::RCP<Teuchos::ParameterList>& params)
4219  {
4220  Teuchos::RCP<CrsMatrixType> destMatrix;
4221  sourceMatrix->importAndFillComplete (destMatrix, rowImporter, domainImporter, domainMap, rangeMap, params);
4222  return destMatrix;
4223  }
4224 
4225  template<class CrsMatrixType>
4226  Teuchos::RCP<CrsMatrixType>
4227  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4228  const Export<typename CrsMatrixType::local_ordinal_type,
4229  typename CrsMatrixType::global_ordinal_type,
4230  typename CrsMatrixType::node_type>& exporter,
4231  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4232  typename CrsMatrixType::global_ordinal_type,
4233  typename CrsMatrixType::node_type> >& domainMap,
4234  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4235  typename CrsMatrixType::global_ordinal_type,
4236  typename CrsMatrixType::node_type> >& rangeMap,
4237  const Teuchos::RCP<Teuchos::ParameterList>& params)
4238  {
4239  Teuchos::RCP<CrsMatrixType> destMatrix;
4240  sourceMatrix->exportAndFillComplete (destMatrix, exporter, domainMap, rangeMap, params);
4241  return destMatrix;
4242  }
4243 
4244  template<class CrsMatrixType>
4245  Teuchos::RCP<CrsMatrixType>
4246  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4247  const Export<typename CrsMatrixType::local_ordinal_type,
4248  typename CrsMatrixType::global_ordinal_type,
4249  typename CrsMatrixType::node_type>& rowExporter,
4250  const Export<typename CrsMatrixType::local_ordinal_type,
4251  typename CrsMatrixType::global_ordinal_type,
4252  typename CrsMatrixType::node_type>& domainExporter,
4253  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4254  typename CrsMatrixType::global_ordinal_type,
4255  typename CrsMatrixType::node_type> >& domainMap,
4256  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4257  typename CrsMatrixType::global_ordinal_type,
4258  typename CrsMatrixType::node_type> >& rangeMap,
4259  const Teuchos::RCP<Teuchos::ParameterList>& params)
4260  {
4261  Teuchos::RCP<CrsMatrixType> destMatrix;
4262  sourceMatrix->exportAndFillComplete (destMatrix, rowExporter, domainExporter, domainMap, rangeMap, params);
4263  return destMatrix;
4264  }
4265 
4266 } // namespace Tpetra
4267 
4275 #endif // TPETRA_CRSMATRIX_DECL_HPP
Forward declaration of Tpetra::CrsMatrix.
Declaration and generic definition of traits class that tells Tpetra::CrsMatrix how to pack and unpac...
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
typename local_graph_device_type::HostMirror local_graph_host_type
The type of the part of the sparse graph on each MPI process.
Kokkos::StaticCrsGraph< local_ordinal_type, Kokkos::LayoutLeft, device_type, void, size_t > local_graph_device_type
The type of the part of the sparse graph on each MPI process.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries.
virtual void insertGlobalValuesImpl(crs_graph_type &graph, RowInfo &rowInfo, const GlobalOrdinal gblColInds[], const impl_scalar_type vals[], const size_t numInputEnt)
Common implementation detail of insertGlobalValues and insertGlobalValuesFiltered.
bool isGloballyIndexed() const override
Whether the matrix is globally indexed on the calling process.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const override
Print this object with the given verbosity level to the given output stream.
size_t getNodeNumRows() const override
The number of matrix rows owned by the calling process.
std::map< GlobalOrdinal, std::pair< Teuchos::Array< GlobalOrdinal >, Teuchos::Array< Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
void localApply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, const Teuchos::ETransp mode=Teuchos::NO_TRANS, const Scalar &alpha=Teuchos::ScalarTraits< Scalar >::one(), const Scalar &beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Compute the local part of a sparse matrix-(Multi)Vector multiply.
CrsMatrix & operator=(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assignment.
ordinal_rowptrs_type ordinalRowptrs
local_ordinal typed version of local matrix's rowptrs. This allows the LocalCrsMatrixOperator to have...
void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< char *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode CM) override
Unpack the imported column indices and values, and combine into matrix.
void replaceRangeMap(const Teuchos::RCP< const map_type > &newRangeMap)
Replace the current range Map with the given objects.
Details::EStorageStatus storageStatus_
Status of the matrix's storage, when not in a fill-complete state.
typename device_type::execution_space execution_space
The Kokkos execution space.
void applyNonTranspose(const MV &X_in, MV &Y_in, Scalar alpha, Scalar beta) const
Special case of apply() for mode == Teuchos::NO_TRANS.
void importAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &destMatrix, const import_type &importer, const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Import from this to the given destination matrix, and make the result fill complete.
CrsGraph< LocalOrdinal, GlobalOrdinal, Node > crs_graph_type
The CrsGraph specialization suitable for this CrsMatrix specialization.
Node node_type
This class' Kokkos Node type.
local_ordinal_type replaceGlobalValues(const global_ordinal_type globalRow, const Kokkos::View< const global_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals)
Replace one or more entries' values, using global indices.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &rowImporter, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &domainImporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
size_t getGlobalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, over all processes in the matrix's communicator.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row,...
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const override
Number of entries in the sparse matrix in the given global row, on the calling (MPI) process.
void scale(const Scalar &alpha)
Scale the matrix's values: this := alpha*this.
GlobalOrdinal global_ordinal_type
The type of each global index in the matrix.
void sortAndMergeIndicesAndValues(const bool sorted, const bool merged)
Sort and merge duplicate local column indices in all rows on the calling process, along with their co...
size_t getNodeNumCols() const override
The number of columns connected to the locally owned rows of this matrix.
void packNew(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< char *, buffer_device_type > &exports, const Kokkos::DualView< size_t *, buffer_device_type > &numPacketsPerLID, size_t &constantNumPackets) const
Pack this object's data for an Import or Export.
Teuchos::RCP< const map_type > getDomainMap() const override
The domain Map of this matrix.
bool hasColMap() const override
Whether the matrix has a well-defined column Map.
Teuchos::RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Return another CrsMatrix with the same entries, but converted to a different Scalar type T.
values_dualv_type::t_dev getValuesViewDeviceNonConst(const RowInfo &rowinfo)
Get a non-const Device view of the locally owned values row myRow, such that rowinfo = getRowInfo(myR...
void expertStaticFillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< const import_type > &importer=Teuchos::null, const Teuchos::RCP< const export_type > &exporter=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Perform a fillComplete on a matrix that already has data.
std::shared_ptr< local_multiply_op_type > getLocalMultiplyOperator() const
The local sparse matrix operator (a wrapper of getLocalMatrixDevice() that supports local matrix-vect...
LocalOrdinal transformLocalValues(const LocalOrdinal lclRow, const typename UnmanagedView< LocalIndicesViewType >::type &inputInds, const typename UnmanagedView< ImplScalarViewType >::type &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault)
Transform CrsMatrix entries in place, using local indices to select the entries in the row to transfo...
local_ordinal_type sumIntoLocalValues(const local_ordinal_type localRow, const Kokkos::View< const local_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals, const bool atomic=useAtomicUpdatesByDefault)
Sum into one or more sparse matrix entries, using local row and column indices.
void computeGlobalConstants()
Compute matrix properties that require collectives.
virtual Teuchos::RCP< RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > add(const Scalar &alpha, const RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, 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 override
Implementation of RowMatrix::add: return alpha*A + beta*this.
CrsMatrix(CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &&)=default
Move constructor.
friend void batchedApply(const MatrixArray &Matrices, const typename std::remove_pointer< typename MultiVectorArray::value_type >::type &X, MultiVectorArray &Y, typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type alpha, typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type beta, Teuchos::RCP< Teuchos::ParameterList > params)
Does multiply matrix apply() calls with a single X vector.
DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
void applyTranspose(const MV &X_in, MV &Y_in, const Teuchos::ETransp mode, Scalar alpha, Scalar beta) const
Special case of apply() for mode != Teuchos::NO_TRANS.
size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override
Number of entries in the sparse matrix in the given local row, on the calling (MPI) process.
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createCrsMatrix(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Create an empty CrsMatrix given a row map and a single integer upper bound on the number of stored en...
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
The communicator over which the matrix is distributed.
bool isFillActive() const
Whether the matrix is not fill complete.
void replaceDomainMapAndImporter(const Teuchos::RCP< const map_type > &newDomainMap, Teuchos::RCP< const import_type > &newImporter)
Replace the current domain Map and Import with the given objects.
LocalOrdinal sumIntoGlobalValues(const GlobalOrdinal globalRow, const Teuchos::ArrayView< const GlobalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals, const bool atomic=useAtomicUpdatesByDefault)
Sum into one or more sparse matrix entries, using global indices.
virtual ~CrsMatrix()=default
Destructor (virtual for memory safety of derived classes).
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const override
Compute a sparse matrix-MultiVector multiply.
mag_type getFrobeniusNorm() const override
Compute and return the Frobenius norm of the matrix.
global_size_t getGlobalNumCols() const override
The number of global columns in the matrix.
Teuchos::RCP< const map_type > getRangeMap() const override
The range Map of this matrix.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply().
void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas, const bool verbose)
Allocate values (and optionally indices) using the Node.
typename Node::device_type device_type
The Kokkos device type.
bool fillComplete_
Whether the matrix is fill complete.
virtual LocalOrdinal sumIntoGlobalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const GlobalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoGlobalValues.
void replaceDomainMap(const Teuchos::RCP< const map_type > &newDomainMap)
Replace the current domain Map with the given objects.
std::string description() const override
A one-line description of this object.
void reindexColumns(crs_graph_type *const graph, const Teuchos::RCP< const map_type > &newColMap, const Teuchos::RCP< const import_type > &newImport=Teuchos::null, const bool sortEachRow=true)
Reindex the column indices in place, and replace the column Map. Optionally, replace the Import objec...
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
KokkosSparse::CrsMatrix< impl_scalar_type, local_ordinal_type, device_type, void, typename local_graph_device_type::size_type > local_matrix_device_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
void replaceRangeMapAndExporter(const Teuchos::RCP< const map_type > &newRangeMap, Teuchos::RCP< const export_type > &newExporter)
Replace the current Range Map and Export with the given objects.
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the matrix's column Map with the given Map.
global_size_t getGlobalNumRows() const override
Number of global elements in the row map of this matrix.
void globalAssemble()
Communicate nonlocal contributions to other processes.
void checkInternalState() const
Check that this object's state is sane; throw if it's not.
bool hasTransposeApply() const override
Whether apply() allows applying the transpose or conjugate transpose.
GlobalOrdinal getIndexBase() const override
The index base for global indices for this matrix.
local_matrix_device_type::values_type getLocalValuesView() const
Get the Kokkos local values.
Scalar scalar_type
The type of each entry in the matrix.
LocalOrdinal local_ordinal_type
The type of each local index in the matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const override
Get a constant, nonpersisting view of a row of this matrix, using local row and column indices,...
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local graph and matrix.
Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization suitable for this CrsMatrix specialization.
local_matrix_device_type getLocalMatrixDevice() const
The local sparse matrix.
void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const override
Get a constant view of a row of this matrix, using local row and column indices.
Teuchos::RCP< const map_type > getColMap() const override
The Map that describes the column distribution in this matrix.
void insertGlobalValues(const GlobalOrdinal globalRow, const Teuchos::ArrayView< const GlobalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using global column indices.
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
void fillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Tell the matrix that you are done changing its structure or values, and that you are ready to do comp...
typename crs_graph_type::local_graph_device_type local_graph_device_type
The part of the sparse matrix's graph on each MPI process.
void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const override
Get a constant, nonpersisting view of a row of this matrix, using global row and column indices.
void setAllValues(const typename local_graph_device_type::row_map_type &ptr, const typename local_graph_device_type::entries_type::non_const_type &ind, const typename local_matrix_device_type::values_type &val)
Set the local matrix using three (compressed sparse row) arrays.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const override
This matrix's graph, as a RowGraph.
void clearGlobalConstants()
Clear matrix properties that require collectives.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap) override
Remove processes owning zero rows from the Maps and their communicator.
size_t getNodeMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, on this process.
virtual LocalOrdinal sumIntoLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoLocalValues.
void swap(CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &matrix)
Swaps the data from *this with the data and maps from crsMatrix.
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
global_size_t getGlobalNumEntries() const override
The global number of entries in this matrix.
virtual LocalOrdinal replaceLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts)
Implementation detail of replaceLocalValues.
mag_type frobNorm_
Cached Frobenius norm of the (global) matrix.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &importer, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
bool isFillComplete() const override
Whether the matrix is fill complete.
LocalOrdinal transformGlobalValues(const GlobalOrdinal gblRow, const Kokkos::View< const GlobalOrdinal *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputInds, const Kokkos::View< const impl_scalar_type *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault)
Transform CrsMatrix entries in place, using global indices to select the entries in the row to transf...
local_matrix_device_type::values_type k_values1D_
The local sparse matrix, wrapped in a multiply operator.
virtual bool checkSizes(const SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
Teuchos::RCP< const map_type > getRowMap() const override
The Map that describes the row distribution in this matrix.
typename device_type::memory_space memory_space
The Kokkos memory space.
ProfileType getProfileType() const
Returns true if the matrix was allocated with static data structures.
local_ordinal_type replaceLocalValues(const local_ordinal_type localRow, const Kokkos::View< const local_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals)
Replace one or more entries' values, using local row and column indices.
size_t getNodeNumEntries() const override
The local number of entries in this matrix.
void exportAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &destMatrix, const export_type &exporter, const Teuchos::RCP< const map_type > &domainMap=Teuchos::null, const Teuchos::RCP< const map_type > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Export from this to the given destination matrix, and make the result fill complete.
values_dualv_type::t_host::const_type getValuesViewHost(const RowInfo &rowinfo) const
Get a const Host view of the locally owned values row myRow, such that rowinfo = getRowInfo(myRow).
CrsMatrix(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy constructor.
bool isLocallyIndexed() const override
Whether the matrix is locally indexed on the calling process.
typename row_matrix_type::impl_scalar_type impl_scalar_type
The type used internally in place of Scalar.
Teuchos::RCP< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
virtual LocalOrdinal replaceGlobalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const GlobalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts)
Implementation detail of replaceGlobalValues.
values_dualv_type::t_host getValuesViewHostNonConst(const RowInfo &rowinfo)
Get a non-const Host view of the locally owned values row myRow, such that rowinfo = getRowInfo(myRow...
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Resume operations that may change the values or structure of the matrix.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
void fillLocalMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local matrix.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the right with the given Vector.
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &rowExporter, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &domainExporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
bool isStorageOptimized() const
Returns true if storage has been optimized.
Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization suitable for this CrsMatrix specialization.
void getLocalRowCopy(LocalOrdinal LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row,...
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &exporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
values_dualv_type::t_dev::const_type getValuesViewDevice(const RowInfo &rowinfo) const
Get a const Device view of the locally owned values row myRow, such that rowinfo = getRowInfo(myRow).
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the left with the given Vector.
virtual bool supportsRowViews() const override
Return true if getLocalRowView() and getGlobalRowView() are valid for this object.
static size_t mergeRowIndicesAndValues(size_t rowLen, local_ordinal_type *cols, impl_scalar_type *vals)
Merge duplicate row indices in the given row, along with their corresponding values.
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix's graph, as a CrsGraph.
void insertLocalValues(const LocalOrdinal localRow, const Teuchos::ArrayView< const LocalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using local column indices.
Keep track of how much more space a CrsGraph or CrsMatrix needs, when the graph or matrix is the targ...
Base class for distributed Tpetra objects that support data redistribution.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Abstract interface for local operators (e.g., matrices and preconditioners).
A parallel distribution of indices over processes.
One or more distributed dense vectors.
Abstract interface for operators (e.g., matrices and preconditioners).
A read-only, row-oriented interface to a sparse matrix.
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Abstract base class for objects that can be the source of an Import or Export operation.
A distributed dense vector.
Implementation details of Tpetra.
EStorageStatus
Status of the graph's or matrix's storage, when not in a fill-complete state.
void residual(const Operator< SC, LO, GO, NO > &A, const MultiVector< SC, LO, GO, NO > &X, const MultiVector< SC, LO, GO, NO > &B, MultiVector< SC, LO, GO, NO > &R)
Computes R = B - A * X.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &exporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
size_t global_size_t
Global size_t object.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &importer, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
CombineMode
Rule for combining data in an Import or Export.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.