Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
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#ifndef TPETRA_CRSMATRIX_DECL_HPP
11#define TPETRA_CRSMATRIX_DECL_HPP
12
15
18#include "KokkosSparse_Utils.hpp"
19#include "KokkosSparse_CrsMatrix.hpp"
20#include "Tpetra_Details_MatrixApplyHelper.hpp"
21#include "Tpetra_RowMatrix_decl.hpp"
22#include "Tpetra_Exceptions.hpp"
23#include "Tpetra_DistObject.hpp"
24#include "Tpetra_CrsGraph.hpp"
25#include "Tpetra_Vector.hpp"
26#include "Tpetra_Details_PackTraits.hpp" // unused here, could delete
27#include "Tpetra_Details_ExecutionSpacesUser.hpp"
28#include "Teuchos_DataAccess.hpp"
29
30#include <memory> // std::shared_ptr
31
32namespace Tpetra {
33
34// Forward declaration for CrsMatrix::swap() test
35template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
36class crsMatrix_Swap_Tester;
37
89template <class CrsMatrixType>
90Teuchos::RCP<CrsMatrixType>
91importAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
92 const Import<typename CrsMatrixType::local_ordinal_type,
93 typename CrsMatrixType::global_ordinal_type,
94 typename CrsMatrixType::node_type>& importer,
95 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
96 typename CrsMatrixType::global_ordinal_type,
97 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
98 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
99 typename CrsMatrixType::global_ordinal_type,
100 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
101 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
102
156template <class CrsMatrixType>
157Teuchos::RCP<CrsMatrixType>
158importAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
159 const Import<typename CrsMatrixType::local_ordinal_type,
160 typename CrsMatrixType::global_ordinal_type,
161 typename CrsMatrixType::node_type>& rowImporter,
162 const Import<typename CrsMatrixType::local_ordinal_type,
163 typename CrsMatrixType::global_ordinal_type,
164 typename CrsMatrixType::node_type>& domainImporter,
165 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
166 typename CrsMatrixType::global_ordinal_type,
167 typename CrsMatrixType::node_type> >& domainMap,
168 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
169 typename CrsMatrixType::global_ordinal_type,
170 typename CrsMatrixType::node_type> >& rangeMap,
171 const Teuchos::RCP<Teuchos::ParameterList>& params);
172
206template <class CrsMatrixType>
207Teuchos::RCP<CrsMatrixType>
208exportAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
209 const Export<typename CrsMatrixType::local_ordinal_type,
210 typename CrsMatrixType::global_ordinal_type,
211 typename CrsMatrixType::node_type>& exporter,
212 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
213 typename CrsMatrixType::global_ordinal_type,
214 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
215 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
216 typename CrsMatrixType::global_ordinal_type,
217 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
218 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
219
253template <class CrsMatrixType>
254Teuchos::RCP<CrsMatrixType>
255exportAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
256 const Export<typename CrsMatrixType::local_ordinal_type,
257 typename CrsMatrixType::global_ordinal_type,
258 typename CrsMatrixType::node_type>& rowExporter,
259 const Export<typename CrsMatrixType::local_ordinal_type,
260 typename CrsMatrixType::global_ordinal_type,
261 typename CrsMatrixType::node_type>& domainExporter,
262 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
263 typename CrsMatrixType::global_ordinal_type,
264 typename CrsMatrixType::node_type> >& domainMap,
265 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
266 typename CrsMatrixType::global_ordinal_type,
267 typename CrsMatrixType::node_type> >& rangeMap,
268 const Teuchos::RCP<Teuchos::ParameterList>& params);
269
272namespace Details {
273template <class SC, class LO, class GO, class NO>
278}
279
393template <class Scalar,
394 class LocalOrdinal,
395 class GlobalOrdinal,
396 class Node>
397class CrsMatrix : public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
398 public DistObject<char, LocalOrdinal, GlobalOrdinal, Node>,
399 public Details::Spaces::User {
400 private:
401 using dist_object_type =
403 Node>;
405
406 public:
408
409
417 using device_type = typename Node::device_type;
419 using execution_space = typename device_type::execution_space;
421 using memory_space = typename device_type::memory_space;
422
427 using node_type = Node;
428
431
434
437
440
456 using mag_type = typename KokkosKernels::ArithTraits<impl_scalar_type>::mag_type;
457
460
463 using local_graph_host_type = typename crs_graph_type::local_graph_host_type;
464
468 KokkosSparse::CrsMatrix<impl_scalar_type,
471 void,
472 typename local_graph_device_type::size_type>;
473 using local_matrix_host_type =
474 typename local_matrix_device_type::host_mirror_type;
475
476 using row_ptrs_device_view_type =
477 typename row_matrix_type::row_ptrs_device_view_type;
478 using row_ptrs_host_view_type =
479 typename row_matrix_type::row_ptrs_host_view_type;
480
481 using local_inds_device_view_type =
482 typename row_matrix_type::local_inds_device_view_type;
483 using local_inds_host_view_type =
484 typename row_matrix_type::local_inds_host_view_type;
485 using nonconst_local_inds_host_view_type =
486 typename row_matrix_type::nonconst_local_inds_host_view_type;
487
488 using global_inds_device_view_type =
489 typename row_matrix_type::global_inds_device_view_type;
490 using global_inds_host_view_type =
491 typename row_matrix_type::global_inds_host_view_type;
492 using nonconst_global_inds_host_view_type =
493 typename row_matrix_type::nonconst_global_inds_host_view_type;
494
495 using values_device_view_type =
496 typename row_matrix_type::values_device_view_type;
497 using values_host_view_type =
498 typename row_matrix_type::values_host_view_type;
499 using nonconst_values_host_view_type =
500 typename row_matrix_type::nonconst_values_host_view_type;
501
503
505
508 GlobalOrdinal, Node>&) = default;
509
512 GlobalOrdinal, Node>&&) = default;
513
515 CrsMatrix&
517 GlobalOrdinal, Node>&) = default;
518
520 CrsMatrix&
522 GlobalOrdinal, Node>&&) = default;
523
537 CrsMatrix(const Teuchos::RCP<const map_type>& rowMap,
538 const size_t maxNumEntriesPerRow,
539 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
540
553 CrsMatrix(const Teuchos::RCP<const map_type>& rowMap,
554 const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
555 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
556
575 CrsMatrix(const Teuchos::RCP<const map_type>& rowMap,
576 const Teuchos::RCP<const map_type>& colMap,
577 const size_t maxNumEntPerRow,
578 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
579
598 CrsMatrix(const Teuchos::RCP<const map_type>& rowMap,
599 const Teuchos::RCP<const map_type>& colMap,
600 const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
601 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
602
632 const Teuchos::RCP<const crs_graph_type>& graph,
633 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
634
659 explicit CrsMatrix(const Teuchos::RCP<const crs_graph_type>& graph,
660 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
661
690 explicit CrsMatrix(const Teuchos::RCP<const crs_graph_type>& graph,
691 const typename local_matrix_device_type::values_type& values,
692 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
693
720 CrsMatrix(const Teuchos::RCP<const map_type>& rowMap,
721 const Teuchos::RCP<const map_type>& colMap,
722 const typename local_graph_device_type::row_map_type& rowPointers,
723 const typename local_graph_device_type::entries_type::non_const_type& columnIndices,
724 const typename local_matrix_device_type::values_type& values,
725 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
726
753 CrsMatrix(const Teuchos::RCP<const map_type>& rowMap,
754 const Teuchos::RCP<const map_type>& colMap,
755 const Teuchos::ArrayRCP<size_t>& rowPointers,
756 const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
757 const Teuchos::ArrayRCP<Scalar>& values,
758 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
759
781 CrsMatrix(const Teuchos::RCP<const map_type>& rowMap,
782 const Teuchos::RCP<const map_type>& colMap,
784 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
785
817 const Teuchos::RCP<const map_type>& rowMap,
818 const Teuchos::RCP<const map_type>& colMap,
819 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
820 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
821 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
822
835 const Teuchos::RCP<const map_type>& rowMap,
836 const Teuchos::RCP<const map_type>& colMap,
837 const Teuchos::RCP<const map_type>& domainMap,
838 const Teuchos::RCP<const map_type>& rangeMap,
839 const Teuchos::RCP<const import_type>& importer,
840 const Teuchos::RCP<const export_type>& exporter,
841 const Teuchos::RCP<Teuchos::ParameterList>& params =
842 Teuchos::null);
843
845 // This function in 'Copy' mode is only guaranteed to work correctly for matrices
846 // which are fillComplete.
848 const Teuchos::DataAccess copyOrView);
849
859 virtual ~CrsMatrix() = default;
860
861 // This friend declaration makes the clone() method work.
862 template <class S2, class LO2, class GO2, class N2>
863 friend class CrsMatrix;
864
865 // This friend declaration allows for fused residual calculation
866 template <class S2, class LO2, class GO2, class N2>
871
872 // This friend declaration allows for batching of apply calls
873 template <class MatrixArray, class MultiVectorArray>
874 friend void batchedApply(const MatrixArray& Matrices,
875 const typename std::remove_pointer<typename MultiVectorArray::value_type>::type& X,
877 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type alpha,
878 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type beta,
879 Teuchos::RCP<Teuchos::ParameterList> params);
880
881 public:
883
885
909 //
951 void
953 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
954 const Teuchos::ArrayView<const Scalar>& vals);
955
970 void
972 const LocalOrdinal numEnt,
973 const Scalar vals[],
974 const GlobalOrdinal inds[]);
975
1018 void
1019 insertLocalValues(const LocalOrdinal localRow,
1020 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1021 const Teuchos::ArrayView<const Scalar>& vals,
1022 const CombineMode CM = ADD);
1023
1043 void
1044 insertLocalValues(const LocalOrdinal localRow,
1045 const LocalOrdinal numEnt,
1046 const Scalar vals[],
1047 const LocalOrdinal cols[],
1048 const CombineMode CM = ADD);
1049
1050 protected:
1062 virtual LocalOrdinal
1064 const crs_graph_type& graph,
1065 const RowInfo& rowInfo,
1066 const GlobalOrdinal inds[],
1067 const impl_scalar_type newVals[],
1068 const LocalOrdinal numElts);
1069
1070 public:
1110 const Kokkos::View<const global_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1111 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1112
1117 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1118 const Teuchos::ArrayView<const Scalar>& vals);
1119
1136 const LocalOrdinal numEnt,
1137 const Scalar vals[],
1138 const GlobalOrdinal cols[]);
1139
1140 protected:
1152 virtual LocalOrdinal
1154 const crs_graph_type& graph,
1155 const RowInfo& rowInfo,
1156 const LocalOrdinal inds[],
1157 const impl_scalar_type newVals[],
1158 const LocalOrdinal numElts);
1159
1160 public:
1198 const local_ordinal_type localRow,
1199 const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1200 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1201
1206 replaceLocalValues(const LocalOrdinal localRow,
1207 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1208 const Teuchos::ArrayView<const Scalar>& vals);
1209
1228 replaceLocalValues(const LocalOrdinal localRow,
1229 const LocalOrdinal numEnt,
1230 const Scalar inputVals[],
1231 const LocalOrdinal inputCols[]);
1232
1233 private:
1238 static const bool useAtomicUpdatesByDefault =
1239#ifdef KOKKOS_ENABLE_SERIAL
1240 !std::is_same<execution_space, Kokkos::Serial>::value;
1241#else
1242 true;
1243#endif // KOKKOS_ENABLE_SERIAL
1244
1270 protected:
1271 virtual LocalOrdinal
1273 const crs_graph_type& graph,
1274 const RowInfo& rowInfo,
1275 const GlobalOrdinal inds[],
1276 const impl_scalar_type newVals[],
1277 const LocalOrdinal numElts,
1278 const bool atomic = useAtomicUpdatesByDefault);
1279
1280 public:
1319 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1320 const Teuchos::ArrayView<const Scalar>& vals,
1321 const bool atomic = useAtomicUpdatesByDefault);
1322
1347 const LocalOrdinal numEnt,
1348 const Scalar vals[],
1349 const GlobalOrdinal cols[],
1350 const bool atomic = useAtomicUpdatesByDefault);
1351
1352 protected:
1366 virtual LocalOrdinal
1368 const crs_graph_type& graph,
1369 const RowInfo& rowInfo,
1370 const LocalOrdinal inds[],
1371 const impl_scalar_type newVals[],
1372 const LocalOrdinal numElts,
1373 const bool atomic = useAtomicUpdatesByDefault);
1374
1375 public:
1414 const local_ordinal_type localRow,
1415 const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1416 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals,
1417 const bool atomic = useAtomicUpdatesByDefault);
1418
1449 sumIntoLocalValues(const LocalOrdinal localRow,
1450 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1451 const Teuchos::ArrayView<const Scalar>& vals,
1452 const bool atomic = useAtomicUpdatesByDefault);
1453
1476 sumIntoLocalValues(const LocalOrdinal localRow,
1477 const LocalOrdinal numEnt,
1478 const Scalar vals[],
1479 const LocalOrdinal cols[],
1480 const bool atomic = useAtomicUpdatesByDefault);
1481
1482 private:
1514 transformLocalValues(impl_scalar_type rowVals[],
1515 const crs_graph_type& graph,
1516 const RowInfo& rowInfo,
1517 const LocalOrdinal inds[],
1518 const impl_scalar_type newVals[],
1519 const LocalOrdinal numElts,
1520 std::function<impl_scalar_type(const impl_scalar_type&, const impl_scalar_type&)> f,
1521 const bool atomic = useAtomicUpdatesByDefault);
1522
1554 transformGlobalValues(impl_scalar_type rowVals[],
1555 const crs_graph_type& graph,
1556 const RowInfo& rowInfo,
1557 const GlobalOrdinal inds[],
1558 const impl_scalar_type newVals[],
1559 const LocalOrdinal numElts,
1560 std::function<impl_scalar_type(const impl_scalar_type&, const impl_scalar_type&)> f,
1561 const bool atomic = useAtomicUpdatesByDefault);
1562
1590 transformLocalValues(const LocalOrdinal lclRow,
1593 const LocalOrdinal inputCols[],
1594 std::function<impl_scalar_type(const impl_scalar_type&, const impl_scalar_type&)> f,
1595 const bool atomic = useAtomicUpdatesByDefault);
1596
1624 transformGlobalValues(const GlobalOrdinal gblRow,
1627 const GlobalOrdinal inputCols[],
1628 std::function<impl_scalar_type(const impl_scalar_type&, const impl_scalar_type&)> f,
1629 const bool atomic = useAtomicUpdatesByDefault);
1630
1631 public:
1675 template <class LocalIndicesViewType,
1676 class ImplScalarViewType,
1677 class BinaryFunction>
1680 const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1681 const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1683 const bool atomic = useAtomicUpdatesByDefault) {
1684 // We use static_assert here to check the template parameters,
1685 // rather than std::enable_if (e.g., on the return value, to
1686 // enable compilation only if the template parameters match the
1687 // desired attributes). This turns obscure link errors into
1688 // clear compilation errors. It also makes the return value a
1689 // lot easier to see.
1690 static_assert(Kokkos::is_view<LocalIndicesViewType>::value,
1691 "First template parameter LocalIndicesViewType must be "
1692 "a Kokkos::View.");
1693 static_assert(Kokkos::is_view<ImplScalarViewType>::value,
1694 "Second template parameter ImplScalarViewType must be a "
1695 "Kokkos::View.");
1696 static_assert(static_cast<int>(LocalIndicesViewType::rank) == 1,
1697 "First template parameter LocalIndicesViewType must "
1698 "have rank 1.");
1699 static_assert(static_cast<int>(ImplScalarViewType::rank) == 1,
1700 "Second template parameter ImplScalarViewType must have "
1701 "rank 1.");
1702 static_assert(std::is_same<
1703 typename LocalIndicesViewType::non_const_value_type,
1704 local_ordinal_type>::value,
1705 "First template parameter LocalIndicesViewType must "
1706 "contain values of type local_ordinal_type.");
1707 static_assert(std::is_same<
1708 typename ImplScalarViewType::non_const_value_type,
1709 impl_scalar_type>::value,
1710 "Second template parameter ImplScalarViewType must "
1711 "contain values of type impl_scalar_type.");
1712 typedef LocalOrdinal LO;
1713 const LO numInputEnt = inputInds.extent(0);
1714 if (static_cast<LO>(inputVals.extent(0)) != numInputEnt) {
1715 return Teuchos::OrdinalTraits<LO>::invalid();
1716 }
1717 return this->transformLocalValues(lclRow,
1719 inputVals.data(),
1720 inputInds.data(),
1721 f,
1722 atomic);
1723 }
1724
1766 template <class BinaryFunction, class InputMemorySpace>
1769 const Kokkos::View<const GlobalOrdinal*,
1771 Kokkos::MemoryUnmanaged>& inputInds,
1772 const Kokkos::View<const impl_scalar_type*,
1774 Kokkos::MemoryUnmanaged>& inputVals,
1776 const bool atomic = useAtomicUpdatesByDefault) {
1777 typedef LocalOrdinal LO;
1778 const LO numInputEnt = inputInds.extent(0);
1779 if (static_cast<LO>(inputVals.extent(0)) != numInputEnt) {
1780 return Teuchos::OrdinalTraits<LO>::invalid();
1781 }
1782 return this->transformGlobalValues(gblRow,
1784 inputVals.data(),
1785 inputInds.data(),
1786 f,
1787 atomic);
1788 }
1789
1791 void setAllToScalar(const Scalar& alpha);
1792
1794 void scale(const Scalar& alpha);
1795
1820 void
1821 setAllValues(const typename local_graph_device_type::row_map_type& ptr,
1822 const typename local_graph_device_type::entries_type::non_const_type& ind,
1823 const typename local_matrix_device_type::values_type& val);
1824
1845 void
1847
1872 void
1873 setAllValues(const Teuchos::ArrayRCP<size_t>& ptr,
1874 const Teuchos::ArrayRCP<LocalOrdinal>& ind,
1875 const Teuchos::ArrayRCP<Scalar>& val);
1876
1878 row_ptrs_host_view_type getLocalRowPtrsHost() const { return getCrsGraph()->getLocalRowPtrsHost(); }
1879
1881 row_ptrs_device_view_type getLocalRowPtrsDevice() const { return getCrsGraph()->getLocalRowPtrsDevice(); }
1882
1884 local_inds_host_view_type getLocalIndicesHost() const { return getCrsGraph()->getLocalIndicesHost(); }
1885
1887 local_inds_device_view_type getLocalIndicesDevice() const { return getCrsGraph()->getLocalIndicesDevice(); }
1888
1890
1892
1921 void globalAssemble();
1922
1936 void resumeFill(const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1937
1995 void
1996 fillComplete(const Teuchos::RCP<const map_type>& domainMap,
1997 const Teuchos::RCP<const map_type>& rangeMap,
1998 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1999
2026 void
2027 fillComplete(const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2028
2055 void
2056 expertStaticFillComplete(const Teuchos::RCP<const map_type>& domainMap,
2057 const Teuchos::RCP<const map_type>& rangeMap,
2058 const Teuchos::RCP<const import_type>& importer = Teuchos::null,
2059 const Teuchos::RCP<const export_type>& exporter = Teuchos::null,
2060 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2061
2079 void
2080 replaceColMap(const Teuchos::RCP<const map_type>& newColMap);
2081
2163 void
2165 const Teuchos::RCP<const map_type>& newColMap,
2166 const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
2167 const bool sortEachRow = true);
2168
2178 void
2179 replaceDomainMap(const Teuchos::RCP<const map_type>& newDomainMap);
2180
2194 void
2195 replaceDomainMapAndImporter(const Teuchos::RCP<const map_type>& newDomainMap,
2196 Teuchos::RCP<const import_type>& newImporter);
2197
2207 void
2208 replaceRangeMap(const Teuchos::RCP<const map_type>& newRangeMap);
2209
2223 void
2224 replaceRangeMapAndExporter(const Teuchos::RCP<const map_type>& newRangeMap,
2225 Teuchos::RCP<const export_type>& newExporter);
2226
2240 virtual void
2241 removeEmptyProcessesInPlace(const Teuchos::RCP<const map_type>& newMap) override;
2242
2244
2246
2248 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const override;
2249
2251 Teuchos::RCP<const map_type> getRowMap() const override;
2252
2254 Teuchos::RCP<const map_type> getColMap() const override;
2255
2257 Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> >
2258 getGraph() const override;
2259
2261 Teuchos::RCP<const crs_graph_type> getCrsGraph() const;
2262
2263 private:
2274 const crs_graph_type& getCrsGraphRef() const;
2275
2276 public:
2277#if __armclang_major__ == 22 && __armclang_minor__ == 1
2278 // On Stria, PR 13052 caused a 25% performance regression in the
2279 // CGSolve performance test that is fixed by forcing
2280 // getLocalMatrixDevice to always be inlined. Restrict the fix
2281 // to the specific toolchain where the problem was observed
2282#define TPETRA_DETAILS_ALWAYS_INLINE __attribute__((always_inline))
2283#else
2284#define TPETRA_DETAILS_ALWAYS_INLINE
2285#endif
2298 TPETRA_DETAILS_ALWAYS_INLINE local_matrix_device_type
2299 getLocalMatrixDevice() const;
2300 local_matrix_host_type getLocalMatrixHost() const;
2301#undef TPETRA_DETAILS_ALWAYS_INLINE
2302
2322 global_size_t getGlobalNumRows() const override;
2323
2329 global_size_t getGlobalNumCols() const override;
2330
2337 size_t getLocalNumRows() const override;
2338
2342 size_t getLocalNumCols() const override;
2343
2345 GlobalOrdinal getIndexBase() const override;
2346
2348 global_size_t getGlobalNumEntries() const override;
2349
2351 size_t getLocalNumEntries() const override;
2352
2359 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const override;
2360
2367 size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override;
2368
2376 size_t getGlobalMaxNumRowEntries() const override;
2377
2385 size_t getLocalMaxNumRowEntries() const override;
2386
2388 virtual LocalOrdinal getBlockSize() const override { return 1; }
2389
2391 bool hasColMap() const override;
2392
2413 bool isLocallyIndexed() const override;
2414
2435 bool isGloballyIndexed() const override;
2436
2459 bool isFillComplete() const override;
2460
2483 bool isFillActive() const;
2484
2486
2492 bool isStorageOptimized() const;
2493
2495 bool isStaticGraph() const;
2496
2504 mag_type getNormInf() const;
2505
2509 //
2515 mag_type getNorm1(bool assumeSymmetric = false) const;
2516
2524 mag_type getFrobeniusNorm() const override;
2525
2528 virtual bool supportsRowViews() const override;
2529
2530 protected:
2531 using values_dualv_type =
2532 Kokkos::DualView<impl_scalar_type*, device_type>;
2533 using values_wdv_type =
2535 values_wdv_type valuesUnpacked_wdv;
2536 mutable values_wdv_type valuesPacked_wdv;
2537
2538 public:
2587 void
2589 nonconst_global_inds_host_view_type& Indices,
2590 nonconst_values_host_view_type& Values,
2591 size_t& NumEntries) const override;
2607 void
2609 nonconst_local_inds_host_view_type& Indices,
2610 nonconst_values_host_view_type& Values,
2611 size_t& NumEntries) const override;
2612
2625
2626 void
2628 global_inds_host_view_type& indices,
2629 values_host_view_type& values) const override;
2630
2643 void
2645 local_inds_host_view_type& indices,
2646 values_host_view_type& values) const override;
2647
2655
2662 void
2664
2708 void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t>& offsets) const;
2709
2731 void
2733 const Kokkos::View<const size_t*, device_type,
2734 Kokkos::MemoryUnmanaged>& offsets) const;
2735
2758 void
2760 const Teuchos::ArrayView<const size_t>& offsets) const;
2761
2766 void
2768
2773 void
2775
2777
2779
2841 void
2844 const Teuchos::ETransp mode = Teuchos::NO_TRANS,
2845 const Scalar& alpha = Teuchos::ScalarTraits<Scalar>::one(),
2846 const Scalar& beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
2847
2850 template <class T>
2851 Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node> >
2852 convert() const;
2853
2855
2857
2875 void
2878 Teuchos::ETransp mode = Teuchos::NO_TRANS,
2879 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
2880 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const override;
2881
2884 bool hasTransposeApply() const override;
2885
2892 Teuchos::RCP<const map_type> getDomainMap() const override;
2893
2900 Teuchos::RCP<const map_type> getRangeMap() const override;
2901
2903
2905
2916 virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
2917 add(const Scalar& alpha,
2919 const Scalar& beta,
2920 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
2921 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
2922 const Teuchos::RCP<Teuchos::ParameterList>& params) const override;
2923
2925
2927
2929 std::string description() const override;
2930
2933 void
2934 describe(Teuchos::FancyOStream& out,
2935 const Teuchos::EVerbosityLevel verbLevel =
2936 Teuchos::Describable::verbLevel_default) const override;
2937
2939
2941
2946 typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
2948
2949 virtual bool
2950 checkSizes(const SrcDistObject& source) override;
2951
2952 void
2953 applyCrsPadding(
2954 const typename crs_graph_type::padding_type& padding,
2955 const bool verbose);
2956
2957 private:
2958 void
2959 copyAndPermuteStaticGraph(
2961 const size_t numSameIDs,
2964 const size_t numPermutes);
2965
2966 void
2967 copyAndPermuteNonStaticGraph(
2969 const size_t numSameIDs,
2970 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs_dv,
2971 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs_dv,
2972 const size_t numPermutes);
2973
2974 protected:
2975 using dist_object_type::
2978
2979 virtual void
2981 const size_t numSameIDs,
2982 const Kokkos::DualView<
2983 const local_ordinal_type*,
2985 const Kokkos::DualView<
2986 const local_ordinal_type*,
2988 const CombineMode CM) override;
2989
2990 virtual void
2991 packAndPrepare(const SrcDistObject& source,
2992 const Kokkos::DualView<
2993 const local_ordinal_type*,
2995 Kokkos::DualView<char*, buffer_device_type>& exports,
2996 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
2997 size_t& constantNumPackets) override;
2998
3003
3004 private:
3007 void
3008 unpackAndCombineImpl(
3009 const Kokkos::DualView<const local_ordinal_type*,
3011 Kokkos::DualView<char*, buffer_device_type> imports,
3012 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3013 const size_t constantNumPackets,
3015 const bool verbose);
3016
3019 void
3020 unpackAndCombineImplNonStatic(
3021 const Kokkos::DualView<const local_ordinal_type*,
3023 Kokkos::DualView<char*, buffer_device_type> imports,
3024 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3025 const size_t constantNumPackets,
3026 const CombineMode combineMode);
3027
3028 public:
3038 void
3039 unpackAndCombine(const Kokkos::DualView<const local_ordinal_type*, 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 CM) override;
3044
3049
3155 void
3156 packNew(const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3157 Kokkos::DualView<char*, buffer_device_type>& exports,
3158 const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3159 size_t& constantNumPackets) const;
3160
3161 private:
3168 void
3169 packNonStaticNew(const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3170 Kokkos::DualView<char*, buffer_device_type>& exports,
3171 const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3172 size_t& constantNumPackets) const;
3173
3203 size_t
3204 packRow(char exports[],
3205 const size_t offset,
3206 const size_t numEnt,
3207 const GlobalOrdinal gidsIn[],
3208 const impl_scalar_type valsIn[],
3209 const size_t numBytesPerValue) const;
3210
3234 bool
3235 packRowStatic(char* const numEntOut,
3236 char* const valOut,
3237 char* const indOut,
3238 const size_t numEnt,
3239 const LocalOrdinal lclRow) const;
3240
3266 size_t
3267 unpackRow(GlobalOrdinal gidsOut[],
3269 const char imports[],
3270 const size_t offset,
3271 const size_t numBytes,
3272 const size_t numEnt,
3273 const size_t numBytesPerValue);
3274
3283 void
3284 allocatePackSpaceNew(Kokkos::DualView<char*, buffer_device_type>& exports,
3285 size_t& totalNumEntries,
3286 const Kokkos::DualView<const local_ordinal_type*,
3289
3290 public:
3292 typename local_matrix_host_type::values_type::const_type
3293 getLocalValuesHost(Access::ReadOnlyStruct s) const {
3294 return valuesPacked_wdv.getHostView(s);
3295 }
3296
3298 typename local_matrix_host_type::values_type
3299 getLocalValuesHost(Access::ReadWriteStruct s) {
3300 return valuesPacked_wdv.getHostView(s);
3301 }
3302
3304 typename local_matrix_host_type::values_type
3305 getLocalValuesHost(Access::OverwriteAllStruct s) {
3306 return valuesPacked_wdv.getHostView(s);
3307 }
3308
3310 typename local_matrix_device_type::values_type::const_type
3311 getLocalValuesDevice(Access::ReadOnlyStruct s) const {
3312 return valuesPacked_wdv.getDeviceView(s);
3313 }
3314
3316 typename local_matrix_device_type::values_type
3317 getLocalValuesDevice(Access::ReadWriteStruct s) {
3318 return valuesPacked_wdv.getDeviceView(s);
3319 }
3320
3322 typename local_matrix_device_type::values_type
3323 getLocalValuesDevice(Access::OverwriteAllStruct s) {
3324 return valuesPacked_wdv.getDeviceView(s);
3325 }
3326
3327 private:
3328 // Friend declaration for nonmember function.
3329 template <class CrsMatrixType>
3330 friend Teuchos::RCP<CrsMatrixType>
3331 Tpetra::importAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3332 const Import<typename CrsMatrixType::local_ordinal_type,
3333 typename CrsMatrixType::global_ordinal_type,
3334 typename CrsMatrixType::node_type>& importer,
3335 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3336 typename CrsMatrixType::global_ordinal_type,
3337 typename CrsMatrixType::node_type> >& domainMap,
3338 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3339 typename CrsMatrixType::global_ordinal_type,
3340 typename CrsMatrixType::node_type> >& rangeMap,
3341 const Teuchos::RCP<Teuchos::ParameterList>& params);
3342
3343 // Friend declaration for nonmember function.
3344 template <class CrsMatrixType>
3345 friend Teuchos::RCP<CrsMatrixType>
3346 Tpetra::importAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3347 const Import<typename CrsMatrixType::local_ordinal_type,
3348 typename CrsMatrixType::global_ordinal_type,
3349 typename CrsMatrixType::node_type>& rowImporter,
3350 const Import<typename CrsMatrixType::local_ordinal_type,
3351 typename CrsMatrixType::global_ordinal_type,
3352 typename CrsMatrixType::node_type>& domainImporter,
3353 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3354 typename CrsMatrixType::global_ordinal_type,
3355 typename CrsMatrixType::node_type> >& domainMap,
3356 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3357 typename CrsMatrixType::global_ordinal_type,
3358 typename CrsMatrixType::node_type> >& rangeMap,
3359 const Teuchos::RCP<Teuchos::ParameterList>& params);
3360
3361 // Friend declaration for nonmember function.
3362 template <class CrsMatrixType>
3363 friend Teuchos::RCP<CrsMatrixType>
3364 Tpetra::exportAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3365 const Export<typename CrsMatrixType::local_ordinal_type,
3366 typename CrsMatrixType::global_ordinal_type,
3367 typename CrsMatrixType::node_type>& exporter,
3368 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3369 typename CrsMatrixType::global_ordinal_type,
3370 typename CrsMatrixType::node_type> >& domainMap,
3371 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3372 typename CrsMatrixType::global_ordinal_type,
3373 typename CrsMatrixType::node_type> >& rangeMap,
3374 const Teuchos::RCP<Teuchos::ParameterList>& params);
3375
3376 // Friend declaration for nonmember function.
3377 template <class CrsMatrixType>
3378 friend Teuchos::RCP<CrsMatrixType>
3379 Tpetra::exportAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3380 const Export<typename CrsMatrixType::local_ordinal_type,
3381 typename CrsMatrixType::global_ordinal_type,
3382 typename CrsMatrixType::node_type>& rowExporter,
3383 const Export<typename CrsMatrixType::local_ordinal_type,
3384 typename CrsMatrixType::global_ordinal_type,
3385 typename CrsMatrixType::node_type>& domainExporter,
3386 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3387 typename CrsMatrixType::global_ordinal_type,
3388 typename CrsMatrixType::node_type> >& domainMap,
3389 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3390 typename CrsMatrixType::global_ordinal_type,
3391 typename CrsMatrixType::node_type> >& rangeMap,
3392 const Teuchos::RCP<Teuchos::ParameterList>& params);
3393
3394 public:
3410 void
3412 const import_type& importer,
3413 const Teuchos::RCP<const map_type>& domainMap,
3414 const Teuchos::RCP<const map_type>& rangeMap,
3415 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3416
3432 void
3434 const import_type& rowImporter,
3436 const Teuchos::RCP<const map_type>& domainMap,
3437 const Teuchos::RCP<const map_type>& rangeMap,
3438 const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3439
3455 void
3457 const export_type& exporter,
3458 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3459 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3460 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3461
3477 void
3479 const export_type& rowExporter,
3481 const Teuchos::RCP<const map_type>& domainMap,
3482 const Teuchos::RCP<const map_type>& rangeMap,
3483 const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3484
3485 private:
3506 void
3507 transferAndFillComplete(Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& destMatrix,
3508 const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3509 const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> >& domainTransfer,
3510 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3511 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3512 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3513
3525 protected:
3526 virtual void
3529 const GlobalOrdinal gblColInds[],
3530 const impl_scalar_type vals[],
3531 const size_t numInputEnt);
3532
3533 private:
3543 void
3544 insertGlobalValuesFiltered(
3546 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3547 const Teuchos::ArrayView<const Scalar>& values,
3548 const bool debug);
3549
3552 void
3553 insertGlobalValuesFilteredChecked(
3555 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3556 const Teuchos::ArrayView<const Scalar>& values,
3557 const char* const prefix,
3558 const bool debug,
3559 const bool verbose);
3560
3572 void
3573 combineGlobalValues(
3575 const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3576 const Teuchos::ArrayView<const Scalar>& values,
3578 const char* const prefix,
3579 const bool debug,
3580 const bool verbose);
3581
3604 combineGlobalValuesRaw(const LocalOrdinal lclRow,
3605 const LocalOrdinal numEnt,
3606 const impl_scalar_type vals[],
3607 const GlobalOrdinal cols[],
3609 const char* const prefix,
3610 const bool debug,
3611 const bool verbose);
3612
3624 template <class BinaryFunction>
3626 transformGlobalValues(const GlobalOrdinal globalRow,
3627 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3628 const Teuchos::ArrayView<const Scalar>& values,
3630 const bool atomic = useAtomicUpdatesByDefault) {
3631 typedef impl_scalar_type IST;
3632 typedef LocalOrdinal LO;
3633 typedef GlobalOrdinal GO;
3634
3635 const LO numInputEnt = static_cast<LO>(indices.size());
3636 if (static_cast<LO>(values.size()) != numInputEnt) {
3637 return Teuchos::OrdinalTraits<LO>::invalid();
3638 }
3639
3640 const GO* const inputCols = indices.getRawPtr();
3641 const IST* const inputVals =
3642 reinterpret_cast<const IST*>(values.getRawPtr());
3643 return this->transformGlobalValues(globalRow, numInputEnt, inputVals,
3644 inputCols, f, atomic);
3645 }
3646
3653 void
3654 insertNonownedGlobalValues(const GlobalOrdinal globalRow,
3655 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3656 const Teuchos::ArrayView<const Scalar>& values);
3657
3700 void
3701 insertIndicesAndValues(crs_graph_type& graph,
3702 RowInfo& rowInfo,
3703 const typename crs_graph_type::SLocalGlobalViews& newInds,
3704 const Teuchos::ArrayView<impl_scalar_type>& oldRowVals,
3705 const Teuchos::ArrayView<const impl_scalar_type>& newRowVals,
3706 const ELocalGlobal lg,
3707 const ELocalGlobal I);
3708
3709 protected:
3710 // useful typedefs
3711 typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
3712 typedef KokkosKernels::ArithTraits<impl_scalar_type> STS;
3713 typedef KokkosKernels::ArithTraits<mag_type> STM;
3714 typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> MV;
3715 typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
3716 typedef crs_graph_type Graph;
3717
3718 // Enums
3719 enum GraphAllocationStatus {
3720 GraphAlreadyAllocated,
3721 GraphNotYetAllocated
3722 };
3723
3724 protected:
3743 void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas,
3744 const bool verbose);
3745
3760 void
3761 sortAndMergeIndicesAndValues(const bool sorted,
3762 const bool merged);
3763
3764 public:
3766 bool haveGlobalConstants() const;
3767
3768 protected:
3781 mutable Teuchos::RCP<MV> importMV_;
3782
3795 mutable Teuchos::RCP<MV> exportMV_;
3796
3816 Teuchos::RCP<MV>
3818 const bool force = false) const;
3819
3841 Teuchos::RCP<MV>
3843 const bool force = false) const;
3844
3851 void
3852 applyNonTranspose(const MV& X_in,
3853 MV& Y_in,
3854 Scalar alpha,
3855 Scalar beta) const;
3856
3865 void
3866 applyTranspose(const MV& X_in,
3867 MV& Y_in,
3868 const Teuchos::ETransp mode,
3869 Scalar alpha,
3870 Scalar beta) const;
3871
3872 // matrix data accessors
3873
3876 typename values_dualv_type::t_host::const_type
3877 getValuesViewHost(const RowInfo& rowinfo) const;
3878
3881 typename values_dualv_type::t_dev::const_type
3882 getValuesViewDevice(const RowInfo& rowinfo) const;
3883
3886 typename values_dualv_type::t_host
3888
3891 typename values_dualv_type::t_dev
3893
3894 private:
3895 // TODO: When KokkosKernels 4.4 is released, local_matrix_device_type can be permanently modified to use the default_size_type
3896 // 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).
3897 //
3898 // At that point the ApplyHelper can be replaced with just a SPMVHandle.
3899 using local_matrix_int_rowptrs_device_type =
3900 KokkosSparse::CrsMatrix<impl_scalar_type,
3903 void,
3904 int>;
3905
3909 local_matrix_int_rowptrs_device_type,
3910 typename MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::device_view_type>;
3911
3912 std::shared_ptr<ApplyHelper> getApplyHelper() const {
3913 if (!applyHelper) {
3914 auto A_lcl = getLocalMatrixDevice();
3915 applyHelper = std::make_shared<ApplyHelper>(A_lcl.nnz(), A_lcl.graph.row_map);
3916 }
3917 return applyHelper;
3918 }
3919
3920 protected:
3921 // Friend the tester for CrsMatrix::swap
3922 friend class Tpetra::crsMatrix_Swap_Tester<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
3923
3924 // Friend the matrix multiply kernels so they can access internally-cached integer
3925 // row pointers without making them part of the CrsMatrix interface
3926 template <typename S, typename LO, typename GO, typename NODE, typename LOV>
3927 friend struct Tpetra::MMdetails::KernelWrappers;
3928 template <typename S, typename LO, typename GO, typename NODE, typename LOV>
3929 friend struct Tpetra::MMdetails::KernelWrappers2;
3930
3931 // friend Matrix Matrix utility function that needs to access integer-typed rowptrs
3932 friend void Tpetra::MMdetails::import_and_extract_views<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
3933 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
3934 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > targetMap,
3935 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
3936 Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > prototypeImporter,
3937 bool userAssertsThereAreNoRemotes,
3938 const std::string& label,
3939 const Teuchos::RCP<Teuchos::ParameterList>& params);
3940
3944 void swap(CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& matrix);
3945
3946 protected:
3952 void fillLocalMatrix(const Teuchos::RCP<Teuchos::ParameterList>& params);
3953
3959 void fillLocalGraphAndMatrix(const Teuchos::RCP<Teuchos::ParameterList>& params);
3960
3962 void checkInternalState() const;
3963
3975
3976 Teuchos::RCP<const Graph> staticGraph_;
3977 Teuchos::RCP<Graph> myGraph_;
3979
3980 protected:
3991 Details::STORAGE_1D_UNPACKED;
3992
3994 bool fillComplete_ = false;
3995
4023 std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
4024 Teuchos::Array<Scalar> > >
4026
4027 private:
4033 mutable std::shared_ptr<ApplyHelper> applyHelper;
4034
4035 public:
4036 // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
4037 // public inner class of CrsMatrix? It looks like it doesn't
4038 // depend on any implementation details of CrsMatrix at all. It
4039 // should really be declared and defined outside of CrsMatrix.
4040 template <class DestViewType, class SrcViewType,
4042 struct pack_functor {
4043 typedef typename DestViewType::execution_space execution_space;
4044 SrcViewType src_;
4045 DestViewType dst_;
4046 SrcOffsetViewType src_offset_;
4047 DestOffsetViewType dst_offset_;
4048 typedef typename DestOffsetViewType::non_const_value_type scalar_index_type;
4049
4050 pack_functor(DestViewType dst,
4051 const SrcViewType src,
4053 const SrcOffsetViewType src_offset)
4054 : src_(src)
4055 , dst_(dst)
4056 , src_offset_(src_offset)
4057 , dst_offset_(dst_offset) {}
4058
4060 void operator()(const LocalOrdinal row) const {
4061 scalar_index_type srcPos = src_offset_(row);
4062 const scalar_index_type dstEnd = dst_offset_(row + 1);
4063 scalar_index_type dstPos = dst_offset_(row);
4064 for (; dstPos < dstEnd; ++dstPos, ++srcPos) {
4065 dst_(dstPos) = src_(srcPos);
4066 }
4067 }
4068 };
4069}; // class CrsMatrix
4070
4075template <class Scalar,
4076 class LocalOrdinal,
4077 class GlobalOrdinal,
4078 class Node>
4079Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
4081 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
4082 const size_t maxNumEntriesPerRow = 0,
4083 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
4084 using matrix_type =
4086 return Teuchos::rcp(new matrix_type(map, maxNumEntriesPerRow,
4087 params));
4088}
4089
4090template <class CrsMatrixType>
4091Teuchos::RCP<CrsMatrixType>
4092importAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4093 const Import<typename CrsMatrixType::local_ordinal_type,
4094 typename CrsMatrixType::global_ordinal_type,
4095 typename CrsMatrixType::node_type>& importer,
4096 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4097 typename CrsMatrixType::global_ordinal_type,
4098 typename CrsMatrixType::node_type> >& domainMap,
4099 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4100 typename CrsMatrixType::global_ordinal_type,
4101 typename CrsMatrixType::node_type> >& rangeMap,
4102 const Teuchos::RCP<Teuchos::ParameterList>& params) {
4103 Teuchos::RCP<CrsMatrixType> destMatrix;
4104 sourceMatrix->importAndFillComplete(destMatrix, importer, domainMap, rangeMap, params);
4105 return destMatrix;
4106}
4107
4108template <class CrsMatrixType>
4109Teuchos::RCP<CrsMatrixType>
4110importAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4111 const Import<typename CrsMatrixType::local_ordinal_type,
4112 typename CrsMatrixType::global_ordinal_type,
4113 typename CrsMatrixType::node_type>& rowImporter,
4114 const Import<typename CrsMatrixType::local_ordinal_type,
4115 typename CrsMatrixType::global_ordinal_type,
4116 typename CrsMatrixType::node_type>& domainImporter,
4117 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4118 typename CrsMatrixType::global_ordinal_type,
4119 typename CrsMatrixType::node_type> >& domainMap,
4120 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4121 typename CrsMatrixType::global_ordinal_type,
4122 typename CrsMatrixType::node_type> >& rangeMap,
4123 const Teuchos::RCP<Teuchos::ParameterList>& params) {
4124 Teuchos::RCP<CrsMatrixType> destMatrix;
4125 sourceMatrix->importAndFillComplete(destMatrix, rowImporter, domainImporter, domainMap, rangeMap, params);
4126 return destMatrix;
4127}
4128
4129template <class CrsMatrixType>
4130Teuchos::RCP<CrsMatrixType>
4131exportAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4132 const Export<typename CrsMatrixType::local_ordinal_type,
4133 typename CrsMatrixType::global_ordinal_type,
4134 typename CrsMatrixType::node_type>& exporter,
4135 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4136 typename CrsMatrixType::global_ordinal_type,
4137 typename CrsMatrixType::node_type> >& domainMap,
4138 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4139 typename CrsMatrixType::global_ordinal_type,
4140 typename CrsMatrixType::node_type> >& rangeMap,
4141 const Teuchos::RCP<Teuchos::ParameterList>& params) {
4142 Teuchos::RCP<CrsMatrixType> destMatrix;
4143 sourceMatrix->exportAndFillComplete(destMatrix, exporter, domainMap, rangeMap, params);
4144 return destMatrix;
4145}
4146
4147template <class CrsMatrixType>
4148Teuchos::RCP<CrsMatrixType>
4149exportAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4150 const Export<typename CrsMatrixType::local_ordinal_type,
4151 typename CrsMatrixType::global_ordinal_type,
4152 typename CrsMatrixType::node_type>& rowExporter,
4153 const Export<typename CrsMatrixType::local_ordinal_type,
4154 typename CrsMatrixType::global_ordinal_type,
4155 typename CrsMatrixType::node_type>& domainExporter,
4156 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4157 typename CrsMatrixType::global_ordinal_type,
4158 typename CrsMatrixType::node_type> >& domainMap,
4159 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4160 typename CrsMatrixType::global_ordinal_type,
4161 typename CrsMatrixType::node_type> >& rangeMap,
4162 const Teuchos::RCP<Teuchos::ParameterList>& params) {
4163 Teuchos::RCP<CrsMatrixType> destMatrix;
4164 sourceMatrix->exportAndFillComplete(destMatrix, rowExporter, domainExporter, domainMap, rangeMap, params);
4165 return destMatrix;
4166}
4167
4174template <class CrsMatrixType>
4176 typename Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitudeType const& threshold =
4177 Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitude(Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::zero())) {
4178 auto localMatrix = matrix.getLocalMatrixDevice();
4179 size_t nnzBefore = localMatrix.nnz();
4180 localMatrix = KokkosSparse::removeCrsMatrixZeros(localMatrix, threshold);
4181 size_t localNNZRemoved = nnzBefore - localMatrix.nnz();
4182 // Skip the expertStaticFillComplete if no entries were removed on any process.
4183 // The fill complete can perform MPI collectives, so it can only be skipped on all processes or none.
4184 size_t globalNNZRemoved = 0;
4185 Teuchos::reduceAll<int, size_t>(*(matrix.getComm()), Teuchos::REDUCE_SUM, 1, &localNNZRemoved, &globalNNZRemoved);
4186 if (globalNNZRemoved != size_t(0)) {
4187 matrix.resumeFill();
4188 matrix.setAllValues(localMatrix);
4189 matrix.expertStaticFillComplete(matrix.getDomainMap(), matrix.getRangeMap());
4190 }
4191}
4192
4193} // namespace Tpetra
4194
4202#endif // TPETRA_CRSMATRIX_DECL_HPP
Forward declaration of Tpetra::CrsMatrix.
Declaration and generic definition of traits class that tells Tpetra::CrsMatrix how to pack and unpac...
Forward declaration of some Tpetra Matrix Matrix objects.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
typename local_graph_device_type::host_mirror_type local_graph_host_type
The type of the part of the sparse graph on each MPI process.
KokkosSparse::StaticCrsGraph< local_ordinal_type, Kokkos::LayoutLeft, device_type, void, size_t > local_graph_device_type
The type of the part of the sparse graph on each MPI process.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries.
virtual void insertGlobalValuesImpl(crs_graph_type &graph, RowInfo &rowInfo, const GlobalOrdinal gblColInds[], const impl_scalar_type vals[], const size_t numInputEnt)
Common implementation detail of insertGlobalValues and insertGlobalValuesFiltered.
bool isGloballyIndexed() const override
Whether the matrix is globally indexed on the calling process.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const override
Print this object with the given verbosity level to the given output stream.
std::map< GlobalOrdinal, std::pair< Teuchos::Array< GlobalOrdinal >, Teuchos::Array< Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
void localApply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, const Teuchos::ETransp mode=Teuchos::NO_TRANS, const Scalar &alpha=Teuchos::ScalarTraits< Scalar >::one(), const Scalar &beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Compute the local part of a sparse matrix-(Multi)Vector multiply.
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.
CrsMatrix & operator=(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assignment.
void replaceRangeMap(const Teuchos::RCP< const map_type > &newRangeMap)
Replace the current range Map with the given objects.
Details::EStorageStatus storageStatus_
Status of the matrix's storage, when not in a fill-complete state.
typename device_type::execution_space execution_space
The Kokkos execution space.
void applyNonTranspose(const MV &X_in, MV &Y_in, Scalar alpha, Scalar beta) const
void importAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &destMatrix, const import_type &importer, const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Import from this to the given destination matrix, and make the result fill complete.
CrsGraph< LocalOrdinal, GlobalOrdinal, Node > crs_graph_type
The CrsGraph specialization suitable for this CrsMatrix specialization.
Node node_type
This class' Kokkos Node type.
local_ordinal_type replaceGlobalValues(const global_ordinal_type globalRow, const Kokkos::View< const global_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals)
Replace one or more entries' values, using global indices.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &rowImporter, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &domainImporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
size_t getGlobalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, over all processes in the matrix's communicator.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row,...
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const override
Number of entries in the sparse matrix in the given global row, on the calling (MPI) process.
void scale(const Scalar &alpha)
Scale the matrix's values: this := alpha*this.
GlobalOrdinal global_ordinal_type
The type of each global index in the matrix.
void sortAndMergeIndicesAndValues(const bool sorted, const bool merged)
Sort and merge duplicate local column indices in all rows on the calling process, along with their co...
void packNew(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< char *, buffer_device_type > &exports, const Kokkos::DualView< size_t *, buffer_device_type > &numPacketsPerLID, size_t &constantNumPackets) const
Pack this object's data for an Import or Export.
size_t getLocalNumCols() const override
The number of columns connected to the locally owned rows of this matrix.
Teuchos::RCP< const map_type > getDomainMap() const override
The domain Map of this matrix.
bool hasColMap() const override
Whether the matrix has a well-defined column Map.
row_ptrs_host_view_type getLocalRowPtrsHost() const
Get a host view of the CRS packed row pointers.
mag_type getNormInf() const
Compute and return the infinity norm of the matrix.
Teuchos::RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Return another CrsMatrix with the same entries, but converted to a different Scalar type T.
values_dualv_type::t_dev getValuesViewDeviceNonConst(const RowInfo &rowinfo)
Get a non-const Device view of the locally owned values row myRow, such that rowinfo = getRowInfo(myR...
void expertStaticFillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< const import_type > &importer=Teuchos::null, const Teuchos::RCP< const export_type > &exporter=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Perform a fillComplete on a matrix that already has data.
LocalOrdinal transformLocalValues(const LocalOrdinal lclRow, const typename UnmanagedView< LocalIndicesViewType >::type &inputInds, const typename UnmanagedView< ImplScalarViewType >::type &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault)
Transform CrsMatrix entries in place, using local indices to select the entries in the row to transfo...
local_ordinal_type sumIntoLocalValues(const local_ordinal_type localRow, const Kokkos::View< const local_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals, const bool atomic=useAtomicUpdatesByDefault)
Sum into one or more sparse matrix entries, using local row and column indices.
virtual Teuchos::RCP< RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > add(const Scalar &alpha, const RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params) const override
Implementation of RowMatrix::add: return alpha*A + beta*this.
CrsMatrix(CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &&)=default
Move constructor.
friend void batchedApply(const MatrixArray &Matrices, const typename std::remove_pointer< typename MultiVectorArray::value_type >::type &X, MultiVectorArray &Y, typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type alpha, typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type beta, Teuchos::RCP< Teuchos::ParameterList > params)
Does multiply matrix apply() calls with a single X vector.
DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
void applyTranspose(const MV &X_in, MV &Y_in, const Teuchos::ETransp mode, Scalar alpha, Scalar beta) const
size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override
Number of entries in the sparse matrix in the given local row, on the calling (MPI) process.
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createCrsMatrix(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Create an empty CrsMatrix given a row map and a single integer upper bound on the number of stored en...
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
The communicator over which the matrix is distributed.
bool isFillActive() const
Whether the matrix is not fill complete.
void replaceDomainMapAndImporter(const Teuchos::RCP< const map_type > &newDomainMap, Teuchos::RCP< const import_type > &newImporter)
Replace the current domain Map and Import with the given objects.
local_matrix_host_type::values_type getLocalValuesHost(Access::ReadWriteStruct s)
Get the Kokkos local values on host, read write.
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.
mag_type getNorm1(bool assumeSymmetric=false) const
Compute and return the 1-norm of the matrix.
virtual ~CrsMatrix()=default
Destructor (virtual for memory safety of derived classes).
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const override
Compute a sparse matrix-MultiVector multiply.
mag_type getFrobeniusNorm() const override
Compute and return the Frobenius norm of the matrix.
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.
global_size_t getGlobalNumCols() const override
The number of global columns in the matrix.
Teuchos::RCP< const map_type > getRangeMap() const override
The range Map of this matrix.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply().
void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas, const bool verbose)
Allocate values (and optionally indices) using the Node.
size_t getLocalNumEntries() const override
The local number of entries in this matrix.
typename Node::device_type device_type
The Kokkos device type.
typename KokkosKernels::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
bool fillComplete_
Whether the matrix is fill complete.
virtual LocalOrdinal sumIntoGlobalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const GlobalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoGlobalValues.
void replaceDomainMap(const Teuchos::RCP< const map_type > &newDomainMap)
Replace the current domain Map with the given objects.
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.
std::string description() const override
A one-line description of this object.
void reindexColumns(crs_graph_type *const graph, const Teuchos::RCP< const map_type > &newColMap, const Teuchos::RCP< const import_type > &newImport=Teuchos::null, const bool sortEachRow=true)
Reindex the column indices in place, and replace the column Map. Optionally, replace the Import objec...
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
KokkosSparse::CrsMatrix< impl_scalar_type, local_ordinal_type, device_type, void, typename local_graph_device_type::size_type > local_matrix_device_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
void replaceRangeMapAndExporter(const Teuchos::RCP< const map_type > &newRangeMap, Teuchos::RCP< const export_type > &newExporter)
Replace the current Range Map and Export with the given objects.
size_t getLocalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, on this process.
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the matrix's column Map with the given Map.
global_size_t getGlobalNumRows() const override
Number of global elements in the row map of this matrix.
local_matrix_host_type::values_type::const_type getLocalValuesHost(Access::ReadOnlyStruct s) const
Get the Kokkos local values on host, read only.
void globalAssemble()
Communicate nonlocal contributions to other processes.
void checkInternalState() const
Check that this object's state is sane; throw if it's not.
bool hasTransposeApply() const override
Whether apply() allows applying the transpose or conjugate transpose.
GlobalOrdinal getIndexBase() const override
The index base for global indices for this matrix.
LocalOrdinal local_ordinal_type
The type of each local index in the matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const override
Get a constant, nonpersisting view of a row of this matrix, using local row and column indices,...
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local graph and matrix.
row_ptrs_device_view_type getLocalRowPtrsDevice() const
Get a device view of the CRS packed row pointers.
Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization suitable for this CrsMatrix specialization.
local_inds_host_view_type getLocalIndicesHost() const
Get a host view of the CRS packed column indicies.
TPETRA_DETAILS_ALWAYS_INLINE local_matrix_device_type getLocalMatrixDevice() const
The local sparse matrix.
void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const override
Get a constant view of a row of this matrix, using local row and column indices.
Teuchos::RCP< const map_type > getColMap() const override
The Map that describes the column distribution in this matrix.
void insertGlobalValues(const GlobalOrdinal globalRow, const Teuchos::ArrayView< const GlobalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using global column indices.
void fillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Tell the matrix that you are done changing its structure or values, and that you are ready to do comp...
typename crs_graph_type::local_graph_device_type local_graph_device_type
The part of the sparse matrix's graph on each MPI process.
void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const override
Get a constant, nonpersisting view of a row of this matrix, using global row and column indices.
void setAllValues(const typename local_graph_device_type::row_map_type &ptr, const typename local_graph_device_type::entries_type::non_const_type &ind, const typename local_matrix_device_type::values_type &val)
Set the local matrix using three (compressed sparse row) arrays.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const override
This matrix's graph, as a RowGraph.
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
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap) override
Remove processes owning zero rows from the Maps and their communicator.
local_matrix_device_type::values_type getLocalValuesDevice(Access::ReadWriteStruct s)
Get the Kokkos local values on device, read write.
virtual LocalOrdinal sumIntoLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoLocalValues.
void swap(CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &matrix)
Swaps the data from *this with the data and maps from crsMatrix.
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
global_size_t getGlobalNumEntries() const override
The global number of entries in this matrix.
virtual LocalOrdinal replaceLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts)
Implementation detail of replaceLocalValues.
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().
size_t getLocalNumRows() const override
The number of matrix rows owned by the calling process.
bool isFillComplete() const override
Whether the matrix is fill complete.
LocalOrdinal transformGlobalValues(const GlobalOrdinal gblRow, const Kokkos::View< const GlobalOrdinal *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputInds, const Kokkos::View< const impl_scalar_type *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault)
Transform CrsMatrix entries in place, using global indices to select the entries in the row to transf...
virtual bool checkSizes(const SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
Teuchos::RCP< const map_type > getRowMap() const override
The Map that describes the row distribution in this matrix.
typename device_type::memory_space memory_space
The Kokkos memory space.
local_matrix_device_type::values_type getLocalValuesDevice(Access::OverwriteAllStruct s)
Get the Kokkos local values on device, overwrite all.
local_ordinal_type replaceLocalValues(const local_ordinal_type localRow, const Kokkos::View< const local_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals)
Replace one or more entries' values, using local row and column indices.
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_host_type::values_type getLocalValuesHost(Access::OverwriteAllStruct s)
Get the Kokkos local values on host, overwrite all.
values_dualv_type::t_host::const_type getValuesViewHost(const RowInfo &rowinfo) const
Get a const Host view of the locally owned values row myRow, such that rowinfo = getRowInfo(myRow).
CrsMatrix(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy constructor.
bool isLocallyIndexed() const override
Whether the matrix is locally indexed on the calling process.
typename row_matrix_type::impl_scalar_type impl_scalar_type
The type used internally in place of Scalar.
Teuchos::RCP< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
local_matrix_device_type::values_type::const_type getLocalValuesDevice(Access::ReadOnlyStruct s) const
Get the Kokkos local values on device, read only.
virtual LocalOrdinal replaceGlobalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const GlobalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts)
Implementation detail of replaceGlobalValues.
values_dualv_type::t_host getValuesViewHostNonConst(const RowInfo &rowinfo)
Get a non-const Host view of the locally owned values row myRow, such that rowinfo = getRowInfo(myRow...
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Resume operations that may change the values or structure of the matrix.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
void fillLocalMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local matrix.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the right with the given Vector.
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &rowExporter, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &domainExporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
bool isStorageOptimized() const
Returns true if storage has been optimized.
Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization suitable for this CrsMatrix specialization.
void getLocalRowCopy(LocalOrdinal LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row,...
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &exporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
values_dualv_type::t_dev::const_type getValuesViewDevice(const RowInfo &rowinfo) const
Get a const Device view of the locally owned values row myRow, such that rowinfo = getRowInfo(myRow).
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the left with the given Vector.
CrsMatrix & operator=(CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &&)=default
Move assignment.
virtual bool supportsRowViews() const override
Return true if getLocalRowView() and getGlobalRowView() are valid for this object.
local_inds_device_view_type getLocalIndicesDevice() const
Get a device_view of the CRS packed column indicies.
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix's graph, as a CrsGraph.
virtual LocalOrdinal getBlockSize() const override
The number of degrees of freedom per mesh point.
Struct that holds views of the contents of a CrsMatrix.
Keep track of how much more space a CrsGraph or CrsMatrix needs, when the graph or matrix is the targ...
A class can inherit from this if it wants to use Tpetra managed spaces.
A wrapper around Kokkos::DualView to safely manage data that might be replicated between host and dev...
Base class for distributed Tpetra objects that support data redistribution.
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).
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.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
A parallel distribution of indices over processes.
One or more distributed dense vectors.
A read-only, row-oriented interface to a sparse matrix.
typename KokkosKernels::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Abstract base class for objects that can be the source of an Import or Export operation.
Implementation details of Tpetra.
EStorageStatus
Status of the graph's or matrix's storage, when not in a fill-complete state.
void residual(const Operator< SC, LO, GO, NO > &A, const MultiVector< SC, LO, GO, NO > &X, const MultiVector< SC, LO, GO, NO > &B, MultiVector< SC, LO, GO, NO > &R)
Computes R = B - A * X.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &exporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
size_t global_size_t
Global size_t object.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &importer, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
CombineMode
Rule for combining data in an Import or Export.
@ ADD
Sum new values.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.