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//
4// Tpetra: Templated Linear Algebra Services Package
5// Copyright (2008) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// ************************************************************************
38// @HEADER
39
40#ifndef TPETRA_CRSMATRIX_DECL_HPP
41#define TPETRA_CRSMATRIX_DECL_HPP
42
45
47#include "Tpetra_LocalCrsMatrixOperator.hpp"
48#include "Tpetra_RowMatrix_decl.hpp"
49#include "Tpetra_Exceptions.hpp"
50#include "Tpetra_DistObject.hpp"
51#include "Tpetra_CrsGraph.hpp"
52#include "Tpetra_Vector.hpp"
53#include "Tpetra_Details_PackTraits.hpp" // unused here, could delete
54#include "KokkosSparse_Utils.hpp"
55#include "KokkosSparse_CrsMatrix.hpp"
56#include "Teuchos_DataAccess.hpp"
57
58#include <memory> // std::shared_ptr
59
60namespace Tpetra {
61
62 // Forward declaration for CrsMatrix::swap() test
63 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> class crsMatrix_Swap_Tester;
64
116 template<class CrsMatrixType>
117 Teuchos::RCP<CrsMatrixType>
118 importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
119 const Import<typename CrsMatrixType::local_ordinal_type,
120 typename CrsMatrixType::global_ordinal_type,
121 typename CrsMatrixType::node_type>& importer,
122 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
123 typename CrsMatrixType::global_ordinal_type,
124 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
125 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
126 typename CrsMatrixType::global_ordinal_type,
127 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
128 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
129
183 template<class CrsMatrixType>
184 Teuchos::RCP<CrsMatrixType>
185 importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
186 const Import<typename CrsMatrixType::local_ordinal_type,
187 typename CrsMatrixType::global_ordinal_type,
188 typename CrsMatrixType::node_type>& rowImporter,
189 const Import<typename CrsMatrixType::local_ordinal_type,
190 typename CrsMatrixType::global_ordinal_type,
191 typename CrsMatrixType::node_type>& domainImporter,
192 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
193 typename CrsMatrixType::global_ordinal_type,
194 typename CrsMatrixType::node_type> >& domainMap,
195 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
196 typename CrsMatrixType::global_ordinal_type,
197 typename CrsMatrixType::node_type> >& rangeMap,
198 const Teuchos::RCP<Teuchos::ParameterList>& params);
199
233 template<class CrsMatrixType>
234 Teuchos::RCP<CrsMatrixType>
235 exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
236 const Export<typename CrsMatrixType::local_ordinal_type,
237 typename CrsMatrixType::global_ordinal_type,
238 typename CrsMatrixType::node_type>& exporter,
239 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
240 typename CrsMatrixType::global_ordinal_type,
241 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
242 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
243 typename CrsMatrixType::global_ordinal_type,
244 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
245 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
246
280 template<class CrsMatrixType>
281 Teuchos::RCP<CrsMatrixType>
282 exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
283 const Export<typename CrsMatrixType::local_ordinal_type,
284 typename CrsMatrixType::global_ordinal_type,
285 typename CrsMatrixType::node_type>& rowExporter,
286 const Export<typename CrsMatrixType::local_ordinal_type,
287 typename CrsMatrixType::global_ordinal_type,
288 typename CrsMatrixType::node_type>& domainExporter,
289 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
290 typename CrsMatrixType::global_ordinal_type,
291 typename CrsMatrixType::node_type> >& domainMap,
292 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
293 typename CrsMatrixType::global_ordinal_type,
294 typename CrsMatrixType::node_type> >& rangeMap,
295 const Teuchos::RCP<Teuchos::ParameterList>& params);
296
299 namespace Details {
300 template<class SC, class LO, class GO, class NO>
301 void residual(const Operator<SC,LO,GO,NO> & A,
305 }
306
420 template <class Scalar,
421 class LocalOrdinal,
422 class GlobalOrdinal,
423 class Node>
424 class CrsMatrix :
425 public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
426 public DistObject<char, LocalOrdinal, GlobalOrdinal, Node>
427 {
428 public:
430
431
439 using device_type = typename Node::device_type;
441 using execution_space = typename device_type::execution_space;
443 using memory_space = typename device_type::memory_space;
444
449 using node_type = Node;
450
453
456
459
462
478 using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
479
482
485 using local_graph_host_type = typename crs_graph_type::local_graph_host_type;
486
490 KokkosSparse::CrsMatrix<impl_scalar_type,
493 void,
494 typename local_graph_device_type::size_type>;
495 using local_matrix_host_type =
496 typename local_matrix_device_type::HostMirror;
497
498
504
505 using row_ptrs_device_view_type =
506 typename row_matrix_type::row_ptrs_device_view_type;
507 using row_ptrs_host_view_type =
508 typename row_matrix_type::row_ptrs_host_view_type;
509
510
511 using local_inds_device_view_type =
512 typename row_matrix_type::local_inds_device_view_type;
513 using local_inds_host_view_type =
514 typename row_matrix_type::local_inds_host_view_type;
515 using nonconst_local_inds_host_view_type =
516 typename row_matrix_type::nonconst_local_inds_host_view_type;
517
518 using global_inds_device_view_type =
519 typename row_matrix_type::global_inds_device_view_type;
520 using global_inds_host_view_type =
521 typename row_matrix_type::global_inds_host_view_type;
522 using nonconst_global_inds_host_view_type =
523 typename row_matrix_type::nonconst_global_inds_host_view_type;
524
525 using values_device_view_type =
526 typename row_matrix_type::values_device_view_type;
527 using values_host_view_type =
528 typename row_matrix_type::values_host_view_type;
529 using nonconst_values_host_view_type =
530 typename row_matrix_type::nonconst_values_host_view_type;
531
533
535
538 GlobalOrdinal, Node>&) = default;
539
542 GlobalOrdinal, Node>&&) = default;
543
545 CrsMatrix&
547 GlobalOrdinal, Node>&) = default;
548
550 CrsMatrix&
552 GlobalOrdinal, Node>&&) = default;
553
567 CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
568 const size_t maxNumEntriesPerRow,
569 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
570
583 CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
584 const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
585 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
586
587
606 CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
607 const Teuchos::RCP<const map_type>& colMap,
608 const size_t maxNumEntPerRow,
609 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
610
629 CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
630 const Teuchos::RCP<const map_type>& colMap,
631 const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
632 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
633
663 const Teuchos::RCP<const crs_graph_type>& graph,
664 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
665
690 explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
691 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
692
721 explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
722 const typename local_matrix_device_type::values_type& values,
723 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
724
751 CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
752 const Teuchos::RCP<const map_type>& colMap,
753 const typename local_graph_device_type::row_map_type& rowPointers,
754 const typename local_graph_device_type::entries_type::non_const_type& columnIndices,
755 const typename local_matrix_device_type::values_type& values,
756 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
757
784 CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
785 const Teuchos::RCP<const map_type>& colMap,
786 const Teuchos::ArrayRCP<size_t>& rowPointers,
787 const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
788 const Teuchos::ArrayRCP<Scalar>& values,
789 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
790
812 CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
813 const Teuchos::RCP<const map_type>& colMap,
815 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
816
848 const Teuchos::RCP<const map_type>& rowMap,
849 const Teuchos::RCP<const map_type>& colMap,
850 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
851 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
852 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
853
859 const Teuchos::RCP<const map_type>& rowMap,
860 const Teuchos::RCP<const map_type>& colMap,
861 const Teuchos::RCP<const map_type>& domainMap,
862 const Teuchos::RCP<const map_type>& rangeMap,
863 const Teuchos::RCP<const import_type>& importer,
864 const Teuchos::RCP<const export_type>& exporter,
865 const Teuchos::RCP<Teuchos::ParameterList>& params =
866 Teuchos::null);
867
869 // This function in 'Copy' mode is only guaranteed to work correctly for matrices
870 // which are fillComplete.
872 const Teuchos::DataAccess copyOrView);
873
883 virtual ~CrsMatrix () = default;
884
885 // This friend declaration makes the clone() method work.
886 template <class S2, class LO2, class GO2, class N2>
887 friend class CrsMatrix;
888
889 // This friend declaration allows for fused residual calculation
890 template <class S2, class LO2, class GO2, class N2>
891 friend void Details::residual(const Operator<S2,LO2,GO2,N2> & A,
895
896 // This friend declaration allows for batching of apply calls
897 template <class MatrixArray, class MultiVectorArray>
898 friend void batchedApply(const MatrixArray &Matrices,
899 const typename std::remove_pointer<typename MultiVectorArray::value_type>::type & X,
901 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type alpha,
902 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type beta,
903 Teuchos::RCP<Teuchos::ParameterList> params);
904
905 public:
907
909
933 //
975 void
977 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
978 const Teuchos::ArrayView<const Scalar>& vals);
979
994 void
996 const LocalOrdinal numEnt,
997 const Scalar vals[],
998 const GlobalOrdinal inds[]);
999
1042 void
1043 insertLocalValues (const LocalOrdinal localRow,
1044 const Teuchos::ArrayView<const LocalOrdinal> &cols,
1045 const Teuchos::ArrayView<const Scalar> &vals,
1046 const CombineMode CM=ADD);
1047
1067 void
1068 insertLocalValues (const LocalOrdinal localRow,
1069 const LocalOrdinal numEnt,
1070 const Scalar vals[],
1071 const LocalOrdinal cols[],
1072 const CombineMode CM=ADD);
1073
1074 protected:
1085 virtual LocalOrdinal
1087 const crs_graph_type& graph,
1088 const RowInfo& rowInfo,
1089 const GlobalOrdinal inds[],
1090 const impl_scalar_type newVals[],
1091 const LocalOrdinal numElts);
1092
1093 public:
1133 const Kokkos::View<const global_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1134 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1135
1140 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1141 const Teuchos::ArrayView<const Scalar>& vals);
1142
1159 const LocalOrdinal numEnt,
1160 const Scalar vals[],
1161 const GlobalOrdinal cols[]);
1162
1163 protected:
1174 virtual LocalOrdinal
1176 const crs_graph_type& graph,
1177 const RowInfo& rowInfo,
1178 const LocalOrdinal inds[],
1179 const impl_scalar_type newVals[],
1180 const LocalOrdinal numElts);
1181
1182 public:
1220 const local_ordinal_type localRow,
1221 const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1222 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1223
1228 replaceLocalValues (const LocalOrdinal localRow,
1229 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1230 const Teuchos::ArrayView<const Scalar>& vals);
1231
1250 replaceLocalValues (const LocalOrdinal localRow,
1251 const LocalOrdinal numEnt,
1252 const Scalar inputVals[],
1253 const LocalOrdinal inputCols[]);
1254
1255 private:
1260 static const bool useAtomicUpdatesByDefault =
1261#ifdef KOKKOS_ENABLE_SERIAL
1262 ! std::is_same<execution_space, Kokkos::Serial>::value;
1263#else
1264 true;
1265#endif // KOKKOS_ENABLE_SERIAL
1266
1290 protected:
1291 virtual LocalOrdinal
1293 const crs_graph_type& graph,
1294 const RowInfo& rowInfo,
1295 const GlobalOrdinal inds[],
1296 const impl_scalar_type newVals[],
1297 const LocalOrdinal numElts,
1298 const bool atomic = useAtomicUpdatesByDefault);
1299
1300 public:
1339 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1340 const Teuchos::ArrayView<const Scalar>& vals,
1341 const bool atomic = useAtomicUpdatesByDefault);
1342
1367 const LocalOrdinal numEnt,
1368 const Scalar vals[],
1369 const GlobalOrdinal cols[],
1370 const bool atomic = useAtomicUpdatesByDefault);
1371
1372 protected:
1385 virtual LocalOrdinal
1387 const crs_graph_type& graph,
1388 const RowInfo& rowInfo,
1389 const LocalOrdinal inds[],
1390 const impl_scalar_type newVals[],
1391 const LocalOrdinal numElts,
1392 const bool atomic = useAtomicUpdatesByDefault);
1393
1394 public:
1433 const local_ordinal_type localRow,
1434 const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1435 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals,
1436 const bool atomic = useAtomicUpdatesByDefault);
1437
1468 sumIntoLocalValues (const LocalOrdinal localRow,
1469 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1470 const Teuchos::ArrayView<const Scalar>& vals,
1471 const bool atomic = useAtomicUpdatesByDefault);
1472
1495 sumIntoLocalValues (const LocalOrdinal localRow,
1496 const LocalOrdinal numEnt,
1497 const Scalar vals[],
1498 const LocalOrdinal cols[],
1499 const bool atomic = useAtomicUpdatesByDefault);
1500
1501 private:
1533 transformLocalValues (impl_scalar_type rowVals[],
1534 const crs_graph_type& graph,
1535 const RowInfo& rowInfo,
1536 const LocalOrdinal inds[],
1537 const impl_scalar_type newVals[],
1538 const LocalOrdinal numElts,
1539 std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1540 const bool atomic = useAtomicUpdatesByDefault);
1541
1573 transformGlobalValues (impl_scalar_type rowVals[],
1574 const crs_graph_type& graph,
1575 const RowInfo& rowInfo,
1576 const GlobalOrdinal inds[],
1577 const impl_scalar_type newVals[],
1578 const LocalOrdinal numElts,
1579 std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1580 const bool atomic = useAtomicUpdatesByDefault);
1581
1609 transformLocalValues (const LocalOrdinal lclRow,
1612 const LocalOrdinal inputCols[],
1613 std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1614 const bool atomic = useAtomicUpdatesByDefault);
1615
1643 transformGlobalValues (const GlobalOrdinal gblRow,
1646 const GlobalOrdinal inputCols[],
1647 std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1648 const bool atomic = useAtomicUpdatesByDefault);
1649
1650 public:
1694 template<class LocalIndicesViewType,
1695 class ImplScalarViewType,
1696 class BinaryFunction>
1699 const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1700 const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1702 const bool atomic = useAtomicUpdatesByDefault)
1703 {
1704 // We use static_assert here to check the template parameters,
1705 // rather than std::enable_if (e.g., on the return value, to
1706 // enable compilation only if the template parameters match the
1707 // desired attributes). This turns obscure link errors into
1708 // clear compilation errors. It also makes the return value a
1709 // lot easier to see.
1710 static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1711 "First template parameter LocalIndicesViewType must be "
1712 "a Kokkos::View.");
1713 static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1714 "Second template parameter ImplScalarViewType must be a "
1715 "Kokkos::View.");
1716 static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1717 "First template parameter LocalIndicesViewType must "
1718 "have rank 1.");
1719 static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1720 "Second template parameter ImplScalarViewType must have "
1721 "rank 1.");
1722 static_assert (std::is_same<
1723 typename LocalIndicesViewType::non_const_value_type,
1724 local_ordinal_type>::value,
1725 "First template parameter LocalIndicesViewType must "
1726 "contain values of type local_ordinal_type.");
1727 static_assert (std::is_same<
1728 typename ImplScalarViewType::non_const_value_type,
1729 impl_scalar_type>::value,
1730 "Second template parameter ImplScalarViewType must "
1731 "contain values of type impl_scalar_type.");
1732 typedef LocalOrdinal LO;
1733 const LO numInputEnt = inputInds.extent (0);
1734 if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1735 return Teuchos::OrdinalTraits<LO>::invalid ();
1736 }
1737 return this->transformLocalValues (lclRow,
1739 inputVals.data (),
1740 inputInds.data (),
1741 f,
1742 atomic);
1743 }
1744
1786 template<class BinaryFunction, class InputMemorySpace>
1789 const Kokkos::View<const GlobalOrdinal*,
1791 Kokkos::MemoryUnmanaged>& inputInds,
1792 const Kokkos::View<const impl_scalar_type*,
1794 Kokkos::MemoryUnmanaged>& inputVals,
1796 const bool atomic = useAtomicUpdatesByDefault)
1797 {
1798 typedef LocalOrdinal LO;
1799 const LO numInputEnt = inputInds.extent (0);
1800 if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1801 return Teuchos::OrdinalTraits<LO>::invalid ();
1802 }
1803 return this->transformGlobalValues (gblRow,
1805 inputVals.data (),
1806 inputInds.data (),
1807 f,
1808 atomic);
1809 }
1810
1812 void setAllToScalar (const Scalar& alpha);
1813
1815 void scale (const Scalar& alpha);
1816
1841 void
1842 setAllValues (const typename local_graph_device_type::row_map_type& ptr,
1843 const typename local_graph_device_type::entries_type::non_const_type& ind,
1844 const typename local_matrix_device_type::values_type& val);
1845
1866 void
1868
1893 void
1894 setAllValues (const Teuchos::ArrayRCP<size_t>& ptr,
1895 const Teuchos::ArrayRCP<LocalOrdinal>& ind,
1896 const Teuchos::ArrayRCP<Scalar>& val);
1897
1899 row_ptrs_host_view_type getLocalRowPtrsHost () const
1900 { return getCrsGraph()->getLocalRowPtrsHost(); }
1901
1903 row_ptrs_device_view_type getLocalRowPtrsDevice () const
1904 { return getCrsGraph()->getLocalRowPtrsDevice(); }
1905
1907 local_inds_host_view_type getLocalIndicesHost () const
1908 { return getCrsGraph()->getLocalIndicesHost(); }
1909
1911 local_inds_device_view_type getLocalIndicesDevice () const
1912 { return getCrsGraph()->getLocalIndicesDevice(); }
1913
1915
1917
1946 void globalAssemble();
1947
1961 void resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1962
2020 void
2021 fillComplete (const Teuchos::RCP<const map_type>& domainMap,
2022 const Teuchos::RCP<const map_type>& rangeMap,
2023 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2024
2051 void
2052 fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2053
2080 void
2081 expertStaticFillComplete (const Teuchos::RCP<const map_type>& domainMap,
2082 const Teuchos::RCP<const map_type>& rangeMap,
2083 const Teuchos::RCP<const import_type>& importer = Teuchos::null,
2084 const Teuchos::RCP<const export_type>& exporter = Teuchos::null,
2085 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2086
2104 void
2105 replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
2106
2188 void
2190 const Teuchos::RCP<const map_type>& newColMap,
2191 const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
2192 const bool sortEachRow = true);
2193
2203 void
2204 replaceDomainMap (const Teuchos::RCP<const map_type>& newDomainMap);
2205
2219 void
2220 replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
2221 Teuchos::RCP<const import_type>& newImporter);
2222
2232 void
2233 replaceRangeMap (const Teuchos::RCP<const map_type>& newRangeMap);
2234
2248 void
2249 replaceRangeMapAndExporter (const Teuchos::RCP<const map_type>& newRangeMap,
2250 Teuchos::RCP<const export_type>& newExporter);
2251
2265 virtual void
2266 removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
2267
2269
2271
2273 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const override;
2274
2275
2277 Teuchos::RCP<const map_type> getRowMap () const override;
2278
2280 Teuchos::RCP<const map_type> getColMap () const override;
2281
2283 Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> >
2284 getGraph () const override;
2285
2287 Teuchos::RCP<const crs_graph_type> getCrsGraph () const;
2288
2289 private:
2300 const crs_graph_type& getCrsGraphRef () const;
2301
2302 public:
2313 local_matrix_host_type getLocalMatrixHost () const;
2314
2320 std::shared_ptr<local_multiply_op_type> getLocalMultiplyOperator () const;
2321
2341 global_size_t getGlobalNumRows() const override;
2342
2348 global_size_t getGlobalNumCols() const override;
2349
2356 size_t getLocalNumRows() const override;
2357
2361 size_t getLocalNumCols() const override;
2362
2364 GlobalOrdinal getIndexBase() const override;
2365
2367 global_size_t getGlobalNumEntries() const override;
2368
2370 size_t getLocalNumEntries() const override;
2371
2378 size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const override;
2379
2386 size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const override;
2387
2395 size_t getGlobalMaxNumRowEntries () const override;
2396
2404 size_t getLocalMaxNumRowEntries () const override;
2405
2407 bool hasColMap () const override;
2408
2409
2430 bool isLocallyIndexed() const override;
2431
2452 bool isGloballyIndexed() const override;
2453
2476 bool isFillComplete() const override;
2477
2500 bool isFillActive() const;
2501
2503
2509 bool isStorageOptimized () const;
2510
2512 bool isStaticGraph () const;
2513
2521 mag_type getFrobeniusNorm () const override;
2522
2525 virtual bool supportsRowViews () const override;
2526
2527protected:
2528 using values_dualv_type =
2529 Kokkos::DualView<impl_scalar_type*, device_type>;
2530 using values_wdv_type =
2531 Details::WrappedDualView<values_dualv_type>;
2532 values_wdv_type valuesUnpacked_wdv;
2533 mutable values_wdv_type valuesPacked_wdv;
2534
2535 using ordinal_rowptrs_type = typename local_multiply_op_type::ordinal_view_type;
2543 mutable ordinal_rowptrs_type ordinalRowptrs;
2544
2545public:
2546
2595 void
2597 nonconst_global_inds_host_view_type &Indices,
2598 nonconst_values_host_view_type &Values,
2599 size_t& NumEntries) const override;
2615 void
2617 nonconst_local_inds_host_view_type &Indices,
2618 nonconst_values_host_view_type &Values,
2619 size_t& NumEntries) const override;
2620
2633
2634 void
2636 global_inds_host_view_type &indices,
2637 values_host_view_type &values) const override;
2638
2651 void
2653 local_inds_host_view_type &indices,
2654 values_host_view_type &values) const override;
2655
2663
2670 void
2672
2716 void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
2717
2739 void
2741 const Kokkos::View<const size_t*, device_type,
2742 Kokkos::MemoryUnmanaged>& offsets) const;
2743
2766 void
2768 const Teuchos::ArrayView<const size_t>& offsets) const;
2769
2774 void
2776
2781 void
2783
2785
2787
2849 void
2852 const Teuchos::ETransp mode = Teuchos::NO_TRANS,
2853 const Scalar& alpha = Teuchos::ScalarTraits<Scalar>::one (),
2854 const Scalar& beta = Teuchos::ScalarTraits<Scalar>::zero ()) const;
2855
2858 template <class T>
2859 Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node> >
2860 convert () const;
2861
2863
2865
2876 void
2879 Teuchos::ETransp mode = Teuchos::NO_TRANS,
2880 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
2881 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const override;
2882
2885 bool hasTransposeApply () const override;
2886
2893 Teuchos::RCP<const map_type> getDomainMap () const override;
2894
2901 Teuchos::RCP<const map_type> getRangeMap () const override;
2902
2904
2906
2917 virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
2918 add (const Scalar& alpha,
2920 const Scalar& beta,
2921 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
2922 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
2923 const Teuchos::RCP<Teuchos::ParameterList>& params) const override;
2924
2926
2928
2930 std::string description () const override;
2931
2934 void
2935 describe (Teuchos::FancyOStream& out,
2936 const Teuchos::EVerbosityLevel verbLevel =
2937 Teuchos::Describable::verbLevel_default) const override;
2938
2940
2942
2947 typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
2949
2950 virtual bool
2951 checkSizes (const SrcDistObject& source) override;
2952
2953 void
2954 applyCrsPadding(
2955 const typename crs_graph_type::padding_type& padding,
2956 const bool verbose);
2957
2958 private:
2959 void
2960 copyAndPermuteStaticGraph(
2962 const size_t numSameIDs,
2965 const size_t numPermutes);
2966
2967 void
2968 copyAndPermuteNonStaticGraph(
2970 const size_t numSameIDs,
2971 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs_dv,
2972 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs_dv,
2973 const size_t numPermutes);
2974
2975 protected:
2976 virtual void
2977 copyAndPermute
2978 (const SrcDistObject& source,
2979 const size_t numSameIDs,
2980 const Kokkos::DualView<
2981 const local_ordinal_type*,
2983 const Kokkos::DualView<
2984 const local_ordinal_type*,
2986 const CombineMode CM) override;
2987
2988 virtual void
2989 packAndPrepare
2990 (const SrcDistObject& source,
2991 const Kokkos::DualView<
2992 const local_ordinal_type*,
2994 Kokkos::DualView<char*, buffer_device_type>& exports,
2995 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
2996 size_t& constantNumPackets) override;
2997
2998 private:
3001 void
3002 unpackAndCombineImpl(
3003 const Kokkos::DualView<const local_ordinal_type*,
3005 Kokkos::DualView<char*, buffer_device_type> imports,
3006 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3007 const size_t constantNumPackets,
3009 const bool verbose);
3010
3013 void
3014 unpackAndCombineImplNonStatic(
3015 const Kokkos::DualView<const local_ordinal_type*,
3017 Kokkos::DualView<char*, buffer_device_type> imports,
3018 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3019 const size_t constantNumPackets,
3020 const CombineMode combineMode);
3021
3022 public:
3032 void
3034 (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& importLIDs,
3035 Kokkos::DualView<char*, buffer_device_type> imports,
3036 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3037 const size_t constantNumPackets,
3038 const CombineMode CM) override;
3039
3145 void
3146 packNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3147 Kokkos::DualView<char*, buffer_device_type>& exports,
3148 const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3149 size_t& constantNumPackets) const;
3150
3151 private:
3158 void
3159 packNonStaticNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3160 Kokkos::DualView<char*, buffer_device_type>& exports,
3161 const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3162 size_t& constantNumPackets) const;
3163
3193 size_t
3194 packRow (char exports[],
3195 const size_t offset,
3196 const size_t numEnt,
3197 const GlobalOrdinal gidsIn[],
3198 const impl_scalar_type valsIn[],
3199 const size_t numBytesPerValue) const;
3200
3224 bool
3225 packRowStatic (char* const numEntOut,
3226 char* const valOut,
3227 char* const indOut,
3228 const size_t numEnt,
3229 const LocalOrdinal lclRow) const;
3230
3256 size_t
3257 unpackRow (GlobalOrdinal gidsOut[],
3259 const char imports[],
3260 const size_t offset,
3261 const size_t numBytes,
3262 const size_t numEnt,
3263 const size_t numBytesPerValue);
3264
3273 void
3274 allocatePackSpaceNew (Kokkos::DualView<char*, buffer_device_type>& exports,
3275 size_t& totalNumEntries,
3276 const Kokkos::DualView<const local_ordinal_type*,
3279
3280 public:
3282 typename local_matrix_host_type::values_type::const_type
3283 getLocalValuesHost (Access::ReadOnlyStruct s) const
3284 {
3285 return valuesPacked_wdv.getHostView(s);
3286 }
3287
3289 typename local_matrix_host_type::values_type
3290 getLocalValuesHost (Access::ReadWriteStruct s)
3291 {
3292 return valuesPacked_wdv.getHostView(s);
3293 }
3294
3296 typename local_matrix_host_type::values_type
3297 getLocalValuesHost (Access::OverwriteAllStruct s)
3298 {
3299 return valuesPacked_wdv.getHostView(s);
3300 }
3301
3303 typename local_matrix_device_type::values_type::const_type
3304 getLocalValuesDevice (Access::ReadOnlyStruct s) const
3305 {
3306 return valuesPacked_wdv.getDeviceView(s);
3307 }
3308
3310 typename local_matrix_device_type::values_type
3311 getLocalValuesDevice (Access::ReadWriteStruct s)
3312 {
3313 return valuesPacked_wdv.getDeviceView(s);
3314 }
3315
3317 typename local_matrix_device_type::values_type
3318 getLocalValuesDevice (Access::OverwriteAllStruct s)
3319 {
3320 return valuesPacked_wdv.getDeviceView(s);
3321 }
3322
3323 private:
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>& importer,
3331 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3332 typename CrsMatrixType::global_ordinal_type,
3333 typename CrsMatrixType::node_type> >& domainMap,
3334 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3335 typename CrsMatrixType::global_ordinal_type,
3336 typename CrsMatrixType::node_type> >& rangeMap,
3337 const Teuchos::RCP<Teuchos::ParameterList>& params);
3338
3339 // Friend declaration for nonmember function.
3340 template<class CrsMatrixType>
3341 friend Teuchos::RCP<CrsMatrixType>
3342 Tpetra::importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3343 const Import<typename CrsMatrixType::local_ordinal_type,
3344 typename CrsMatrixType::global_ordinal_type,
3345 typename CrsMatrixType::node_type>& rowImporter,
3346 const Import<typename CrsMatrixType::local_ordinal_type,
3347 typename CrsMatrixType::global_ordinal_type,
3348 typename CrsMatrixType::node_type>& domainImporter,
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
3358 // Friend declaration for nonmember function.
3359 template<class CrsMatrixType>
3360 friend Teuchos::RCP<CrsMatrixType>
3361 Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3362 const Export<typename CrsMatrixType::local_ordinal_type,
3363 typename CrsMatrixType::global_ordinal_type,
3364 typename CrsMatrixType::node_type>& exporter,
3365 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3366 typename CrsMatrixType::global_ordinal_type,
3367 typename CrsMatrixType::node_type> >& domainMap,
3368 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3369 typename CrsMatrixType::global_ordinal_type,
3370 typename CrsMatrixType::node_type> >& rangeMap,
3371 const Teuchos::RCP<Teuchos::ParameterList>& params);
3372
3373 // Friend declaration for nonmember function.
3374 template<class CrsMatrixType>
3375 friend Teuchos::RCP<CrsMatrixType>
3376 Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3377 const Export<typename CrsMatrixType::local_ordinal_type,
3378 typename CrsMatrixType::global_ordinal_type,
3379 typename CrsMatrixType::node_type>& rowExporter,
3380 const Export<typename CrsMatrixType::local_ordinal_type,
3381 typename CrsMatrixType::global_ordinal_type,
3382 typename CrsMatrixType::node_type>& domainExporter,
3383 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3384 typename CrsMatrixType::global_ordinal_type,
3385 typename CrsMatrixType::node_type> >& domainMap,
3386 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3387 typename CrsMatrixType::global_ordinal_type,
3388 typename CrsMatrixType::node_type> >& rangeMap,
3389 const Teuchos::RCP<Teuchos::ParameterList>& params);
3390
3391 public:
3407 void
3409 const import_type& importer,
3410 const Teuchos::RCP<const map_type>& domainMap,
3411 const Teuchos::RCP<const map_type>& rangeMap,
3412 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3413
3429 void
3431 const import_type& rowImporter,
3433 const Teuchos::RCP<const map_type>& domainMap,
3434 const Teuchos::RCP<const map_type>& rangeMap,
3435 const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3436
3437
3453 void
3455 const export_type& exporter,
3456 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3457 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3458 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3459
3475 void
3477 const export_type& rowExporter,
3479 const Teuchos::RCP<const map_type>& domainMap,
3480 const Teuchos::RCP<const map_type>& rangeMap,
3481 const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3482
3483
3484 private:
3505 void
3506 transferAndFillComplete (Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& destMatrix,
3507 const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3508 const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > & domainTransfer,
3509 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3510 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3511 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3512
3524 protected:
3525 virtual void
3528 const GlobalOrdinal gblColInds[],
3529 const impl_scalar_type vals[],
3530 const size_t numInputEnt);
3531
3532 private:
3542 void
3543 insertGlobalValuesFiltered(
3545 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3546 const Teuchos::ArrayView<const Scalar>& values,
3547 const bool debug);
3548
3551 void
3552 insertGlobalValuesFilteredChecked(
3554 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3555 const Teuchos::ArrayView<const Scalar>& values,
3556 const char* const prefix,
3557 const bool debug,
3558 const bool verbose);
3559
3571 void
3572 combineGlobalValues(
3574 const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3575 const Teuchos::ArrayView<const Scalar>& values,
3577 const char* const prefix,
3578 const bool debug,
3579 const bool verbose);
3580
3603 combineGlobalValuesRaw(const LocalOrdinal lclRow,
3604 const LocalOrdinal numEnt,
3605 const impl_scalar_type vals[],
3606 const GlobalOrdinal cols[],
3608 const char* const prefix,
3609 const bool debug,
3610 const bool verbose);
3611
3623 template<class BinaryFunction>
3625 transformGlobalValues (const GlobalOrdinal globalRow,
3626 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3627 const Teuchos::ArrayView<const Scalar>& values,
3629 const bool atomic = useAtomicUpdatesByDefault)
3630 {
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
3710 typedef DistObject<char, LocalOrdinal, GlobalOrdinal, Node> dist_object_type;
3711
3712 protected:
3713 // useful typedefs
3714 typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
3715 typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
3716 typedef Kokkos::Details::ArithTraits<mag_type> STM;
3717 typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> MV;
3718 typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
3719 typedef crs_graph_type Graph;
3720
3721 // Enums
3722 enum GraphAllocationStatus {
3723 GraphAlreadyAllocated,
3724 GraphNotYetAllocated
3725 };
3726
3727 protected:
3746 void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas,
3747 const bool verbose);
3748
3759 static size_t
3760 mergeRowIndicesAndValues (size_t rowLen, local_ordinal_type* cols, impl_scalar_type* vals);
3761
3776 void
3777 sortAndMergeIndicesAndValues (const bool sorted,
3778 const bool merged);
3779
3780 public:
3781
3783 bool haveGlobalConstants() const;
3784
3785 protected:
3798 mutable Teuchos::RCP<MV> importMV_;
3799
3812 mutable Teuchos::RCP<MV> exportMV_;
3813
3833 Teuchos::RCP<MV>
3835 const bool force = false) const;
3836
3858 Teuchos::RCP<MV>
3860 const bool force = false) const;
3861
3863 void
3864 applyNonTranspose (const MV& X_in,
3865 MV& Y_in,
3866 Scalar alpha,
3867 Scalar beta) const;
3868
3870 void
3871 applyTranspose (const MV& X_in,
3872 MV& Y_in,
3873 const Teuchos::ETransp mode,
3874 Scalar alpha,
3875 Scalar beta) const;
3876
3877 // matrix data accessors
3878
3881 typename values_dualv_type::t_host::const_type
3882 getValuesViewHost (const RowInfo& rowinfo) const;
3883
3886 typename values_dualv_type::t_dev::const_type
3887 getValuesViewDevice (const RowInfo& rowinfo) const;
3888
3891 typename values_dualv_type::t_host
3893
3896 typename values_dualv_type::t_dev
3898
3899
3900 protected:
3901
3902 // Friend the tester for CrsMatrix::swap
3903 friend class Tpetra::crsMatrix_Swap_Tester<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
3904
3909
3910
3911 protected:
3912
3918 void fillLocalMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
3919
3925 void fillLocalGraphAndMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
3926
3928 void checkInternalState () const;
3929
3941
3942 Teuchos::RCP<const Graph> staticGraph_;
3943 Teuchos::RCP< Graph> myGraph_;
3945
3946protected:
3957 Details::STORAGE_1D_UNPACKED;
3958
3960 bool fillComplete_ = false;
3961
3989 std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
3990 Teuchos::Array<Scalar> > > nonlocals_;
3991
3992 public:
3993 // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
3994 // public inner class of CrsMatrix? It looks like it doesn't
3995 // depend on any implementation details of CrsMatrix at all. It
3996 // should really be declared and defined outside of CrsMatrix.
3997 template<class DestViewType, class SrcViewType,
3999 struct pack_functor {
4000 typedef typename DestViewType::execution_space execution_space;
4001 SrcViewType src_;
4002 DestViewType dst_;
4003 SrcOffsetViewType src_offset_;
4004 DestOffsetViewType dst_offset_;
4005 typedef typename DestOffsetViewType::non_const_value_type scalar_index_type;
4006
4007 pack_functor (DestViewType dst,
4008 const SrcViewType src,
4010 const SrcOffsetViewType src_offset) :
4011 src_ (src),
4012 dst_ (dst),
4013 src_offset_ (src_offset),
4014 dst_offset_ (dst_offset)
4015 {}
4016
4018 void operator () (const LocalOrdinal row) const {
4019 scalar_index_type srcPos = src_offset_(row);
4020 const scalar_index_type dstEnd = dst_offset_(row+1);
4021 scalar_index_type dstPos = dst_offset_(row);
4022 for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
4023 dst_(dstPos) = src_(srcPos);
4024 }
4025 }
4026 };
4027 }; // class CrsMatrix
4028
4033 template<class Scalar,
4034 class LocalOrdinal,
4035 class GlobalOrdinal,
4036 class Node>
4037 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
4039 const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& map,
4040 const size_t maxNumEntriesPerRow = 0,
4041 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4042 {
4043 using matrix_type =
4045 return Teuchos::rcp(new matrix_type(map, maxNumEntriesPerRow,
4046 params));
4047 }
4048
4049 template<class CrsMatrixType>
4050 Teuchos::RCP<CrsMatrixType>
4051 importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4052 const Import<typename CrsMatrixType::local_ordinal_type,
4053 typename CrsMatrixType::global_ordinal_type,
4054 typename CrsMatrixType::node_type>& importer,
4055 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4056 typename CrsMatrixType::global_ordinal_type,
4057 typename CrsMatrixType::node_type> >& domainMap,
4058 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4059 typename CrsMatrixType::global_ordinal_type,
4060 typename CrsMatrixType::node_type> >& rangeMap,
4061 const Teuchos::RCP<Teuchos::ParameterList>& params)
4062 {
4063 Teuchos::RCP<CrsMatrixType> destMatrix;
4064 sourceMatrix->importAndFillComplete (destMatrix, importer, domainMap, rangeMap, params);
4065 return destMatrix;
4066 }
4067
4068 template<class CrsMatrixType>
4069 Teuchos::RCP<CrsMatrixType>
4070 importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4071 const Import<typename CrsMatrixType::local_ordinal_type,
4072 typename CrsMatrixType::global_ordinal_type,
4073 typename CrsMatrixType::node_type>& rowImporter,
4074 const Import<typename CrsMatrixType::local_ordinal_type,
4075 typename CrsMatrixType::global_ordinal_type,
4076 typename CrsMatrixType::node_type>& domainImporter,
4077 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4078 typename CrsMatrixType::global_ordinal_type,
4079 typename CrsMatrixType::node_type> >& domainMap,
4080 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4081 typename CrsMatrixType::global_ordinal_type,
4082 typename CrsMatrixType::node_type> >& rangeMap,
4083 const Teuchos::RCP<Teuchos::ParameterList>& params)
4084 {
4085 Teuchos::RCP<CrsMatrixType> destMatrix;
4086 sourceMatrix->importAndFillComplete (destMatrix, rowImporter, domainImporter, domainMap, rangeMap, params);
4087 return destMatrix;
4088 }
4089
4090 template<class CrsMatrixType>
4091 Teuchos::RCP<CrsMatrixType>
4092 exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4093 const Export<typename CrsMatrixType::local_ordinal_type,
4094 typename CrsMatrixType::global_ordinal_type,
4095 typename CrsMatrixType::node_type>& exporter,
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 {
4104 Teuchos::RCP<CrsMatrixType> destMatrix;
4105 sourceMatrix->exportAndFillComplete (destMatrix, exporter, domainMap, rangeMap, params);
4106 return destMatrix;
4107 }
4108
4109 template<class CrsMatrixType>
4110 Teuchos::RCP<CrsMatrixType>
4111 exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4112 const Export<typename CrsMatrixType::local_ordinal_type,
4113 typename CrsMatrixType::global_ordinal_type,
4114 typename CrsMatrixType::node_type>& rowExporter,
4115 const Export<typename CrsMatrixType::local_ordinal_type,
4116 typename CrsMatrixType::global_ordinal_type,
4117 typename CrsMatrixType::node_type>& domainExporter,
4118 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4119 typename CrsMatrixType::global_ordinal_type,
4120 typename CrsMatrixType::node_type> >& domainMap,
4121 const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4122 typename CrsMatrixType::global_ordinal_type,
4123 typename CrsMatrixType::node_type> >& rangeMap,
4124 const Teuchos::RCP<Teuchos::ParameterList>& params)
4125 {
4126 Teuchos::RCP<CrsMatrixType> destMatrix;
4127 sourceMatrix->exportAndFillComplete (destMatrix, rowExporter, domainExporter, domainMap, rangeMap, params);
4128 return destMatrix;
4129 }
4130
4137 template<class CrsMatrixType>
4138 void
4140 typename Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitudeType const & threshold =
4141 Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitude( Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::zero() ))
4142 {
4143 auto localMatrix = matrix.getLocalMatrixDevice();
4144 localMatrix = KokkosSparse::removeCrsMatrixZeros(localMatrix,threshold);
4145 matrix.resumeFill();
4146 matrix.setAllValues(localMatrix);
4147 matrix.expertStaticFillComplete(matrix.getDomainMap(),matrix.getRangeMap());
4148 }
4149
4150} // namespace Tpetra
4151
4159#endif // TPETRA_CRSMATRIX_DECL_HPP
Forward declaration of Tpetra::CrsMatrix.
Declaration and generic definition of traits class that tells Tpetra::CrsMatrix how to pack and unpac...
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
Kokkos::StaticCrsGraph< local_ordinal_type, Kokkos::LayoutLeft, device_type, void, size_t > local_graph_device_type
The type of the part of the sparse graph on each MPI process.
typename local_graph_device_type::HostMirror local_graph_host_type
The type of the part of the sparse graph on each MPI process.
Struct that holds views of the contents of a CrsMatrix.
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.
ordinal_rowptrs_type ordinalRowptrs
local_ordinal typed version of local matrix's rowptrs. This allows the LocalCrsMatrixOperator to have...
void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< char *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode CM) override
Unpack the imported column indices and values, and combine into matrix.
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.
Teuchos::RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Return another CrsMatrix with the same entries, but converted to a different Scalar type T.
values_dualv_type::t_dev getValuesViewDeviceNonConst(const RowInfo &rowinfo)
Get a non-const Device view of the locally owned values row myRow, such that rowinfo = getRowInfo(myR...
void expertStaticFillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< const import_type > &importer=Teuchos::null, const Teuchos::RCP< const export_type > &exporter=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Perform a fillComplete on a matrix that already has data.
std::shared_ptr< local_multiply_op_type > getLocalMultiplyOperator() const
The local sparse matrix operator (a wrapper of getLocalMatrixDevice() that supports local matrix-vect...
LocalOrdinal transformLocalValues(const LocalOrdinal lclRow, const typename UnmanagedView< LocalIndicesViewType >::type &inputInds, const typename UnmanagedView< ImplScalarViewType >::type &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault)
Transform CrsMatrix entries in place, using local indices to select the entries in the row to transfo...
local_ordinal_type sumIntoLocalValues(const local_ordinal_type localRow, const Kokkos::View< const local_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals, const bool atomic=useAtomicUpdatesByDefault)
Sum into one or more sparse matrix entries, using local row and column indices.
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.
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.
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.
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.
Scalar scalar_type
The type of each entry in the matrix.
LocalOrdinal local_ordinal_type
The type of each local index in the matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const override
Get a constant, nonpersisting view of a row of this matrix, using local row and column indices,...
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local graph and matrix.
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.
local_matrix_device_type getLocalMatrixDevice() const
The local sparse matrix.
void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const override
Get a constant view of a row of this matrix, using local row and column indices.
Teuchos::RCP< const map_type > getColMap() const override
The Map that describes the column distribution in this matrix.
void insertGlobalValues(const GlobalOrdinal globalRow, const Teuchos::ArrayView< const GlobalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using global column indices.
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
void fillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Tell the matrix that you are done changing its structure or values, and that you are ready to do comp...
typename crs_graph_type::local_graph_device_type local_graph_device_type
The part of the sparse matrix's graph on each MPI process.
void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const override
Get a constant, nonpersisting view of a row of this matrix, using global row and column indices.
void setAllValues(const typename local_graph_device_type::row_map_type &ptr, const typename local_graph_device_type::entries_type::non_const_type &ind, const typename local_matrix_device_type::values_type &val)
Set the local matrix using three (compressed sparse row) arrays.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const override
This matrix's graph, as a RowGraph.
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().
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...
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.
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.
Keep track of how much more space a CrsGraph or CrsMatrix needs, when the graph or matrix is the targ...
Base class for distributed Tpetra objects that support data redistribution.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Abstract interface for local operators (e.g., matrices and preconditioners).
A parallel distribution of indices over processes.
One or more distributed dense vectors.
A read-only, row-oriented interface to a sparse matrix.
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Abstract base class for objects that can be the source of an Import or Export operation.
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.