42 #ifndef TPETRA_CRSMATRIX_DECL_HPP 43 #define TPETRA_CRSMATRIX_DECL_HPP 53 #include "Tpetra_ConfigDefs.hpp" 54 #include "Tpetra_RowMatrix_decl.hpp" 55 #include "Tpetra_Exceptions.hpp" 56 #include "Tpetra_DistObject.hpp" 57 #include "Tpetra_CrsGraph.hpp" 58 #include "Tpetra_Vector.hpp" 60 #include "KokkosCompat_ClassicNodeAPI_Wrapper.hpp" 64 #include "Kokkos_Sparse.hpp" 69 #include "Kokkos_Sparse_impl_sor.hpp" 188 class GlobalOrdinal = Details::DefaultTypes::global_ordinal_type,
190 const bool classic = Node::classic>
192 public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
193 public DistObject<char, LocalOrdinal, GlobalOrdinal, Node, classic>
229 typedef typename Kokkos::Details::ArithTraits<impl_scalar_type>::mag_type
mag_type;
256 typedef typename local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D
TPETRA_DEPRECATED;
284 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
285 size_t maxNumEntriesPerRow,
287 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
306 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
307 const Teuchos::ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
309 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
333 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
334 const Teuchos::RCP<const map_type>& colMap,
335 size_t maxNumEntriesPerRow,
337 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
361 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
362 const Teuchos::RCP<const map_type>& colMap,
363 const Teuchos::ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
365 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
391 explicit CrsMatrix (
const Teuchos::RCP<const crs_graph_type>& graph,
392 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
417 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
418 const Teuchos::RCP<const map_type>& colMap,
419 const typename local_matrix_type::row_map_type& rowPointers,
420 const typename local_graph_type::entries_type::non_const_type& columnIndices,
421 const typename local_matrix_type::values_type& values,
422 const Teuchos::RCP<Teuchos::ParameterList>& params = null);
447 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
448 const Teuchos::RCP<const map_type>& colMap,
449 const Teuchos::ArrayRCP<size_t>& rowPointers,
450 const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
451 const Teuchos::ArrayRCP<Scalar>& values,
452 const Teuchos::RCP<ParameterList>& params = null);
474 CrsMatrix (
const Teuchos::RCP<const map_type>& rowMap,
475 const Teuchos::RCP<const map_type>& colMap,
476 const local_matrix_type& lclMatrix,
477 const Teuchos::RCP<Teuchos::ParameterList>& params = null);
480 template <
class S2,
class LO2,
class GO2,
class N2, const
bool isClassic>
507 template <
class Node2>
508 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node2, Node2::classic> >
509 clone (
const Teuchos::RCP<Node2>& node2,
510 const Teuchos::RCP<Teuchos::ParameterList>& params = null)
const 512 using Teuchos::ArrayRCP;
514 using Teuchos::ParameterList;
517 using Teuchos::sublist;
520 const char tfecfFuncName[] =
"clone";
523 bool fillCompleteClone =
true;
524 bool useLocalIndices = this->
hasColMap ();
526 if (! params.is_null ()) {
527 fillCompleteClone = params->get (
"fillComplete clone", fillCompleteClone);
528 useLocalIndices = params->get (
"Locally indexed clone", useLocalIndices);
530 bool staticProfileClone =
true;
531 staticProfileClone = params->get (
"Static profile clone", staticProfileClone);
535 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
536 ! this->
hasColMap () && useLocalIndices, std::runtime_error,
537 ": You requested that the returned clone have local indices, but the " 538 "the source matrix does not have a column Map yet.");
540 RCP<const Map2> clonedRowMap = this->
getRowMap ()->template clone<Node2> (node2);
543 RCP<CrsMatrix2> clonedMatrix;
544 ArrayRCP<const size_t> numEntriesPerRow;
545 size_t numEntriesForAll = 0;
546 bool boundSameForAllLocalRows =
false;
547 staticGraph_->getNumEntriesPerLocalRowUpperBound (numEntriesPerRow,
549 boundSameForAllLocalRows);
550 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
551 numEntriesForAll != 0 &&
552 static_cast<size_t> (numEntriesPerRow.size ()) != 0,
553 std::logic_error,
": getNumEntriesPerLocalRowUpperBound returned a " 554 "nonzero numEntriesForAll = " << numEntriesForAll <<
" , as well as a " 555 "numEntriesPerRow array of nonzero length " << numEntriesPerRow.size ()
556 <<
". This should never happen. Please report this bug to the Tpetra " 558 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
559 numEntriesForAll != 0 && ! boundSameForAllLocalRows,
560 std::logic_error,
": getNumEntriesPerLocalRowUpperBound returned a " 561 "nonzero numEntriesForAll = " << numEntriesForAll <<
" , but claims " 562 "(via its third output value) that the upper bound is not the same for " 563 "all rows. This should never happen. Please report this bug to the " 564 "Tpetra developers.");
565 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
566 numEntriesPerRow.size () != 0 && boundSameForAllLocalRows,
567 std::logic_error,
": getNumEntriesPerLocalRowUpperBound returned a " 568 "numEntriesPerRow array of nonzero length " << numEntriesPerRow.size ()
569 <<
", but claims (via its third output value) that the upper bound is " 570 "not the same for all rows. This should never happen. Please report " 571 "this bug to the Tpetra developers.");
573 RCP<ParameterList> matParams =
574 params.is_null () ? null : sublist (params,
"CrsMatrix");
575 if (useLocalIndices) {
576 RCP<const Map2> clonedColMap =
577 this->
getColMap ()->template clone<Node2> (node2);
578 if (numEntriesPerRow.is_null ()) {
579 clonedMatrix = rcp (
new CrsMatrix2 (clonedRowMap, clonedColMap,
580 numEntriesForAll, pftype,
584 clonedMatrix = rcp (
new CrsMatrix2 (clonedRowMap, clonedColMap,
585 numEntriesPerRow, pftype,
590 if (numEntriesPerRow.is_null ()) {
591 clonedMatrix = rcp (
new CrsMatrix2 (clonedRowMap, numEntriesForAll,
595 clonedMatrix = rcp (
new CrsMatrix2 (clonedRowMap, numEntriesPerRow,
600 numEntriesPerRow = Teuchos::null;
601 numEntriesForAll = 0;
603 if (useLocalIndices) {
604 clonedMatrix->allocateValues (LocalIndices,
605 CrsMatrix2::GraphNotYetAllocated);
607 ArrayView<const LocalOrdinal> linds;
608 ArrayView<const Scalar> vals;
609 for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
610 lrow <= clonedRowMap->getMaxLocalIndex ();
614 clonedMatrix->insertLocalValues (lrow, linds, vals);
619 Array<LocalOrdinal> linds;
621 for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
622 lrow <= clonedRowMap->getMaxLocalIndex ();
625 if (theNumEntries > static_cast<size_t> (linds.size ())) {
626 linds.resize (theNumEntries);
628 if (theNumEntries > static_cast<size_t> (vals.size ())) {
629 vals.resize (theNumEntries);
632 linds (), vals (), theNumEntries);
633 if (theNumEntries != 0) {
634 clonedMatrix->insertLocalValues (lrow, linds (0, theNumEntries),
635 vals (0, theNumEntries));
641 clonedMatrix->allocateValues (GlobalIndices,
642 CrsMatrix2::GraphNotYetAllocated);
644 ArrayView<const GlobalOrdinal> ginds;
645 ArrayView<const Scalar> vals;
646 for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
647 grow <= clonedRowMap->getMaxGlobalIndex ();
650 if (ginds.size () > 0) {
651 clonedMatrix->insertGlobalValues (grow, ginds, vals);
656 Array<GlobalOrdinal> ginds;
658 for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
659 grow <= clonedRowMap->getMaxGlobalIndex ();
662 if (theNumEntries > static_cast<size_t> (ginds.size ())) {
663 ginds.resize (theNumEntries);
665 if (theNumEntries > static_cast<size_t> (vals.size ())) {
666 vals.resize (theNumEntries);
669 if (theNumEntries != 0) {
670 clonedMatrix->insertGlobalValues (grow, ginds (0, theNumEntries),
671 vals (0, theNumEntries));
677 if (fillCompleteClone) {
678 RCP<const Map2> clonedRangeMap;
679 RCP<const Map2> clonedDomainMap;
683 clonedRangeMap = this->
getRangeMap ()->template clone<Node2> (node2);
686 clonedRangeMap = clonedRowMap;
690 clonedDomainMap = this->
getDomainMap ()->template clone<Node2> (node2);
693 clonedDomainMap = clonedRowMap;
696 catch (std::exception &e) {
697 const bool caughtExceptionOnClone =
true;
698 TEUCHOS_TEST_FOR_EXCEPTION
699 (caughtExceptionOnClone, std::runtime_error,
700 Teuchos::typeName (*
this) <<
"::clone: Caught the following " 701 "exception while cloning range and domain Maps on a clone of " 702 "type " << Teuchos::typeName (*clonedMatrix) <<
": " << e.what ());
705 RCP<ParameterList> fillparams =
706 params.is_null () ? Teuchos::null : sublist (params,
"fillComplete");
708 clonedMatrix->fillComplete (clonedDomainMap, clonedRangeMap,
711 catch (std::exception &e) {
712 const bool caughtExceptionOnClone =
true;
713 TEUCHOS_TEST_FOR_EXCEPTION(
714 caughtExceptionOnClone, std::runtime_error,
715 Teuchos::typeName (*
this) <<
"::clone: Caught the following " 716 "exception while calling fillComplete() on a clone of type " 717 << Teuchos::typeName (*clonedMatrix) <<
": " << e.what ());
800 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
801 const Teuchos::ArrayView<const Scalar>& vals);
844 const ArrayView<const LocalOrdinal> &cols,
845 const ArrayView<const Scalar> &vals);
883 const Kokkos::View<
const GlobalOrdinal*, device_type,
884 Kokkos::MemoryUnmanaged>& cols,
885 const Kokkos::View<
const impl_scalar_type*, device_type,
886 Kokkos::MemoryUnmanaged>& vals)
const;
892 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
893 const Teuchos::ArrayView<const Scalar>& vals)
const;
930 template<
class LocalIndicesViewType,
931 class ImplScalarViewType>
932 typename std::enable_if<Kokkos::is_view<LocalIndicesViewType>::value &&
933 Kokkos::is_view<ImplScalarViewType>::value &&
934 std::is_same<
typename LocalIndicesViewType::non_const_value_type,
935 local_ordinal_type>::value &&
936 std::is_same<
typename ImplScalarViewType::non_const_value_type,
937 impl_scalar_type>::value, LocalOrdinal>::type
939 const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
940 const typename UnmanagedView<ImplScalarViewType>::type& inputVals)
const 942 typedef LocalOrdinal LO;
946 return Teuchos::OrdinalTraits<LO>::invalid ();
949 const RowInfo rowInfo = staticGraph_->getRowInfo (localRow);
950 if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
953 return static_cast<LO
> (0);
956 auto curVals = this->getRowViewNonConst (rowInfo);
957 typedef typename std::remove_const<typename std::remove_reference<decltype (curVals)>::type>::type OSVT;
958 typedef typename UnmanagedView<LocalIndicesViewType>::type LIVT;
959 typedef typename UnmanagedView<ImplScalarViewType>::type ISVT;
960 return staticGraph_->template replaceLocalValues<OSVT, LIVT, ISVT> (rowInfo,
969 const Teuchos::ArrayView<const LocalOrdinal>& cols,
970 const Teuchos::ArrayView<const Scalar>& vals)
const;
977 static const bool useAtomicUpdatesByDefault =
978 #ifdef KOKKOS_HAVE_SERIAL 979 ! std::is_same<execution_space, Kokkos::Serial>::value;
982 #endif // KOKKOS_HAVE_SERIAL 1021 const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1022 const Teuchos::ArrayView<const Scalar>& vals,
1023 const bool atomic = useAtomicUpdatesByDefault);
1061 template<
class LocalIndicesViewType,
1062 class ImplScalarViewType>
1063 typename std::enable_if<Kokkos::is_view<LocalIndicesViewType>::value &&
1064 Kokkos::is_view<ImplScalarViewType>::value &&
1065 std::is_same<
typename LocalIndicesViewType::non_const_value_type,
1066 local_ordinal_type>::value &&
1067 std::is_same<
typename ImplScalarViewType::non_const_value_type,
1068 impl_scalar_type>::value, LocalOrdinal>::type
1070 const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1071 const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1072 const bool atomic = useAtomicUpdatesByDefault)
const 1074 typedef LocalOrdinal LO;
1076 if (! this->
isFillActive () || this->staticGraph_.is_null ()) {
1078 return Teuchos::OrdinalTraits<LO>::invalid ();
1081 const RowInfo rowInfo = this->staticGraph_->getRowInfo (localRow);
1082 if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1085 return static_cast<LO
> (0);
1088 auto curVals = this->getRowViewNonConst (rowInfo);
1089 typedef typename std::remove_const<typename std::remove_reference<decltype (curVals)>::type>::type OSVT;
1090 typedef typename UnmanagedView<LocalIndicesViewType>::type LIVT;
1091 typedef typename UnmanagedView<ImplScalarViewType>::type ISVT;
1092 return staticGraph_->template sumIntoLocalValues<OSVT, LIVT, ISVT> (rowInfo,
1130 const Teuchos::ArrayView<const LocalOrdinal>& cols,
1131 const Teuchos::ArrayView<const Scalar>& vals,
1132 const bool atomic = useAtomicUpdatesByDefault)
const;
1177 template<
class LocalIndicesViewType,
1178 class ImplScalarViewType,
1179 class BinaryFunction>
1180 typename std::enable_if<Kokkos::is_view<LocalIndicesViewType>::value &&
1181 Kokkos::is_view<ImplScalarViewType>::value &&
1182 std::is_same<
typename LocalIndicesViewType::non_const_value_type,
1183 local_ordinal_type>::value &&
1184 std::is_same<
typename ImplScalarViewType::non_const_value_type,
1185 impl_scalar_type>::value, LocalOrdinal>::type
1187 const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1188 const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1190 const bool atomic = useAtomicUpdatesByDefault)
const 1192 typedef LocalOrdinal LO;
1193 typedef BinaryFunction BF;
1197 return Teuchos::OrdinalTraits<LO>::invalid ();
1200 const RowInfo rowInfo = staticGraph_->getRowInfo (localRow);
1201 if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1204 return static_cast<LO
> (0);
1207 auto curRowVals = this->getRowViewNonConst (rowInfo);
1208 typedef typename std::remove_const<typename std::remove_reference<decltype (curRowVals)>::type>::type OSVT;
1209 typedef typename UnmanagedView<LocalIndicesViewType>::type LIVT;
1210 typedef typename UnmanagedView<ImplScalarViewType>::type ISVT;
1211 return staticGraph_->template transformLocalValues<OSVT, LIVT, ISVT, BF> (rowInfo,
1255 template<
class BinaryFunction,
class InputMemorySpace>
1258 const Kokkos::View<
const GlobalOrdinal*,
1260 Kokkos::MemoryUnmanaged>& inputInds,
1261 const Kokkos::View<
const impl_scalar_type*,
1263 Kokkos::MemoryUnmanaged>& inputVals,
1265 const bool atomic = useAtomicUpdatesByDefault)
const 1267 using Kokkos::MemoryUnmanaged;
1269 typedef impl_scalar_type ST;
1270 typedef BinaryFunction BF;
1271 typedef device_type DD;
1272 typedef InputMemorySpace ID;
1276 return Teuchos::OrdinalTraits<LocalOrdinal>::invalid ();
1280 staticGraph_->getRowInfoFromGlobalRowIndex (globalRow);
1281 if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1284 return static_cast<LocalOrdinal
> (0);
1286 auto curRowVals = this->getRowViewNonConst (rowInfo);
1288 return staticGraph_->template transformGlobalValues<ST, BF, ID, DD> (rowInfo,
1299 void scale (
const Scalar& alpha);
1310 setAllValues (
const typename local_matrix_type::row_map_type& rowPointers,
1311 const typename local_graph_type::entries_type::non_const_type& columnIndices,
1312 const typename local_matrix_type::values_type& values);
1327 setAllValues (
const Teuchos::ArrayRCP<size_t>& rowPointers,
1328 const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
1329 const Teuchos::ArrayRCP<Scalar>& values);
1332 getAllValues (Teuchos::ArrayRCP<const size_t>& rowPointers,
1333 Teuchos::ArrayRCP<const LocalOrdinal>& columnIndices,
1334 Teuchos::ArrayRCP<const Scalar>& values)
const;
1383 void resumeFill (
const RCP<ParameterList>& params = null);
1420 const RCP<const map_type>& rangeMap,
1421 const RCP<ParameterList>& params = null);
1435 void fillComplete (
const RCP<ParameterList>& params = null);
1450 const RCP<const map_type>& rangeMap,
1451 const RCP<const import_type>& importer = Teuchos::null,
1452 const RCP<const export_type>& exporter = Teuchos::null,
1453 const RCP<ParameterList>& params = Teuchos::null);
1465 replaceColMap (
const Teuchos::RCP<const map_type>& newColMap);
1550 const Teuchos::RCP<const map_type>& newColMap,
1551 const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
1552 const bool sortEachRow =
true);
1568 Teuchos::RCP<const import_type>& newImporter);
1591 Teuchos::RCP<const Teuchos::Comm<int> >
getComm()
const;
1594 Teuchos::RCP<node_type>
getNode ()
const;
1597 Teuchos::RCP<const map_type>
getRowMap ()
const;
1600 Teuchos::RCP<const map_type>
getColMap ()
const;
1603 Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> >
getGraph ()
const;
1606 Teuchos::RCP<const crs_graph_type>
getCrsGraph ()
const;
1874 const Teuchos::ArrayView<GlobalOrdinal>& Indices,
1875 const Teuchos::ArrayView<Scalar>& Values,
1876 size_t& NumEntries)
const;
1897 const Teuchos::ArrayView<LocalOrdinal>& colInds,
1898 const Teuchos::ArrayView<Scalar>& vals,
1899 size_t& numEntries)
const;
1916 Teuchos::ArrayView<const GlobalOrdinal>& indices,
1917 Teuchos::ArrayView<const Scalar>& values)
const;
1934 Teuchos::ArrayView<const LocalOrdinal>& indices,
1935 Teuchos::ArrayView<const Scalar>& values)
const;
2003 const Teuchos::ArrayView<const size_t>& offsets)
const;
2067 template <
class DomainScalar,
class RangeScalar>
2071 Teuchos::ETransp mode,
2073 RangeScalar beta)
const 2075 using Teuchos::NO_TRANS;
2079 typedef typename MultiVector<RangeScalar, LocalOrdinal, GlobalOrdinal,
2081 #ifdef HAVE_TPETRA_DEBUG 2082 const char tfecfFuncName[] =
"localMultiply: ";
2083 #endif // HAVE_TPETRA_DEBUG 2085 const range_impl_scalar_type theAlpha =
static_cast<range_impl_scalar_type
> (alpha);
2086 const range_impl_scalar_type theBeta =
static_cast<range_impl_scalar_type
> (beta);
2087 const bool conjugate = (mode == Teuchos::CONJ_TRANS);
2088 const bool transpose = (mode != Teuchos::NO_TRANS);
2090 #ifdef HAVE_TPETRA_DEBUG 2091 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2093 "X.getNumVectors() = " << X.
getNumVectors () <<
" != Y.getNumVectors() = " 2095 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2097 std::runtime_error,
"NO_TRANS case: X has the wrong number of local rows. " 2098 "X.getLocalLength() = " << X.
getLocalLength () <<
" != getColMap()->" 2099 "getNodeNumElements() = " <<
getColMap ()->getNodeNumElements () <<
".");
2100 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2102 std::runtime_error,
"NO_TRANS case: Y has the wrong number of local rows. " 2103 "Y.getLocalLength() = " << Y.
getLocalLength () <<
" != getRowMap()->" 2104 "getNodeNumElements() = " <<
getRowMap ()->getNodeNumElements () <<
".");
2105 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2107 std::runtime_error,
"TRANS or CONJ_TRANS case: X has the wrong number of " 2108 "local rows. X.getLocalLength() = " << X.
getLocalLength () <<
" != " 2109 "getRowMap()->getNodeNumElements() = " 2110 <<
getRowMap ()->getNodeNumElements () <<
".");
2111 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2113 std::runtime_error,
"TRANS or CONJ_TRANS case: X has the wrong number of " 2114 "local rows. Y.getLocalLength() = " << Y.
getLocalLength () <<
" != " 2115 "getColMap()->getNodeNumElements() = " 2116 <<
getColMap ()->getNodeNumElements () <<
".");
2117 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2118 (! isFillComplete (), std::runtime_error,
"The matrix is not fill " 2119 "complete. You must call fillComplete() (possibly with domain and range " 2120 "Map arguments) without an intervening resumeFill() call before you may " 2121 "call this method.");
2122 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2124 "X and Y must be constant stride.");
2127 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2130 std::runtime_error,
"X and Y may not alias one another.");
2131 #endif // HAVE_TPETRA_DEBUG 2135 KokkosSparse::spmv (conjugate ? KokkosSparse::ConjugateTranspose : KokkosSparse::Transpose,
2138 X.template getLocalView<device_type> (),
2140 Y.template getLocalView<device_type> ());
2143 KokkosSparse::spmv (KokkosSparse::NoTranspose,
2146 X.template getLocalView<device_type> (),
2148 Y.template getLocalView<device_type> ());
2176 template <
class DomainScalar,
class RangeScalar>
2181 const RangeScalar& dampingFactor,
2182 const KokkosClassic::ESweepDirection direction)
const 2184 typedef LocalOrdinal LO;
2185 typedef GlobalOrdinal GO;
2189 typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2191 typedef typename k_local_graph_type::size_type offset_type;
2192 const char prefix[] =
"Tpetra::CrsMatrix::localGaussSeidel: ";
2194 TEUCHOS_TEST_FOR_EXCEPTION
2195 (! this->isFillComplete (), std::runtime_error,
2196 prefix <<
"The matrix is not fill complete.");
2199 TEUCHOS_TEST_FOR_EXCEPTION
2201 prefix <<
"B.getNumVectors() = " << numVecs <<
" != " 2203 TEUCHOS_TEST_FOR_EXCEPTION
2206 <<
" != this->getNodeNumRows() = " << lclNumRows <<
".");
2208 typename DMV::dual_view_type::t_host B_lcl = B.template getLocalView<HMDT> ();
2209 typename RMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
2210 typename MMV::dual_view_type::t_host D_lcl = D.template getLocalView<HMDT> ();
2212 offset_type B_stride[8], X_stride[8], D_stride[8];
2213 B_lcl.stride (B_stride);
2214 X_lcl.stride (X_stride);
2215 D_lcl.stride (D_stride);
2218 k_local_graph_type lclGraph = lclMatrix.graph;
2219 typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
2220 typename local_matrix_type::index_type ind = lclGraph.entries;
2221 typename local_matrix_type::values_type val = lclMatrix.values;
2222 const offset_type*
const ptrRaw = ptr.ptr_on_device ();
2223 const LO*
const indRaw = ind.ptr_on_device ();
2224 const impl_scalar_type*
const valRaw = val.ptr_on_device ();
2226 const std::string dir ((direction == KokkosClassic::Forward) ?
"F" :
"B");
2227 KokkosSparse::Impl::Sequential::gaussSeidel (static_cast<LO> (lclNumRows),
2228 static_cast<LO> (numVecs),
2229 ptrRaw, indRaw, valRaw,
2230 B_lcl.ptr_on_device (), B_stride[1],
2231 X_lcl.ptr_on_device (), X_stride[1],
2232 D_lcl.ptr_on_device (),
2233 static_cast<impl_scalar_type
> (dampingFactor),
2263 template <
class DomainScalar,
class RangeScalar>
2268 const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2269 const RangeScalar& dampingFactor,
2270 const KokkosClassic::ESweepDirection direction)
const 2272 typedef LocalOrdinal LO;
2273 typedef GlobalOrdinal GO;
2277 typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2279 typedef typename k_local_graph_type::size_type offset_type;
2280 const char prefix[] =
"Tpetra::CrsMatrix::reorderedLocalGaussSeidel: ";
2282 TEUCHOS_TEST_FOR_EXCEPTION
2283 (! this->isFillComplete (), std::runtime_error,
2284 prefix <<
"The matrix is not fill complete.");
2287 TEUCHOS_TEST_FOR_EXCEPTION
2289 prefix <<
"B.getNumVectors() = " << numVecs <<
" != " 2291 TEUCHOS_TEST_FOR_EXCEPTION
2294 <<
" != this->getNodeNumRows() = " << lclNumRows <<
".");
2295 TEUCHOS_TEST_FOR_EXCEPTION
2296 (static_cast<size_t> (rowIndices.size ()) < lclNumRows,
2297 std::invalid_argument, prefix <<
"rowIndices.size() = " 2298 << rowIndices.size () <<
" < this->getNodeNumRows() = " 2299 << lclNumRows <<
".");
2301 typename DMV::dual_view_type::t_host B_lcl = B.template getLocalView<HMDT> ();
2302 typename RMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
2303 typename MMV::dual_view_type::t_host D_lcl = D.template getLocalView<HMDT> ();
2305 offset_type B_stride[8], X_stride[8], D_stride[8];
2306 B_lcl.stride (B_stride);
2307 X_lcl.stride (X_stride);
2308 D_lcl.stride (D_stride);
2312 typename local_matrix_type::index_type ind = lclGraph.entries;
2313 typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
2314 typename local_matrix_type::values_type val = lclMatrix.values;
2315 const offset_type*
const ptrRaw = ptr.ptr_on_device ();
2316 const LO*
const indRaw = ind.ptr_on_device ();
2317 const impl_scalar_type*
const valRaw = val.ptr_on_device ();
2319 const std::string dir = (direction == KokkosClassic::Forward) ?
"F" :
"B";
2320 KokkosSparse::Impl::Sequential::reorderedGaussSeidel (static_cast<LO> (lclNumRows),
2321 static_cast<LO> (numVecs),
2322 ptrRaw, indRaw, valRaw,
2323 B_lcl.ptr_on_device (),
2325 X_lcl.ptr_on_device (),
2327 D_lcl.ptr_on_device (),
2328 rowIndices.getRawPtr (),
2329 static_cast<LO
> (lclNumRows),
2330 static_cast<impl_scalar_type> (dampingFactor),
2352 template <
class DomainScalar,
class RangeScalar>
2356 Teuchos::ETransp mode)
const 2358 using Teuchos::CONJ_TRANS;
2359 using Teuchos::NO_TRANS;
2360 using Teuchos::TRANS;
2361 typedef LocalOrdinal LO;
2362 typedef GlobalOrdinal GO;
2365 typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2367 const char tfecfFuncName[] =
"localSolve: ";
2369 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2370 (! isFillComplete (), std::runtime_error,
2371 "The matrix is not fill complete.");
2372 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2374 "X and Y must be constant stride.");
2375 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2376 (! isUpperTriangular () && ! isLowerTriangular (), std::runtime_error,
2377 "The matrix is neither upper triangular or lower triangular. " 2378 "You may only call this method if the matrix is triangular. " 2379 "Remember that this is a local (per MPI process) property, and that " 2380 "Tpetra only knows how to do a local (per process) triangular solve.");
2381 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2382 (STS::isComplex && mode == TRANS, std::logic_error,
"This method does " 2383 "not currently support non-conjugated transposed solve (mode == " 2384 "Teuchos::TRANS) for complex scalar types.");
2401 const std::string trans = (mode == Teuchos::CONJ_TRANS) ?
"C" :
2402 (mode == Teuchos::TRANS ?
"T" :
"N");
2403 const std::string diag =
2416 typename DMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
2417 typename RMV::dual_view_type::t_host Y_lcl = Y.template getLocalView<HMDT> ();
2418 KokkosSparse::trsv (uplo.c_str (), trans.c_str (), diag.c_str (), A_lcl, Y_lcl, X_lcl);
2422 for (
size_t j = 0; j < numVecs; ++j) {
2425 auto X_lcl = X_j->template getLocalView<HMDT> ();
2426 auto Y_lcl = Y_j->template getLocalView<HMDT> ();
2427 KokkosSparse::trsv (uplo.c_str (), trans.c_str (), diag.c_str (), A_lcl, Y_lcl, X_lcl);
2435 Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node, classic> >
2455 Teuchos::ETransp mode = Teuchos::NO_TRANS,
2456 Scalar alpha = ScalarTraits<Scalar>::one(),
2457 Scalar beta = ScalarTraits<Scalar>::zero())
const;
2476 Teuchos::RCP<const map_type>
getRangeMap ()
const;
2550 const Scalar& dampingFactor,
2552 const int numSweeps)
const;
2624 const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2625 const Scalar& dampingFactor,
2627 const int numSweeps)
const;
2661 const Scalar& dampingFactor,
2663 const int numSweeps,
2664 const bool zeroInitialGuess)
const;
2699 const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2700 const Scalar& dampingFactor,
2702 const int numSweeps,
2703 const bool zeroInitialGuess)
const;
2715 virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
2716 add (
const Scalar& alpha,
2721 const Teuchos::RCP<Teuchos::ParameterList>& params)
const;
2732 describe (Teuchos::FancyOStream &out,
2733 const Teuchos::EVerbosityLevel verbLevel =
2734 Teuchos::Describable::verbLevel_default)
const;
2746 const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs,
2747 const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs);
2751 const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
2752 Teuchos::Array<char>& exports,
2753 const Teuchos::ArrayView<size_t>& numPacketsPerLID,
2754 size_t& constantNumPackets,
2761 unpackAndCombineImpl (
const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
2762 const Teuchos::ArrayView<const char> &imports,
2763 const Teuchos::ArrayView<size_t> &numPacketsPerLID,
2764 size_t constantNumPackets,
2779 unpackAndCombine (
const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
2780 const Teuchos::ArrayView<const char> &imports,
2781 const Teuchos::ArrayView<size_t> &numPacketsPerLID,
2782 size_t constantNumPackets,
2907 pack (
const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
2908 Teuchos::Array<char>& exports,
2909 const Teuchos::ArrayView<size_t>& numPacketsPerLID,
2910 size_t& constantNumPackets,
2932 packRow (
char*
const numEntOut,
2935 const size_t numEnt,
2936 const LocalOrdinal lclRow)
const;
2961 unpackRow (Scalar*
const valInTmp,
2962 GlobalOrdinal*
const indInTmp,
2963 const size_t tmpNumEnt,
2964 const char*
const valIn,
2965 const char*
const indIn,
2966 const size_t numEnt,
2967 const LocalOrdinal lclRow,
2976 allocatePackSpace (Teuchos::Array<char>& exports,
2977 size_t& totalNumEntries,
2978 const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs)
const;
2989 template<
class CrsMatrixType>
2990 friend Teuchos::RCP<CrsMatrixType>
2992 const Import<
typename CrsMatrixType::local_ordinal_type,
2993 typename CrsMatrixType::global_ordinal_type,
2994 typename CrsMatrixType::node_type>& importer,
2995 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
2996 typename CrsMatrixType::global_ordinal_type,
2997 typename CrsMatrixType::node_type> >& domainMap,
2998 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
2999 typename CrsMatrixType::global_ordinal_type,
3000 typename CrsMatrixType::node_type> >& rangeMap,
3001 const Teuchos::RCP<Teuchos::ParameterList>& params);
3004 template<
class CrsMatrixType>
3005 friend Teuchos::RCP<CrsMatrixType>
3007 const Export<
typename CrsMatrixType::local_ordinal_type,
3008 typename CrsMatrixType::global_ordinal_type,
3009 typename CrsMatrixType::node_type>& exporter,
3010 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3011 typename CrsMatrixType::global_ordinal_type,
3012 typename CrsMatrixType::node_type> >& domainMap,
3013 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3014 typename CrsMatrixType::global_ordinal_type,
3015 typename CrsMatrixType::node_type> >& rangeMap,
3016 const Teuchos::RCP<Teuchos::ParameterList>& params);
3036 const import_type& importer,
3037 const Teuchos::RCP<const map_type>& domainMap,
3038 const Teuchos::RCP<const map_type>& rangeMap,
3039 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
const;
3058 const export_type& exporter,
3059 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3060 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3061 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
const;
3088 const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3089 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3090 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3091 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
const;
3111 insertGlobalValuesFiltered (
const GlobalOrdinal globalRow,
3112 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3113 const Teuchos::ArrayView<const Scalar>& values);
3125 insertLocalValuesFiltered (
const LocalOrdinal localRow,
3126 const Teuchos::ArrayView<const LocalOrdinal>& indices,
3127 const Teuchos::ArrayView<const Scalar>& values);
3141 combineGlobalValues (
const GlobalOrdinal globalRowIndex,
3142 const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3143 const Teuchos::ArrayView<const Scalar>& values,
3157 template<
class BinaryFunction>
3160 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3161 const Teuchos::ArrayView<const Scalar>& values,
3163 const bool atomic = useAtomicUpdatesByDefault)
const 3165 using Kokkos::MemoryUnmanaged;
3167 typedef impl_scalar_type ST;
3168 typedef BinaryFunction BF;
3169 typedef GlobalOrdinal GO;
3170 typedef device_type DD;
3171 typedef typename View<GO*, DD>::HostMirror::device_type HD;
3175 const ST*
const rawInputVals =
3176 reinterpret_cast<const ST*
> (values.getRawPtr ());
3177 View<const ST*, HD, MemoryUnmanaged> inputValsK (rawInputVals,
3179 View<const GO*, HD, MemoryUnmanaged> inputIndsK (indices.getRawPtr (),
3181 return this->
template transformGlobalValues<BF, HD> (globalRow,
3195 insertNonownedGlobalValues (
const GlobalOrdinal globalRow,
3196 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3197 const Teuchos::ArrayView<const Scalar>& values);
3204 typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
3205 typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
3206 typedef Kokkos::Details::ArithTraits<mag_type> STM;
3209 typedef crs_graph_type
Graph;
3212 enum GraphAllocationStatus {
3213 GraphAlreadyAllocated,
3214 GraphNotYetAllocated
3233 void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas);
3317 const bool force =
false)
const;
3342 const bool force =
false)
const;
3355 const Teuchos::ETransp mode,
3368 Teuchos::ArrayView<const impl_scalar_type>
getView (
RowInfo rowinfo)
const;
3391 Kokkos::View<const impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
3392 getRowView (
const RowInfo& rowInfo)
const;
3405 Kokkos::View<impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
3406 getRowViewNonConst (
const RowInfo& rowInfo)
const;
3415 void fillLocalMatrix (
const Teuchos::RCP<Teuchos::ParameterList>& params);
3439 Teuchos::RCP<const Graph> staticGraph_;
3440 Teuchos::RCP< Graph> myGraph_;
3459 typename local_matrix_type::values_type k_values1D_;
3460 Teuchos::ArrayRCP<Teuchos::Array<impl_scalar_type> > values2D_;
3504 std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
3519 template<
class ViewType,
class OffsetViewType>
3520 struct pack_functor {
3524 OffsetViewType src_offset_;
3525 OffsetViewType dst_offset_;
3526 typedef typename OffsetViewType::non_const_value_type scalar_index_type;
3528 pack_functor (ViewType dst, ViewType src,
3529 OffsetViewType dst_offset, OffsetViewType src_offset) :
3532 src_offset_ (src_offset),
3533 dst_offset_ (dst_offset)
3536 KOKKOS_INLINE_FUNCTION
3537 void operator () (
const LocalOrdinal row)
const {
3538 scalar_index_type srcPos = src_offset_(row);
3539 const scalar_index_type dstEnd = dst_offset_(row+1);
3540 scalar_index_type dstPos = dst_offset_(row);
3541 for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
3542 dst_(dstPos) = src_(srcPos);
3557 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node, const
bool classic = Node::
classic>
3558 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
3560 size_t maxNumEntriesPerRow = 0,
3561 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
3564 return Teuchos::rcp (
new matrix_type (map, maxNumEntriesPerRow,
3619 template<
class CrsMatrixType>
3620 Teuchos::RCP<CrsMatrixType>
3622 const Import<
typename CrsMatrixType::local_ordinal_type,
3623 typename CrsMatrixType::global_ordinal_type,
3624 typename CrsMatrixType::node_type>& importer,
3625 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3626 typename CrsMatrixType::global_ordinal_type,
3627 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
3628 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3629 typename CrsMatrixType::global_ordinal_type,
3630 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
3631 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
3633 Teuchos::RCP<CrsMatrixType> destMatrix;
3634 sourceMatrix->importAndFillComplete (destMatrix,importer, domainMap, rangeMap, params);
3671 template<
class CrsMatrixType>
3672 Teuchos::RCP<CrsMatrixType>
3674 const Export<
typename CrsMatrixType::local_ordinal_type,
3675 typename CrsMatrixType::global_ordinal_type,
3676 typename CrsMatrixType::node_type>& exporter,
3677 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3678 typename CrsMatrixType::global_ordinal_type,
3679 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
3680 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
3681 typename CrsMatrixType::global_ordinal_type,
3682 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
3683 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
3685 Teuchos::RCP<CrsMatrixType> destMatrix;
3686 sourceMatrix->exportAndFillComplete (destMatrix,exporter, domainMap, rangeMap, params);
3698 #endif // TPETRA_CRSMATRIX_DECL_HPP size_t getLocalLength() const
Local number of rows on the calling process.
Kokkos::CrsMatrix< impl_scalar_type, LocalOrdinal, execution_space, void, typename local_graph_type::size_type > local_matrix_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
std::string description() const
A one-line description of this object.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
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...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Teuchos::RCP< node_type > getNode() const
The Kokkos Node instance.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
Teuchos::ArrayView< const impl_scalar_type > getView(RowInfo rowinfo) const
Constant view of all entries (including extra space) in the given row.
void getLocalRowCopy(LocalOrdinal localRow, const Teuchos::ArrayView< LocalOrdinal > &colInds, const Teuchos::ArrayView< Scalar > &vals, size_t &numEntries) const
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row...
LocalOrdinal local_ordinal_type
This class' second template parameter; the type of local indices.
void checkInternalState() const
Check that this object's state is sane; throw if it's not.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix's graph, as a CrsGraph.
void sortEntries()
Sort the entries of each row by their column indices.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
This matrix's graph, as a RowGraph.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
virtual void copyAndPermute(const SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteToLIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteFromLIDs)
Perform copies and permutations that are local to this process.
void gaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
"Hybrid" Jacobi + (Gauss-Seidel or SOR) on .
Teuchos::RCP< const map_type > getRowMap() const
The Map that describes the row distribution in this matrix.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &x)
Details::EStorageStatus storageStatus_
Status of the matrix's storage, when not in a fill-complete state.
void getGlobalRowView(GlobalOrdinal GlobalRow, Teuchos::ArrayView< const GlobalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const
Get a constant, nonpersisting view of a row of this matrix, using global row and column indices...
Teuchos::RCP< const map_type > getColMap() const
The Map that describes the column distribution in this matrix.
One or more distributed dense vectors.
GlobalOrdinal global_ordinal_type
This class' third template parameter; the type of global indices.
void mergeRedundantEntries()
Merge entries in each row with the same column indices.
bool isLocallyIndexed() const
Whether the matrix is locally indexed on the calling process.
virtual bool supportsRowViews() const
Return true if getLocalRowView() and getGlobalRowView() are valid for this object.
bool isUpperTriangular() const
Indicates whether the matrix is upper triangular.
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the matrix's column Map with the given Map.
virtual bool checkSizes(const SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
void setAllValues(const typename local_matrix_type::row_map_type &rowPointers, const typename local_graph_type::entries_type::non_const_type &columnIndices, const typename local_matrix_type::values_type &values)
Sets the 1D pointer arrays of the graph.
size_t getNodeNumRows() const
The number of matrix rows owned by the calling process.
Node node_type
This class' fourth template parameter; the Kokkos device type.
bool fillComplete_
Whether the matrix is fill complete.
Node::device_type device_type
The Kokkos device type.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
std::enable_if< Kokkos::is_view< LocalIndicesViewType >::value &&Kokkos::is_view< ImplScalarViewType >::value &&std::is_same< typename LocalIndicesViewType::non_const_value_type, local_ordinal_type >::value &&std::is_same< typename ImplScalarViewType::non_const_value_type, impl_scalar_type >::value, LocalOrdinal >::type replaceLocalValues(const LocalOrdinal localRow, const typename UnmanagedView< LocalIndicesViewType >::type &inputInds, const typename UnmanagedView< ImplScalarViewType >::type &inputVals) const
Replace one or more entries' values, using local row and column indices.
GlobalOrdinal getIndexBase() const
The index base for global indices for this matrix.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const Teuchos::ArrayView< GlobalOrdinal > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row...
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization suitable for this CrsMatrix specialization.
int local_ordinal_type
Default value of LocalOrdinal template parameter.
local_matrix_type::row_map_type t_RowPtrs TPETRA_DEPRECATED
DEPRECATED; use local_matrix_type::row_map_type instead.
Teuchos::RCP< const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > > getVector(const size_t j) const
Return a Vector which is a const view of column j.
local_matrix_type::values_type getLocalValuesView() const
Get the Kokkos local values.
Teuchos::RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node, classic > > convert() const
Return another CrsMatrix with the same entries, but converted to a different Scalar type T...
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap)
Remove processes owning zero rows from the Maps and their communicator.
void insertLocalValues(const LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using local indices.
void getLocalRowView(LocalOrdinal LocalRow, Teuchos::ArrayView< const LocalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const
Get a constant, nonpersisting view of a row of this matrix, using local row and column indices...
device_type::execution_space execution_space
The Kokkos execution space.
mag_type frobNorm_
Cached Frobenius norm of the (global) matrix.
Teuchos::ArrayView< impl_scalar_type > getViewNonConst(const RowInfo &rowinfo) const
Nonconst view of all entries (including extra space) in the given row.
void localGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const RangeScalar &dampingFactor, const KokkosClassic::ESweepDirection direction) const
Gauss-Seidel or SOR on .
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 indices.
void fillLocalMatrix(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Fill data into the local matrix.
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().
size_t global_size_t
Global size_t object.
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.
Kokkos::StaticCrsGraph< LocalOrdinal, Kokkos::LayoutLeft, execution_space > local_graph_type
The type of the part of the sparse graph on each MPI process.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &diag) const
Get a copy of the diagonal entries of the matrix.
std::enable_if< Kokkos::is_view< LocalIndicesViewType >::value &&Kokkos::is_view< ImplScalarViewType >::value &&std::is_same< typename LocalIndicesViewType::non_const_value_type, local_ordinal_type >::value &&std::is_same< typename ImplScalarViewType::non_const_value_type, impl_scalar_type >::value, LocalOrdinal >::type sumIntoLocalValues(const LocalOrdinal localRow, const typename UnmanagedView< LocalIndicesViewType >::type &inputInds, const typename UnmanagedView< ImplScalarViewType >::type &inputVals, const bool atomic=useAtomicUpdatesByDefault) const
Sum into one or more sparse matrix entries, using local row and column indices.
void localMultiply(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &Y, Teuchos::ETransp mode, RangeScalar alpha, RangeScalar beta) const
Compute a sparse matrix-MultiVector product local to each process.
dual_view_type getDualView() const
Get the Kokkos::DualView which implements local storage.
Teuchos::RCP< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
bool isLowerTriangular() const
Indicates whether the matrix is lower triangular.
local_matrix_type::values_type t_ValuesType TPETRA_DEPRECATED
DEPRECATED; use local_matrix_type::values_type instead.
ESweepDirection
Sweep direction for Gauss-Seidel or Successive Over-Relaxation (SOR).
void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas)
Allocate values (and optionally indices) using the Node.
Teuchos::RCP< const map_type > getDomainMap() const
The domain Map of this matrix.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
local_matrix_type::row_map_type::non_const_type t_RowPtrsNC TPETRA_DEPRECATED
DEPRECATED; use local_matrix_type::row_map_type::non_const_type instead.
bool isFillComplete() const
Whether the matrix is fill complete.
void scale(const Scalar &alpha)
Scale the matrix's values: this := alpha*this.
void resumeFill(const RCP< ParameterList > ¶ms=null)
Resume operations that may change the values or structure of the matrix.
void unpackAndCombine(const Teuchos::ArrayView< const LocalOrdinal > &importLIDs, const Teuchos::ArrayView< const char > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Distributor &distor, CombineMode combineMode)
Unpack the imported column indices and values, and combine into matrix.
LocalOrdinal transformGlobalValues(const GlobalOrdinal globalRow, const Kokkos::View< const GlobalOrdinal *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputInds, const Kokkos::View< const impl_scalar_type *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault) const
Transform CrsMatrix entries in place, using global indices to select the entries in the row to transf...
Sets up and executes a communication plan for a Tpetra DistObject.
void reorderedGaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
Reordered "Hybrid" Jacobi + (Gauss-Seidel or SOR) on .
CombineMode
Rule for combining data in an Import or Export.
bool isStorageOptimized() const
Returns true if storage has been optimized.
void exportAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > > &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.
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
local_matrix_type getLocalMatrix() const
The local sparse matrix.
ProfileType getProfileType() const
Returns true if the matrix was allocated with static data structures.
virtual ~CrsMatrix()
Destructor.
Abstract base class for objects that can be the source of an Import or Export operation.
crs_graph_type::local_graph_type local_graph_type
The part of the sparse matrix's graph on each MPI process.
double scalar_type
Default value of Scalar template parameter.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
void reorderedLocalGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const RangeScalar &dampingFactor, const KokkosClassic::ESweepDirection direction) const
Reordered Gauss-Seidel or SOR on .
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
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.
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
bool hasTransposeApply() const
Whether apply() allows applying the transpose or conjugate transpose.
void computeGlobalConstants()
Compute matrix properties that require collectives.
bool isFillActive() const
Whether the matrix is not fill complete.
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
void localSolve(const MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &Y, MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, Teuchos::ETransp mode) const
Solves a linear system when the underlying matrix is locally triangular.
global_size_t getGlobalNumCols() const
The number of global columns in the matrix.
bool hasColMap() const
Indicates whether the matrix has a well-defined column map.
mag_type getFrobeniusNorm() const
Compute and return the Frobenius norm of the matrix.
std::enable_if< Kokkos::is_view< LocalIndicesViewType >::value &&Kokkos::is_view< ImplScalarViewType >::value &&std::is_same< typename LocalIndicesViewType::non_const_value_type, local_ordinal_type >::value &&std::is_same< typename ImplScalarViewType::non_const_value_type, impl_scalar_type >::value, LocalOrdinal >::type transformLocalValues(const LocalOrdinal localRow, const typename UnmanagedView< LocalIndicesViewType >::type &inputInds, const typename UnmanagedView< ImplScalarViewType >::type &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault) const
Transform CrsMatrix entries in place, using local indices to select the entries in the row to transfo...
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node2, Node2::classic > > clone(const Teuchos::RCP< Node2 > &node2, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=null) const
Create a deep copy of this CrsMatrix, where the copy may have a different Node type.
Scalar scalar_type
This class' first template parameter; the type of each entry in the matrix.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &x)
local_matrix_type k_local_matrix_type TPETRA_DEPRECATED
DEPRECATED; use local_matrix_type instead.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply() and gaussSeidel().
local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D TPETRA_DEPRECATED
DEPRECATED; use local_graph_type::entries_type::non_const_type instead.
Describes a parallel distribution of objects over processes.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
global_size_t getGlobalNumEntries() const
The global number of entries in this matrix.
A read-only, row-oriented interface to a sparse matrix.
std::map< GlobalOrdinal, std::pair< Teuchos::Array< GlobalOrdinal >, Teuchos::Array< Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
A distributed dense vector.
virtual void pack(const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< char > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor) const
Pack this object's data for an Import or Export.
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().
void expertStaticFillComplete(const RCP< const map_type > &domainMap, const RCP< const map_type > &rangeMap, const RCP< const import_type > &importer=Teuchos::null, const RCP< const export_type > &exporter=Teuchos::null, const RCP< ParameterList > ¶ms=Teuchos::null)
Perform a fillComplete on a matrix that already has data.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
size_t getNumVectors() const
Number of columns in the multivector.
CrsGraph< LocalOrdinal, GlobalOrdinal, Node, classic > crs_graph_type
The CrsGraph specialization suitable for this CrsMatrix specialization.
void globalAssemble()
Communicate nonlocal contributions to other processes.
Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
LocalOrdinal replaceGlobalValues(const GlobalOrdinal globalRow, const Kokkos::View< const GlobalOrdinal *, device_type, Kokkos::MemoryUnmanaged > &cols, const Kokkos::View< const impl_scalar_type *, device_type, Kokkos::MemoryUnmanaged > &vals) const
Replace one or more entries' values, using global indices.
void gaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of gaussSeidel(), with fewer requirements on X.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
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< MV > exportMV_
Row Map MultiVector used in apply().
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > > createCrsMatrix(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Non-member function to create an empty CrsMatrix given a row map and a non-zero profile.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
Map< LocalOrdinal, GlobalOrdinal, Node > map_type
The Map specialization suitable for this CrsMatrix specialization.
Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization suitable for this CrsMatrix specialization.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Compute a sparse matrix-MultiVector multiply.
size_t getNodeNumCols() const
The number of columns connected to the locally owned rows of this matrix.
void reorderedGaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of reorderedGaussSeidel(), with fewer requirements on X.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
Base class for distributed Tpetra objects that support data redistribution.
size_t getNodeNumEntries() const
The local number of entries in this matrix.
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
Implementation of RowMatrix::add: return alpha*A + beta*this.
void clearGlobalConstants()
Clear matrix properties that require collectives.
bool isGloballyIndexed() const
Whether the matrix is globally indexed on the calling process.
EStorageStatus
Status of the graph's or matrix's storage, when not in a fill-complete state.
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 fillComplete(const RCP< const map_type > &domainMap, const RCP< const map_type > &rangeMap, const RCP< ParameterList > ¶ms=null)
Signal that data entry is complete, specifying domain and range maps.
local_matrix_type lclMatrix_
The local sparse matrix.
void importAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > > &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.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Fill data into the local graph and matrix.
Teuchos::RCP< const map_type > getRangeMap() const
The range Map of this matrix.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.