Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_CrsMatrix_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // clang-format off
11 #ifndef TPETRA_CRSMATRIX_DECL_HPP
12 #define TPETRA_CRSMATRIX_DECL_HPP
13 
16 
17 #include "Tpetra_CrsMatrix_fwd.hpp"
19 #include "KokkosSparse_Utils.hpp"
20 #include "KokkosSparse_CrsMatrix.hpp"
21 #if KOKKOSKERNELS_VERSION >= 40299
22 #include "Tpetra_Details_MatrixApplyHelper.hpp"
23 #else
24 #include "Tpetra_LocalCrsMatrixOperator.hpp"
25 #endif
26 #include "Tpetra_RowMatrix_decl.hpp"
27 #include "Tpetra_Exceptions.hpp"
28 #include "Tpetra_DistObject.hpp"
29 #include "Tpetra_CrsGraph.hpp"
30 #include "Tpetra_Vector.hpp"
31 #include "Tpetra_Details_PackTraits.hpp" // unused here, could delete
32 #include "Tpetra_Details_ExecutionSpacesUser.hpp"
33 #include "Teuchos_DataAccess.hpp"
34 
35 
36 #include <memory> // std::shared_ptr
37 
38 namespace Tpetra {
39 
40  // Forward declaration for CrsMatrix::swap() test
41  template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> class crsMatrix_Swap_Tester;
42 
94  template<class CrsMatrixType>
95  Teuchos::RCP<CrsMatrixType>
96  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
97  const Import<typename CrsMatrixType::local_ordinal_type,
98  typename CrsMatrixType::global_ordinal_type,
99  typename CrsMatrixType::node_type>& importer,
100  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
101  typename CrsMatrixType::global_ordinal_type,
102  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
103  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
104  typename CrsMatrixType::global_ordinal_type,
105  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
106  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
107 
161  template<class CrsMatrixType>
162  Teuchos::RCP<CrsMatrixType>
163  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
164  const Import<typename CrsMatrixType::local_ordinal_type,
165  typename CrsMatrixType::global_ordinal_type,
166  typename CrsMatrixType::node_type>& rowImporter,
167  const Import<typename CrsMatrixType::local_ordinal_type,
168  typename CrsMatrixType::global_ordinal_type,
169  typename CrsMatrixType::node_type>& domainImporter,
170  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
171  typename CrsMatrixType::global_ordinal_type,
172  typename CrsMatrixType::node_type> >& domainMap,
173  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
174  typename CrsMatrixType::global_ordinal_type,
175  typename CrsMatrixType::node_type> >& rangeMap,
176  const Teuchos::RCP<Teuchos::ParameterList>& params);
177 
211  template<class CrsMatrixType>
212  Teuchos::RCP<CrsMatrixType>
213  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
214  const Export<typename CrsMatrixType::local_ordinal_type,
215  typename CrsMatrixType::global_ordinal_type,
216  typename CrsMatrixType::node_type>& exporter,
217  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
218  typename CrsMatrixType::global_ordinal_type,
219  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
220  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
221  typename CrsMatrixType::global_ordinal_type,
222  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
223  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
224 
258  template<class CrsMatrixType>
259  Teuchos::RCP<CrsMatrixType>
260  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
261  const Export<typename CrsMatrixType::local_ordinal_type,
262  typename CrsMatrixType::global_ordinal_type,
263  typename CrsMatrixType::node_type>& rowExporter,
264  const Export<typename CrsMatrixType::local_ordinal_type,
265  typename CrsMatrixType::global_ordinal_type,
266  typename CrsMatrixType::node_type>& domainExporter,
267  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
268  typename CrsMatrixType::global_ordinal_type,
269  typename CrsMatrixType::node_type> >& domainMap,
270  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
271  typename CrsMatrixType::global_ordinal_type,
272  typename CrsMatrixType::node_type> >& rangeMap,
273  const Teuchos::RCP<Teuchos::ParameterList>& params);
274 
277  namespace Details {
278  template<class SC, class LO, class GO, class NO>
279  void residual(const Operator<SC,LO,GO,NO> & A,
280  const MultiVector<SC,LO,GO,NO> & X,
281  const MultiVector<SC,LO,GO,NO> & B,
282  MultiVector<SC,LO,GO,NO> & R);
283  }
284 
398  template <class Scalar,
399  class LocalOrdinal,
400  class GlobalOrdinal,
401  class Node>
402  class CrsMatrix :
403  public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
404  public DistObject<char, LocalOrdinal, GlobalOrdinal, Node>,
405  public Details::Spaces::User
406  {
407  // clang-format on
408 private:
409  using dist_object_type =
410  DistObject<char, LocalOrdinal, GlobalOrdinal,
411  Node>;
412  // clang-format off
414 
415  public:
417 
418 
420  using scalar_type = Scalar;
422  using local_ordinal_type = LocalOrdinal;
424  using global_ordinal_type = GlobalOrdinal;
426  using device_type = typename Node::device_type;
428  using execution_space = typename device_type::execution_space;
430  using memory_space = typename device_type::memory_space;
431 
436  using node_type = Node;
437 
440 
443 
446 
449 
465  using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
466 
469 
472  using local_graph_host_type = typename crs_graph_type::local_graph_host_type;
473 
477  KokkosSparse::CrsMatrix<impl_scalar_type,
479  device_type,
480  void,
481  typename local_graph_device_type::size_type>;
482  using local_matrix_host_type =
483  typename local_matrix_device_type::HostMirror;
484 
485 #if KOKKOSKERNELS_VERSION < 40299
486  using local_multiply_op_type =
489  scalar_type,
491 #endif
492 
493  using row_ptrs_device_view_type =
494  typename row_matrix_type::row_ptrs_device_view_type;
495  using row_ptrs_host_view_type =
496  typename row_matrix_type::row_ptrs_host_view_type;
497 
498 
499  using local_inds_device_view_type =
500  typename row_matrix_type::local_inds_device_view_type;
501  using local_inds_host_view_type =
502  typename row_matrix_type::local_inds_host_view_type;
503  using nonconst_local_inds_host_view_type =
504  typename row_matrix_type::nonconst_local_inds_host_view_type;
505 
506  using global_inds_device_view_type =
507  typename row_matrix_type::global_inds_device_view_type;
508  using global_inds_host_view_type =
509  typename row_matrix_type::global_inds_host_view_type;
510  using nonconst_global_inds_host_view_type =
511  typename row_matrix_type::nonconst_global_inds_host_view_type;
512 
513  using values_device_view_type =
514  typename row_matrix_type::values_device_view_type;
515  using values_host_view_type =
516  typename row_matrix_type::values_host_view_type;
517  using nonconst_values_host_view_type =
518  typename row_matrix_type::nonconst_values_host_view_type;
519 
521 
523 
525  CrsMatrix (const CrsMatrix<Scalar, LocalOrdinal,
526  GlobalOrdinal, Node>&) = default;
527 
529  CrsMatrix (CrsMatrix<Scalar, LocalOrdinal,
530  GlobalOrdinal, Node>&&) = default;
531 
533  CrsMatrix&
534  operator= (const CrsMatrix<Scalar, LocalOrdinal,
535  GlobalOrdinal, Node>&) = default;
536 
538  CrsMatrix&
539  operator= (CrsMatrix<Scalar, LocalOrdinal,
540  GlobalOrdinal, Node>&&) = default;
541 
555  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
556  const size_t maxNumEntriesPerRow,
557  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
558 
571  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
572  const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
573  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
574 
575 
594  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
595  const Teuchos::RCP<const map_type>& colMap,
596  const size_t maxNumEntPerRow,
597  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
598 
617  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
618  const Teuchos::RCP<const map_type>& colMap,
619  const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
620  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
621 
651  const Teuchos::RCP<const crs_graph_type>& graph,
652  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
653 
678  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
679  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
680 
709  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
710  const typename local_matrix_device_type::values_type& values,
711  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
712 
739  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
740  const Teuchos::RCP<const map_type>& colMap,
741  const typename local_graph_device_type::row_map_type& rowPointers,
742  const typename local_graph_device_type::entries_type::non_const_type& columnIndices,
743  const typename local_matrix_device_type::values_type& values,
744  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
745 
772  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
773  const Teuchos::RCP<const map_type>& colMap,
774  const Teuchos::ArrayRCP<size_t>& rowPointers,
775  const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
776  const Teuchos::ArrayRCP<Scalar>& values,
777  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
778 
800  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
801  const Teuchos::RCP<const map_type>& colMap,
802  const local_matrix_device_type& lclMatrix,
803  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
804 
835  CrsMatrix (const local_matrix_device_type& lclMatrix,
836  const Teuchos::RCP<const map_type>& rowMap,
837  const Teuchos::RCP<const map_type>& colMap,
838  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
839  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
840  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
841 
846  CrsMatrix (const local_matrix_device_type& lclMatrix,
847  const Teuchos::RCP<const map_type>& rowMap,
848  const Teuchos::RCP<const map_type>& colMap,
849  const Teuchos::RCP<const map_type>& domainMap,
850  const Teuchos::RCP<const map_type>& rangeMap,
851  const Teuchos::RCP<const import_type>& importer,
852  const Teuchos::RCP<const export_type>& exporter,
853  const Teuchos::RCP<Teuchos::ParameterList>& params =
854  Teuchos::null);
855 
857  // This function in 'Copy' mode is only guaranteed to work correctly for matrices
858  // which are fillComplete.
860  const Teuchos::DataAccess copyOrView);
861 
871  virtual ~CrsMatrix () = default;
872 
873  // This friend declaration makes the clone() method work.
874  template <class S2, class LO2, class GO2, class N2>
875  friend class CrsMatrix;
876 
877  // This friend declaration allows for fused residual calculation
878  template <class S2, class LO2, class GO2, class N2>
879  friend void Details::residual(const Operator<S2,LO2,GO2,N2> & A,
880  const MultiVector<S2,LO2,GO2,N2> & X,
881  const MultiVector<S2,LO2,GO2,N2> & B,
883 
884  // This friend declaration allows for batching of apply calls
885  template <class MatrixArray, class MultiVectorArray>
886  friend void batchedApply(const MatrixArray &Matrices,
887  const typename std::remove_pointer<typename MultiVectorArray::value_type>::type & X,
888  MultiVectorArray &Y,
889  typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type alpha,
890  typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type beta,
891  Teuchos::RCP<Teuchos::ParameterList> params);
892 
893  public:
895 
897 
921  //
963  void
964  insertGlobalValues (const GlobalOrdinal globalRow,
965  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
966  const Teuchos::ArrayView<const Scalar>& vals);
967 
982  void
983  insertGlobalValues (const GlobalOrdinal globalRow,
984  const LocalOrdinal numEnt,
985  const Scalar vals[],
986  const GlobalOrdinal inds[]);
987 
1030  void
1031  insertLocalValues (const LocalOrdinal localRow,
1032  const Teuchos::ArrayView<const LocalOrdinal> &cols,
1033  const Teuchos::ArrayView<const Scalar> &vals,
1034  const CombineMode CM=ADD);
1035 
1055  void
1056  insertLocalValues (const LocalOrdinal localRow,
1057  const LocalOrdinal numEnt,
1058  const Scalar vals[],
1059  const LocalOrdinal cols[],
1060  const CombineMode CM=ADD);
1061 
1062  protected:
1073  virtual LocalOrdinal
1075  const crs_graph_type& graph,
1076  const RowInfo& rowInfo,
1077  const GlobalOrdinal inds[],
1078  const impl_scalar_type newVals[],
1079  const LocalOrdinal numElts);
1080 
1081  public:
1120  const global_ordinal_type globalRow,
1121  const Kokkos::View<const global_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1122  const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1123 
1126  LocalOrdinal
1127  replaceGlobalValues (const GlobalOrdinal globalRow,
1128  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1129  const Teuchos::ArrayView<const Scalar>& vals);
1130 
1145  LocalOrdinal
1146  replaceGlobalValues (const GlobalOrdinal globalRow,
1147  const LocalOrdinal numEnt,
1148  const Scalar vals[],
1149  const GlobalOrdinal cols[]);
1150 
1151  protected:
1162  virtual LocalOrdinal
1164  const crs_graph_type& graph,
1165  const RowInfo& rowInfo,
1166  const LocalOrdinal inds[],
1167  const impl_scalar_type newVals[],
1168  const LocalOrdinal numElts);
1169 
1170  public:
1208  const local_ordinal_type localRow,
1209  const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1210  const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1211 
1215  LocalOrdinal
1216  replaceLocalValues (const LocalOrdinal localRow,
1217  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1218  const Teuchos::ArrayView<const Scalar>& vals);
1219 
1237  LocalOrdinal
1238  replaceLocalValues (const LocalOrdinal localRow,
1239  const LocalOrdinal numEnt,
1240  const Scalar inputVals[],
1241  const LocalOrdinal inputCols[]);
1242 
1243  private:
1248  static const bool useAtomicUpdatesByDefault =
1249 #ifdef KOKKOS_ENABLE_SERIAL
1250  ! std::is_same<execution_space, Kokkos::Serial>::value;
1251 #else
1252  true;
1253 #endif // KOKKOS_ENABLE_SERIAL
1254 
1278  protected:
1279  virtual LocalOrdinal
1281  const crs_graph_type& graph,
1282  const RowInfo& rowInfo,
1283  const GlobalOrdinal inds[],
1284  const impl_scalar_type newVals[],
1285  const LocalOrdinal numElts,
1286  const bool atomic = useAtomicUpdatesByDefault);
1287 
1288  public:
1325  LocalOrdinal
1326  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1327  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1328  const Teuchos::ArrayView<const Scalar>& vals,
1329  const bool atomic = useAtomicUpdatesByDefault);
1330 
1353  LocalOrdinal
1354  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1355  const LocalOrdinal numEnt,
1356  const Scalar vals[],
1357  const GlobalOrdinal cols[],
1358  const bool atomic = useAtomicUpdatesByDefault);
1359 
1360  protected:
1373  virtual LocalOrdinal
1375  const crs_graph_type& graph,
1376  const RowInfo& rowInfo,
1377  const LocalOrdinal inds[],
1378  const impl_scalar_type newVals[],
1379  const LocalOrdinal numElts,
1380  const bool atomic = useAtomicUpdatesByDefault);
1381 
1382  public:
1421  const local_ordinal_type localRow,
1422  const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1423  const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals,
1424  const bool atomic = useAtomicUpdatesByDefault);
1425 
1455  LocalOrdinal
1456  sumIntoLocalValues (const LocalOrdinal localRow,
1457  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1458  const Teuchos::ArrayView<const Scalar>& vals,
1459  const bool atomic = useAtomicUpdatesByDefault);
1460 
1482  LocalOrdinal
1483  sumIntoLocalValues (const LocalOrdinal localRow,
1484  const LocalOrdinal numEnt,
1485  const Scalar vals[],
1486  const LocalOrdinal cols[],
1487  const bool atomic = useAtomicUpdatesByDefault);
1488 
1489  private:
1520  LocalOrdinal
1521  transformLocalValues (impl_scalar_type rowVals[],
1522  const crs_graph_type& graph,
1523  const RowInfo& rowInfo,
1524  const LocalOrdinal inds[],
1525  const impl_scalar_type newVals[],
1526  const LocalOrdinal numElts,
1527  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1528  const bool atomic = useAtomicUpdatesByDefault);
1529 
1560  LocalOrdinal
1561  transformGlobalValues (impl_scalar_type rowVals[],
1562  const crs_graph_type& graph,
1563  const RowInfo& rowInfo,
1564  const GlobalOrdinal inds[],
1565  const impl_scalar_type newVals[],
1566  const LocalOrdinal numElts,
1567  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1568  const bool atomic = useAtomicUpdatesByDefault);
1569 
1596  LocalOrdinal
1597  transformLocalValues (const LocalOrdinal lclRow,
1598  const LocalOrdinal numInputEnt,
1599  const impl_scalar_type inputVals[],
1600  const LocalOrdinal inputCols[],
1601  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1602  const bool atomic = useAtomicUpdatesByDefault);
1603 
1630  LocalOrdinal
1631  transformGlobalValues (const GlobalOrdinal gblRow,
1632  const LocalOrdinal numInputEnt,
1633  const impl_scalar_type inputVals[],
1634  const GlobalOrdinal inputCols[],
1635  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1636  const bool atomic = useAtomicUpdatesByDefault);
1637 
1638  public:
1682  template<class LocalIndicesViewType,
1683  class ImplScalarViewType,
1684  class BinaryFunction>
1685  LocalOrdinal
1686  transformLocalValues (const LocalOrdinal lclRow,
1687  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1688  const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1689  BinaryFunction f,
1690  const bool atomic = useAtomicUpdatesByDefault)
1691  {
1692  // We use static_assert here to check the template parameters,
1693  // rather than std::enable_if (e.g., on the return value, to
1694  // enable compilation only if the template parameters match the
1695  // desired attributes). This turns obscure link errors into
1696  // clear compilation errors. It also makes the return value a
1697  // lot easier to see.
1698  static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1699  "First template parameter LocalIndicesViewType must be "
1700  "a Kokkos::View.");
1701  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1702  "Second template parameter ImplScalarViewType must be a "
1703  "Kokkos::View.");
1704  static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1705  "First template parameter LocalIndicesViewType must "
1706  "have rank 1.");
1707  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1708  "Second template parameter ImplScalarViewType must have "
1709  "rank 1.");
1710  static_assert (std::is_same<
1711  typename LocalIndicesViewType::non_const_value_type,
1712  local_ordinal_type>::value,
1713  "First template parameter LocalIndicesViewType must "
1714  "contain values of type local_ordinal_type.");
1715  static_assert (std::is_same<
1716  typename ImplScalarViewType::non_const_value_type,
1717  impl_scalar_type>::value,
1718  "Second template parameter ImplScalarViewType must "
1719  "contain values of type impl_scalar_type.");
1720  typedef LocalOrdinal LO;
1721  const LO numInputEnt = inputInds.extent (0);
1722  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1723  return Teuchos::OrdinalTraits<LO>::invalid ();
1724  }
1725  return this->transformLocalValues (lclRow,
1726  numInputEnt,
1727  inputVals.data (),
1728  inputInds.data (),
1729  f,
1730  atomic);
1731  }
1732 
1774  template<class BinaryFunction, class InputMemorySpace>
1775  LocalOrdinal
1776  transformGlobalValues (const GlobalOrdinal gblRow,
1777  const Kokkos::View<const GlobalOrdinal*,
1778  InputMemorySpace,
1779  Kokkos::MemoryUnmanaged>& inputInds,
1780  const Kokkos::View<const impl_scalar_type*,
1781  InputMemorySpace,
1782  Kokkos::MemoryUnmanaged>& inputVals,
1783  BinaryFunction f,
1784  const bool atomic = useAtomicUpdatesByDefault)
1785  {
1786  typedef LocalOrdinal LO;
1787  const LO numInputEnt = inputInds.extent (0);
1788  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1789  return Teuchos::OrdinalTraits<LO>::invalid ();
1790  }
1791  return this->transformGlobalValues (gblRow,
1792  numInputEnt,
1793  inputVals.data (),
1794  inputInds.data (),
1795  f,
1796  atomic);
1797  }
1798 
1800  void setAllToScalar (const Scalar& alpha);
1801 
1803  void scale (const Scalar& alpha);
1804 
1829  void
1830  setAllValues (const typename local_graph_device_type::row_map_type& ptr,
1831  const typename local_graph_device_type::entries_type::non_const_type& ind,
1832  const typename local_matrix_device_type::values_type& val);
1833 
1854  void
1855  setAllValues (const local_matrix_device_type& localMatrix);
1856 
1881  void
1882  setAllValues (const Teuchos::ArrayRCP<size_t>& ptr,
1883  const Teuchos::ArrayRCP<LocalOrdinal>& ind,
1884  const Teuchos::ArrayRCP<Scalar>& val);
1885 
1887  row_ptrs_host_view_type getLocalRowPtrsHost () const
1888  { return getCrsGraph()->getLocalRowPtrsHost(); }
1889 
1891  row_ptrs_device_view_type getLocalRowPtrsDevice () const
1892  { return getCrsGraph()->getLocalRowPtrsDevice(); }
1893 
1895  local_inds_host_view_type getLocalIndicesHost () const
1896  { return getCrsGraph()->getLocalIndicesHost(); }
1897 
1899  local_inds_device_view_type getLocalIndicesDevice () const
1900  { return getCrsGraph()->getLocalIndicesDevice(); }
1901 
1903 
1905 
1934  void globalAssemble();
1935 
1949  void resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1950 
2008  void
2009  fillComplete (const Teuchos::RCP<const map_type>& domainMap,
2010  const Teuchos::RCP<const map_type>& rangeMap,
2011  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2012 
2039  void
2040  fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2041 
2068  void
2069  expertStaticFillComplete (const Teuchos::RCP<const map_type>& domainMap,
2070  const Teuchos::RCP<const map_type>& rangeMap,
2071  const Teuchos::RCP<const import_type>& importer = Teuchos::null,
2072  const Teuchos::RCP<const export_type>& exporter = Teuchos::null,
2073  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2074 
2092  void
2093  replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
2094 
2176  void
2177  reindexColumns (crs_graph_type* const graph,
2178  const Teuchos::RCP<const map_type>& newColMap,
2179  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
2180  const bool sortEachRow = true);
2181 
2191  void
2192  replaceDomainMap (const Teuchos::RCP<const map_type>& newDomainMap);
2193 
2207  void
2208  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
2209  Teuchos::RCP<const import_type>& newImporter);
2210 
2220  void
2221  replaceRangeMap (const Teuchos::RCP<const map_type>& newRangeMap);
2222 
2236  void
2237  replaceRangeMapAndExporter (const Teuchos::RCP<const map_type>& newRangeMap,
2238  Teuchos::RCP<const export_type>& newExporter);
2239 
2253  virtual void
2254  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
2255 
2257 
2259 
2261  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const override;
2262 
2263 
2265  Teuchos::RCP<const map_type> getRowMap () const override;
2266 
2268  Teuchos::RCP<const map_type> getColMap () const override;
2269 
2271  Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> >
2272  getGraph () const override;
2273 
2275  Teuchos::RCP<const crs_graph_type> getCrsGraph () const;
2276 
2277  private:
2288  const crs_graph_type& getCrsGraphRef () const;
2289 
2290  public:
2291 #if __armclang_major__ == 22 && __armclang_minor__ == 1
2292  // On Stria, PR 13052 caused a 25% performance regression in the
2293  // CGSolve performance test that is fixed by forcing
2294  // getLocalMatrixDevice to always be inlined. Restrict the fix
2295  // to the specific toolchain where the problem was observed
2296 #define TPETRA_DETAILS_ALWAYS_INLINE __attribute__((always_inline))
2297 #else
2298 #define TPETRA_DETAILS_ALWAYS_INLINE
2299 #endif
2300  TPETRA_DETAILS_ALWAYS_INLINE local_matrix_device_type
2313  getLocalMatrixDevice () const;
2314  local_matrix_host_type getLocalMatrixHost () const;
2315 #undef TPETRA_DETAILS_ALWAYS_INLINE
2316 
2317 #if KOKKOSKERNELS_VERSION < 40299
2318  std::shared_ptr<local_multiply_op_type> getLocalMultiplyOperator () const;
2324 #endif
2325 
2345  global_size_t getGlobalNumRows() const override;
2346 
2352  global_size_t getGlobalNumCols() const override;
2353 
2360  size_t getLocalNumRows() const override;
2361 
2365  size_t getLocalNumCols() const override;
2366 
2368  GlobalOrdinal getIndexBase() const override;
2369 
2371  global_size_t getGlobalNumEntries() const override;
2372 
2374  size_t getLocalNumEntries() const override;
2375 
2382  size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const override;
2383 
2390  size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const override;
2391 
2399  size_t getGlobalMaxNumRowEntries () const override;
2400 
2408  size_t getLocalMaxNumRowEntries () const override;
2409 
2411  virtual LocalOrdinal getBlockSize () const override { return 1; }
2412 
2414  bool hasColMap () const override;
2415 
2416 
2437  bool isLocallyIndexed() const override;
2438 
2459  bool isGloballyIndexed() const override;
2460 
2483  bool isFillComplete() const override;
2484 
2507  bool isFillActive() const;
2508 
2510 
2516  bool isStorageOptimized () const;
2517 
2519  bool isStaticGraph () const;
2520 
2528  mag_type getFrobeniusNorm () const override;
2529 
2532  virtual bool supportsRowViews () const override;
2533 
2534 protected:
2535  using values_dualv_type =
2536  Kokkos::DualView<impl_scalar_type*, device_type>;
2537  using values_wdv_type =
2539  values_wdv_type valuesUnpacked_wdv;
2540  mutable values_wdv_type valuesPacked_wdv;
2541 
2542 #if KOKKOSKERNELS_VERSION < 40299
2543  using ordinal_rowptrs_type = typename local_multiply_op_type::ordinal_view_type;
2551  mutable ordinal_rowptrs_type ordinalRowptrs;
2552 #endif
2553 
2554 public:
2555 
2604  void
2605  getGlobalRowCopy (GlobalOrdinal GlobalRow,
2606  nonconst_global_inds_host_view_type &Indices,
2607  nonconst_values_host_view_type &Values,
2608  size_t& NumEntries) const override;
2624  void
2625  getLocalRowCopy (LocalOrdinal LocalRow,
2626  nonconst_local_inds_host_view_type &Indices,
2627  nonconst_values_host_view_type &Values,
2628  size_t& NumEntries) const override;
2629 
2642 
2643  void
2644  getGlobalRowView (GlobalOrdinal GlobalRow,
2645  global_inds_host_view_type &indices,
2646  values_host_view_type &values) const override;
2647 
2660  void
2661  getLocalRowView(LocalOrdinal LocalRow,
2662  local_inds_host_view_type &indices,
2663  values_host_view_type &values) const override;
2664 
2672 
2679  void
2681 
2725  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
2726 
2748  void
2750  const Kokkos::View<const size_t*, device_type,
2751  Kokkos::MemoryUnmanaged>& offsets) const;
2752 
2775  void
2777  const Teuchos::ArrayView<const size_t>& offsets) const;
2778 
2783  void
2785 
2790  void
2792 
2794 
2796 
2858  void
2861  const Teuchos::ETransp mode = Teuchos::NO_TRANS,
2862  const Scalar& alpha = Teuchos::ScalarTraits<Scalar>::one (),
2863  const Scalar& beta = Teuchos::ScalarTraits<Scalar>::zero ()) const;
2864 
2867  template <class T>
2868  Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node> >
2869  convert () const;
2870 
2872 
2874 
2885  void
2888  Teuchos::ETransp mode = Teuchos::NO_TRANS,
2889  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
2890  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const override;
2891 
2894  bool hasTransposeApply () const override;
2895 
2902  Teuchos::RCP<const map_type> getDomainMap () const override;
2903 
2910  Teuchos::RCP<const map_type> getRangeMap () const override;
2911 
2913 
2915 
2926  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
2927  add (const Scalar& alpha,
2929  const Scalar& beta,
2930  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
2931  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
2932  const Teuchos::RCP<Teuchos::ParameterList>& params) const override;
2933 
2935 
2937 
2939  std::string description () const override;
2940 
2943  void
2944  describe (Teuchos::FancyOStream& out,
2945  const Teuchos::EVerbosityLevel verbLevel =
2946  Teuchos::Describable::verbLevel_default) const override;
2947 
2949 
2951 
2956  typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
2958 
2959  virtual bool
2960  checkSizes (const SrcDistObject& source) override;
2961 
2962  void
2963  applyCrsPadding(
2964  const typename crs_graph_type::padding_type& padding,
2965  const bool verbose);
2966 
2967  private:
2968  void
2969  copyAndPermuteStaticGraph(
2971  const size_t numSameIDs,
2972  const LocalOrdinal permuteToLIDs[],
2973  const LocalOrdinal permuteFromLIDs[],
2974  const size_t numPermutes);
2975 
2976  void
2977  copyAndPermuteNonStaticGraph(
2979  const size_t numSameIDs,
2980  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs_dv,
2981  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs_dv,
2982  const size_t numPermutes);
2983 
2984  protected:
2985 
2986  // clang-format on
2987  using dist_object_type::
2989  // clang-format off
2991 
2992  virtual void
2994  (const SrcDistObject& source,
2995  const size_t numSameIDs,
2996  const Kokkos::DualView<
2997  const local_ordinal_type*,
2998  buffer_device_type>& permuteToLIDs,
2999  const Kokkos::DualView<
3000  const local_ordinal_type*,
3001  buffer_device_type>& permuteFromLIDs,
3002  const CombineMode CM) override;
3003 
3004  virtual void
3005  packAndPrepare
3006  (const SrcDistObject& source,
3007  const Kokkos::DualView<
3008  const local_ordinal_type*,
3009  buffer_device_type>& exportLIDs,
3010  Kokkos::DualView<char*, buffer_device_type>& exports,
3011  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3012  size_t& constantNumPackets) override;
3013 
3014  // clang-format on
3016  // clang-format off
3020 
3021  private:
3024  void
3025  unpackAndCombineImpl(
3026  const Kokkos::DualView<const local_ordinal_type*,
3027  buffer_device_type>& importLIDs,
3028  Kokkos::DualView<char*, buffer_device_type> imports,
3029  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3030  const size_t constantNumPackets,
3031  const CombineMode combineMode,
3032  const bool verbose);
3033 
3036  void
3037  unpackAndCombineImplNonStatic(
3038  const Kokkos::DualView<const local_ordinal_type*,
3039  buffer_device_type>& importLIDs,
3040  Kokkos::DualView<char*, buffer_device_type> imports,
3041  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3042  const size_t constantNumPackets,
3043  const CombineMode combineMode);
3044 
3045  public:
3055  void
3057  (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& importLIDs,
3058  Kokkos::DualView<char*, buffer_device_type> imports,
3059  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3060  const size_t constantNumPackets,
3061  const CombineMode CM) override;
3062 
3063  // clang-format on
3065  // clang-format off
3069 
3175  void
3176  packNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3177  Kokkos::DualView<char*, buffer_device_type>& exports,
3178  const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3179  size_t& constantNumPackets) const;
3180 
3181  private:
3188  void
3189  packNonStaticNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3190  Kokkos::DualView<char*, buffer_device_type>& exports,
3191  const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3192  size_t& constantNumPackets) const;
3193 
3223  size_t
3224  packRow (char exports[],
3225  const size_t offset,
3226  const size_t numEnt,
3227  const GlobalOrdinal gidsIn[],
3228  const impl_scalar_type valsIn[],
3229  const size_t numBytesPerValue) const;
3230 
3254  bool
3255  packRowStatic (char* const numEntOut,
3256  char* const valOut,
3257  char* const indOut,
3258  const size_t numEnt,
3259  const LocalOrdinal lclRow) const;
3260 
3286  size_t
3287  unpackRow (GlobalOrdinal gidsOut[],
3288  impl_scalar_type valsOut[],
3289  const char imports[],
3290  const size_t offset,
3291  const size_t numBytes,
3292  const size_t numEnt,
3293  const size_t numBytesPerValue);
3294 
3303  void
3304  allocatePackSpaceNew (Kokkos::DualView<char*, buffer_device_type>& exports,
3305  size_t& totalNumEntries,
3306  const Kokkos::DualView<const local_ordinal_type*,
3307  buffer_device_type>& exportLIDs) const;
3309 
3310  public:
3312  typename local_matrix_host_type::values_type::const_type
3313  getLocalValuesHost (Access::ReadOnlyStruct s) const
3314  {
3315  return valuesPacked_wdv.getHostView(s);
3316  }
3317 
3319  typename local_matrix_host_type::values_type
3320  getLocalValuesHost (Access::ReadWriteStruct s)
3321  {
3322  return valuesPacked_wdv.getHostView(s);
3323  }
3324 
3326  typename local_matrix_host_type::values_type
3327  getLocalValuesHost (Access::OverwriteAllStruct s)
3328  {
3329  return valuesPacked_wdv.getHostView(s);
3330  }
3331 
3333  typename local_matrix_device_type::values_type::const_type
3334  getLocalValuesDevice (Access::ReadOnlyStruct s) const
3335  {
3336  return valuesPacked_wdv.getDeviceView(s);
3337  }
3338 
3340  typename local_matrix_device_type::values_type
3341  getLocalValuesDevice (Access::ReadWriteStruct s)
3342  {
3343  return valuesPacked_wdv.getDeviceView(s);
3344  }
3345 
3347  typename local_matrix_device_type::values_type
3348  getLocalValuesDevice (Access::OverwriteAllStruct s)
3349  {
3350  return valuesPacked_wdv.getDeviceView(s);
3351  }
3352 
3353  private:
3354  // Friend declaration for nonmember function.
3355  template<class CrsMatrixType>
3356  friend Teuchos::RCP<CrsMatrixType>
3357  Tpetra::importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3358  const Import<typename CrsMatrixType::local_ordinal_type,
3359  typename CrsMatrixType::global_ordinal_type,
3360  typename CrsMatrixType::node_type>& importer,
3361  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3362  typename CrsMatrixType::global_ordinal_type,
3363  typename CrsMatrixType::node_type> >& domainMap,
3364  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3365  typename CrsMatrixType::global_ordinal_type,
3366  typename CrsMatrixType::node_type> >& rangeMap,
3367  const Teuchos::RCP<Teuchos::ParameterList>& params);
3368 
3369  // Friend declaration for nonmember function.
3370  template<class CrsMatrixType>
3371  friend Teuchos::RCP<CrsMatrixType>
3372  Tpetra::importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3373  const Import<typename CrsMatrixType::local_ordinal_type,
3374  typename CrsMatrixType::global_ordinal_type,
3375  typename CrsMatrixType::node_type>& rowImporter,
3376  const Import<typename CrsMatrixType::local_ordinal_type,
3377  typename CrsMatrixType::global_ordinal_type,
3378  typename CrsMatrixType::node_type>& domainImporter,
3379  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3380  typename CrsMatrixType::global_ordinal_type,
3381  typename CrsMatrixType::node_type> >& domainMap,
3382  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3383  typename CrsMatrixType::global_ordinal_type,
3384  typename CrsMatrixType::node_type> >& rangeMap,
3385  const Teuchos::RCP<Teuchos::ParameterList>& params);
3386 
3387 
3388  // Friend declaration for nonmember function.
3389  template<class CrsMatrixType>
3390  friend Teuchos::RCP<CrsMatrixType>
3391  Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3392  const Export<typename CrsMatrixType::local_ordinal_type,
3393  typename CrsMatrixType::global_ordinal_type,
3394  typename CrsMatrixType::node_type>& exporter,
3395  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3396  typename CrsMatrixType::global_ordinal_type,
3397  typename CrsMatrixType::node_type> >& domainMap,
3398  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3399  typename CrsMatrixType::global_ordinal_type,
3400  typename CrsMatrixType::node_type> >& rangeMap,
3401  const Teuchos::RCP<Teuchos::ParameterList>& params);
3402 
3403  // Friend declaration for nonmember function.
3404  template<class CrsMatrixType>
3405  friend Teuchos::RCP<CrsMatrixType>
3406  Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3407  const Export<typename CrsMatrixType::local_ordinal_type,
3408  typename CrsMatrixType::global_ordinal_type,
3409  typename CrsMatrixType::node_type>& rowExporter,
3410  const Export<typename CrsMatrixType::local_ordinal_type,
3411  typename CrsMatrixType::global_ordinal_type,
3412  typename CrsMatrixType::node_type>& domainExporter,
3413  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3414  typename CrsMatrixType::global_ordinal_type,
3415  typename CrsMatrixType::node_type> >& domainMap,
3416  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3417  typename CrsMatrixType::global_ordinal_type,
3418  typename CrsMatrixType::node_type> >& rangeMap,
3419  const Teuchos::RCP<Teuchos::ParameterList>& params);
3420 
3421  public:
3437  void
3439  const import_type& importer,
3440  const Teuchos::RCP<const map_type>& domainMap,
3441  const Teuchos::RCP<const map_type>& rangeMap,
3442  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3443 
3459  void
3461  const import_type& rowImporter,
3462  const import_type& domainImporter,
3463  const Teuchos::RCP<const map_type>& domainMap,
3464  const Teuchos::RCP<const map_type>& rangeMap,
3465  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3466 
3467 
3483  void
3485  const export_type& exporter,
3486  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3487  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3488  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3489 
3505  void
3507  const export_type& rowExporter,
3508  const export_type& domainExporter,
3509  const Teuchos::RCP<const map_type>& domainMap,
3510  const Teuchos::RCP<const map_type>& rangeMap,
3511  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3512 
3513 
3514  private:
3535  void
3536  transferAndFillComplete (Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& destMatrix,
3537  const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3538  const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > & domainTransfer,
3539  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3540  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3541  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3542 
3554  protected:
3555  virtual void
3557  RowInfo& rowInfo,
3558  const GlobalOrdinal gblColInds[],
3559  const impl_scalar_type vals[],
3560  const size_t numInputEnt);
3561 
3562  private:
3572  void
3573  insertGlobalValuesFiltered(
3574  const GlobalOrdinal globalRow,
3575  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3576  const Teuchos::ArrayView<const Scalar>& values,
3577  const bool debug);
3578 
3581  void
3582  insertGlobalValuesFilteredChecked(
3583  const GlobalOrdinal globalRow,
3584  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3585  const Teuchos::ArrayView<const Scalar>& values,
3586  const char* const prefix,
3587  const bool debug,
3588  const bool verbose);
3589 
3601  void
3602  combineGlobalValues(
3603  const GlobalOrdinal globalRowIndex,
3604  const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3605  const Teuchos::ArrayView<const Scalar>& values,
3606  const Tpetra::CombineMode combineMode,
3607  const char* const prefix,
3608  const bool debug,
3609  const bool verbose);
3610 
3632  LocalOrdinal
3633  combineGlobalValuesRaw(const LocalOrdinal lclRow,
3634  const LocalOrdinal numEnt,
3635  const impl_scalar_type vals[],
3636  const GlobalOrdinal cols[],
3637  const Tpetra::CombineMode combineMode,
3638  const char* const prefix,
3639  const bool debug,
3640  const bool verbose);
3641 
3653  template<class BinaryFunction>
3654  LocalOrdinal
3655  transformGlobalValues (const GlobalOrdinal globalRow,
3656  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3657  const Teuchos::ArrayView<const Scalar>& values,
3658  BinaryFunction f,
3659  const bool atomic = useAtomicUpdatesByDefault)
3660  {
3661  typedef impl_scalar_type IST;
3662  typedef LocalOrdinal LO;
3663  typedef GlobalOrdinal GO;
3664 
3665  const LO numInputEnt = static_cast<LO> (indices.size ());
3666  if (static_cast<LO> (values.size ()) != numInputEnt) {
3667  return Teuchos::OrdinalTraits<LO>::invalid ();
3668  }
3669 
3670  const GO* const inputCols = indices.getRawPtr ();
3671  const IST* const inputVals =
3672  reinterpret_cast<const IST*> (values.getRawPtr ());
3673  return this->transformGlobalValues (globalRow, numInputEnt, inputVals,
3674  inputCols, f, atomic);
3675  }
3676 
3683  void
3684  insertNonownedGlobalValues (const GlobalOrdinal globalRow,
3685  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3686  const Teuchos::ArrayView<const Scalar>& values);
3687 
3730  void
3731  insertIndicesAndValues (crs_graph_type& graph,
3732  RowInfo& rowInfo,
3733  const typename crs_graph_type::SLocalGlobalViews& newInds,
3734  const Teuchos::ArrayView<impl_scalar_type>& oldRowVals,
3735  const Teuchos::ArrayView<const impl_scalar_type>& newRowVals,
3736  const ELocalGlobal lg,
3737  const ELocalGlobal I);
3738 
3739  protected:
3740  // useful typedefs
3741  typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
3742  typedef Kokkos::ArithTraits<impl_scalar_type> STS;
3743  typedef Kokkos::ArithTraits<mag_type> STM;
3744  typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> MV;
3745  typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
3746  typedef crs_graph_type Graph;
3747 
3748  // Enums
3749  enum GraphAllocationStatus {
3750  GraphAlreadyAllocated,
3751  GraphNotYetAllocated
3752  };
3753 
3754  protected:
3773  void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas,
3774  const bool verbose);
3775 
3786  static size_t
3787  mergeRowIndicesAndValues (size_t rowLen, local_ordinal_type* cols, impl_scalar_type* vals);
3788 
3803  void
3804  sortAndMergeIndicesAndValues (const bool sorted,
3805  const bool merged);
3806 
3807  public:
3808 
3810  bool haveGlobalConstants() const;
3811 
3812  protected:
3825  mutable Teuchos::RCP<MV> importMV_;
3826 
3839  mutable Teuchos::RCP<MV> exportMV_;
3840 
3860  Teuchos::RCP<MV>
3861  getColumnMapMultiVector (const MV& X_domainMap,
3862  const bool force = false) const;
3863 
3885  Teuchos::RCP<MV>
3886  getRowMapMultiVector (const MV& Y_rangeMap,
3887  const bool force = false) const;
3888 
3890  void
3891  applyNonTranspose (const MV& X_in,
3892  MV& Y_in,
3893  Scalar alpha,
3894  Scalar beta) const;
3895 
3897  void
3898  applyTranspose (const MV& X_in,
3899  MV& Y_in,
3900  const Teuchos::ETransp mode,
3901  Scalar alpha,
3902  Scalar beta) const;
3903 
3904  // matrix data accessors
3905 
3908  typename values_dualv_type::t_host::const_type
3909  getValuesViewHost (const RowInfo& rowinfo) const;
3910 
3913  typename values_dualv_type::t_dev::const_type
3914  getValuesViewDevice (const RowInfo& rowinfo) const;
3915 
3918  typename values_dualv_type::t_host
3919  getValuesViewHostNonConst (const RowInfo& rowinfo);
3920 
3923  typename values_dualv_type::t_dev
3924  getValuesViewDeviceNonConst (const RowInfo& rowinfo);
3925 
3926 #if KOKKOSKERNELS_VERSION >= 40299
3927 private:
3928  // TODO: When KokkosKernels 4.4 is released, local_matrix_device_type can be permanently modified to use the default_size_type
3929  // of KK. This is always a type that is enabled by KK's ETI (preferring int if both or neither int and size_t are enabled).
3930  //
3931  // At that point the ApplyHelper can be replaced with just a SPMVHandle.
3932  using local_matrix_int_rowptrs_device_type =
3933  KokkosSparse::CrsMatrix<impl_scalar_type,
3935  device_type,
3936  void,
3937  int>;
3938 
3940  using ApplyHelper = Details::MatrixApplyHelper<
3942  local_matrix_int_rowptrs_device_type,
3944 
3945 
3946  std::shared_ptr<ApplyHelper> getApplyHelper() const {
3947  if (!applyHelper) {
3948  auto A_lcl = getLocalMatrixDevice();
3949  applyHelper = std::make_shared<ApplyHelper>(A_lcl.nnz(), A_lcl.graph.row_map);
3950  }
3951  return applyHelper;
3952  }
3953 #endif
3954 
3955  protected:
3956 
3957  // Friend the tester for CrsMatrix::swap
3958  friend class Tpetra::crsMatrix_Swap_Tester<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
3959 
3960  // Friend the matrix multiply kernels so they can access internally-cached integer
3961  // row pointers without making them part of the CrsMatrix interface
3962  template<typename S, typename LO, typename GO, typename NODE, typename LOV> friend struct Tpetra::MMdetails::KernelWrappers;
3963  template<typename S, typename LO, typename GO, typename NODE, typename LOV> friend struct Tpetra::MMdetails::KernelWrappers2;
3964 
3965 
3966  // friend Matrix Matrix utility function that needs to access integer-typed rowptrs
3967  friend
3968  void Tpetra::MMdetails::import_and_extract_views<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
3969  const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
3970  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > targetMap,
3971  CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
3972  Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > prototypeImporter,
3973  bool userAssertsThereAreNoRemotes,
3974  const std::string& label,
3975  const Teuchos::RCP<Teuchos::ParameterList>& params);
3976 
3980  void swap(CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> & matrix);
3981 
3982 
3983  protected:
3984 
3990  void fillLocalMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
3991 
3997  void fillLocalGraphAndMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
3998 
4000  void checkInternalState () const;
4001 
4013 
4014  Teuchos::RCP<const Graph> staticGraph_;
4015  Teuchos::RCP< Graph> myGraph_;
4017 
4018 protected:
4029  Details::STORAGE_1D_UNPACKED;
4030 
4032  bool fillComplete_ = false;
4033 
4061  std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
4062  Teuchos::Array<Scalar> > > nonlocals_;
4063 
4064  private:
4065 #if KOKKOSKERNELS_VERSION >= 40299
4066  mutable std::shared_ptr<ApplyHelper> applyHelper;
4072 #endif
4073 
4074  public:
4075  // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
4076  // public inner class of CrsMatrix? It looks like it doesn't
4077  // depend on any implementation details of CrsMatrix at all. It
4078  // should really be declared and defined outside of CrsMatrix.
4079  template<class DestViewType, class SrcViewType,
4080  class DestOffsetViewType, class SrcOffsetViewType>
4081  struct pack_functor {
4082  typedef typename DestViewType::execution_space execution_space;
4083  SrcViewType src_;
4084  DestViewType dst_;
4085  SrcOffsetViewType src_offset_;
4086  DestOffsetViewType dst_offset_;
4087  typedef typename DestOffsetViewType::non_const_value_type scalar_index_type;
4088 
4089  pack_functor (DestViewType dst,
4090  const SrcViewType src,
4091  DestOffsetViewType dst_offset,
4092  const SrcOffsetViewType src_offset) :
4093  src_ (src),
4094  dst_ (dst),
4095  src_offset_ (src_offset),
4096  dst_offset_ (dst_offset)
4097  {}
4098 
4099  KOKKOS_INLINE_FUNCTION
4100  void operator () (const LocalOrdinal row) const {
4101  scalar_index_type srcPos = src_offset_(row);
4102  const scalar_index_type dstEnd = dst_offset_(row+1);
4103  scalar_index_type dstPos = dst_offset_(row);
4104  for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
4105  dst_(dstPos) = src_(srcPos);
4106  }
4107  }
4108  };
4109  }; // class CrsMatrix
4110 
4115  template<class Scalar,
4116  class LocalOrdinal,
4117  class GlobalOrdinal,
4118  class Node>
4119  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
4121  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
4122  const size_t maxNumEntriesPerRow = 0,
4123  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4124  {
4125  using matrix_type =
4127  return Teuchos::rcp(new matrix_type(map, maxNumEntriesPerRow,
4128  params));
4129  }
4130 
4131  template<class CrsMatrixType>
4132  Teuchos::RCP<CrsMatrixType>
4133  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4134  const Import<typename CrsMatrixType::local_ordinal_type,
4135  typename CrsMatrixType::global_ordinal_type,
4136  typename CrsMatrixType::node_type>& importer,
4137  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4138  typename CrsMatrixType::global_ordinal_type,
4139  typename CrsMatrixType::node_type> >& domainMap,
4140  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4141  typename CrsMatrixType::global_ordinal_type,
4142  typename CrsMatrixType::node_type> >& rangeMap,
4143  const Teuchos::RCP<Teuchos::ParameterList>& params)
4144  {
4145  Teuchos::RCP<CrsMatrixType> destMatrix;
4146  sourceMatrix->importAndFillComplete (destMatrix, importer, domainMap, rangeMap, params);
4147  return destMatrix;
4148  }
4149 
4150  template<class CrsMatrixType>
4151  Teuchos::RCP<CrsMatrixType>
4152  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4153  const Import<typename CrsMatrixType::local_ordinal_type,
4154  typename CrsMatrixType::global_ordinal_type,
4155  typename CrsMatrixType::node_type>& rowImporter,
4156  const Import<typename CrsMatrixType::local_ordinal_type,
4157  typename CrsMatrixType::global_ordinal_type,
4158  typename CrsMatrixType::node_type>& domainImporter,
4159  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4160  typename CrsMatrixType::global_ordinal_type,
4161  typename CrsMatrixType::node_type> >& domainMap,
4162  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4163  typename CrsMatrixType::global_ordinal_type,
4164  typename CrsMatrixType::node_type> >& rangeMap,
4165  const Teuchos::RCP<Teuchos::ParameterList>& params)
4166  {
4167  Teuchos::RCP<CrsMatrixType> destMatrix;
4168  sourceMatrix->importAndFillComplete (destMatrix, rowImporter, domainImporter, domainMap, rangeMap, params);
4169  return destMatrix;
4170  }
4171 
4172  template<class CrsMatrixType>
4173  Teuchos::RCP<CrsMatrixType>
4174  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4175  const Export<typename CrsMatrixType::local_ordinal_type,
4176  typename CrsMatrixType::global_ordinal_type,
4177  typename CrsMatrixType::node_type>& exporter,
4178  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4179  typename CrsMatrixType::global_ordinal_type,
4180  typename CrsMatrixType::node_type> >& domainMap,
4181  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4182  typename CrsMatrixType::global_ordinal_type,
4183  typename CrsMatrixType::node_type> >& rangeMap,
4184  const Teuchos::RCP<Teuchos::ParameterList>& params)
4185  {
4186  Teuchos::RCP<CrsMatrixType> destMatrix;
4187  sourceMatrix->exportAndFillComplete (destMatrix, exporter, domainMap, rangeMap, params);
4188  return destMatrix;
4189  }
4190 
4191  template<class CrsMatrixType>
4192  Teuchos::RCP<CrsMatrixType>
4193  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4194  const Export<typename CrsMatrixType::local_ordinal_type,
4195  typename CrsMatrixType::global_ordinal_type,
4196  typename CrsMatrixType::node_type>& rowExporter,
4197  const Export<typename CrsMatrixType::local_ordinal_type,
4198  typename CrsMatrixType::global_ordinal_type,
4199  typename CrsMatrixType::node_type>& domainExporter,
4200  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4201  typename CrsMatrixType::global_ordinal_type,
4202  typename CrsMatrixType::node_type> >& domainMap,
4203  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4204  typename CrsMatrixType::global_ordinal_type,
4205  typename CrsMatrixType::node_type> >& rangeMap,
4206  const Teuchos::RCP<Teuchos::ParameterList>& params)
4207  {
4208  Teuchos::RCP<CrsMatrixType> destMatrix;
4209  sourceMatrix->exportAndFillComplete (destMatrix, rowExporter, domainExporter, domainMap, rangeMap, params);
4210  return destMatrix;
4211  }
4212 
4219  template<class CrsMatrixType>
4220  void
4221  removeCrsMatrixZeros(CrsMatrixType& matrix,
4222  typename Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitudeType const & threshold =
4223  Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitude( Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::zero() ))
4224  {
4225  auto localMatrix = matrix.getLocalMatrixDevice();
4226  size_t nnzBefore = localMatrix.nnz();
4227  localMatrix = KokkosSparse::removeCrsMatrixZeros(localMatrix,threshold);
4228  size_t localNNZRemoved = nnzBefore - localMatrix.nnz();
4229  //Skip the expertStaticFillComplete if no entries were removed on any process.
4230  //The fill complete can perform MPI collectives, so it can only be skipped on all processes or none.
4231  size_t globalNNZRemoved = 0;
4232  Teuchos::reduceAll<int, size_t> (*(matrix.getComm()), Teuchos::REDUCE_SUM, 1, &localNNZRemoved, &globalNNZRemoved);
4233  if(globalNNZRemoved != size_t(0)) {
4234  matrix.resumeFill();
4235  matrix.setAllValues(localMatrix);
4236  matrix.expertStaticFillComplete(matrix.getDomainMap(),matrix.getRangeMap());
4237  }
4238  }
4239 
4240 } // namespace Tpetra
4241 
4249 #endif // TPETRA_CRSMATRIX_DECL_HPP
CrsMatrix & operator=(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assignment.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
bool hasColMap() const override
Whether the matrix has a well-defined column Map.
global_size_t getGlobalNumCols() const override
The number of global columns in the matrix.
void checkInternalState() const
Check that this object&#39;s state is sane; throw if it&#39;s not.
Abstract interface for local operators (e.g., matrices and preconditioners).
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
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().
CrsGraph< LocalOrdinal, GlobalOrdinal, Node > crs_graph_type
The CrsGraph specialization suitable for this CrsMatrix specialization.
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the matrix&#39;s column Map with the given Map.
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.
virtual bool supportsRowViews() const override
Return true if getLocalRowView() and getGlobalRowView() are valid for this object.
ordinal_rowptrs_type ordinalRowptrs
local_ordinal typed version of local matrix&#39;s rowptrs. This allows the LocalCrsMatrixOperator to have...
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.
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.
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...
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM)
Perform copies and permutations that are local to the calling (MPI) process.
Teuchos::RCP< const map_type > getRangeMap() const override
The range Map of this matrix.
global_size_t getGlobalNumRows() const override
Number of global elements in the row map of this matrix.
std::map< GlobalOrdinal, std::pair< Teuchos::Array< GlobalOrdinal >, Teuchos::Array< Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
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...
typename device_type::execution_space execution_space
The Kokkos execution space.
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&#39;s data for an Import or Export.
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.
row_ptrs_device_view_type getLocalRowPtrsDevice() const
Get a device view of the CRS packed row pointers.
local_matrix_device_type::values_type getLocalValuesDevice(Access::OverwriteAllStruct s)
Get the Kokkos local values on device, overwrite all.
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
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 setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
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.
One or more distributed dense vectors.
void scale(const Scalar &alpha)
Scale the matrix&#39;s values: this := alpha*this.
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.
size_t getLocalNumCols() const override
The number of columns connected to the locally owned rows of this matrix.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local graph and matrix.
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Resume operations that may change the values or structure of the matrix.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the left with the given Vector.
GlobalOrdinal global_ordinal_type
The type of each global index in the matrix.
Declaration and generic definition of traits class that tells Tpetra::CrsMatrix how to pack and unpac...
local_inds_host_view_type getLocalIndicesHost() const
Get a host view of the CRS packed column indicies.
typename device_type::memory_space memory_space
The Kokkos memory space.
virtual ~CrsMatrix()=default
Destructor (virtual for memory safety of derived classes).
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...
Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization suitable for this CrsMatrix specialization.
local_matrix_host_type::values_type getLocalValuesHost(Access::OverwriteAllStruct s)
Get the Kokkos local values on host, overwrite all.
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix&#39;s graph, as a CrsGraph.
virtual void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< packet_type *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode combineMode)
Perform any unpacking and combining after communication.
size_t getGlobalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, over all processes in the matrix&#39;s communicator...
void applyNonTranspose(const MV &X_in, MV &Y_in, Scalar alpha, Scalar beta) const
Special case of apply() for mode == Teuchos::NO_TRANS.
Teuchos::RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Return another CrsMatrix with the same entries, but converted to a different Scalar type T...
Scalar scalar_type
The type of each entry in the matrix.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
void swap(CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &matrix)
Swaps the data from *this with the data and maps from crsMatrix.
void fillLocalMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local matrix.
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...
void globalAssemble()
Communicate nonlocal contributions to other processes.
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...
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...
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.
local_matrix_host_type::values_type::const_type getLocalValuesHost(Access::ReadOnlyStruct s) const
Get the Kokkos local values on host, read only.
bool isFillActive() const
Whether the matrix is not fill complete.
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply().
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
size_t global_size_t
Global size_t object.
bool hasTransposeApply() const override
Whether apply() allows applying the transpose or conjugate transpose.
size_t getLocalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, on this process.
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_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)...
bool isFillComplete() const override
Whether the matrix is fill complete.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
The communicator over which the matrix is distributed.
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.
Abstract interface for operators (e.g., matrices and preconditioners).
TPETRA_DETAILS_ALWAYS_INLINE local_matrix_device_type getLocalMatrixDevice() const
The local sparse matrix.
local_matrix_device_type::values_type getLocalValuesDevice(Access::ReadWriteStruct s)
Get the Kokkos local values on device, read write.
GlobalOrdinal getIndexBase() const override
The index base for global indices for this matrix.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
virtual void packAndPrepare(const SrcDistObject &source, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< packet_type *, buffer_device_type > &exports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, size_t &constantNumPackets)
Pack data and metadata for communication (sends).
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...
Node node_type
This class&#39; Kokkos Node type.
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
Keep track of how much more space a CrsGraph or CrsMatrix needs, when the graph or matrix is the targ...
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.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const override
This matrix&#39;s graph, as a RowGraph.
CombineMode
Rule for combining data in an Import or Export.
Sum new values.
row_ptrs_host_view_type getLocalRowPtrsHost() const
Get a host view of the CRS packed row pointers.
DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
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.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
A class can inherit from this if it wants to use Tpetra managed spaces.
bool isGloballyIndexed() const override
Whether the matrix is globally indexed on the calling process.
Forward declaration of Tpetra::CrsMatrix.
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.
bool fillComplete_
Whether the matrix is fill complete.
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.
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&#39; values, using global indices.
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.
Abstract base class for objects that can be the source of an Import or Export operation.
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.
typename Node::device_type device_type
The Kokkos device type.
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< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
std::string description() const override
A one-line description of this object.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const override
Compute a sparse matrix-MultiVector multiply.
size_t getLocalNumEntries() const override
The local number of entries in this matrix.
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...
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.
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.
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...
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap) override
Remove processes owning zero rows from the Maps and their communicator.
virtual bool checkSizes(const SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
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...
virtual LocalOrdinal getBlockSize() const override
The number of degrees of freedom per mesh point.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
typename row_matrix_type::impl_scalar_type impl_scalar_type
The type used internally in place of Scalar.
A parallel distribution of indices over processes.
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< const map_type > getDomainMap() const override
The domain Map of this matrix.
local_matrix_host_type::values_type getLocalValuesHost(Access::ReadWriteStruct s)
Get the Kokkos local values on host, read write.
void insertLocalValues(const LocalOrdinal localRow, const Teuchos::ArrayView< const LocalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals, const CombineMode CM=ADD)
Insert one or more entries into the matrix, using local column indices.
Details::EStorageStatus storageStatus_
Status of the matrix&#39;s storage, when not in a fill-complete state.
A read-only, row-oriented interface to a sparse matrix.
local_inds_device_view_type getLocalIndicesDevice() const
Get a device_view of the CRS packed column indicies.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the right with the given Vector.
void replaceDomainMap(const Teuchos::RCP< const map_type > &newDomainMap)
Replace the current domain Map with the given objects.
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.
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).
A distributed dense vector.
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().
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.
void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas, const bool verbose)
Allocate values (and optionally indices) using the Node.
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.
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 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.
local_matrix_device_type::values_type::const_type getLocalValuesDevice(Access::ReadOnlyStruct s) const
Get the Kokkos local values on device, read only.
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.
bool isLocallyIndexed() const override
Whether the matrix is locally indexed on the calling process.
Teuchos::RCP< const map_type > getColMap() const override
The Map that describes the column distribution in this matrix.
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&#39; values, using local row and column indices.
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.
void replaceRangeMap(const Teuchos::RCP< const map_type > &newRangeMap)
Replace the current range Map with the given objects.
Base class for distributed Tpetra objects that support data redistribution.
std::shared_ptr< local_multiply_op_type > getLocalMultiplyOperator() const
The local sparse matrix operator (a wrapper of getLocalMatrixDevice() that supports local matrix-vect...
typename local_graph_device_type::HostMirror local_graph_host_type
The type of the part of the sparse graph on each MPI process.
void removeCrsMatrixZeros(CrsMatrixType &matrix, typename Teuchos::ScalarTraits< typename CrsMatrixType::scalar_type >::magnitudeType const &threshold=Teuchos::ScalarTraits< typename CrsMatrixType::scalar_type >::magnitude(Teuchos::ScalarTraits< typename CrsMatrixType::scalar_type >::zero()))
Remove zero entries from a matrix.
LocalOrdinal local_ordinal_type
The type of each local index in the matrix.
EStorageStatus
Status of the graph&#39;s or matrix&#39;s storage, when not in a fill-complete state.
mag_type getFrobeniusNorm() const override
Compute and return the Frobenius norm of the matrix.
typename crs_graph_type::local_graph_device_type local_graph_device_type
The part of the sparse matrix&#39;s graph on each MPI process.
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.
Forward declaration of some Tpetra Matrix Matrix objects.
bool isStorageOptimized() const
Returns true if storage has been optimized.
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM) override
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...
Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization suitable for this CrsMatrix specialization.
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
size_t getLocalNumRows() const override
The number of matrix rows owned by the calling process.
Teuchos::RCP< const map_type > getRowMap() const override
The Map that describes the row distribution in this matrix.
global_size_t getGlobalNumEntries() const override
The global number of entries in this matrix.