11 #ifndef TPETRA_CRSMATRIX_DECL_HPP
12 #define TPETRA_CRSMATRIX_DECL_HPP
19 #include "KokkosSparse_Utils.hpp"
20 #include "KokkosSparse_CrsMatrix.hpp"
21 #include "Tpetra_Details_MatrixApplyHelper.hpp"
22 #include "Tpetra_RowMatrix_decl.hpp"
23 #include "Tpetra_Exceptions.hpp"
24 #include "Tpetra_DistObject.hpp"
25 #include "Tpetra_CrsGraph.hpp"
26 #include "Tpetra_Vector.hpp"
28 #include "Tpetra_Details_ExecutionSpacesUser.hpp"
29 #include "Teuchos_DataAccess.hpp"
37 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
class crsMatrix_Swap_Tester;
90 template<
class CrsMatrixType>
91 Teuchos::RCP<CrsMatrixType>
93 const Import<
typename CrsMatrixType::local_ordinal_type,
94 typename CrsMatrixType::global_ordinal_type,
95 typename CrsMatrixType::node_type>& importer,
96 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
97 typename CrsMatrixType::global_ordinal_type,
98 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
99 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
100 typename CrsMatrixType::global_ordinal_type,
101 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
102 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
157 template<
class CrsMatrixType>
158 Teuchos::RCP<CrsMatrixType>
160 const Import<
typename CrsMatrixType::local_ordinal_type,
161 typename CrsMatrixType::global_ordinal_type,
162 typename CrsMatrixType::node_type>& rowImporter,
163 const Import<
typename CrsMatrixType::local_ordinal_type,
164 typename CrsMatrixType::global_ordinal_type,
165 typename CrsMatrixType::node_type>& domainImporter,
166 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
167 typename CrsMatrixType::global_ordinal_type,
168 typename CrsMatrixType::node_type> >& domainMap,
169 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
170 typename CrsMatrixType::global_ordinal_type,
171 typename CrsMatrixType::node_type> >& rangeMap,
172 const Teuchos::RCP<Teuchos::ParameterList>& params);
207 template<
class CrsMatrixType>
208 Teuchos::RCP<CrsMatrixType>
210 const Export<
typename CrsMatrixType::local_ordinal_type,
211 typename CrsMatrixType::global_ordinal_type,
212 typename CrsMatrixType::node_type>& exporter,
213 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
214 typename CrsMatrixType::global_ordinal_type,
215 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
216 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
217 typename CrsMatrixType::global_ordinal_type,
218 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
219 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
254 template<
class CrsMatrixType>
255 Teuchos::RCP<CrsMatrixType>
257 const Export<
typename CrsMatrixType::local_ordinal_type,
258 typename CrsMatrixType::global_ordinal_type,
259 typename CrsMatrixType::node_type>& rowExporter,
260 const Export<
typename CrsMatrixType::local_ordinal_type,
261 typename CrsMatrixType::global_ordinal_type,
262 typename CrsMatrixType::node_type>& domainExporter,
263 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
264 typename CrsMatrixType::global_ordinal_type,
265 typename CrsMatrixType::node_type> >& domainMap,
266 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
267 typename CrsMatrixType::global_ordinal_type,
268 typename CrsMatrixType::node_type> >& rangeMap,
269 const Teuchos::RCP<Teuchos::ParameterList>& params);
274 template<
class SC,
class LO,
class GO,
class NO>
275 void residual(
const Operator<SC,LO,GO,NO> & A,
276 const MultiVector<SC,LO,GO,NO> & X,
277 const MultiVector<SC,LO,GO,NO> & B,
278 MultiVector<SC,LO,GO,NO> & R);
394 template <
class Scalar,
399 public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
400 public DistObject<char, LocalOrdinal, GlobalOrdinal, Node>,
461 using mag_type =
typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
477 typename local_graph_device_type::size_type>;
478 #if KOKKOS_VERSION >= 40799
479 using local_matrix_host_type =
480 typename local_matrix_device_type::host_mirror_type;
482 using local_matrix_host_type =
483 typename local_matrix_device_type::HostMirror;
486 using row_ptrs_device_view_type =
487 typename row_matrix_type::row_ptrs_device_view_type;
488 using row_ptrs_host_view_type =
489 typename row_matrix_type::row_ptrs_host_view_type;
492 using local_inds_device_view_type =
493 typename row_matrix_type::local_inds_device_view_type;
494 using local_inds_host_view_type =
495 typename row_matrix_type::local_inds_host_view_type;
496 using nonconst_local_inds_host_view_type =
497 typename row_matrix_type::nonconst_local_inds_host_view_type;
499 using global_inds_device_view_type =
500 typename row_matrix_type::global_inds_device_view_type;
501 using global_inds_host_view_type =
502 typename row_matrix_type::global_inds_host_view_type;
503 using nonconst_global_inds_host_view_type =
504 typename row_matrix_type::nonconst_global_inds_host_view_type;
506 using values_device_view_type =
507 typename row_matrix_type::values_device_view_type;
508 using values_host_view_type =
509 typename row_matrix_type::values_host_view_type;
510 using nonconst_values_host_view_type =
511 typename row_matrix_type::nonconst_values_host_view_type;
519 GlobalOrdinal, Node>&) =
default;
523 GlobalOrdinal, Node>&&) =
default;
528 GlobalOrdinal, Node>&) =
default;
533 GlobalOrdinal, Node>&&) =
default;
548 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
549 const size_t maxNumEntriesPerRow,
550 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
564 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
565 const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
566 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
587 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
588 const Teuchos::RCP<const map_type>& colMap,
589 const size_t maxNumEntPerRow,
590 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
610 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
611 const Teuchos::RCP<const map_type>& colMap,
612 const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
613 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
644 const Teuchos::RCP<const crs_graph_type>& graph,
645 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
671 explicit CrsMatrix (
const Teuchos::RCP<const crs_graph_type>& graph,
672 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
702 explicit CrsMatrix (
const Teuchos::RCP<const crs_graph_type>& graph,
703 const typename local_matrix_device_type::values_type& values,
704 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
732 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
733 const Teuchos::RCP<const map_type>& colMap,
734 const typename local_graph_device_type::row_map_type& rowPointers,
735 const typename local_graph_device_type::entries_type::non_const_type& columnIndices,
736 const typename local_matrix_device_type::values_type& values,
737 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
765 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
766 const Teuchos::RCP<const map_type>& colMap,
767 const Teuchos::ArrayRCP<size_t>& rowPointers,
768 const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
769 const Teuchos::ArrayRCP<Scalar>& values,
770 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
793 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
794 const Teuchos::RCP<const map_type>& colMap,
796 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
829 const Teuchos::RCP<const map_type>& rowMap,
830 const Teuchos::RCP<const map_type>& colMap,
831 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
832 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
833 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
840 const Teuchos::RCP<const map_type>& rowMap,
841 const Teuchos::RCP<const map_type>& colMap,
842 const Teuchos::RCP<const map_type>& domainMap,
843 const Teuchos::RCP<const map_type>& rangeMap,
844 const Teuchos::RCP<const import_type>& importer,
845 const Teuchos::RCP<const export_type>& exporter,
846 const Teuchos::RCP<Teuchos::ParameterList>& params =
853 const Teuchos::DataAccess copyOrView);
867 template <
class S2,
class LO2,
class GO2,
class N2>
871 template <
class S2,
class LO2,
class GO2,
class N2>
878 template <
class MatrixArray,
class MultiVectorArray>
880 const typename std::remove_pointer<typename MultiVectorArray::value_type>::type & X,
882 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type alpha,
883 typename std::remove_pointer<typename MatrixArray::value_type>::type::scalar_type beta,
884 Teuchos::RCP<Teuchos::ParameterList> params);
958 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
959 const Teuchos::ArrayView<const Scalar>& vals);
977 const LocalOrdinal numEnt,
979 const GlobalOrdinal inds[]);
1025 const Teuchos::ArrayView<const LocalOrdinal> &cols,
1026 const Teuchos::ArrayView<const Scalar> &vals,
1050 const LocalOrdinal numEnt,
1051 const Scalar vals[],
1052 const LocalOrdinal cols[],
1066 virtual LocalOrdinal
1070 const GlobalOrdinal inds[],
1072 const LocalOrdinal numElts);
1114 const Kokkos::View<const global_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1115 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1121 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1122 const Teuchos::ArrayView<const Scalar>& vals);
1140 const LocalOrdinal numEnt,
1141 const Scalar vals[],
1142 const GlobalOrdinal cols[]);
1155 virtual LocalOrdinal
1159 const LocalOrdinal inds[],
1161 const LocalOrdinal numElts);
1202 const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1203 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals);
1210 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1211 const Teuchos::ArrayView<const Scalar>& vals);
1232 const LocalOrdinal numEnt,
1233 const Scalar inputVals[],
1234 const LocalOrdinal inputCols[]);
1241 static const bool useAtomicUpdatesByDefault =
1242 #ifdef KOKKOS_ENABLE_SERIAL
1243 ! std::is_same<execution_space, Kokkos::Serial>::value;
1246 #endif // KOKKOS_ENABLE_SERIAL
1272 virtual LocalOrdinal
1276 const GlobalOrdinal inds[],
1278 const LocalOrdinal numElts,
1279 const bool atomic = useAtomicUpdatesByDefault);
1320 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1321 const Teuchos::ArrayView<const Scalar>& vals,
1322 const bool atomic = useAtomicUpdatesByDefault);
1348 const LocalOrdinal numEnt,
1349 const Scalar vals[],
1350 const GlobalOrdinal cols[],
1351 const bool atomic = useAtomicUpdatesByDefault);
1366 virtual LocalOrdinal
1370 const LocalOrdinal inds[],
1372 const LocalOrdinal numElts,
1373 const bool atomic = useAtomicUpdatesByDefault);
1415 const Kokkos::View<const local_ordinal_type*, Kokkos::AnonymousSpace>& inputInds,
1416 const Kokkos::View<const impl_scalar_type*, Kokkos::AnonymousSpace>& inputVals,
1417 const bool atomic = useAtomicUpdatesByDefault);
1450 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1451 const Teuchos::ArrayView<const Scalar>& vals,
1452 const bool atomic = useAtomicUpdatesByDefault);
1477 const LocalOrdinal numEnt,
1478 const Scalar vals[],
1479 const LocalOrdinal cols[],
1480 const bool atomic = useAtomicUpdatesByDefault);
1517 const LocalOrdinal inds[],
1519 const LocalOrdinal numElts,
1521 const bool atomic = useAtomicUpdatesByDefault);
1557 const GlobalOrdinal inds[],
1559 const LocalOrdinal numElts,
1561 const bool atomic = useAtomicUpdatesByDefault);
1590 transformLocalValues (
const LocalOrdinal lclRow,
1591 const LocalOrdinal numInputEnt,
1593 const LocalOrdinal inputCols[],
1595 const bool atomic = useAtomicUpdatesByDefault);
1624 transformGlobalValues (
const GlobalOrdinal gblRow,
1625 const LocalOrdinal numInputEnt,
1627 const GlobalOrdinal inputCols[],
1629 const bool atomic = useAtomicUpdatesByDefault);
1675 template<
class LocalIndicesViewType,
1676 class ImplScalarViewType,
1677 class BinaryFunction>
1680 const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1681 const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1683 const bool atomic = useAtomicUpdatesByDefault)
1691 static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1692 "First template parameter LocalIndicesViewType must be "
1694 static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1695 "Second template parameter ImplScalarViewType must be a "
1697 static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1698 "First template parameter LocalIndicesViewType must "
1700 static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1701 "Second template parameter ImplScalarViewType must have "
1703 static_assert (std::is_same<
1704 typename LocalIndicesViewType::non_const_value_type,
1706 "First template parameter LocalIndicesViewType must "
1707 "contain values of type local_ordinal_type.");
1708 static_assert (std::is_same<
1709 typename ImplScalarViewType::non_const_value_type,
1711 "Second template parameter ImplScalarViewType must "
1712 "contain values of type impl_scalar_type.");
1713 typedef LocalOrdinal LO;
1714 const LO numInputEnt = inputInds.extent (0);
1715 if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1716 return Teuchos::OrdinalTraits<LO>::invalid ();
1718 return this->transformLocalValues (lclRow,
1767 template<
class BinaryFunction,
class InputMemorySpace>
1770 const Kokkos::View<
const GlobalOrdinal*,
1772 Kokkos::MemoryUnmanaged>& inputInds,
1775 Kokkos::MemoryUnmanaged>& inputVals,
1777 const bool atomic = useAtomicUpdatesByDefault)
1779 typedef LocalOrdinal LO;
1780 const LO numInputEnt = inputInds.extent (0);
1781 if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1782 return Teuchos::OrdinalTraits<LO>::invalid ();
1784 return this->transformGlobalValues (gblRow,
1796 void scale (
const Scalar& alpha);
1823 setAllValues (
const typename local_graph_device_type::row_map_type& ptr,
1824 const typename local_graph_device_type::entries_type::non_const_type& ind,
1825 const typename local_matrix_device_type::values_type& val);
1876 const Teuchos::ArrayRCP<LocalOrdinal>& ind,
1877 const Teuchos::ArrayRCP<Scalar>& val);
1885 {
return getCrsGraph()->getLocalRowPtrsDevice(); }
1893 {
return getCrsGraph()->getLocalIndicesDevice(); }
1942 void resumeFill (
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2002 fillComplete (
const Teuchos::RCP<const map_type>& domainMap,
2003 const Teuchos::RCP<const map_type>& rangeMap,
2004 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2033 fillComplete (
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2063 const Teuchos::RCP<const map_type>& rangeMap,
2064 const Teuchos::RCP<const import_type>& importer = Teuchos::null,
2065 const Teuchos::RCP<const export_type>& exporter = Teuchos::null,
2066 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2086 replaceColMap (
const Teuchos::RCP<const map_type>& newColMap);
2171 const Teuchos::RCP<const map_type>& newColMap,
2172 const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
2173 const bool sortEachRow =
true);
2202 Teuchos::RCP<const import_type>& newImporter);
2231 Teuchos::RCP<const export_type>& newExporter);
2254 Teuchos::RCP<const Teuchos::Comm<int> >
getComm()
const override;
2258 Teuchos::RCP<const map_type>
getRowMap ()
const override;
2261 Teuchos::RCP<const map_type>
getColMap ()
const override;
2264 Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> >
2268 Teuchos::RCP<const crs_graph_type>
getCrsGraph ()
const;
2284 #if __armclang_major__ == 22 && __armclang_minor__ == 1
2289 #define TPETRA_DETAILS_ALWAYS_INLINE __attribute__((always_inline))
2291 #define TPETRA_DETAILS_ALWAYS_INLINE
2307 local_matrix_host_type getLocalMatrixHost ()
const;
2308 #undef TPETRA_DETAILS_ALWAYS_INLINE
2539 using values_dualv_type =
2540 Kokkos::DualView<impl_scalar_type*, device_type>;
2541 using values_wdv_type =
2543 values_wdv_type valuesUnpacked_wdv;
2544 mutable values_wdv_type valuesPacked_wdv;
2598 nonconst_global_inds_host_view_type &Indices,
2599 nonconst_values_host_view_type &Values,
2600 size_t& NumEntries)
const override;
2618 nonconst_local_inds_host_view_type &Indices,
2619 nonconst_values_host_view_type &Values,
2620 size_t& NumEntries)
const override;
2637 global_inds_host_view_type &indices,
2638 values_host_view_type &values)
const override;
2654 local_inds_host_view_type &indices,
2655 values_host_view_type &values)
const override;
2743 Kokkos::MemoryUnmanaged>& offsets)
const;
2769 const Teuchos::ArrayView<const size_t>& offsets)
const;
2853 const Teuchos::ETransp mode = Teuchos::NO_TRANS,
2854 const Scalar& alpha = Teuchos::ScalarTraits<Scalar>::one (),
2855 const Scalar& beta = Teuchos::ScalarTraits<Scalar>::zero ())
const;
2860 Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node> >
2880 Teuchos::ETransp mode = Teuchos::NO_TRANS,
2881 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
2882 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero())
const override;
2894 Teuchos::RCP<const map_type>
getDomainMap ()
const override;
2902 Teuchos::RCP<const map_type>
getRangeMap ()
const override;
2918 virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
2919 add (
const Scalar& alpha,
2924 const Teuchos::RCP<Teuchos::ParameterList>& params)
const override;
2936 describe (Teuchos::FancyOStream& out,
2937 const Teuchos::EVerbosityLevel verbLevel =
2938 Teuchos::Describable::verbLevel_default)
const override;
2948 typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
2957 const bool verbose);
2961 copyAndPermuteStaticGraph(
2963 const size_t numSameIDs,
2964 const LocalOrdinal permuteToLIDs[],
2965 const LocalOrdinal permuteFromLIDs[],
2966 const size_t numPermutes);
2969 copyAndPermuteNonStaticGraph(
2971 const size_t numSameIDs,
2972 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteToLIDs_dv,
2973 const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& permuteFromLIDs_dv,
2974 const size_t numPermutes);
2987 const size_t numSameIDs,
2988 const Kokkos::DualView<
2991 const Kokkos::DualView<
2999 const Kokkos::DualView<
3002 Kokkos::DualView<char*, buffer_device_type>& exports,
3003 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3004 size_t& constantNumPackets)
override;
3017 unpackAndCombineImpl(
3020 Kokkos::DualView<char*, buffer_device_type> imports,
3021 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3022 const size_t constantNumPackets,
3024 const bool verbose);
3029 unpackAndCombineImplNonStatic(
3032 Kokkos::DualView<char*, buffer_device_type> imports,
3033 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3034 const size_t constantNumPackets,
3049 (
const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& importLIDs,
3050 Kokkos::DualView<char*, buffer_device_type> imports,
3051 Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3052 const size_t constantNumPackets,
3168 packNew (
const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3169 Kokkos::DualView<char*, buffer_device_type>& exports,
3170 const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3171 size_t& constantNumPackets)
const;
3181 packNonStaticNew (
const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3182 Kokkos::DualView<char*, buffer_device_type>& exports,
3183 const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3184 size_t& constantNumPackets)
const;
3216 packRow (
char exports[],
3217 const size_t offset,
3218 const size_t numEnt,
3219 const GlobalOrdinal gidsIn[],
3221 const size_t numBytesPerValue)
const;
3247 packRowStatic (
char*
const numEntOut,
3250 const size_t numEnt,
3251 const LocalOrdinal lclRow)
const;
3279 unpackRow (GlobalOrdinal gidsOut[],
3281 const char imports[],
3282 const size_t offset,
3283 const size_t numBytes,
3284 const size_t numEnt,
3285 const size_t numBytesPerValue);
3296 allocatePackSpaceNew (Kokkos::DualView<char*, buffer_device_type>& exports,
3297 size_t& totalNumEntries,
3304 typename local_matrix_host_type::values_type::const_type
3307 return valuesPacked_wdv.getHostView(s);
3311 typename local_matrix_host_type::values_type
3314 return valuesPacked_wdv.getHostView(s);
3318 typename local_matrix_host_type::values_type
3321 return valuesPacked_wdv.getHostView(s);
3325 typename local_matrix_device_type::values_type::const_type
3328 return valuesPacked_wdv.getDeviceView(s);
3332 typename local_matrix_device_type::values_type
3335 return valuesPacked_wdv.getDeviceView(s);
3339 typename local_matrix_device_type::values_type
3342 return valuesPacked_wdv.getDeviceView(s);
3347 template<
class CrsMatrixType>
3348 friend Teuchos::RCP<CrsMatrixType>
3350 const Import<
typename CrsMatrixType::local_ordinal_type,
3351 typename CrsMatrixType::global_ordinal_type,
3352 typename CrsMatrixType::node_type>& importer,
3353 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3354 typename CrsMatrixType::global_ordinal_type,
3355 typename CrsMatrixType::node_type> >& domainMap,
3356 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3357 typename CrsMatrixType::global_ordinal_type,
3358 typename CrsMatrixType::node_type> >& rangeMap,
3359 const Teuchos::RCP<Teuchos::ParameterList>& params);
3362 template<
class CrsMatrixType>
3363 friend Teuchos::RCP<CrsMatrixType>
3365 const Import<
typename CrsMatrixType::local_ordinal_type,
3366 typename CrsMatrixType::global_ordinal_type,
3367 typename CrsMatrixType::node_type>& rowImporter,
3368 const Import<
typename CrsMatrixType::local_ordinal_type,
3369 typename CrsMatrixType::global_ordinal_type,
3370 typename CrsMatrixType::node_type>& domainImporter,
3371 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3372 typename CrsMatrixType::global_ordinal_type,
3373 typename CrsMatrixType::node_type> >& domainMap,
3374 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3375 typename CrsMatrixType::global_ordinal_type,
3376 typename CrsMatrixType::node_type> >& rangeMap,
3377 const Teuchos::RCP<Teuchos::ParameterList>& params);
3381 template<
class CrsMatrixType>
3382 friend Teuchos::RCP<CrsMatrixType>
3384 const Export<
typename CrsMatrixType::local_ordinal_type,
3385 typename CrsMatrixType::global_ordinal_type,
3386 typename CrsMatrixType::node_type>& exporter,
3387 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3388 typename CrsMatrixType::global_ordinal_type,
3389 typename CrsMatrixType::node_type> >& domainMap,
3390 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3391 typename CrsMatrixType::global_ordinal_type,
3392 typename CrsMatrixType::node_type> >& rangeMap,
3393 const Teuchos::RCP<Teuchos::ParameterList>& params);
3396 template<
class CrsMatrixType>
3397 friend Teuchos::RCP<CrsMatrixType>
3399 const Export<
typename CrsMatrixType::local_ordinal_type,
3400 typename CrsMatrixType::global_ordinal_type,
3401 typename CrsMatrixType::node_type>& rowExporter,
3402 const Export<
typename CrsMatrixType::local_ordinal_type,
3403 typename CrsMatrixType::global_ordinal_type,
3404 typename CrsMatrixType::node_type>& domainExporter,
3405 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3406 typename CrsMatrixType::global_ordinal_type,
3407 typename CrsMatrixType::node_type> >& domainMap,
3408 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3409 typename CrsMatrixType::global_ordinal_type,
3410 typename CrsMatrixType::node_type> >& rangeMap,
3411 const Teuchos::RCP<Teuchos::ParameterList>& params);
3432 const Teuchos::RCP<const map_type>& domainMap,
3433 const Teuchos::RCP<const map_type>& rangeMap,
3434 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
const;
3455 const Teuchos::RCP<const map_type>& domainMap,
3456 const Teuchos::RCP<const map_type>& rangeMap,
3457 const Teuchos::RCP<Teuchos::ParameterList>& params)
const;
3478 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3479 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3480 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
const;
3501 const Teuchos::RCP<const map_type>& domainMap,
3502 const Teuchos::RCP<const map_type>& rangeMap,
3503 const Teuchos::RCP<Teuchos::ParameterList>& params)
const;
3529 const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3530 const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > & domainTransfer,
3531 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3532 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3533 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
const;
3550 const GlobalOrdinal gblColInds[],
3552 const size_t numInputEnt);
3565 insertGlobalValuesFiltered(
3566 const GlobalOrdinal globalRow,
3567 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3568 const Teuchos::ArrayView<const Scalar>& values,
3574 insertGlobalValuesFilteredChecked(
3575 const GlobalOrdinal globalRow,
3576 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3577 const Teuchos::ArrayView<const Scalar>& values,
3578 const char*
const prefix,
3580 const bool verbose);
3594 combineGlobalValues(
3595 const GlobalOrdinal globalRowIndex,
3596 const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3597 const Teuchos::ArrayView<const Scalar>& values,
3599 const char*
const prefix,
3601 const bool verbose);
3625 combineGlobalValuesRaw(
const LocalOrdinal lclRow,
3626 const LocalOrdinal numEnt,
3628 const GlobalOrdinal cols[],
3630 const char*
const prefix,
3632 const bool verbose);
3645 template<
class BinaryFunction>
3647 transformGlobalValues (
const GlobalOrdinal globalRow,
3648 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3649 const Teuchos::ArrayView<const Scalar>& values,
3651 const bool atomic = useAtomicUpdatesByDefault)
3654 typedef LocalOrdinal LO;
3655 typedef GlobalOrdinal GO;
3657 const LO numInputEnt =
static_cast<LO
> (indices.size ());
3658 if (static_cast<LO> (values.size ()) != numInputEnt) {
3659 return Teuchos::OrdinalTraits<LO>::invalid ();
3662 const GO*
const inputCols = indices.getRawPtr ();
3663 const IST*
const inputVals =
3664 reinterpret_cast<const IST*
> (values.getRawPtr ());
3665 return this->transformGlobalValues (globalRow, numInputEnt, inputVals,
3666 inputCols, f, atomic);
3676 insertNonownedGlobalValues (
const GlobalOrdinal globalRow,
3677 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3678 const Teuchos::ArrayView<const Scalar>& values);
3725 const typename crs_graph_type::SLocalGlobalViews& newInds,
3726 const Teuchos::ArrayView<impl_scalar_type>& oldRowVals,
3727 const Teuchos::ArrayView<const impl_scalar_type>& newRowVals,
3728 const ELocalGlobal lg,
3729 const ELocalGlobal I);
3733 typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
3734 typedef Kokkos::ArithTraits<impl_scalar_type> STS;
3735 typedef Kokkos::ArithTraits<mag_type> STM;
3736 typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> MV;
3737 typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
3741 enum GraphAllocationStatus {
3742 GraphAlreadyAllocated,
3743 GraphNotYetAllocated
3766 const bool verbose);
3854 const bool force =
false)
const;
3879 const bool force =
false)
const;
3892 const Teuchos::ETransp mode,
3900 typename values_dualv_type::t_host::const_type
3905 typename values_dualv_type::t_dev::const_type
3910 typename values_dualv_type::t_host
3915 typename values_dualv_type::t_dev
3923 using local_matrix_int_rowptrs_device_type =
3933 local_matrix_int_rowptrs_device_type,
3937 std::shared_ptr<ApplyHelper> getApplyHelper()
const {
3940 applyHelper = std::make_shared<ApplyHelper>(A_lcl.nnz(), A_lcl.graph.row_map);
3948 friend class Tpetra::crsMatrix_Swap_Tester<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
3952 template<
typename S,
typename LO,
typename GO,
typename NODE,
typename LOV>
friend struct Tpetra::MMdetails::KernelWrappers;
3953 template<
typename S,
typename LO,
typename GO,
typename NODE,
typename LOV>
friend struct Tpetra::MMdetails::KernelWrappers2;
3958 void Tpetra::MMdetails::import_and_extract_views<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
3959 const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& A,
3960 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > targetMap,
3961 CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview,
3962 Teuchos::RCP<const Import<LocalOrdinal, GlobalOrdinal, Node> > prototypeImporter,
3963 bool userAssertsThereAreNoRemotes,
3964 const std::string& label,
3965 const Teuchos::RCP<Teuchos::ParameterList>& params);
3970 void swap(CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> & matrix);
3980 void fillLocalMatrix (
const Teuchos::RCP<Teuchos::ParameterList>& params);
4004 Teuchos::RCP<const Graph> staticGraph_;
4005 Teuchos::RCP< Graph> myGraph_;
4019 Details::STORAGE_1D_UNPACKED;
4051 std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
4060 mutable std::shared_ptr<ApplyHelper> applyHelper;
4067 template<
class DestViewType,
class SrcViewType,
4068 class DestOffsetViewType,
class SrcOffsetViewType>
4069 struct pack_functor {
4073 SrcOffsetViewType src_offset_;
4074 DestOffsetViewType dst_offset_;
4075 typedef typename DestOffsetViewType::non_const_value_type scalar_index_type;
4077 pack_functor (DestViewType dst,
4078 const SrcViewType src,
4079 DestOffsetViewType dst_offset,
4080 const SrcOffsetViewType src_offset) :
4083 src_offset_ (src_offset),
4084 dst_offset_ (dst_offset)
4087 KOKKOS_INLINE_FUNCTION
4088 void operator () (
const LocalOrdinal row)
const {
4089 scalar_index_type srcPos = src_offset_(row);
4090 const scalar_index_type dstEnd = dst_offset_(row+1);
4091 scalar_index_type dstPos = dst_offset_(row);
4092 for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
4093 dst_(dstPos) = src_(srcPos);
4103 template<
class Scalar,
4105 class GlobalOrdinal,
4107 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
4110 const size_t maxNumEntriesPerRow = 0,
4111 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4115 return Teuchos::rcp(
new matrix_type(map, maxNumEntriesPerRow,
4119 template<
class CrsMatrixType>
4120 Teuchos::RCP<CrsMatrixType>
4122 const Import<
typename CrsMatrixType::local_ordinal_type,
4123 typename CrsMatrixType::global_ordinal_type,
4124 typename CrsMatrixType::node_type>& importer,
4125 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
4126 typename CrsMatrixType::global_ordinal_type,
4127 typename CrsMatrixType::node_type> >& domainMap,
4128 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
4129 typename CrsMatrixType::global_ordinal_type,
4130 typename CrsMatrixType::node_type> >& rangeMap,
4131 const Teuchos::RCP<Teuchos::ParameterList>& params)
4133 Teuchos::RCP<CrsMatrixType> destMatrix;
4134 sourceMatrix->importAndFillComplete (destMatrix, importer, domainMap, rangeMap, params);
4138 template<
class CrsMatrixType>
4139 Teuchos::RCP<CrsMatrixType>
4141 const Import<
typename CrsMatrixType::local_ordinal_type,
4142 typename CrsMatrixType::global_ordinal_type,
4143 typename CrsMatrixType::node_type>& rowImporter,
4144 const Import<
typename CrsMatrixType::local_ordinal_type,
4145 typename CrsMatrixType::global_ordinal_type,
4146 typename CrsMatrixType::node_type>& domainImporter,
4147 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
4148 typename CrsMatrixType::global_ordinal_type,
4149 typename CrsMatrixType::node_type> >& domainMap,
4150 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
4151 typename CrsMatrixType::global_ordinal_type,
4152 typename CrsMatrixType::node_type> >& rangeMap,
4153 const Teuchos::RCP<Teuchos::ParameterList>& params)
4155 Teuchos::RCP<CrsMatrixType> destMatrix;
4156 sourceMatrix->importAndFillComplete (destMatrix, rowImporter, domainImporter, domainMap, rangeMap, params);
4160 template<
class CrsMatrixType>
4161 Teuchos::RCP<CrsMatrixType>
4163 const Export<
typename CrsMatrixType::local_ordinal_type,
4164 typename CrsMatrixType::global_ordinal_type,
4165 typename CrsMatrixType::node_type>& exporter,
4166 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
4167 typename CrsMatrixType::global_ordinal_type,
4168 typename CrsMatrixType::node_type> >& domainMap,
4169 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
4170 typename CrsMatrixType::global_ordinal_type,
4171 typename CrsMatrixType::node_type> >& rangeMap,
4172 const Teuchos::RCP<Teuchos::ParameterList>& params)
4174 Teuchos::RCP<CrsMatrixType> destMatrix;
4175 sourceMatrix->exportAndFillComplete (destMatrix, exporter, domainMap, rangeMap, params);
4179 template<
class CrsMatrixType>
4180 Teuchos::RCP<CrsMatrixType>
4182 const Export<
typename CrsMatrixType::local_ordinal_type,
4183 typename CrsMatrixType::global_ordinal_type,
4184 typename CrsMatrixType::node_type>& rowExporter,
4185 const Export<
typename CrsMatrixType::local_ordinal_type,
4186 typename CrsMatrixType::global_ordinal_type,
4187 typename CrsMatrixType::node_type>& domainExporter,
4188 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
4189 typename CrsMatrixType::global_ordinal_type,
4190 typename CrsMatrixType::node_type> >& domainMap,
4191 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
4192 typename CrsMatrixType::global_ordinal_type,
4193 typename CrsMatrixType::node_type> >& rangeMap,
4194 const Teuchos::RCP<Teuchos::ParameterList>& params)
4196 Teuchos::RCP<CrsMatrixType> destMatrix;
4197 sourceMatrix->exportAndFillComplete (destMatrix, rowExporter, domainExporter, domainMap, rangeMap, params);
4207 template<
class CrsMatrixType>
4210 typename Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitudeType
const & threshold =
4211 Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::magnitude( Teuchos::ScalarTraits<typename CrsMatrixType::scalar_type>::zero() ))
4213 auto localMatrix = matrix.getLocalMatrixDevice();
4214 size_t nnzBefore = localMatrix.nnz();
4216 size_t localNNZRemoved = nnzBefore - localMatrix.nnz();
4219 size_t globalNNZRemoved = 0;
4220 Teuchos::reduceAll<int, size_t> (*(matrix.getComm()), Teuchos::REDUCE_SUM, 1, &localNNZRemoved, &globalNNZRemoved);
4221 if(globalNNZRemoved !=
size_t(0)) {
4222 matrix.resumeFill();
4223 matrix.setAllValues(localMatrix);
4224 matrix.expertStaticFillComplete(matrix.getDomainMap(),matrix.getRangeMap());
4237 #endif // TPETRA_CRSMATRIX_DECL_HPP
CrsMatrix & operator=(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assignment.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
bool hasColMap() const override
Whether the matrix has a well-defined column Map.
global_size_t getGlobalNumCols() const override
The number of global columns in the matrix.
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.
void checkInternalState() const
Check that this object's state is sane; throw if it's not.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &exporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
CrsGraph< LocalOrdinal, GlobalOrdinal, Node > crs_graph_type
The CrsGraph specialization suitable for this CrsMatrix specialization.
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the matrix's column Map with the given Map.
virtual LocalOrdinal replaceGlobalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const GlobalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts)
Implementation detail of replaceGlobalValues.
virtual bool supportsRowViews() const override
Return true if getLocalRowView() and getGlobalRowView() are valid for this object.
mag_type getNormInf() const
Compute and return the infinity norm of the matrix.
void replaceDomainMapAndImporter(const Teuchos::RCP< const map_type > &newDomainMap, Teuchos::RCP< const import_type > &newImporter)
Replace the current domain Map and Import with the given objects.
static size_t mergeRowIndicesAndValues(size_t rowLen, local_ordinal_type *cols, impl_scalar_type *vals)
Merge duplicate row indices in the given row, along with their corresponding values.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row...
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM)
Perform copies and permutations that are local to the calling (MPI) process.
Teuchos::RCP< const map_type > getRangeMap() const override
The range Map of this matrix.
global_size_t getGlobalNumRows() const override
Number of global elements in the row map of this matrix.
std::map< GlobalOrdinal, std::pair< Teuchos::Array< GlobalOrdinal >, Teuchos::Array< Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
void sortAndMergeIndicesAndValues(const bool sorted, const bool merged)
Sort and merge duplicate local column indices in all rows on the calling process, along with their co...
typename device_type::execution_space execution_space
The Kokkos execution space.
void packNew(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< char *, buffer_device_type > &exports, const Kokkos::DualView< size_t *, buffer_device_type > &numPacketsPerLID, size_t &constantNumPackets) const
Pack this object's data for an Import or Export.
virtual void insertGlobalValuesImpl(crs_graph_type &graph, RowInfo &rowInfo, const GlobalOrdinal gblColInds[], const impl_scalar_type vals[], const size_t numInputEnt)
Common implementation detail of insertGlobalValues and insertGlobalValuesFiltered.
row_ptrs_device_view_type getLocalRowPtrsDevice() const
Get a device view of the CRS packed row pointers.
local_matrix_device_type::values_type getLocalValuesDevice(Access::OverwriteAllStruct s)
Get the Kokkos local values on device, overwrite all.
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const override
Get a constant, nonpersisting view of a row of this matrix, using global row and column indices...
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
mag_type getNorm1(bool assumeSymmetric=false) const
Compute and return the 1-norm of the matrix.
void replaceRangeMapAndExporter(const Teuchos::RCP< const map_type > &newRangeMap, Teuchos::RCP< const export_type > &newExporter)
Replace the current Range Map and Export with the given objects.
One or more distributed dense vectors.
void scale(const Scalar &alpha)
Scale the matrix's values: this := alpha*this.
size_t getLocalNumCols() const override
The number of columns connected to the locally owned rows of this matrix.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Fill data into the local graph and matrix.
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Resume operations that may change the values or structure of the matrix.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the left with the given Vector.
GlobalOrdinal global_ordinal_type
The type of each global index in the matrix.
Declaration and generic definition of traits class that tells Tpetra::CrsMatrix how to pack and unpac...
local_inds_host_view_type getLocalIndicesHost() const
Get a host view of the CRS packed column indicies.
typename device_type::memory_space memory_space
The Kokkos memory space.
virtual ~CrsMatrix()=default
Destructor (virtual for memory safety of derived classes).
void reindexColumns(crs_graph_type *const graph, const Teuchos::RCP< const map_type > &newColMap, const Teuchos::RCP< const import_type > &newImport=Teuchos::null, const bool sortEachRow=true)
Reindex the column indices in place, and replace the column Map. Optionally, replace the Import objec...
Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization suitable for this CrsMatrix specialization.
local_matrix_host_type::values_type getLocalValuesHost(Access::OverwriteAllStruct s)
Get the Kokkos local values on host, overwrite all.
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix's graph, as a CrsGraph.
virtual void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< packet_type *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode combineMode)
Perform any unpacking and combining after communication.
size_t getGlobalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, over all processes in the matrix's communicator...
void applyNonTranspose(const MV &X_in, MV &Y_in, Scalar alpha, Scalar beta) const
Special case of apply() for mode == Teuchos::NO_TRANS.
Teuchos::RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Return another CrsMatrix with the same entries, but converted to a different Scalar type T...
Scalar scalar_type
The type of each entry in the matrix.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
void swap(CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &matrix)
Swaps the data from *this with the data and maps from crsMatrix.
void fillLocalMatrix(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Fill data into the local matrix.
LocalOrdinal transformGlobalValues(const GlobalOrdinal gblRow, const Kokkos::View< const GlobalOrdinal *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputInds, const Kokkos::View< const impl_scalar_type *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault)
Transform CrsMatrix entries in place, using global indices to select the entries in the row to transf...
void globalAssemble()
Communicate nonlocal contributions to other processes.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const override
Get a constant, nonpersisting view of a row of this matrix, using local row and column indices...
KokkosSparse::CrsMatrix< impl_scalar_type, local_ordinal_type, device_type, void, typename local_graph_device_type::size_type > local_matrix_device_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
virtual LocalOrdinal sumIntoLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoLocalValues.
local_matrix_host_type::values_type::const_type getLocalValuesHost(Access::ReadOnlyStruct s) const
Get the Kokkos local values on host, read only.
bool isFillActive() const
Whether the matrix is not fill complete.
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply().
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
size_t global_size_t
Global size_t object.
bool hasTransposeApply() const override
Whether apply() allows applying the transpose or conjugate transpose.
size_t getLocalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, on this process.
void exportAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &destMatrix, const export_type &exporter, const Teuchos::RCP< const map_type > &domainMap=Teuchos::null, const Teuchos::RCP< const map_type > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null) const
Export from this to the given destination matrix, and make the result fill complete.
values_dualv_type::t_dev::const_type getValuesViewDevice(const RowInfo &rowinfo) const
Get a const Device view of the locally owned values row myRow, such that rowinfo = getRowInfo(myRow)...
bool isFillComplete() const override
Whether the matrix is fill complete.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
The communicator over which the matrix is distributed.
void importAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &destMatrix, const import_type &importer, const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null) const
Import from this to the given destination matrix, and make the result fill complete.
Abstract interface for operators (e.g., matrices and preconditioners).
TPETRA_DETAILS_ALWAYS_INLINE local_matrix_device_type getLocalMatrixDevice() const
The local sparse matrix.
local_matrix_device_type::values_type getLocalValuesDevice(Access::ReadWriteStruct s)
Get the Kokkos local values on device, read write.
GlobalOrdinal getIndexBase() const override
The index base for global indices for this matrix.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
virtual void packAndPrepare(const SrcDistObject &source, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< packet_type *, buffer_device_type > &exports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, size_t &constantNumPackets)
Pack data and metadata for communication (sends).
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createCrsMatrix(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, const size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Create an empty CrsMatrix given a row map and a single integer upper bound on the number of stored en...
Node node_type
This class' Kokkos Node type.
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
Keep track of how much more space a CrsGraph or CrsMatrix needs, when the graph or matrix is the targ...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const override
Print this object with the given verbosity level to the given output stream.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const override
This matrix's graph, as a RowGraph.
CombineMode
Rule for combining data in an Import or Export.
row_ptrs_host_view_type getLocalRowPtrsHost() const
Get a host view of the CRS packed row pointers.
DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< char *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode CM) override
Unpack the imported column indices and values, and combine into matrix.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
A class can inherit from this if it wants to use Tpetra managed spaces.
bool isGloballyIndexed() const override
Whether the matrix is globally indexed on the calling process.
Forward declaration of Tpetra::CrsMatrix.
LocalOrdinal sumIntoGlobalValues(const GlobalOrdinal globalRow, const Teuchos::ArrayView< const GlobalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals, const bool atomic=useAtomicUpdatesByDefault)
Sum into one or more sparse matrix entries, using global indices.
bool fillComplete_
Whether the matrix is fill complete.
virtual Teuchos::RCP< RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > add(const Scalar &alpha, const RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > ¶ms) const override
Implementation of RowMatrix::add: return alpha*A + beta*this.
local_ordinal_type replaceGlobalValues(const global_ordinal_type globalRow, const Kokkos::View< const global_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals)
Replace one or more entries' values, using global indices.
virtual LocalOrdinal sumIntoGlobalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const GlobalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts, const bool atomic=useAtomicUpdatesByDefault)
Implementation detail of sumIntoGlobalValues.
Abstract base class for objects that can be the source of an Import or Export operation.
local_ordinal_type sumIntoLocalValues(const local_ordinal_type localRow, const Kokkos::View< const local_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals, const bool atomic=useAtomicUpdatesByDefault)
Sum into one or more sparse matrix entries, using local row and column indices.
typename Node::device_type device_type
The Kokkos device type.
size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override
Number of entries in the sparse matrix in the given local row, on the calling (MPI) process...
Teuchos::RCP< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
std::string description() const override
A one-line description of this object.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const override
Compute a sparse matrix-MultiVector multiply.
size_t getLocalNumEntries() const override
The local number of entries in this matrix.
void fillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Tell the matrix that you are done changing its structure or values, and that you are ready to do comp...
void insertGlobalValues(const GlobalOrdinal globalRow, const Teuchos::ArrayView< const GlobalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using global column indices.
virtual LocalOrdinal replaceLocalValuesImpl(impl_scalar_type rowVals[], const crs_graph_type &graph, const RowInfo &rowInfo, const LocalOrdinal inds[], const impl_scalar_type newVals[], const LocalOrdinal numElts)
Implementation detail of replaceLocalValues.
values_dualv_type::t_dev getValuesViewDeviceNonConst(const RowInfo &rowinfo)
Get a non-const Device view of the locally owned values row myRow, such that rowinfo = getRowInfo(myR...
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap) override
Remove processes owning zero rows from the Maps and their communicator.
virtual bool checkSizes(const SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
LocalOrdinal transformLocalValues(const LocalOrdinal lclRow, const typename UnmanagedView< LocalIndicesViewType >::type &inputInds, const typename UnmanagedView< ImplScalarViewType >::type &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault)
Transform CrsMatrix entries in place, using local indices to select the entries in the row to transfo...
virtual LocalOrdinal getBlockSize() const override
The number of degrees of freedom per mesh point.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
typename row_matrix_type::impl_scalar_type impl_scalar_type
The type used internally in place of Scalar.
A parallel distribution of indices over processes.
void getLocalRowCopy(LocalOrdinal LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row...
Teuchos::RCP< const map_type > getDomainMap() const override
The domain Map of this matrix.
local_matrix_host_type::values_type getLocalValuesHost(Access::ReadWriteStruct s)
Get the Kokkos local values on host, read write.
void insertLocalValues(const LocalOrdinal localRow, const Teuchos::ArrayView< const LocalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals, const CombineMode CM=ADD)
Insert one or more entries into the matrix, using local column indices.
Details::EStorageStatus storageStatus_
Status of the matrix's storage, when not in a fill-complete state.
A read-only, row-oriented interface to a sparse matrix.
local_inds_device_view_type getLocalIndicesDevice() const
Get a device_view of the CRS packed column indicies.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the right with the given Vector.
void replaceDomainMap(const Teuchos::RCP< const map_type > &newDomainMap)
Replace the current domain Map with the given objects.
void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const override
Get a constant view of a row of this matrix, using local row and column indices.
values_dualv_type::t_host::const_type getValuesViewHost(const RowInfo &rowinfo) const
Get a const Host view of the locally owned values row myRow, such that rowinfo = getRowInfo(myRow).
A distributed dense vector.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &importer, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
void applyTranspose(const MV &X_in, MV &Y_in, const Teuchos::ETransp mode, Scalar alpha, Scalar beta) const
Special case of apply() for mode != Teuchos::NO_TRANS.
void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas, const bool verbose)
Allocate values (and optionally indices) using the Node.
void expertStaticFillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< const import_type > &importer=Teuchos::null, const Teuchos::RCP< const export_type > &exporter=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Perform a fillComplete on a matrix that already has data.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const override
Number of entries in the sparse matrix in the given global row, on the calling (MPI) process...
void residual(const Operator< SC, LO, GO, NO > &A, const MultiVector< SC, LO, GO, NO > &X, const MultiVector< SC, LO, GO, NO > &B, MultiVector< SC, LO, GO, NO > &R)
Computes R = B - A * X.
local_matrix_device_type::values_type::const_type getLocalValuesDevice(Access::ReadOnlyStruct s) const
Get the Kokkos local values on device, read only.
void setAllValues(const typename local_graph_device_type::row_map_type &ptr, const typename local_graph_device_type::entries_type::non_const_type &ind, const typename local_matrix_device_type::values_type &val)
Set the local matrix using three (compressed sparse row) arrays.
bool isLocallyIndexed() const override
Whether the matrix is locally indexed on the calling process.
Teuchos::RCP< const map_type > getColMap() const override
The Map that describes the column distribution in this matrix.
local_ordinal_type replaceLocalValues(const local_ordinal_type localRow, const Kokkos::View< const local_ordinal_type *, Kokkos::AnonymousSpace > &inputInds, const Kokkos::View< const impl_scalar_type *, Kokkos::AnonymousSpace > &inputVals)
Replace one or more entries' values, using local row and column indices.
friend void batchedApply(const MatrixArray &Matrices, const typename std::remove_pointer< typename MultiVectorArray::value_type >::type &X, MultiVectorArray &Y, typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type alpha, typename std::remove_pointer< typename MatrixArray::value_type >::type::scalar_type beta, Teuchos::RCP< Teuchos::ParameterList > params)
Does multiply matrix apply() calls with a single X vector.
void replaceRangeMap(const Teuchos::RCP< const map_type > &newRangeMap)
Replace the current range Map with the given objects.
Base class for distributed Tpetra objects that support data redistribution.
typename local_graph_device_type::HostMirror local_graph_host_type
The type of the part of the sparse graph on each MPI process.
void removeCrsMatrixZeros(CrsMatrixType &matrix, typename Teuchos::ScalarTraits< typename CrsMatrixType::scalar_type >::magnitudeType const &threshold=Teuchos::ScalarTraits< typename CrsMatrixType::scalar_type >::magnitude(Teuchos::ScalarTraits< typename CrsMatrixType::scalar_type >::zero()))
Remove zero entries from a matrix.
LocalOrdinal local_ordinal_type
The type of each local index in the matrix.
EStorageStatus
Status of the graph's or matrix's storage, when not in a fill-complete state.
mag_type getFrobeniusNorm() const override
Compute and return the Frobenius norm of the matrix.
typename crs_graph_type::local_graph_device_type local_graph_device_type
The part of the sparse matrix's graph on each MPI process.
void localApply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, const Teuchos::ETransp mode=Teuchos::NO_TRANS, const Scalar &alpha=Teuchos::ScalarTraits< Scalar >::one(), const Scalar &beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Compute the local part of a sparse matrix-(Multi)Vector multiply.
Forward declaration of some Tpetra Matrix Matrix objects.
bool isStorageOptimized() const
Returns true if storage has been optimized.
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM) override
values_dualv_type::t_host getValuesViewHostNonConst(const RowInfo &rowinfo)
Get a non-const Host view of the locally owned values row myRow, such that rowinfo = getRowInfo(myRow...
Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization suitable for this CrsMatrix specialization.
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
size_t getLocalNumRows() const override
The number of matrix rows owned by the calling process.
Teuchos::RCP< const map_type > getRowMap() const override
The Map that describes the row distribution in this matrix.
global_size_t getGlobalNumEntries() const override
The global number of entries in this matrix.