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 //
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 
50 
51 #include "Tpetra_CrsMatrix_fwd.hpp"
52 #include "Tpetra_LocalCrsMatrixOperator_fwd.hpp"
53 #include "Tpetra_RowMatrix_decl.hpp"
54 #include "Tpetra_Exceptions.hpp"
55 #include "Tpetra_DistObject.hpp"
56 #include "Tpetra_CrsGraph.hpp"
57 #include "Tpetra_Vector.hpp"
58 #include "Tpetra_Details_PackTraits.hpp" // unused here, could delete
59 #include "KokkosSparse_CrsMatrix.hpp"
60 
61 // localGaussSeidel and reorderedLocalGaussSeidel are templated on
62 // DomainScalar and RangeScalar, so we have to include this header
63 // file here, rather than in the _def header file, so that we can get
64 // the interfaces to the corresponding local computational kernels.
65 #include "KokkosSparse_sor_sequential_impl.hpp"
66 
67 #include <memory> // std::shared_ptr
68 
69 namespace Tpetra {
70 
71  // Forward declaration for CrsMatrix::swap() test
72  template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> class crsMatrix_Swap_Tester;
73 
125  template<class CrsMatrixType>
126  Teuchos::RCP<CrsMatrixType>
127  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
128  const Import<typename CrsMatrixType::local_ordinal_type,
129  typename CrsMatrixType::global_ordinal_type,
130  typename CrsMatrixType::node_type>& importer,
131  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
132  typename CrsMatrixType::global_ordinal_type,
133  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
134  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
135  typename CrsMatrixType::global_ordinal_type,
136  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
137  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
138 
192  template<class CrsMatrixType>
193  Teuchos::RCP<CrsMatrixType>
194  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
195  const Import<typename CrsMatrixType::local_ordinal_type,
196  typename CrsMatrixType::global_ordinal_type,
197  typename CrsMatrixType::node_type>& rowImporter,
198  const Import<typename CrsMatrixType::local_ordinal_type,
199  typename CrsMatrixType::global_ordinal_type,
200  typename CrsMatrixType::node_type>& domainImporter,
201  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
202  typename CrsMatrixType::global_ordinal_type,
203  typename CrsMatrixType::node_type> >& domainMap,
204  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
205  typename CrsMatrixType::global_ordinal_type,
206  typename CrsMatrixType::node_type> >& rangeMap,
207  const Teuchos::RCP<Teuchos::ParameterList>& params);
208 
242  template<class CrsMatrixType>
243  Teuchos::RCP<CrsMatrixType>
244  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
245  const Export<typename CrsMatrixType::local_ordinal_type,
246  typename CrsMatrixType::global_ordinal_type,
247  typename CrsMatrixType::node_type>& exporter,
248  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
249  typename CrsMatrixType::global_ordinal_type,
250  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
251  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
252  typename CrsMatrixType::global_ordinal_type,
253  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
254  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
255 
289  template<class CrsMatrixType>
290  Teuchos::RCP<CrsMatrixType>
291  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
292  const Export<typename CrsMatrixType::local_ordinal_type,
293  typename CrsMatrixType::global_ordinal_type,
294  typename CrsMatrixType::node_type>& rowExporter,
295  const Export<typename CrsMatrixType::local_ordinal_type,
296  typename CrsMatrixType::global_ordinal_type,
297  typename CrsMatrixType::node_type>& domainExporter,
298  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
299  typename CrsMatrixType::global_ordinal_type,
300  typename CrsMatrixType::node_type> >& domainMap,
301  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
302  typename CrsMatrixType::global_ordinal_type,
303  typename CrsMatrixType::node_type> >& rangeMap,
304  const Teuchos::RCP<Teuchos::ParameterList>& params);
305 
308  namespace Details {
309  template<class SC, class LO, class GO, class NO>
310  void residual(const Operator<SC,LO,GO,NO> & A,
311  const MultiVector<SC,LO,GO,NO> & X,
312  const MultiVector<SC,LO,GO,NO> & B,
313  MultiVector<SC,LO,GO,NO> & R);
314  }
315 
429  template <class Scalar,
430  class LocalOrdinal,
431  class GlobalOrdinal,
432  class Node>
433  class CrsMatrix :
434  public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
435  public DistObject<char, LocalOrdinal, GlobalOrdinal, Node>
436  {
437  public:
439 
440 
442  using scalar_type = Scalar;
452  using impl_scalar_type = typename Kokkos::ArithTraits<Scalar>::val_type;
454  using local_ordinal_type = LocalOrdinal;
456  using global_ordinal_type = GlobalOrdinal;
458  using device_type = typename Node::device_type;
460  using execution_space = typename device_type::execution_space;
461 
466  using node_type = Node;
467 
473  using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
474 
477 
480 
483 
486 
489 
492  using local_matrix_type =
493  KokkosSparse::CrsMatrix<impl_scalar_type,
495  device_type,
496  void,
497  typename local_graph_type::size_type>;
498 
500  using local_multiply_op_type =
502  scalar_type,
504 
506 
508 
510  CrsMatrix (const CrsMatrix<Scalar, LocalOrdinal,
511  GlobalOrdinal, Node>&) = default;
512 
514  CrsMatrix (CrsMatrix<Scalar, LocalOrdinal,
515  GlobalOrdinal, Node>&&) = default;
516 
518  CrsMatrix&
519  operator= (const CrsMatrix<Scalar, LocalOrdinal,
520  GlobalOrdinal, Node>&) = default;
521 
523  CrsMatrix&
524  operator= (CrsMatrix<Scalar, LocalOrdinal,
525  GlobalOrdinal, Node>&&) = default;
526 
542  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
543  const size_t maxNumEntriesPerRow,
544  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
545  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
546 
561  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
562  const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
563  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
564  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
565 
566 
587  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
588  const Teuchos::RCP<const map_type>& colMap,
589  const size_t maxNumEntPerRow,
590  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
591  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
592 
613  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
614  const Teuchos::RCP<const map_type>& colMap,
615  const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
616  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
617  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
618 
619 
644  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
645  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
646 
675  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
676  const typename local_matrix_type::values_type& values,
677  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
678 
705  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
706  const Teuchos::RCP<const map_type>& colMap,
707  const typename local_matrix_type::row_map_type& rowPointers,
708  const typename local_graph_type::entries_type::non_const_type& columnIndices,
709  const typename local_matrix_type::values_type& values,
710  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
711 
738  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
739  const Teuchos::RCP<const map_type>& colMap,
740  const Teuchos::ArrayRCP<size_t>& rowPointers,
741  const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
742  const Teuchos::ArrayRCP<Scalar>& values,
743  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
744 
766  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
767  const Teuchos::RCP<const map_type>& colMap,
768  const local_matrix_type& lclMatrix,
769  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
770 
801  CrsMatrix (const local_matrix_type& lclMatrix,
802  const Teuchos::RCP<const map_type>& rowMap,
803  const Teuchos::RCP<const map_type>& colMap,
804  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
805  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
806  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
807 
812  CrsMatrix (const local_matrix_type& lclMatrix,
813  const Teuchos::RCP<const map_type>& rowMap,
814  const Teuchos::RCP<const map_type>& colMap,
815  const Teuchos::RCP<const map_type>& domainMap,
816  const Teuchos::RCP<const map_type>& rangeMap,
817  const Teuchos::RCP<const import_type>& importer,
818  const Teuchos::RCP<const export_type>& exporter,
819  const Teuchos::RCP<Teuchos::ParameterList>& params =
820  Teuchos::null);
821 
823  // This function in 'Copy' mode is only guaranteed to work correctly for matrices
824  // which are fillComplete.
826  const Teuchos::DataAccess copyOrView);
827 
837  virtual ~CrsMatrix () = default;
838 
839  // This friend declaration makes the clone() method work.
840  template <class S2, class LO2, class GO2, class N2>
841  friend class CrsMatrix;
842 
843  // This friend declaration allows for fused residual calculation
844  template <class S2, class LO2, class GO2, class N2>
845  friend void Details::residual(const Operator<S2,LO2,GO2,N2> & A,
846  const MultiVector<S2,LO2,GO2,N2> & X,
847  const MultiVector<S2,LO2,GO2,N2> & B,
849 
850  // This friend declaration allows for batching of apply calls
851  template <class MatrixArray, class MultiVectorArray>
852  friend void batchedApply(const MatrixArray &Matrices,
853  const typename std::remove_pointer<typename MultiVectorArray::value_type>::type & X,
854  MultiVectorArray &Y,
855  typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type alpha,
856  typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type beta,
857  Teuchos::RCP<Teuchos::ParameterList> params);
858  public:
860 
862 
886  //
932  void
933  insertGlobalValues (const GlobalOrdinal globalRow,
934  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
935  const Teuchos::ArrayView<const Scalar>& vals);
936 
951  void
952  insertGlobalValues (const GlobalOrdinal globalRow,
953  const LocalOrdinal numEnt,
954  const Scalar vals[],
955  const GlobalOrdinal inds[]);
956 
997  void
998  insertLocalValues (const LocalOrdinal localRow,
999  const Teuchos::ArrayView<const LocalOrdinal> &cols,
1000  const Teuchos::ArrayView<const Scalar> &vals);
1001 
1016  void
1017  insertLocalValues (const LocalOrdinal localRow,
1018  const LocalOrdinal numEnt,
1019  const Scalar vals[],
1020  const LocalOrdinal cols[]);
1021 
1022  private:
1033  LocalOrdinal
1034  replaceGlobalValuesImpl (impl_scalar_type rowVals[],
1035  const crs_graph_type& graph,
1036  const RowInfo& rowInfo,
1037  const GlobalOrdinal inds[],
1038  const impl_scalar_type newVals[],
1039  const LocalOrdinal numElts) const;
1040 
1041  public:
1080  const global_ordinal_type globalRow,
1081  const Kokkos::View<const global_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1082  const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals) const;
1083 
1086  LocalOrdinal
1087  replaceGlobalValues (const GlobalOrdinal globalRow,
1088  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1089  const Teuchos::ArrayView<const Scalar>& vals) const;
1090 
1105  LocalOrdinal
1106  replaceGlobalValues (const GlobalOrdinal globalRow,
1107  const LocalOrdinal numEnt,
1108  const Scalar vals[],
1109  const GlobalOrdinal cols[]) const;
1110 
1111  private:
1122  LocalOrdinal
1123  replaceLocalValuesImpl (impl_scalar_type rowVals[],
1124  const crs_graph_type& graph,
1125  const RowInfo& rowInfo,
1126  const LocalOrdinal inds[],
1127  const impl_scalar_type newVals[],
1128  const LocalOrdinal numElts) const;
1129 
1130  public:
1168  const local_ordinal_type localRow,
1169  const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1170  const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals) const;
1171 
1175  LocalOrdinal
1176  replaceLocalValues (const LocalOrdinal localRow,
1177  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1178  const Teuchos::ArrayView<const Scalar>& vals) const;
1179 
1197  LocalOrdinal
1198  replaceLocalValues (const LocalOrdinal localRow,
1199  const LocalOrdinal numEnt,
1200  const Scalar inputVals[],
1201  const LocalOrdinal inputCols[]) const;
1202 
1203  private:
1208  static const bool useAtomicUpdatesByDefault =
1209 #ifdef KOKKOS_ENABLE_SERIAL
1210  ! std::is_same<execution_space, Kokkos::Serial>::value;
1211 #else
1212  true;
1213 #endif // KOKKOS_ENABLE_SERIAL
1214 
1238  LocalOrdinal
1239  sumIntoGlobalValuesImpl (impl_scalar_type rowVals[],
1240  const crs_graph_type& graph,
1241  const RowInfo& rowInfo,
1242  const GlobalOrdinal inds[],
1243  const impl_scalar_type newVals[],
1244  const LocalOrdinal numElts,
1245  const bool atomic = useAtomicUpdatesByDefault) const;
1246 
1247  public:
1284  LocalOrdinal
1285  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1286  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1287  const Teuchos::ArrayView<const Scalar>& vals,
1288  const bool atomic = useAtomicUpdatesByDefault);
1289 
1312  LocalOrdinal
1313  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1314  const LocalOrdinal numEnt,
1315  const Scalar vals[],
1316  const GlobalOrdinal cols[],
1317  const bool atomic = useAtomicUpdatesByDefault);
1318 
1319  private:
1332  LocalOrdinal
1333  sumIntoLocalValuesImpl (impl_scalar_type rowVals[],
1334  const crs_graph_type& graph,
1335  const RowInfo& rowInfo,
1336  const LocalOrdinal inds[],
1337  const impl_scalar_type newVals[],
1338  const LocalOrdinal numElts,
1339  const bool atomic = useAtomicUpdatesByDefault) const;
1340 
1341  public:
1380  const local_ordinal_type localRow,
1381  const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1382  const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals,
1383  const bool atomic = useAtomicUpdatesByDefault) const;
1384 
1414  LocalOrdinal
1415  sumIntoLocalValues (const LocalOrdinal localRow,
1416  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1417  const Teuchos::ArrayView<const Scalar>& vals,
1418  const bool atomic = useAtomicUpdatesByDefault) const;
1419 
1441  LocalOrdinal
1442  sumIntoLocalValues (const LocalOrdinal localRow,
1443  const LocalOrdinal numEnt,
1444  const Scalar vals[],
1445  const LocalOrdinal cols[],
1446  const bool atomic = useAtomicUpdatesByDefault) const;
1447 
1448  private:
1479  LocalOrdinal
1480  transformLocalValues (impl_scalar_type rowVals[],
1481  const crs_graph_type& graph,
1482  const RowInfo& rowInfo,
1483  const LocalOrdinal inds[],
1484  const impl_scalar_type newVals[],
1485  const LocalOrdinal numElts,
1486  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1487  const bool atomic = useAtomicUpdatesByDefault) const;
1488 
1519  LocalOrdinal
1520  transformGlobalValues (impl_scalar_type rowVals[],
1521  const crs_graph_type& graph,
1522  const RowInfo& rowInfo,
1523  const GlobalOrdinal inds[],
1524  const impl_scalar_type newVals[],
1525  const LocalOrdinal numElts,
1526  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1527  const bool atomic = useAtomicUpdatesByDefault) const;
1528 
1555  LocalOrdinal
1556  transformLocalValues (const LocalOrdinal lclRow,
1557  const LocalOrdinal numInputEnt,
1558  const impl_scalar_type inputVals[],
1559  const LocalOrdinal inputCols[],
1560  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1561  const bool atomic = useAtomicUpdatesByDefault) const;
1562 
1589  LocalOrdinal
1590  transformGlobalValues (const GlobalOrdinal gblRow,
1591  const LocalOrdinal numInputEnt,
1592  const impl_scalar_type inputVals[],
1593  const GlobalOrdinal inputCols[],
1594  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1595  const bool atomic = useAtomicUpdatesByDefault) const;
1596 
1597  public:
1641  template<class LocalIndicesViewType,
1642  class ImplScalarViewType,
1643  class BinaryFunction>
1644  LocalOrdinal
1645  transformLocalValues (const LocalOrdinal lclRow,
1646  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1647  const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1648  BinaryFunction f,
1649  const bool atomic = useAtomicUpdatesByDefault) const
1650  {
1651  // We use static_assert here to check the template parameters,
1652  // rather than std::enable_if (e.g., on the return value, to
1653  // enable compilation only if the template parameters match the
1654  // desired attributes). This turns obscure link errors into
1655  // clear compilation errors. It also makes the return value a
1656  // lot easier to see.
1657  static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1658  "First template parameter LocalIndicesViewType must be "
1659  "a Kokkos::View.");
1660  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1661  "Second template parameter ImplScalarViewType must be a "
1662  "Kokkos::View.");
1663  static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1664  "First template parameter LocalIndicesViewType must "
1665  "have rank 1.");
1666  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1667  "Second template parameter ImplScalarViewType must have "
1668  "rank 1.");
1669  static_assert (std::is_same<
1670  typename LocalIndicesViewType::non_const_value_type,
1671  local_ordinal_type>::value,
1672  "First template parameter LocalIndicesViewType must "
1673  "contain values of type local_ordinal_type.");
1674  static_assert (std::is_same<
1675  typename ImplScalarViewType::non_const_value_type,
1676  impl_scalar_type>::value,
1677  "Second template parameter ImplScalarViewType must "
1678  "contain values of type impl_scalar_type.");
1679  typedef LocalOrdinal LO;
1680  const LO numInputEnt = inputInds.extent (0);
1681  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1682  return Teuchos::OrdinalTraits<LO>::invalid ();
1683  }
1684  return this->transformLocalValues (lclRow,
1685  numInputEnt,
1686  inputVals.data (),
1687  inputInds.data (),
1688  f,
1689  atomic);
1690  }
1691 
1733  template<class BinaryFunction, class InputMemorySpace>
1734  LocalOrdinal
1735  transformGlobalValues (const GlobalOrdinal gblRow,
1736  const Kokkos::View<const GlobalOrdinal*,
1737  InputMemorySpace,
1738  Kokkos::MemoryUnmanaged>& inputInds,
1739  const Kokkos::View<const impl_scalar_type*,
1740  InputMemorySpace,
1741  Kokkos::MemoryUnmanaged>& inputVals,
1742  BinaryFunction f,
1743  const bool atomic = useAtomicUpdatesByDefault) const
1744  {
1745  typedef LocalOrdinal LO;
1746  const LO numInputEnt = inputInds.extent (0);
1747  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1748  return Teuchos::OrdinalTraits<LO>::invalid ();
1749  }
1750  return this->transformGlobalValues (gblRow,
1751  numInputEnt,
1752  inputVals.data (),
1753  inputInds.data (),
1754  f,
1755  atomic);
1756  }
1757 
1759  void setAllToScalar (const Scalar& alpha);
1760 
1762  void scale (const Scalar& alpha);
1763 
1788  void
1789  setAllValues (const typename local_matrix_type::row_map_type& ptr,
1790  const typename local_graph_type::entries_type::non_const_type& ind,
1791  const typename local_matrix_type::values_type& val);
1792 
1817  void
1818  setAllValues (const Teuchos::ArrayRCP<size_t>& ptr,
1819  const Teuchos::ArrayRCP<LocalOrdinal>& ind,
1820  const Teuchos::ArrayRCP<Scalar>& val);
1821 
1822  void
1823  getAllValues (Teuchos::ArrayRCP<const size_t>& rowPointers,
1824  Teuchos::ArrayRCP<const LocalOrdinal>& columnIndices,
1825  Teuchos::ArrayRCP<const Scalar>& values) const;
1826 
1828 
1830 
1859  void globalAssemble();
1860 
1874  void resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1875 
1933  void
1934  fillComplete (const Teuchos::RCP<const map_type>& domainMap,
1935  const Teuchos::RCP<const map_type>& rangeMap,
1936  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1937 
1964  void
1965  fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1966 
1993  void
1994  expertStaticFillComplete (const Teuchos::RCP<const map_type>& domainMap,
1995  const Teuchos::RCP<const map_type>& rangeMap,
1996  const Teuchos::RCP<const import_type>& importer = Teuchos::null,
1997  const Teuchos::RCP<const export_type>& exporter = Teuchos::null,
1998  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1999 
2017  void
2018  replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
2019 
2101  void
2102  reindexColumns (crs_graph_type* const graph,
2103  const Teuchos::RCP<const map_type>& newColMap,
2104  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
2105  const bool sortEachRow = true);
2106 
2119  void
2120  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
2121  Teuchos::RCP<const import_type>& newImporter);
2122 
2136  virtual void
2137  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
2138 
2140 
2142 
2144  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const override;
2145 
2146 
2148  Teuchos::RCP<const map_type> getRowMap () const override;
2149 
2151  Teuchos::RCP<const map_type> getColMap () const override;
2152 
2154  Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> >
2155  getGraph () const override;
2156 
2158  Teuchos::RCP<const crs_graph_type> getCrsGraph () const;
2159 
2160  private:
2171  const crs_graph_type& getCrsGraphRef () const;
2172 
2173  public:
2184 
2189  std::shared_ptr<local_multiply_op_type> getLocalMultiplyOperator () const;
2190 
2210  global_size_t getGlobalNumRows() const override;
2211 
2217  global_size_t getGlobalNumCols() const override;
2218 
2225  size_t getNodeNumRows() const override;
2226 
2230  size_t getNodeNumCols() const override;
2231 
2233  GlobalOrdinal getIndexBase() const override;
2234 
2236  global_size_t getGlobalNumEntries() const override;
2237 
2239  size_t getNodeNumEntries() const override;
2240 
2247  size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const override;
2248 
2255  size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const override;
2256 
2264  size_t getGlobalMaxNumRowEntries () const override;
2265 
2273  size_t getNodeMaxNumRowEntries () const override;
2274 
2276  bool hasColMap () const override;
2277 
2278 
2299  bool isLocallyIndexed() const override;
2300 
2321  bool isGloballyIndexed() const override;
2322 
2345  bool isFillComplete() const override;
2346 
2369  bool isFillActive() const;
2370 
2372 
2378  bool isStorageOptimized () const;
2379 
2381  ProfileType getProfileType () const;
2382 
2384  bool isStaticGraph () const;
2385 
2397  mag_type getFrobeniusNorm () const override;
2398 
2401  virtual bool supportsRowViews () const override;
2402 
2451  void
2452  getGlobalRowCopy (GlobalOrdinal GlobalRow,
2453  const Teuchos::ArrayView<GlobalOrdinal>& Indices,
2454  const Teuchos::ArrayView<Scalar>& Values,
2455  size_t& NumEntries) const override;
2456 
2472  void
2473  getLocalRowCopy (LocalOrdinal localRow,
2474  const Teuchos::ArrayView<LocalOrdinal>& colInds,
2475  const Teuchos::ArrayView<Scalar>& vals,
2476  size_t& numEntries) const override;
2477 
2490  void
2491  getGlobalRowView (GlobalOrdinal GlobalRow,
2492  Teuchos::ArrayView<const GlobalOrdinal>& indices,
2493  Teuchos::ArrayView<const Scalar>& values) const override;
2494 
2507  void
2508  getLocalRowView (LocalOrdinal LocalRow,
2509  Teuchos::ArrayView<const LocalOrdinal>& indices,
2510  Teuchos::ArrayView<const Scalar>& values) const override;
2511 
2536  LocalOrdinal
2537  getLocalRowViewRaw (const LocalOrdinal lclRow,
2538  LocalOrdinal& numEnt,
2539  const LocalOrdinal*& lclColInds,
2540  const Scalar*& vals) const override;
2541 
2565  LocalOrdinal
2566  getLocalRowView (const LocalOrdinal lclRow,
2567  LocalOrdinal& numEnt,
2568  const impl_scalar_type*& val,
2569  const LocalOrdinal*& ind) const;
2570 
2578  template<class OutputScalarType>
2579  typename std::enable_if<! std::is_same<OutputScalarType, impl_scalar_type>::value &&
2580  std::is_convertible<impl_scalar_type, OutputScalarType>::value,
2581  LocalOrdinal>::type
2582  getLocalRowView (const LocalOrdinal lclRow,
2583  LocalOrdinal& numEnt,
2584  const OutputScalarType*& val,
2585  const LocalOrdinal*& ind) const
2586  {
2587  const impl_scalar_type* valTmp = NULL;
2588  const LocalOrdinal err = this->getLocalRowView (lclRow, numEnt, valTmp, ind);
2589  // Cast is legitimate because impl_scalar_type is convertible to
2590  // OutputScalarType.
2591  val = reinterpret_cast<const OutputScalarType*> (valTmp);
2592  return err;
2593  }
2594 
2601  void
2603 
2647  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
2648 
2670  void
2672  const Kokkos::View<const size_t*, device_type,
2673  Kokkos::MemoryUnmanaged>& offsets) const;
2674 
2697  void
2699  const Teuchos::ArrayView<const size_t>& offsets) const;
2700 
2705  void
2707 
2712  void
2714 
2716 
2718 
2780  void
2783  const Teuchos::ETransp mode = Teuchos::NO_TRANS,
2784  const Scalar& alpha = Teuchos::ScalarTraits<Scalar>::one (),
2785  const Scalar& beta = Teuchos::ScalarTraits<Scalar>::zero ()) const;
2786 
2811  template <class DomainScalar, class RangeScalar>
2812  void
2816  const RangeScalar& dampingFactor,
2817  const ESweepDirection direction) const
2818  {
2819  typedef LocalOrdinal LO;
2820  typedef GlobalOrdinal GO;
2823  typedef typename Node::device_type::memory_space dev_mem_space;
2824  typedef typename MMV::dual_view_type::t_host::device_type host_mem_space;
2825  typedef typename Graph::local_graph_type k_local_graph_type;
2826  typedef typename k_local_graph_type::size_type offset_type;
2827  const char prefix[] = "Tpetra::CrsMatrix::localGaussSeidel: ";
2828 
2829  TEUCHOS_TEST_FOR_EXCEPTION
2830  (! this->isFillComplete (), std::runtime_error,
2831  prefix << "The matrix is not fill complete.");
2832  const size_t lclNumRows = this->getNodeNumRows ();
2833  const size_t numVecs = B.getNumVectors ();
2834  TEUCHOS_TEST_FOR_EXCEPTION
2835  (X.getNumVectors () != numVecs, std::invalid_argument,
2836  prefix << "B.getNumVectors() = " << numVecs << " != "
2837  "X.getNumVectors() = " << X.getNumVectors () << ".");
2838  TEUCHOS_TEST_FOR_EXCEPTION
2839  (B.getLocalLength () != lclNumRows, std::invalid_argument,
2840  prefix << "B.getLocalLength() = " << B.getLocalLength ()
2841  << " != this->getNodeNumRows() = " << lclNumRows << ".");
2842 
2843  // mfh 28 Aug 2017: The current local Gauss-Seidel kernel only
2844  // runs on host. (See comments below.) Thus, we need to access
2845  // the host versions of these data.
2846  const_cast<DMV&> (B).sync_host ();
2847  X.sync_host ();
2848  X.modify_host ();
2849  const_cast<MMV&> (D).sync_host ();
2850 
2851  auto B_lcl = B.template getLocalView<host_mem_space> ();
2852  auto X_lcl = X.template getLocalView<host_mem_space> ();
2853  auto D_lcl = D.template getLocalView<host_mem_space> ();
2854 
2855  offset_type B_stride[8], X_stride[8], D_stride[8];
2856  B_lcl.stride (B_stride);
2857  X_lcl.stride (X_stride);
2858  D_lcl.stride (D_stride);
2859 
2860  local_matrix_type lclMatrix = this->getLocalMatrix ();
2861  k_local_graph_type lclGraph = lclMatrix.graph;
2862  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
2863  typename local_matrix_type::index_type ind = lclGraph.entries;
2864  typename local_matrix_type::values_type val = lclMatrix.values;
2865  const offset_type* const ptrRaw = ptr.data ();
2866  const LO* const indRaw = ind.data ();
2867  const impl_scalar_type* const valRaw = val.data ();
2868 
2869  const std::string dir ((direction == Forward) ? "F" : "B");
2870  // NOTE (mfh 28 Aug 2017) This assumes UVM. We can't get around
2871  // that on GPUs without using a GPU-based sparse triangular
2872  // solve to implement Gauss-Seidel. This exists in cuSPARSE,
2873  // but we would need to implement a wrapper with a fall-back
2874  // algorithm for unsupported Scalar and LO types.
2875  KokkosSparse::Impl::Sequential::gaussSeidel (static_cast<LO> (lclNumRows),
2876  static_cast<LO> (numVecs),
2877  ptrRaw, indRaw, valRaw,
2878  B_lcl.data (), B_stride[1],
2879  X_lcl.data (), X_stride[1],
2880  D_lcl.data (),
2881  static_cast<impl_scalar_type> (dampingFactor),
2882  dir.c_str ());
2883  const_cast<DMV&> (B).template sync<dev_mem_space> ();
2884  X.template sync<dev_mem_space> ();
2885  const_cast<MMV&> (D).template sync<dev_mem_space> ();
2886  }
2887 
2914  template <class DomainScalar, class RangeScalar>
2915  void
2919  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2920  const RangeScalar& dampingFactor,
2921  const ESweepDirection direction) const
2922  {
2923  typedef LocalOrdinal LO;
2924  typedef GlobalOrdinal GO;
2927  typedef typename Node::device_type::memory_space dev_mem_space;
2928  typedef typename MMV::dual_view_type::t_host::device_type host_mem_space;
2929  typedef typename Graph::local_graph_type k_local_graph_type;
2930  typedef typename k_local_graph_type::size_type offset_type;
2931  const char prefix[] = "Tpetra::CrsMatrix::reorderedLocalGaussSeidel: ";
2932 
2933  TEUCHOS_TEST_FOR_EXCEPTION
2934  (! this->isFillComplete (), std::runtime_error,
2935  prefix << "The matrix is not fill complete.");
2936  const size_t lclNumRows = this->getNodeNumRows ();
2937  const size_t numVecs = B.getNumVectors ();
2938  TEUCHOS_TEST_FOR_EXCEPTION
2939  (X.getNumVectors () != numVecs, std::invalid_argument,
2940  prefix << "B.getNumVectors() = " << numVecs << " != "
2941  "X.getNumVectors() = " << X.getNumVectors () << ".");
2942  TEUCHOS_TEST_FOR_EXCEPTION
2943  (B.getLocalLength () != lclNumRows, std::invalid_argument,
2944  prefix << "B.getLocalLength() = " << B.getLocalLength ()
2945  << " != this->getNodeNumRows() = " << lclNumRows << ".");
2946  TEUCHOS_TEST_FOR_EXCEPTION
2947  (static_cast<size_t> (rowIndices.size ()) < lclNumRows,
2948  std::invalid_argument, prefix << "rowIndices.size() = "
2949  << rowIndices.size () << " < this->getNodeNumRows() = "
2950  << lclNumRows << ".");
2951 
2952  // mfh 28 Aug 2017: The current local Gauss-Seidel kernel only
2953  // runs on host. (See comments below.) Thus, we need to access
2954  // the host versions of these data.
2955  const_cast<DMV&> (B).sync_host ();
2956  X.sync_host ();
2957  X.modify_host ();
2958  const_cast<MMV&> (D).sync_host ();
2959 
2960  auto B_lcl = B.template getLocalView<host_mem_space> ();
2961  auto X_lcl = X.template getLocalView<host_mem_space> ();
2962  auto D_lcl = D.template getLocalView<host_mem_space> ();
2963 
2964  offset_type B_stride[8], X_stride[8], D_stride[8];
2965  B_lcl.stride (B_stride);
2966  X_lcl.stride (X_stride);
2967  D_lcl.stride (D_stride);
2968 
2969  local_matrix_type lclMatrix = this->getLocalMatrix ();
2970  typename Graph::local_graph_type lclGraph = lclMatrix.graph;
2971  typename local_matrix_type::index_type ind = lclGraph.entries;
2972  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
2973  typename local_matrix_type::values_type val = lclMatrix.values;
2974  const offset_type* const ptrRaw = ptr.data ();
2975  const LO* const indRaw = ind.data ();
2976  const impl_scalar_type* const valRaw = val.data ();
2977 
2978  const std::string dir = (direction == Forward) ? "F" : "B";
2979  // NOTE (mfh 28 Aug 2017) This assumes UVM. We can't get around
2980  // that on GPUs without using a GPU-based sparse triangular
2981  // solve to implement Gauss-Seidel, and also handling the
2982  // permutations correctly.
2983  KokkosSparse::Impl::Sequential::reorderedGaussSeidel (static_cast<LO> (lclNumRows),
2984  static_cast<LO> (numVecs),
2985  ptrRaw, indRaw, valRaw,
2986  B_lcl.data (),
2987  B_stride[1],
2988  X_lcl.data (),
2989  X_stride[1],
2990  D_lcl.data (),
2991  rowIndices.getRawPtr (),
2992  static_cast<LO> (lclNumRows),
2993  static_cast<impl_scalar_type> (dampingFactor),
2994  dir.c_str ());
2995  const_cast<DMV&> (B).template sync<dev_mem_space> ();
2996  X.template sync<dev_mem_space> ();
2997  const_cast<MMV&> (D).template sync<dev_mem_space> ();
2998  }
2999 
3002  template <class T>
3003  Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node> >
3004  convert () const;
3005 
3007 
3009 
3020  void
3023  Teuchos::ETransp mode = Teuchos::NO_TRANS,
3024  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
3025  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const override;
3026 
3029  bool hasTransposeApply () const override;
3030 
3037  Teuchos::RCP<const map_type> getDomainMap () const override;
3038 
3045  Teuchos::RCP<const map_type> getRangeMap () const override;
3046 
3048 
3050 
3115  void
3119  const Scalar& dampingFactor,
3120  const ESweepDirection direction,
3121  const int numSweeps) const;
3122 
3189  void
3193  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
3194  const Scalar& dampingFactor,
3195  const ESweepDirection direction,
3196  const int numSweeps) const;
3197 
3226  void
3230  const Scalar& dampingFactor,
3231  const ESweepDirection direction,
3232  const int numSweeps,
3233  const bool zeroInitialGuess) const;
3234 
3264  void
3268  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
3269  const Scalar& dampingFactor,
3270  const ESweepDirection direction,
3271  const int numSweeps,
3272  const bool zeroInitialGuess) const;
3273 
3284  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3285  add (const Scalar& alpha,
3287  const Scalar& beta,
3288  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
3289  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
3290  const Teuchos::RCP<Teuchos::ParameterList>& params) const override;
3291 
3293 
3295 
3297  std::string description () const override;
3298 
3301  void
3302  describe (Teuchos::FancyOStream& out,
3303  const Teuchos::EVerbosityLevel verbLevel =
3304  Teuchos::Describable::verbLevel_default) const override;
3305 
3307 
3309 
3314  typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
3316 
3317  virtual bool
3318  checkSizes (const SrcDistObject& source) override;
3319 
3320  void
3321  applyCrsPadding(
3322  const typename crs_graph_type::padding_type& padding,
3323  const bool verbose);
3324 
3325  private:
3326  void
3327  copyAndPermuteStaticGraph(
3329  const size_t numSameIDs,
3330  const LocalOrdinal permuteToLIDs[],
3331  const LocalOrdinal permuteFromLIDs[],
3332  const size_t numPermutes);
3333 
3334  void
3335  copyAndPermuteNonStaticGraph(
3337  const size_t numSameIDs,
3338  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs_dv,
3339  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs_dv,
3340  const size_t numPermutes);
3341 
3342  protected:
3343  virtual void
3344  copyAndPermute
3345  (const SrcDistObject& source,
3346  const size_t numSameIDs,
3347  const Kokkos::DualView<
3348  const local_ordinal_type*,
3349  buffer_device_type>& permuteToLIDs,
3350  const Kokkos::DualView<
3351  const local_ordinal_type*,
3352  buffer_device_type>& permuteFromLIDs) override;
3353 
3354  virtual void
3355  packAndPrepare
3356  (const SrcDistObject& source,
3357  const Kokkos::DualView<
3358  const local_ordinal_type*,
3359  buffer_device_type>& exportLIDs,
3360  Kokkos::DualView<char*, buffer_device_type>& exports,
3361  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3362  size_t& constantNumPackets,
3363  Distributor& distor) override;
3364 
3365  private:
3368  void
3369  unpackAndCombineImpl(
3370  const Kokkos::DualView<const local_ordinal_type*,
3371  buffer_device_type>& importLIDs,
3372  Kokkos::DualView<char*, buffer_device_type> imports,
3373  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3374  const size_t constantNumPackets,
3375  Distributor& distor,
3376  const CombineMode combineMode,
3377  const bool verbose);
3378 
3381  void
3382  unpackAndCombineImplNonStatic(
3383  const Kokkos::DualView<const local_ordinal_type*,
3384  buffer_device_type>& importLIDs,
3385  Kokkos::DualView<char*, buffer_device_type> imports,
3386  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3387  const size_t constantNumPackets,
3388  Distributor& distor,
3389  const CombineMode combineMode);
3390 
3391  public:
3401  void
3403  (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& importLIDs,
3404  Kokkos::DualView<char*, buffer_device_type> imports,
3405  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3406  const size_t constantNumPackets,
3407  Distributor& distor,
3408  const CombineMode CM) override;
3409 
3517  void
3518  packNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3519  Kokkos::DualView<char*, buffer_device_type>& exports,
3520  const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3521  size_t& constantNumPackets,
3522  Distributor& dist) const;
3523 
3524  private:
3531  void
3532  packNonStaticNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3533  Kokkos::DualView<char*, buffer_device_type>& exports,
3534  const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3535  size_t& constantNumPackets,
3536  Distributor& distor) const;
3537 
3567  size_t
3568  packRow (char exports[],
3569  const size_t offset,
3570  const size_t numEnt,
3571  const GlobalOrdinal gidsIn[],
3572  const impl_scalar_type valsIn[],
3573  const size_t numBytesPerValue) const;
3574 
3598  bool
3599  packRowStatic (char* const numEntOut,
3600  char* const valOut,
3601  char* const indOut,
3602  const size_t numEnt,
3603  const LocalOrdinal lclRow) const;
3604 
3630  size_t
3631  unpackRow (GlobalOrdinal gidsOut[],
3632  impl_scalar_type valsOut[],
3633  const char imports[],
3634  const size_t offset,
3635  const size_t numBytes,
3636  const size_t numEnt,
3637  const size_t numBytesPerValue);
3638 
3647  void
3648  allocatePackSpaceNew (Kokkos::DualView<char*, buffer_device_type>& exports,
3649  size_t& totalNumEntries,
3650  const Kokkos::DualView<const local_ordinal_type*,
3651  buffer_device_type>& exportLIDs) const;
3653 
3654  public:
3656  typename local_matrix_type::values_type getLocalValuesView () const {
3657  return k_values1D_;
3658  }
3659 
3660  private:
3661  // Friend declaration for nonmember function.
3662  template<class CrsMatrixType>
3663  friend Teuchos::RCP<CrsMatrixType>
3664  Tpetra::importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3665  const Import<typename CrsMatrixType::local_ordinal_type,
3666  typename CrsMatrixType::global_ordinal_type,
3667  typename CrsMatrixType::node_type>& importer,
3668  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3669  typename CrsMatrixType::global_ordinal_type,
3670  typename CrsMatrixType::node_type> >& domainMap,
3671  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3672  typename CrsMatrixType::global_ordinal_type,
3673  typename CrsMatrixType::node_type> >& rangeMap,
3674  const Teuchos::RCP<Teuchos::ParameterList>& params);
3675 
3676  // Friend declaration for nonmember function.
3677  template<class CrsMatrixType>
3678  friend Teuchos::RCP<CrsMatrixType>
3679  Tpetra::importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3680  const Import<typename CrsMatrixType::local_ordinal_type,
3681  typename CrsMatrixType::global_ordinal_type,
3682  typename CrsMatrixType::node_type>& rowImporter,
3683  const Import<typename CrsMatrixType::local_ordinal_type,
3684  typename CrsMatrixType::global_ordinal_type,
3685  typename CrsMatrixType::node_type>& domainImporter,
3686  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3687  typename CrsMatrixType::global_ordinal_type,
3688  typename CrsMatrixType::node_type> >& domainMap,
3689  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3690  typename CrsMatrixType::global_ordinal_type,
3691  typename CrsMatrixType::node_type> >& rangeMap,
3692  const Teuchos::RCP<Teuchos::ParameterList>& params);
3693 
3694 
3695  // Friend declaration for nonmember function.
3696  template<class CrsMatrixType>
3697  friend Teuchos::RCP<CrsMatrixType>
3698  Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3699  const Export<typename CrsMatrixType::local_ordinal_type,
3700  typename CrsMatrixType::global_ordinal_type,
3701  typename CrsMatrixType::node_type>& exporter,
3702  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3703  typename CrsMatrixType::global_ordinal_type,
3704  typename CrsMatrixType::node_type> >& domainMap,
3705  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3706  typename CrsMatrixType::global_ordinal_type,
3707  typename CrsMatrixType::node_type> >& rangeMap,
3708  const Teuchos::RCP<Teuchos::ParameterList>& params);
3709 
3710  // Friend declaration for nonmember function.
3711  template<class CrsMatrixType>
3712  friend Teuchos::RCP<CrsMatrixType>
3713  Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3714  const Export<typename CrsMatrixType::local_ordinal_type,
3715  typename CrsMatrixType::global_ordinal_type,
3716  typename CrsMatrixType::node_type>& rowExporter,
3717  const Export<typename CrsMatrixType::local_ordinal_type,
3718  typename CrsMatrixType::global_ordinal_type,
3719  typename CrsMatrixType::node_type>& domainExporter,
3720  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3721  typename CrsMatrixType::global_ordinal_type,
3722  typename CrsMatrixType::node_type> >& domainMap,
3723  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3724  typename CrsMatrixType::global_ordinal_type,
3725  typename CrsMatrixType::node_type> >& rangeMap,
3726  const Teuchos::RCP<Teuchos::ParameterList>& params);
3727 
3728  public:
3744  void
3746  const import_type& importer,
3747  const Teuchos::RCP<const map_type>& domainMap,
3748  const Teuchos::RCP<const map_type>& rangeMap,
3749  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3750 
3766  void
3768  const import_type& rowImporter,
3769  const import_type& domainImporter,
3770  const Teuchos::RCP<const map_type>& domainMap,
3771  const Teuchos::RCP<const map_type>& rangeMap,
3772  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3773 
3774 
3790  void
3792  const export_type& exporter,
3793  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3794  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3795  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3796 
3812  void
3814  const export_type& rowExporter,
3815  const export_type& domainExporter,
3816  const Teuchos::RCP<const map_type>& domainMap,
3817  const Teuchos::RCP<const map_type>& rangeMap,
3818  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3819 
3820 
3821  private:
3842  void
3843  transferAndFillComplete (Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& destMatrix,
3844  const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3845  const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > & domainTransfer,
3846  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3847  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3848  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3849 
3861  void
3862  insertGlobalValuesImpl (crs_graph_type& graph,
3863  RowInfo& rowInfo,
3864  const GlobalOrdinal gblColInds[],
3865  const impl_scalar_type vals[],
3866  const size_t numInputEnt);
3867 
3877  void
3878  insertGlobalValuesFiltered(
3879  const GlobalOrdinal globalRow,
3880  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3881  const Teuchos::ArrayView<const Scalar>& values,
3882  const bool debug);
3883 
3886  void
3887  insertGlobalValuesFilteredChecked(
3888  const GlobalOrdinal globalRow,
3889  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3890  const Teuchos::ArrayView<const Scalar>& values,
3891  const char* const prefix,
3892  const bool debug,
3893  const bool verbose);
3894 
3906  void
3907  combineGlobalValues(
3908  const GlobalOrdinal globalRowIndex,
3909  const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3910  const Teuchos::ArrayView<const Scalar>& values,
3911  const Tpetra::CombineMode combineMode,
3912  const char* const prefix,
3913  const bool debug,
3914  const bool verbose);
3915 
3937  LocalOrdinal
3938  combineGlobalValuesRaw(const LocalOrdinal lclRow,
3939  const LocalOrdinal numEnt,
3940  const impl_scalar_type vals[],
3941  const GlobalOrdinal cols[],
3942  const Tpetra::CombineMode combineMode,
3943  const char* const prefix,
3944  const bool debug,
3945  const bool verbose);
3946 
3958  template<class BinaryFunction>
3959  LocalOrdinal
3960  transformGlobalValues (const GlobalOrdinal globalRow,
3961  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3962  const Teuchos::ArrayView<const Scalar>& values,
3963  BinaryFunction f,
3964  const bool atomic = useAtomicUpdatesByDefault) const
3965  {
3966  typedef impl_scalar_type IST;
3967  typedef LocalOrdinal LO;
3968  typedef GlobalOrdinal GO;
3969 
3970  const LO numInputEnt = static_cast<LO> (indices.size ());
3971  if (static_cast<LO> (values.size ()) != numInputEnt) {
3972  return Teuchos::OrdinalTraits<LO>::invalid ();
3973  }
3974 
3975  const GO* const inputCols = indices.getRawPtr ();
3976  const IST* const inputVals =
3977  reinterpret_cast<const IST*> (values.getRawPtr ());
3978  return this->transformGlobalValues (globalRow, numInputEnt, inputVals,
3979  inputCols, f, atomic);
3980  }
3981 
3988  void
3989  insertNonownedGlobalValues (const GlobalOrdinal globalRow,
3990  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3991  const Teuchos::ArrayView<const Scalar>& values);
3992 
4035  void
4036  insertIndicesAndValues (crs_graph_type& graph,
4037  RowInfo& rowInfo,
4038  const typename crs_graph_type::SLocalGlobalViews& newInds,
4039  const Teuchos::ArrayView<impl_scalar_type>& oldRowVals,
4040  const Teuchos::ArrayView<const impl_scalar_type>& newRowVals,
4041  const ELocalGlobal lg,
4042  const ELocalGlobal I);
4043 
4045  typedef DistObject<char, LocalOrdinal, GlobalOrdinal, Node> dist_object_type;
4046 
4047  protected:
4048  // useful typedefs
4049  typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
4050  typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
4051  typedef Kokkos::Details::ArithTraits<mag_type> STM;
4052  typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> MV;
4053  typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
4054  typedef crs_graph_type Graph;
4055 
4056  // Enums
4057  enum GraphAllocationStatus {
4058  GraphAlreadyAllocated,
4059  GraphNotYetAllocated
4060  };
4061 
4062  protected:
4081  void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas,
4082  const bool verbose);
4083 
4093  size_t
4095  const RowInfo& rowInfo);
4096 
4111  void
4112  sortAndMergeIndicesAndValues (const bool sorted,
4113  const bool merged);
4114 
4122  void clearGlobalConstants();
4123 
4131  public:
4133  void computeGlobalConstants();
4135  bool haveGlobalConstants() const;
4136  protected:
4149  mutable Teuchos::RCP<MV> importMV_;
4150 
4163  mutable Teuchos::RCP<MV> exportMV_;
4164 
4184  Teuchos::RCP<MV>
4185  getColumnMapMultiVector (const MV& X_domainMap,
4186  const bool force = false) const;
4187 
4209  Teuchos::RCP<MV>
4210  getRowMapMultiVector (const MV& Y_rangeMap,
4211  const bool force = false) const;
4212 
4214  void
4215  applyNonTranspose (const MV& X_in,
4216  MV& Y_in,
4217  Scalar alpha,
4218  Scalar beta) const;
4219 
4221  void
4222  applyTranspose (const MV& X_in,
4223  MV& Y_in,
4224  const Teuchos::ETransp mode,
4225  Scalar alpha,
4226  Scalar beta) const;
4227 
4228  // matrix data accessors
4229 
4248  LocalOrdinal
4249  getViewRawConst (const impl_scalar_type*& vals,
4250  LocalOrdinal& numEnt,
4251  const RowInfo& rowinfo) const;
4252 
4271  LocalOrdinal
4272  getViewRaw (impl_scalar_type*& vals,
4273  LocalOrdinal& numEnt,
4274  const RowInfo& rowinfo) const;
4275 
4283  Teuchos::ArrayView<const impl_scalar_type> getView (RowInfo rowinfo) const;
4284 
4296  Teuchos::ArrayView<impl_scalar_type>
4297  getViewNonConst (const RowInfo& rowinfo) const;
4298 
4299  private:
4307  Kokkos::View<const impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
4308  getRowView (const RowInfo& rowInfo) const;
4309 
4321  Kokkos::View<impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
4322  getRowViewNonConst (const RowInfo& rowInfo) const;
4323 
4324 
4325  protected:
4326 
4327  // Friend the tester for CrsMatrix::swap
4328  friend class Tpetra::crsMatrix_Swap_Tester<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
4329 
4334 
4335 
4336  protected:
4337 
4343  void fillLocalMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4344 
4350  void fillLocalGraphAndMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4351 
4353  void checkInternalState () const;
4354 
4366 
4367  Teuchos::RCP<const Graph> staticGraph_;
4368  Teuchos::RCP< Graph> myGraph_;
4370 
4372  std::shared_ptr<local_multiply_op_type> lclMatrix_;
4373 
4378  typename local_matrix_type::values_type k_values1D_;
4379 
4390  Details::STORAGE_1D_UNPACKED;
4391 
4393  bool fillComplete_ = false;
4394 
4422  std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
4423  Teuchos::Array<Scalar> > > nonlocals_;
4424 
4430  mutable mag_type frobNorm_ = -STM::one();
4431 
4432  public:
4433  // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
4434  // public inner class of CrsMatrix? It looks like it doesn't
4435  // depend on any implementation details of CrsMatrix at all. It
4436  // should really be declared and defined outside of CrsMatrix.
4437  template<class ViewType, class OffsetViewType>
4438  struct pack_functor {
4439  typedef typename ViewType::execution_space execution_space;
4440  ViewType src_;
4441  ViewType dst_;
4442  OffsetViewType src_offset_;
4443  OffsetViewType dst_offset_;
4444  typedef typename OffsetViewType::non_const_value_type scalar_index_type;
4445 
4446  pack_functor (ViewType dst, ViewType src,
4447  OffsetViewType dst_offset, OffsetViewType src_offset) :
4448  src_ (src),
4449  dst_ (dst),
4450  src_offset_ (src_offset),
4451  dst_offset_ (dst_offset)
4452  {}
4453 
4454  KOKKOS_INLINE_FUNCTION
4455  void operator () (const LocalOrdinal row) const {
4456  scalar_index_type srcPos = src_offset_(row);
4457  const scalar_index_type dstEnd = dst_offset_(row+1);
4458  scalar_index_type dstPos = dst_offset_(row);
4459  for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
4460  dst_(dstPos) = src_(srcPos);
4461  }
4462  }
4463  };
4464  }; // class CrsMatrix
4465 
4470  template<class Scalar,
4471  class LocalOrdinal,
4472  class GlobalOrdinal,
4473  class Node>
4474  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
4476  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
4477  const size_t maxNumEntriesPerRow = 0,
4478  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4479  {
4480  using matrix_type =
4482  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE;
4483  return Teuchos::rcp(new matrix_type(map, maxNumEntriesPerRow,
4484  pftype, params));
4485  }
4486 
4487  template<class CrsMatrixType>
4488  Teuchos::RCP<CrsMatrixType>
4489  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4490  const Import<typename CrsMatrixType::local_ordinal_type,
4491  typename CrsMatrixType::global_ordinal_type,
4492  typename CrsMatrixType::node_type>& importer,
4493  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4494  typename CrsMatrixType::global_ordinal_type,
4495  typename CrsMatrixType::node_type> >& domainMap,
4496  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4497  typename CrsMatrixType::global_ordinal_type,
4498  typename CrsMatrixType::node_type> >& rangeMap,
4499  const Teuchos::RCP<Teuchos::ParameterList>& params)
4500  {
4501  Teuchos::RCP<CrsMatrixType> destMatrix;
4502  sourceMatrix->importAndFillComplete (destMatrix, importer, domainMap, rangeMap, params);
4503  return destMatrix;
4504  }
4505 
4506  template<class CrsMatrixType>
4507  Teuchos::RCP<CrsMatrixType>
4508  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4509  const Import<typename CrsMatrixType::local_ordinal_type,
4510  typename CrsMatrixType::global_ordinal_type,
4511  typename CrsMatrixType::node_type>& rowImporter,
4512  const Import<typename CrsMatrixType::local_ordinal_type,
4513  typename CrsMatrixType::global_ordinal_type,
4514  typename CrsMatrixType::node_type>& domainImporter,
4515  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4516  typename CrsMatrixType::global_ordinal_type,
4517  typename CrsMatrixType::node_type> >& domainMap,
4518  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4519  typename CrsMatrixType::global_ordinal_type,
4520  typename CrsMatrixType::node_type> >& rangeMap,
4521  const Teuchos::RCP<Teuchos::ParameterList>& params)
4522  {
4523  Teuchos::RCP<CrsMatrixType> destMatrix;
4524  sourceMatrix->importAndFillComplete (destMatrix, rowImporter, domainImporter, domainMap, rangeMap, params);
4525  return destMatrix;
4526  }
4527 
4528  template<class CrsMatrixType>
4529  Teuchos::RCP<CrsMatrixType>
4530  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4531  const Export<typename CrsMatrixType::local_ordinal_type,
4532  typename CrsMatrixType::global_ordinal_type,
4533  typename CrsMatrixType::node_type>& exporter,
4534  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4535  typename CrsMatrixType::global_ordinal_type,
4536  typename CrsMatrixType::node_type> >& domainMap,
4537  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4538  typename CrsMatrixType::global_ordinal_type,
4539  typename CrsMatrixType::node_type> >& rangeMap,
4540  const Teuchos::RCP<Teuchos::ParameterList>& params)
4541  {
4542  Teuchos::RCP<CrsMatrixType> destMatrix;
4543  sourceMatrix->exportAndFillComplete (destMatrix, exporter, domainMap, rangeMap, params);
4544  return destMatrix;
4545  }
4546 
4547  template<class CrsMatrixType>
4548  Teuchos::RCP<CrsMatrixType>
4549  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4550  const Export<typename CrsMatrixType::local_ordinal_type,
4551  typename CrsMatrixType::global_ordinal_type,
4552  typename CrsMatrixType::node_type>& rowExporter,
4553  const Export<typename CrsMatrixType::local_ordinal_type,
4554  typename CrsMatrixType::global_ordinal_type,
4555  typename CrsMatrixType::node_type>& domainExporter,
4556  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4557  typename CrsMatrixType::global_ordinal_type,
4558  typename CrsMatrixType::node_type> >& domainMap,
4559  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4560  typename CrsMatrixType::global_ordinal_type,
4561  typename CrsMatrixType::node_type> >& rangeMap,
4562  const Teuchos::RCP<Teuchos::ParameterList>& params)
4563  {
4564  Teuchos::RCP<CrsMatrixType> destMatrix;
4565  sourceMatrix->exportAndFillComplete (destMatrix, rowExporter, domainExporter, domainMap, rangeMap, params);
4566  return destMatrix;
4567  }
4568 
4569 } // namespace Tpetra
4570 
4578 #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...
size_t getNodeNumCols() const override
The number of columns connected to the locally owned rows of this matrix.
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 bool supportsRowViews() const override
Return true if getLocalRowView() and getGlobalRowView() are valid for this object.
LocalOrdinal getViewRaw(impl_scalar_type *&vals, LocalOrdinal &numEnt, const RowInfo &rowinfo) const
Nonconst pointer to all entries (including extra space) in the given row.
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.
Kokkos::StaticCrsGraph< local_ordinal_type, Kokkos::LayoutLeft, device_type > local_graph_type
The type of the part of the sparse graph on each MPI process.
std::enable_if<!std::is_same< OutputScalarType, impl_scalar_type >::value &&std::is_convertible< impl_scalar_type, OutputScalarType >::value, LocalOrdinal >::type getLocalRowView(const LocalOrdinal lclRow, LocalOrdinal &numEnt, const OutputScalarType *&val, const LocalOrdinal *&ind) const
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_type::size_type > local_matrix_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
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 getLocalRowCopy(LocalOrdinal localRow, const Teuchos::ArrayView< LocalOrdinal > &colInds, const Teuchos::ArrayView< Scalar > &vals, size_t &numEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row...
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
size_t getNumVectors() const
Number of columns in the multivector.
size_t getLocalLength() const
Local number of rows on the calling process.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
One or more distributed dense vectors.
size_t getNodeNumEntries() const override
The local number of entries in this matrix.
void scale(const Scalar &alpha)
Scale the matrix&#39;s values: this := alpha*this.
size_t getNodeNumRows() const override
The number of matrix rows owned by the calling process.
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...
virtual ~CrsMatrix()=default
Destructor (virtual for memory safety of derived classes).
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, Distributor &distor, const CombineMode CM) override
Unpack the imported column indices and values, and combine into matrix.
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.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const Teuchos::ArrayView< GlobalOrdinal > &Indices, const Teuchos::ArrayView< Scalar > &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 crs_graph_type > getCrsGraph() const
This matrix&#39;s graph, as a CrsGraph.
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.
void globalAssemble()
Communicate nonlocal contributions to other processes.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const override
Get a copy of the diagonal entries of the matrix.
std::shared_ptr< local_multiply_op_type > lclMatrix_
The local sparse matrix, wrapped in a multiply operator.
void gaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
&quot;Hybrid&quot; Jacobi + (Gauss-Seidel or SOR) on .
bool isFillActive() const
Whether the matrix is not fill complete.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply() and gaussSeidel().
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
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.
void clearGlobalConstants()
Clear matrix properties that require collectives.
void gaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of gaussSeidel(), with fewer requirements on X.
LocalOrdinal getLocalRowViewRaw(const LocalOrdinal lclRow, LocalOrdinal &numEnt, const LocalOrdinal *&lclColInds, const Scalar *&vals) const override
Get a constant, nonpersisting, locally indexed view of the given row of the matrix, using &quot;raw&quot; pointers instead of Teuchos::ArrayView.
LocalOrdinal transformLocalValues(const LocalOrdinal lclRow, const typename UnmanagedView< LocalIndicesViewType >::type &inputInds, const typename UnmanagedView< ImplScalarViewType >::type &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault) const
Transform CrsMatrix entries in place, using local indices to select the entries in the row to transfo...
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.
local_matrix_type::values_type k_values1D_
Sparse matrix values, as part of compressed sparse row (&quot;1-D&quot;) storage.
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 sync_host()
Synchronize to Host.
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.
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) const
Replace one or more entries&#39; values, using global indices.
Abstract interface for operators (e.g., matrices and preconditioners).
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, Distributor &dist) const
Pack this object&#39;s data for an Import or Export.
void reorderedGaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of reorderedGaussSeidel(), with fewer requirements on X.
ESweepDirection
Sweep direction for Gauss-Seidel or Successive Over-Relaxation (SOR).
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) const
Replace one or more entries&#39; values, using local row and column indices.
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...
typename crs_graph_type::local_graph_type local_graph_type
The part of the sparse matrix&#39;s graph on each 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...
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...
Sets up and executes a communication plan for a Tpetra DistObject.
mag_type frobNorm_
Cached Frobenius norm of the (global) matrix.
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.
DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
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.
void localGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const RangeScalar &dampingFactor, const ESweepDirection direction) const
Gauss-Seidel or SOR on .
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 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) const
Sum into one or more sparse matrix entries, using local row and column indices.
Abstract base class for objects that can be the source of an Import or Export operation.
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.
void computeGlobalConstants()
Compute matrix properties that require collectives.
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.
void modify_host()
Mark data as modified on the host side.
local_matrix_type::values_type getLocalValuesView() const
Get the Kokkos local values.
ProfileType getProfileType() const
Returns true if the matrix was allocated with static data structures.
void getGlobalRowView(GlobalOrdinal GlobalRow, Teuchos::ArrayView< const GlobalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const override
Get a constant, nonpersisting view of a row of this matrix, using global row and column indices...
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) const
Transform CrsMatrix entries in place, using global indices to select the entries in the row to transf...
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.
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.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
A parallel distribution of indices over processes.
Teuchos::RCP< const map_type > getDomainMap() const override
The domain Map of this matrix.
Teuchos::ArrayView< const impl_scalar_type > getView(RowInfo rowinfo) const
Constant view of all entries (including extra space) in the given row.
void setAllValues(const typename local_matrix_type::row_map_type &ptr, const typename local_graph_type::entries_type::non_const_type &ind, const typename local_matrix_type::values_type &val)
Set the local matrix using three (compressed sparse row) arrays.
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_matrix_type getLocalMatrix() const
The local sparse matrix.
void getLocalRowView(LocalOrdinal LocalRow, Teuchos::ArrayView< const LocalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const override
Get a constant, nonpersisting view of a row of this matrix, using local row and column indices...
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the right with the given Vector.
size_t getNodeMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, on this process.
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.
size_t mergeRowIndicesAndValues(crs_graph_type &graph, const RowInfo &rowInfo)
Merge duplicate row indices in the given row, along with their corresponding values.
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.
void reorderedGaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
Reordered &quot;Hybrid&quot; Jacobi + (Gauss-Seidel or SOR) on .
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.
Teuchos::ArrayView< impl_scalar_type > getViewNonConst(const RowInfo &rowinfo) const
Nonconst view of all entries (including extra space) in the given row.
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 getLocalMatrix() that supports local matrix-vector mul...
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.
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.
void reorderedLocalGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const RangeScalar &dampingFactor, const ESweepDirection direction) const
Reordered Gauss-Seidel or SOR on .
LocalOrdinal getViewRawConst(const impl_scalar_type *&vals, LocalOrdinal &numEnt, const RowInfo &rowinfo) const
Const pointer to all entries (including extra space) in the given row.
bool isStorageOptimized() const
Returns true if storage has been optimized.
Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization suitable for this CrsMatrix specialization.
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
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.