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
828 const Teuchos::RCP<const map_type>& rowMap,
829 const Teuchos::RCP<const map_type>& colMap,
830 const Teuchos::RCP<const map_type>& domainMap,
831 const Teuchos::RCP<const map_type>& rangeMap,
832 const Teuchos::RCP<const import_type>& importer,
833 const Teuchos::RCP<const export_type>& exporter,
834 const Teuchos::RCP<Teuchos::ParameterList>& params =
835 Teuchos::null);
836
838 // This function in 'Copy' mode is only guaranteed to work correctly for matrices
839 // which are fillComplete.
841 const Teuchos::DataAccess copyOrView);
842
852 virtual ~CrsMatrix() = default;
853
854 // This friend declaration makes the clone() method work.
855 template <class S2, class LO2, class GO2, class N2>
856 friend class CrsMatrix;
857
858 // This friend declaration allows for fused residual calculation
859 template <class S2, class LO2, class GO2, class N2>
864
865 // This friend declaration allows for batching of apply calls
866 template <class MatrixArray, class MultiVectorArray>
867 friend void batchedApply(const MatrixArray& Matrices,
868 const typename std::remove_pointer<typename MultiVectorArray::value_type>::type& X,
870 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type alpha,
871 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type beta,
872 Teuchos::RCP<Teuchos::ParameterList> params);
873
874 public:
876
878
902 //
944 void
946 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
947 const Teuchos::ArrayView<const Scalar>& vals);
948
963 void
965 const LocalOrdinal numEnt,
966 const Scalar vals[],
967 const GlobalOrdinal inds[]);
968
1011 void
1012 insertLocalValues(const LocalOrdinal localRow,
1013 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1014 const Teuchos::ArrayView<const Scalar>& vals,
1015 const CombineMode CM = ADD);
1016
1036 void
1037 insertLocalValues(const LocalOrdinal localRow,
1038 const LocalOrdinal numEnt,
1039 const Scalar vals[],
1040 const LocalOrdinal cols[],
1041 const CombineMode CM = ADD);
1042
1043 protected:
1054 virtual LocalOrdinal
1056 const crs_graph_type& graph,
1057 const RowInfo& rowInfo,
1058 const GlobalOrdinal inds[],
1059 const impl_scalar_type newVals[],
1060 const LocalOrdinal numElts);
1061
1062 public:
1102 const Kokkos::View<const global_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1103 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1104
1109 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1110 const Teuchos::ArrayView<const Scalar>& vals);
1111
1128 const LocalOrdinal numEnt,
1129 const Scalar vals[],
1130 const GlobalOrdinal cols[]);
1131
1132 protected:
1143 virtual LocalOrdinal
1145 const crs_graph_type& graph,
1146 const RowInfo& rowInfo,
1147 const LocalOrdinal inds[],
1148 const impl_scalar_type newVals[],
1149 const LocalOrdinal numElts);
1150
1151 public:
1189 const local_ordinal_type localRow,
1190 const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1191 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1192
1197 replaceLocalValues(const LocalOrdinal localRow,
1198 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1199 const Teuchos::ArrayView<const Scalar>& vals);
1200
1219 replaceLocalValues(const LocalOrdinal localRow,
1220 const LocalOrdinal numEnt,
1221 const Scalar inputVals[],
1222 const LocalOrdinal inputCols[]);
1223
1224 private:
1229 static const bool useAtomicUpdatesByDefault =
1230#ifdef KOKKOS_ENABLE_SERIAL
1231 !std::is_same<execution_space, Kokkos::Serial>::value;
1232#else
1233 true;
1234#endif // KOKKOS_ENABLE_SERIAL
1235
1259 protected:
1260 virtual LocalOrdinal
1262 const crs_graph_type& graph,
1263 const RowInfo& rowInfo,
1264 const GlobalOrdinal inds[],
1265 const impl_scalar_type newVals[],
1266 const LocalOrdinal numElts,
1267 const bool atomic = useAtomicUpdatesByDefault);
1268
1269 public:
1308 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1309 const Teuchos::ArrayView<const Scalar>& vals,
1310 const bool atomic = useAtomicUpdatesByDefault);
1311
1336 const LocalOrdinal numEnt,
1337 const Scalar vals[],
1338 const GlobalOrdinal cols[],
1339 const bool atomic = useAtomicUpdatesByDefault);
1340
1341 protected:
1354 virtual LocalOrdinal
1356 const crs_graph_type& graph,
1357 const RowInfo& rowInfo,
1358 const LocalOrdinal inds[],
1359 const impl_scalar_type newVals[],
1360 const LocalOrdinal numElts,
1361 const bool atomic = useAtomicUpdatesByDefault);
1362
1363 public:
1402 const local_ordinal_type localRow,
1403 const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1404 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals,
1405 const bool atomic = useAtomicUpdatesByDefault);
1406
1437 sumIntoLocalValues(const LocalOrdinal localRow,
1438 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1439 const Teuchos::ArrayView<const Scalar>& vals,
1440 const bool atomic = useAtomicUpdatesByDefault);
1441
1464 sumIntoLocalValues(const LocalOrdinal localRow,
1465 const LocalOrdinal numEnt,
1466 const Scalar vals[],
1467 const LocalOrdinal cols[],
1468 const bool atomic = useAtomicUpdatesByDefault);
1469
1470 private:
1502 transformLocalValues(impl_scalar_type rowVals[],
1503 const crs_graph_type& graph,
1504 const RowInfo& rowInfo,
1505 const LocalOrdinal inds[],
1506 const impl_scalar_type newVals[],
1507 const LocalOrdinal numElts,
1508 std::function<impl_scalar_type(const impl_scalar_type&, const impl_scalar_type&)> f,
1509 const bool atomic = useAtomicUpdatesByDefault);
1510
1542 transformGlobalValues(impl_scalar_type rowVals[],
1543 const crs_graph_type& graph,
1544 const RowInfo& rowInfo,
1545 const GlobalOrdinal inds[],
1546 const impl_scalar_type newVals[],
1547 const LocalOrdinal numElts,
1548 std::function<impl_scalar_type(const impl_scalar_type&, const impl_scalar_type&)> f,
1549 const bool atomic = useAtomicUpdatesByDefault);
1550
1578 transformLocalValues(const LocalOrdinal lclRow,
1581 const LocalOrdinal inputCols[],
1582 std::function<impl_scalar_type(const impl_scalar_type&, const impl_scalar_type&)> f,
1583 const bool atomic = useAtomicUpdatesByDefault);
1584
1612 transformGlobalValues(const GlobalOrdinal gblRow,
1615 const GlobalOrdinal inputCols[],
1616 std::function<impl_scalar_type(const impl_scalar_type&, const impl_scalar_type&)> f,
1617 const bool atomic = useAtomicUpdatesByDefault);
1618
1619 public:
1663 template <class LocalIndicesViewType,
1664 class ImplScalarViewType,
1665 class BinaryFunction>
1668 const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1669 const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1671 const bool atomic = useAtomicUpdatesByDefault) {
1672 // We use static_assert here to check the template parameters,
1673 // rather than std::enable_if (e.g., on the return value, to
1674 // enable compilation only if the template parameters match the
1675 // desired attributes). This turns obscure link errors into
1676 // clear compilation errors. It also makes the return value a
1677 // lot easier to see.
1678 static_assert(Kokkos::is_view<LocalIndicesViewType>::value,
1679 "First template parameter LocalIndicesViewType must be "
1680 "a Kokkos::View.");
1681 static_assert(Kokkos::is_view<ImplScalarViewType>::value,
1682 "Second template parameter ImplScalarViewType must be a "
1683 "Kokkos::View.");
1684 static_assert(static_cast<int>(LocalIndicesViewType::rank) == 1,
1685 "First template parameter LocalIndicesViewType must "
1686 "have rank 1.");
1687 static_assert(static_cast<int>(ImplScalarViewType::rank) == 1,
1688 "Second template parameter ImplScalarViewType must have "
1689 "rank 1.");
1690 static_assert(std::is_same<
1691 typename LocalIndicesViewType::non_const_value_type,
1692 local_ordinal_type>::value,
1693 "First template parameter LocalIndicesViewType must "
1694 "contain values of type local_ordinal_type.");
1695 static_assert(std::is_same<
1696 typename ImplScalarViewType::non_const_value_type,
1697 impl_scalar_type>::value,
1698 "Second template parameter ImplScalarViewType must "
1699 "contain values of type impl_scalar_type.");
1700 typedef LocalOrdinal LO;
1701 const LO numInputEnt = inputInds.extent(0);
1702 if (static_cast<LO>(inputVals.extent(0)) != numInputEnt) {
1703 return Teuchos::OrdinalTraits<LO>::invalid();
1704 }
1705 return this->transformLocalValues(lclRow,
1707 inputVals.data(),
1708 inputInds.data(),
1709 f,
1710 atomic);
1711 }
1712
1754 template <class BinaryFunction, class InputMemorySpace>
1757 const Kokkos::View<const GlobalOrdinal*,
1759 Kokkos::MemoryUnmanaged>& inputInds,
1760 const Kokkos::View<const impl_scalar_type*,
1762 Kokkos::MemoryUnmanaged>& inputVals,
1764 const bool atomic = useAtomicUpdatesByDefault) {
1765 typedef LocalOrdinal LO;
1766 const LO numInputEnt = inputInds.extent(0);
1767 if (static_cast<LO>(inputVals.extent(0)) != numInputEnt) {
1768 return Teuchos::OrdinalTraits<LO>::invalid();
1769 }
1770 return this->transformGlobalValues(gblRow,
1772 inputVals.data(),
1773 inputInds.data(),
1774 f,
1775 atomic);
1776 }
1777
1779 void setAllToScalar(const Scalar& alpha);
1780
1782 void scale(const Scalar& alpha);
1783
1808 void
1809 setAllValues(const typename local_graph_device_type::row_map_type& ptr,
1810 const typename local_graph_device_type::entries_type::non_const_type& ind,
1811 const typename local_matrix_device_type::values_type& val);
1812
1833 void
1835
1860 void
1861 setAllValues(const Teuchos::ArrayRCP<size_t>& ptr,
1862 const Teuchos::ArrayRCP<LocalOrdinal>& ind,
1863 const Teuchos::ArrayRCP<Scalar>& val);
1864
1866 row_ptrs_host_view_type getLocalRowPtrsHost() const { return getCrsGraph()->getLocalRowPtrsHost(); }
1867
1869 row_ptrs_device_view_type getLocalRowPtrsDevice() const { return getCrsGraph()->getLocalRowPtrsDevice(); }
1870
1872 local_inds_host_view_type getLocalIndicesHost() const { return getCrsGraph()->getLocalIndicesHost(); }
1873
1875 local_inds_device_view_type getLocalIndicesDevice() const { return getCrsGraph()->getLocalIndicesDevice(); }
1876
1878
1880
1909 void globalAssemble();
1910
1924 void resumeFill(const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1925
1983 void
1984 fillComplete(const Teuchos::RCP<const map_type>& domainMap,
1985 const Teuchos::RCP<const map_type>& rangeMap,
1986 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1987
2014 void
2015 fillComplete(const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2016
2043 void
2044 expertStaticFillComplete(const Teuchos::RCP<const map_type>& domainMap,
2045 const Teuchos::RCP<const map_type>& rangeMap,
2046 const Teuchos::RCP<const import_type>& importer = Teuchos::null,
2047 const Teuchos::RCP<const export_type>& exporter = Teuchos::null,
2048 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2049
2067 void
2068 replaceColMap(const Teuchos::RCP<const map_type>& newColMap);
2069
2151 void
2153 const Teuchos::RCP<const map_type>& newColMap,
2154 const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
2155 const bool sortEachRow = true);
2156
2166 void
2167 replaceDomainMap(const Teuchos::RCP<const map_type>& newDomainMap);
2168
2182 void
2183 replaceDomainMapAndImporter(const Teuchos::RCP<const map_type>& newDomainMap,
2184 Teuchos::RCP<const import_type>& newImporter);
2185
2195 void
2196 replaceRangeMap(const Teuchos::RCP<const map_type>& newRangeMap);
2197
2211 void
2212 replaceRangeMapAndExporter(const Teuchos::RCP<const map_type>& newRangeMap,
2213 Teuchos::RCP<const export_type>& newExporter);
2214
2228 virtual void
2229 removeEmptyProcessesInPlace(const Teuchos::RCP<const map_type>& newMap) override;
2230
2232
2234
2236 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const override;
2237
2239 Teuchos::RCP<const map_type> getRowMap() const override;
2240
2242 Teuchos::RCP<const map_type> getColMap() const override;
2243
2245 Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> >
2246 getGraph() const override;
2247
2249 Teuchos::RCP<const crs_graph_type> getCrsGraph() const;
2250
2251 private:
2262 const crs_graph_type& getCrsGraphRef() const;
2263
2264 public:
2265#if __armclang_major__ == 22 && __armclang_minor__ == 1
2266 // On Stria, PR 13052 caused a 25% performance regression in the
2267 // CGSolve performance test that is fixed by forcing
2268 // getLocalMatrixDevice to always be inlined. Restrict the fix
2269 // to the specific toolchain where the problem was observed
2270#define TPETRA_DETAILS_ALWAYS_INLINE __attribute__((always_inline))
2271#else
2272#define TPETRA_DETAILS_ALWAYS_INLINE
2273#endif
2286 TPETRA_DETAILS_ALWAYS_INLINE local_matrix_device_type
2287 getLocalMatrixDevice() const;
2288 local_matrix_host_type getLocalMatrixHost() const;
2289#undef TPETRA_DETAILS_ALWAYS_INLINE
2290
2310 global_size_t getGlobalNumRows() const override;
2311
2317 global_size_t getGlobalNumCols() const override;
2318
2325 size_t getLocalNumRows() const override;
2326
2330 size_t getLocalNumCols() const override;
2331
2333 GlobalOrdinal getIndexBase() const override;
2334
2336 global_size_t getGlobalNumEntries() const override;
2337
2339 size_t getLocalNumEntries() const override;
2340
2347 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const override;
2348
2355 size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override;
2356
2364 size_t getGlobalMaxNumRowEntries() const override;
2365
2373 size_t getLocalMaxNumRowEntries() const override;
2374
2376 virtual LocalOrdinal getBlockSize() const override { return 1; }
2377
2379 bool hasColMap() const override;
2380
2401 bool isLocallyIndexed() const override;
2402
2423 bool isGloballyIndexed() const override;
2424
2447 bool isFillComplete() const override;
2448
2471 bool isFillActive() const;
2472
2474
2480 bool isStorageOptimized() const;
2481
2483 bool isStaticGraph() const;
2484
2492 mag_type getNormInf() const;
2493
2497 //
2503 mag_type getNorm1(bool assumeSymmetric = false) const;
2504
2512 mag_type getFrobeniusNorm() const override;
2513
2516 virtual bool supportsRowViews() const override;
2517
2518 protected:
2519 using values_dualv_type =
2520 Kokkos::DualView<impl_scalar_type*, device_type>;
2521 using values_wdv_type =
2523 values_wdv_type valuesUnpacked_wdv;
2524 mutable values_wdv_type valuesPacked_wdv;
2525
2526 public:
2575 void
2577 nonconst_global_inds_host_view_type& Indices,
2578 nonconst_values_host_view_type& Values,
2579 size_t& NumEntries) const override;
2595 void
2597 nonconst_local_inds_host_view_type& Indices,
2598 nonconst_values_host_view_type& Values,
2599 size_t& NumEntries) const override;
2600
2613
2614 void
2616 global_inds_host_view_type& indices,
2617 values_host_view_type& values) const override;
2618
2631 void
2633 local_inds_host_view_type& indices,
2634 values_host_view_type& values) const override;
2635
2643
2650 void
2652
2696 void getLocalDiagOffsets(Teuchos::ArrayRCP<size_t>& offsets) const;
2697
2719 void
2721 const Kokkos::View<const size_t*, device_type,
2722 Kokkos::MemoryUnmanaged>& offsets) const;
2723
2746 void
2748 const Teuchos::ArrayView<const size_t>& offsets) const;
2749
2754 void
2756
2761 void
2763
2765
2767
2829 void
2832 const Teuchos::ETransp mode = Teuchos::NO_TRANS,
2833 const Scalar& alpha = Teuchos::ScalarTraits<Scalar>::one(),
2834 const Scalar& beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
2835
2838 template <class T>
2839 Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node> >
2840 convert() const;
2841
2843
2845
2856 void
2859 Teuchos::ETransp mode = Teuchos::NO_TRANS,
2860 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
2861 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const override;
2862
2865 bool hasTransposeApply() const override;
2866
2873 Teuchos::RCP<const map_type> getDomainMap() const override;
2874
2881 Teuchos::RCP<const map_type> getRangeMap() const override;
2882
2884
2886
2897 virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
2898 add(const Scalar& alpha,
2900 const Scalar& beta,
2901 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
2902 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
2903 const Teuchos::RCP<Teuchos::ParameterList>& params) const override;
2904
2906
2908
2910 std::string description() const override;
2911
2914 void
2915 describe(Teuchos::FancyOStream& out,
2916 const Teuchos::EVerbosityLevel verbLevel =
2917 Teuchos::Describable::verbLevel_default) const override;
2918
2920
2922
2927 typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
2929
2930 virtual bool
2931 checkSizes(const SrcDistObject& source) override;
2932
2933 void
2934 applyCrsPadding(
2935 const typename crs_graph_type::padding_type& padding,
2936 const bool verbose);
2937
2938 private:
2939 void
2940 copyAndPermuteStaticGraph(
2942 const size_t numSameIDs,
2945 const size_t numPermutes);
2946
2947 void
2948 copyAndPermuteNonStaticGraph(
2950 const size_t numSameIDs,
2951 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs_dv,
2952 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs_dv,
2953 const size_t numPermutes);
2954
2955 protected:
2956 using dist_object_type::
2959
2960 virtual void
2962 const size_t numSameIDs,
2963 const Kokkos::DualView<
2964 const local_ordinal_type*,
2966 const Kokkos::DualView<
2967 const local_ordinal_type*,
2969 const CombineMode CM) override;
2970
2971 virtual void
2972 packAndPrepare(const SrcDistObject& source,
2973 const Kokkos::DualView<
2974 const local_ordinal_type*,
2976 Kokkos::DualView<char*, buffer_device_type>& exports,
2977 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
2978 size_t& constantNumPackets) override;
2979
2984
2985 private:
2988 void
2989 unpackAndCombineImpl(
2990 const Kokkos::DualView<const local_ordinal_type*,
2992 Kokkos::DualView<char*, buffer_device_type> imports,
2993 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
2994 const size_t constantNumPackets,
2996 const bool verbose);
2997
3000 void
3001 unpackAndCombineImplNonStatic(
3002 const Kokkos::DualView<const local_ordinal_type*,
3004 Kokkos::DualView<char*, buffer_device_type> imports,
3005 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3006 const size_t constantNumPackets,
3007 const CombineMode combineMode);
3008
3009 public:
3019 void
3020 unpackAndCombine(const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& importLIDs,
3021 Kokkos::DualView<char*, buffer_device_type> imports,
3022 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3023 const size_t constantNumPackets,
3024 const CombineMode CM) override;
3025
3030
3136 void
3137 packNew(const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3138 Kokkos::DualView<char*, buffer_device_type>& exports,
3139 const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3140 size_t& constantNumPackets) const;
3141
3142 private:
3149 void
3150 packNonStaticNew(const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3151 Kokkos::DualView<char*, buffer_device_type>& exports,
3152 const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3153 size_t& constantNumPackets) const;
3154
3184 size_t
3185 packRow(char exports[],
3186 const size_t offset,
3187 const size_t numEnt,
3188 const GlobalOrdinal gidsIn[],
3189 const impl_scalar_type valsIn[],
3190 const size_t numBytesPerValue) const;
3191
3215 bool
3216 packRowStatic(char* const numEntOut,
3217 char* const valOut,
3218 char* const indOut,
3219 const size_t numEnt,
3220 const LocalOrdinal lclRow) const;
3221
3247 size_t
3248 unpackRow(GlobalOrdinal gidsOut[],
3250 const char imports[],
3251 const size_t offset,
3252 const size_t numBytes,
3253 const size_t numEnt,
3254 const size_t numBytesPerValue);
3255
3264 void
3265 allocatePackSpaceNew(Kokkos::DualView<char*, buffer_device_type>& exports,
3266 size_t& totalNumEntries,
3267 const Kokkos::DualView<const local_ordinal_type*,
3270
3271 public:
3273 typename local_matrix_host_type::values_type::const_type
3274 getLocalValuesHost(Access::ReadOnlyStruct s) const {
3275 return valuesPacked_wdv.getHostView(s);
3276 }
3277
3279 typename local_matrix_host_type::values_type
3280 getLocalValuesHost(Access::ReadWriteStruct s) {
3281 return valuesPacked_wdv.getHostView(s);
3282 }
3283
3285 typename local_matrix_host_type::values_type
3286 getLocalValuesHost(Access::OverwriteAllStruct s) {
3287 return valuesPacked_wdv.getHostView(s);
3288 }
3289
3291 typename local_matrix_device_type::values_type::const_type
3292 getLocalValuesDevice(Access::ReadOnlyStruct s) const {
3293 return valuesPacked_wdv.getDeviceView(s);
3294 }
3295
3297 typename local_matrix_device_type::values_type
3298 getLocalValuesDevice(Access::ReadWriteStruct s) {
3299 return valuesPacked_wdv.getDeviceView(s);
3300 }
3301
3303 typename local_matrix_device_type::values_type
3304 getLocalValuesDevice(Access::OverwriteAllStruct s) {
3305 return valuesPacked_wdv.getDeviceView(s);
3306 }
3307
3308 private:
3309 // Friend declaration for nonmember function.
3310 template <class CrsMatrixType>
3311 friend Teuchos::RCP<CrsMatrixType>
3312 Tpetra::importAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3313 const Import<typename CrsMatrixType::local_ordinal_type,
3314 typename CrsMatrixType::global_ordinal_type,
3315 typename CrsMatrixType::node_type>& importer,
3316 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3317 typename CrsMatrixType::global_ordinal_type,
3318 typename CrsMatrixType::node_type> >& domainMap,
3319 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3320 typename CrsMatrixType::global_ordinal_type,
3321 typename CrsMatrixType::node_type> >& rangeMap,
3322 const Teuchos::RCP<Teuchos::ParameterList>& params);
3323
3324 // Friend declaration for nonmember function.
3325 template <class CrsMatrixType>
3326 friend Teuchos::RCP<CrsMatrixType>
3327 Tpetra::importAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3328 const Import<typename CrsMatrixType::local_ordinal_type,
3329 typename CrsMatrixType::global_ordinal_type,
3330 typename CrsMatrixType::node_type>& rowImporter,
3331 const Import<typename CrsMatrixType::local_ordinal_type,
3332 typename CrsMatrixType::global_ordinal_type,
3333 typename CrsMatrixType::node_type>& domainImporter,
3334 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3335 typename CrsMatrixType::global_ordinal_type,
3336 typename CrsMatrixType::node_type> >& domainMap,
3337 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3338 typename CrsMatrixType::global_ordinal_type,
3339 typename CrsMatrixType::node_type> >& rangeMap,
3340 const Teuchos::RCP<Teuchos::ParameterList>& params);
3341
3342 // Friend declaration for nonmember function.
3343 template <class CrsMatrixType>
3344 friend Teuchos::RCP<CrsMatrixType>
3345 Tpetra::exportAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3346 const Export<typename CrsMatrixType::local_ordinal_type,
3347 typename CrsMatrixType::global_ordinal_type,
3348 typename CrsMatrixType::node_type>& exporter,
3349 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3350 typename CrsMatrixType::global_ordinal_type,
3351 typename CrsMatrixType::node_type> >& domainMap,
3352 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3353 typename CrsMatrixType::global_ordinal_type,
3354 typename CrsMatrixType::node_type> >& rangeMap,
3355 const Teuchos::RCP<Teuchos::ParameterList>& params);
3356
3357 // Friend declaration for nonmember function.
3358 template <class CrsMatrixType>
3359 friend Teuchos::RCP<CrsMatrixType>
3360 Tpetra::exportAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3361 const Export<typename CrsMatrixType::local_ordinal_type,
3362 typename CrsMatrixType::global_ordinal_type,
3363 typename CrsMatrixType::node_type>& rowExporter,
3364 const Export<typename CrsMatrixType::local_ordinal_type,
3365 typename CrsMatrixType::global_ordinal_type,
3366 typename CrsMatrixType::node_type>& domainExporter,
3367 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3368 typename CrsMatrixType::global_ordinal_type,
3369 typename CrsMatrixType::node_type> >& domainMap,
3370 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3371 typename CrsMatrixType::global_ordinal_type,
3372 typename CrsMatrixType::node_type> >& rangeMap,
3373 const Teuchos::RCP<Teuchos::ParameterList>& params);
3374
3375 public:
3391 void
3393 const import_type& importer,
3394 const Teuchos::RCP<const map_type>& domainMap,
3395 const Teuchos::RCP<const map_type>& rangeMap,
3396 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3397
3413 void
3415 const import_type& rowImporter,
3417 const Teuchos::RCP<const map_type>& domainMap,
3418 const Teuchos::RCP<const map_type>& rangeMap,
3419 const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3420
3436 void
3438 const export_type& exporter,
3439 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3440 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3441 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3442
3458 void
3460 const export_type& rowExporter,
3462 const Teuchos::RCP<const map_type>& domainMap,
3463 const Teuchos::RCP<const map_type>& rangeMap,
3464 const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3465
3466 private:
3487 void
3488 transferAndFillComplete(Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& destMatrix,
3489 const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3490 const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> >& domainTransfer,
3491 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3492 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3493 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3494
3506 protected:
3507 virtual void
3510 const GlobalOrdinal gblColInds[],
3511 const impl_scalar_type vals[],
3512 const size_t numInputEnt);
3513
3514 private:
3524 void
3525 insertGlobalValuesFiltered(
3527 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3528 const Teuchos::ArrayView<const Scalar>& values,
3529 const bool debug);
3530
3533 void
3534 insertGlobalValuesFilteredChecked(
3536 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3537 const Teuchos::ArrayView<const Scalar>& values,
3538 const char* const prefix,
3539 const bool debug,
3540 const bool verbose);
3541
3553 void
3554 combineGlobalValues(
3556 const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3557 const Teuchos::ArrayView<const Scalar>& values,
3559 const char* const prefix,
3560 const bool debug,
3561 const bool verbose);
3562
3585 combineGlobalValuesRaw(const LocalOrdinal lclRow,
3586 const LocalOrdinal numEnt,
3587 const impl_scalar_type vals[],
3588 const GlobalOrdinal cols[],
3590 const char* const prefix,
3591 const bool debug,
3592 const bool verbose);
3593
3605 template <class BinaryFunction>
3607 transformGlobalValues(const GlobalOrdinal globalRow,
3608 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3609 const Teuchos::ArrayView<const Scalar>& values,
3611 const bool atomic = useAtomicUpdatesByDefault) {
3612 typedef impl_scalar_type IST;
3613 typedef LocalOrdinal LO;
3614 typedef GlobalOrdinal GO;
3615
3616 const LO numInputEnt = static_cast<LO>(indices.size());
3617 if (static_cast<LO>(values.size()) != numInputEnt) {
3618 return Teuchos::OrdinalTraits<LO>::invalid();
3619 }
3620
3621 const GO* const inputCols = indices.getRawPtr();
3622 const IST* const inputVals =
3623 reinterpret_cast<const IST*>(values.getRawPtr());
3624 return this->transformGlobalValues(globalRow, numInputEnt, inputVals,
3625 inputCols, f, atomic);
3626 }
3627
3634 void
3635 insertNonownedGlobalValues(const GlobalOrdinal globalRow,
3636 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3637 const Teuchos::ArrayView<const Scalar>& values);
3638
3681 void
3682 insertIndicesAndValues(crs_graph_type& graph,
3683 RowInfo& rowInfo,
3684 const typename crs_graph_type::SLocalGlobalViews& newInds,
3685 const Teuchos::ArrayView<impl_scalar_type>& oldRowVals,
3686 const Teuchos::ArrayView<const impl_scalar_type>& newRowVals,
3687 const ELocalGlobal lg,
3688 const ELocalGlobal I);
3689
3690 protected:
3691 // useful typedefs
3692 typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
3693 typedef KokkosKernels::ArithTraits<impl_scalar_type> STS;
3694 typedef KokkosKernels::ArithTraits<mag_type> STM;
3695 typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> MV;
3696 typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
3697 typedef crs_graph_type Graph;
3698
3699 // Enums
3700 enum GraphAllocationStatus {
3701 GraphAlreadyAllocated,
3702 GraphNotYetAllocated
3703 };
3704
3705 protected:
3724 void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas,
3725 const bool verbose);
3726
3737 static size_t
3739
3754 void
3755 sortAndMergeIndicesAndValues(const bool sorted,
3756 const bool merged);
3757
3758 public:
3760 bool haveGlobalConstants() const;
3761
3762 protected:
3775 mutable Teuchos::RCP<MV> importMV_;
3776
3789 mutable Teuchos::RCP<MV> exportMV_;
3790
3810 Teuchos::RCP<MV>
3812 const bool force = false) const;
3813
3835 Teuchos::RCP<MV>
3837 const bool force = false) const;
3838
3840 void
3841 applyNonTranspose(const MV& X_in,
3842 MV& Y_in,
3843 Scalar alpha,
3844 Scalar beta) const;
3845
3847 void
3848 applyTranspose(const MV& X_in,
3849 MV& Y_in,
3850 const Teuchos::ETransp mode,
3851 Scalar alpha,
3852 Scalar beta) const;
3853
3854 // matrix data accessors
3855
3858 typename values_dualv_type::t_host::const_type
3859 getValuesViewHost(const RowInfo& rowinfo) const;
3860
3863 typename values_dualv_type::t_dev::const_type
3864 getValuesViewDevice(const RowInfo& rowinfo) const;
3865
3868 typename values_dualv_type::t_host
3870
3873 typename values_dualv_type::t_dev
3875
3876 private:
3877 // TODO: When KokkosKernels 4.4 is released, local_matrix_device_type can be permanently modified to use the default_size_type
3878 // 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).
3879 //
3880 // At that point the ApplyHelper can be replaced with just a SPMVHandle.
3881 using local_matrix_int_rowptrs_device_type =
3882 KokkosSparse::CrsMatrix<impl_scalar_type,
3885 void,
3886 int>;
3887
3891 local_matrix_int_rowptrs_device_type,
3892 typename MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::device_view_type>;
3893
3894 std::shared_ptr<ApplyHelper> getApplyHelper() const {
3895 if (!applyHelper) {
3896 auto A_lcl = getLocalMatrixDevice();
3897 applyHelper = std::make_shared<ApplyHelper>(A_lcl.nnz(), A_lcl.graph.row_map);
3898 }
3899 return applyHelper;
3900 }
3901
3902 protected:
3903 // Friend the tester for CrsMatrix::swap
3904 friend class Tpetra::crsMatrix_Swap_Tester<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
3905
3906 // Friend the matrix multiply kernels so they can access internally-cached integer
3907 // row pointers without making them part of the CrsMatrix interface
3908 template <typename S, typename LO, typename GO, typename NODE, typename LOV>
3909 friend struct Tpetra::MMdetails::KernelWrappers;
3910 template <typename S, typename LO, typename GO, typename NODE, typename LOV>
3911 friend struct Tpetra::MMdetails::KernelWrappers2;
3912
3913 // friend Matrix Matrix utility function that needs to access integer-typed rowptrs
3914 friend void Tpetra::MMdetails::import_and_extract_views<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
3915 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
3916 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > targetMap,
3917 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
3918 Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > prototypeImporter,
3919 bool userAssertsThereAreNoRemotes,
3920 const std::string& label,
3921 const Teuchos::RCP<Teuchos::ParameterList>& params);
3922
3926 void swap(CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& matrix);
3927
3928 protected:
3934 void fillLocalMatrix(const Teuchos::RCP<Teuchos::ParameterList>& params);
3935
3941 void fillLocalGraphAndMatrix(const Teuchos::RCP<Teuchos::ParameterList>& params);
3942
3944 void checkInternalState() const;
3945
3957
3958 Teuchos::RCP<const Graph> staticGraph_;
3959 Teuchos::RCP<Graph> myGraph_;
3961
3962 protected:
3973 Details::STORAGE_1D_UNPACKED;
3974
3976 bool fillComplete_ = false;
3977
4005 std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
4006 Teuchos::Array<Scalar> > >
4008
4009 private:
4015 mutable std::shared_ptr<ApplyHelper> applyHelper;
4016
4017 public:
4018 // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
4019 // public inner class of CrsMatrix? It looks like it doesn't
4020 // depend on any implementation details of CrsMatrix at all. It
4021 // should really be declared and defined outside of CrsMatrix.
4022 template <class DestViewType, class SrcViewType,
4024 struct pack_functor {
4025 typedef typename DestViewType::execution_space execution_space;
4026 SrcViewType src_;
4027 DestViewType dst_;
4028 SrcOffsetViewType src_offset_;
4029 DestOffsetViewType dst_offset_;
4030 typedef typename DestOffsetViewType::non_const_value_type scalar_index_type;
4031
4032 pack_functor(DestViewType dst,
4033 const SrcViewType src,
4035 const SrcOffsetViewType src_offset)
4036 : src_(src)
4037 , dst_(dst)
4038 , src_offset_(src_offset)
4039 , dst_offset_(dst_offset) {}
4040
4042 void operator()(const LocalOrdinal row) const {
4043 scalar_index_type srcPos = src_offset_(row);
4044 const scalar_index_type dstEnd = dst_offset_(row + 1);
4045 scalar_index_type dstPos = dst_offset_(row);
4046 for (; dstPos < dstEnd; ++dstPos, ++srcPos) {
4047 dst_(dstPos) = src_(srcPos);
4048 }
4049 }
4050 };
4051}; // class CrsMatrix
4052
4057template <class Scalar,
4058 class LocalOrdinal,
4059 class GlobalOrdinal,
4060 class Node>
4061Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
4063 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
4064 const size_t maxNumEntriesPerRow = 0,
4065 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
4066 using matrix_type =
4068 return Teuchos::rcp(new matrix_type(map, maxNumEntriesPerRow,
4069 params));
4070}
4071
4072template <class CrsMatrixType>
4073Teuchos::RCP<CrsMatrixType>
4074importAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4075 const Import<typename CrsMatrixType::local_ordinal_type,
4076 typename CrsMatrixType::global_ordinal_type,
4077 typename CrsMatrixType::node_type>& importer,
4078 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4079 typename CrsMatrixType::global_ordinal_type,
4080 typename CrsMatrixType::node_type> >& domainMap,
4081 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4082 typename CrsMatrixType::global_ordinal_type,
4083 typename CrsMatrixType::node_type> >& rangeMap,
4084 const Teuchos::RCP<Teuchos::ParameterList>& params) {
4085 Teuchos::RCP<CrsMatrixType> destMatrix;
4086 sourceMatrix->importAndFillComplete(destMatrix, importer, domainMap, rangeMap, params);
4087 return destMatrix;
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>& rowImporter,
4096 const Import<typename CrsMatrixType::local_ordinal_type,
4097 typename CrsMatrixType::global_ordinal_type,
4098 typename CrsMatrixType::node_type>& domainImporter,
4099 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4100 typename CrsMatrixType::global_ordinal_type,
4101 typename CrsMatrixType::node_type> >& domainMap,
4102 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4103 typename CrsMatrixType::global_ordinal_type,
4104 typename CrsMatrixType::node_type> >& rangeMap,
4105 const Teuchos::RCP<Teuchos::ParameterList>& params) {
4106 Teuchos::RCP<CrsMatrixType> destMatrix;
4107 sourceMatrix->importAndFillComplete(destMatrix, rowImporter, domainImporter, domainMap, rangeMap, params);
4108 return destMatrix;
4109}
4110
4111template <class CrsMatrixType>
4112Teuchos::RCP<CrsMatrixType>
4113exportAndFillCompleteCrsMatrix(const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4114 const Export<typename CrsMatrixType::local_ordinal_type,
4115 typename CrsMatrixType::global_ordinal_type,
4116 typename CrsMatrixType::node_type>& exporter,
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->exportAndFillComplete(destMatrix, exporter, 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>& rowExporter,
4135 const Export<typename CrsMatrixType::local_ordinal_type,
4136 typename CrsMatrixType::global_ordinal_type,
4137 typename CrsMatrixType::node_type>& domainExporter,
4138 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4139 typename CrsMatrixType::global_ordinal_type,
4140 typename CrsMatrixType::node_type> >& domainMap,
4141 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4142 typename CrsMatrixType::global_ordinal_type,
4143 typename CrsMatrixType::node_type> >& rangeMap,
4144 const Teuchos::RCP<Teuchos::ParameterList>& params) {
4145 Teuchos::RCP<CrsMatrixType> destMatrix;
4146 sourceMatrix->exportAndFillComplete(destMatrix, rowExporter, domainExporter, domainMap, rangeMap, params);
4147 return destMatrix;
4148}
4149
4156template <class CrsMatrixType>
4158 typename Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitudeType const& threshold =
4159 Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitude(Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::zero())) {
4160 auto localMatrix = matrix.getLocalMatrixDevice();
4161 size_t nnzBefore = localMatrix.nnz();
4162 localMatrix = KokkosSparse::removeCrsMatrixZeros(localMatrix, threshold);
4163 size_t localNNZRemoved = nnzBefore - localMatrix.nnz();
4164 // Skip the expertStaticFillComplete if no entries were removed on any process.
4165 // The fill complete can perform MPI collectives, so it can only be skipped on all processes or none.
4166 size_t globalNNZRemoved = 0;
4167 Teuchos::reduceAll<int, size_t>(*(matrix.getComm()), Teuchos::REDUCE_SUM, 1, &localNNZRemoved, &globalNNZRemoved);
4168 if (globalNNZRemoved != size_t(0)) {
4169 matrix.resumeFill();
4170 matrix.setAllValues(localMatrix);
4171 matrix.expertStaticFillComplete(matrix.getDomainMap(), matrix.getRangeMap());
4172 }
4173}
4174
4175} // namespace Tpetra
4176
4184#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
Special case of apply() for mode == Teuchos::NO_TRANS.
void importAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &destMatrix, const import_type &importer, const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Import from this to the given destination matrix, and make the result fill complete.
CrsGraph< LocalOrdinal, GlobalOrdinal, Node > crs_graph_type
The CrsGraph specialization suitable for this CrsMatrix specialization.
Node node_type
This class' Kokkos Node type.
local_ordinal_type replaceGlobalValues(const global_ordinal_type globalRow, const Kokkos::View< const global_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals)
Replace one or more entries' values, using global indices.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &rowImporter, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &domainImporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
size_t getGlobalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, over all processes in the matrix's communicator.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row,...
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const override
Number of entries in the sparse matrix in the given global row, on the calling (MPI) process.
void scale(const Scalar &alpha)
Scale the matrix's values: this := alpha*this.
GlobalOrdinal global_ordinal_type
The type of each global index in the matrix.
void sortAndMergeIndicesAndValues(const bool sorted, const bool merged)
Sort and merge duplicate local column indices in all rows on the calling process, along with their co...
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
Special case of apply() for mode != Teuchos::NO_TRANS.
size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override
Number of entries in the sparse matrix in the given local row, on the calling (MPI) process.
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createCrsMatrix(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Create an empty CrsMatrix given a row map and a single integer upper bound on the number of stored en...
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
The communicator over which the matrix is distributed.
bool isFillActive() const
Whether the matrix is not fill complete.
void replaceDomainMapAndImporter(const Teuchos::RCP< const map_type > &newDomainMap, Teuchos::RCP< const import_type > &newImporter)
Replace the current domain Map and Import with the given objects.
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.
static size_t mergeRowIndicesAndValues(size_t rowLen, local_ordinal_type *cols, impl_scalar_type *vals)
Merge duplicate row indices in the given row, along with their corresponding values.
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix's graph, as a CrsGraph.
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.