Tpetra parallel linear algebra  Version of the Day
Tpetra_CrsMatrix_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_CRSMATRIX_DECL_HPP
43 #define TPETRA_CRSMATRIX_DECL_HPP
44 
52 
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"
59 
60 #include "KokkosCompat_ClassicNodeAPI_Wrapper.hpp"
61 // localMultiply is templated on DomainScalar and RangeScalar, so we
62 // have to include this header file here, rather than in the _def
63 // header file, so that we can get KokkosSparse::spmv.
64 #include "Kokkos_Sparse.hpp"
65 // localGaussSeidel and reorderedLocalGaussSeidel are templated on
66 // DomainScalar and RangeScalar, so we have to include this header
67 // file here, rather than in the _def header file, so that we can get
68 // the interfaces to the corresponding local computational kernels.
69 #include "Kokkos_Sparse_impl_sor.hpp"
70 
71 
72 namespace Tpetra {
186  template <class Scalar = Details::DefaultTypes::scalar_type,
187  class LocalOrdinal = Details::DefaultTypes::local_ordinal_type,
188  class GlobalOrdinal = Details::DefaultTypes::global_ordinal_type,
190  const bool classic = Node::classic>
191  class CrsMatrix :
192  public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
193  public DistObject<char, LocalOrdinal, GlobalOrdinal, Node, classic>
194  {
195  public:
197 
198 
201  typedef Scalar scalar_type;
211  typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
213  typedef LocalOrdinal local_ordinal_type;
215  typedef GlobalOrdinal global_ordinal_type;
217  typedef Node node_type;
218 
220  typedef typename Node::device_type device_type;
222  typedef typename device_type::execution_space execution_space;
223 
229  typedef typename Kokkos::Details::ArithTraits<impl_scalar_type>::mag_type mag_type;
230 
233 
236 
239 
242 
245 
248  typedef Kokkos::CrsMatrix<impl_scalar_type, LocalOrdinal, execution_space, void,
249  typename local_graph_type::size_type> local_matrix_type;
250 
252  typedef typename local_matrix_type::row_map_type t_RowPtrs TPETRA_DEPRECATED;
254  typedef typename local_matrix_type::row_map_type::non_const_type t_RowPtrsNC TPETRA_DEPRECATED;
256  typedef typename local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D TPETRA_DEPRECATED;
258  typedef typename local_matrix_type::values_type t_ValuesType TPETRA_DEPRECATED;
259 
261  typedef local_matrix_type k_local_matrix_type TPETRA_DEPRECATED;
262 
264 
266 
284  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
285  size_t maxNumEntriesPerRow,
286  ProfileType pftype = DynamicProfile,
287  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
288 
306  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
307  const Teuchos::ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
308  ProfileType pftype = DynamicProfile,
309  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
310 
333  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
334  const Teuchos::RCP<const map_type>& colMap,
335  size_t maxNumEntriesPerRow,
336  ProfileType pftype = DynamicProfile,
337  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
338 
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,
364  ProfileType pftype = DynamicProfile,
365  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
366 
391  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
392  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
393 
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);
423 
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);
453 
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);
478 
479  // This friend declaration makes the clone() method work.
480  template <class S2, class LO2, class GO2, class N2, const bool isClassic>
481  friend class CrsMatrix;
482 
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
511  {
512  using Teuchos::ArrayRCP;
513  using Teuchos::null;
514  using Teuchos::ParameterList;
515  using Teuchos::RCP;
516  using Teuchos::rcp;
517  using Teuchos::sublist;
520  const char tfecfFuncName[] = "clone";
521 
522  // Get parameter values. Set them initially to their default values.
523  bool fillCompleteClone = true;
524  bool useLocalIndices = this->hasColMap ();
525  ProfileType pftype = StaticProfile;
526  if (! params.is_null ()) {
527  fillCompleteClone = params->get ("fillComplete clone", fillCompleteClone);
528  useLocalIndices = params->get ("Locally indexed clone", useLocalIndices);
529 
530  bool staticProfileClone = true;
531  staticProfileClone = params->get ("Static profile clone", staticProfileClone);
532  pftype = staticProfileClone ? StaticProfile : DynamicProfile;
533  }
534 
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.");
539 
540  RCP<const Map2> clonedRowMap = this->getRowMap ()->template clone<Node2> (node2);
541 
542  // Get an upper bound on the number of entries per row.
543  RCP<CrsMatrix2> clonedMatrix;
544  ArrayRCP<const size_t> numEntriesPerRow;
545  size_t numEntriesForAll = 0;
546  bool boundSameForAllLocalRows = false;
547  staticGraph_->getNumEntriesPerLocalRowUpperBound (numEntriesPerRow,
548  numEntriesForAll,
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 "
557  "developers.");
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.");
572 
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,
581  matParams));
582  }
583  else {
584  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, clonedColMap,
585  numEntriesPerRow, pftype,
586  matParams));
587  }
588  }
589  else {
590  if (numEntriesPerRow.is_null ()) {
591  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, numEntriesForAll,
592  pftype, matParams));
593  }
594  else {
595  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, numEntriesPerRow,
596  pftype, matParams));
597  }
598  }
599  // done with these
600  numEntriesPerRow = Teuchos::null;
601  numEntriesForAll = 0;
602 
603  if (useLocalIndices) {
604  clonedMatrix->allocateValues (LocalIndices,
605  CrsMatrix2::GraphNotYetAllocated);
606  if (this->isLocallyIndexed ()) {
607  ArrayView<const LocalOrdinal> linds;
608  ArrayView<const Scalar> vals;
609  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
610  lrow <= clonedRowMap->getMaxLocalIndex ();
611  ++lrow) {
612  this->getLocalRowView (lrow, linds, vals);
613  if (linds.size ()) {
614  clonedMatrix->insertLocalValues (lrow, linds, vals);
615  }
616  }
617  }
618  else { // this->isGloballyIndexed()
619  Array<LocalOrdinal> linds;
620  Array<Scalar> vals;
621  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
622  lrow <= clonedRowMap->getMaxLocalIndex ();
623  ++lrow) {
624  size_t theNumEntries = this->getNumEntriesInLocalRow (lrow);
625  if (theNumEntries > static_cast<size_t> (linds.size ())) {
626  linds.resize (theNumEntries);
627  }
628  if (theNumEntries > static_cast<size_t> (vals.size ())) {
629  vals.resize (theNumEntries);
630  }
631  this->getLocalRowCopy (clonedRowMap->getGlobalElement (lrow),
632  linds (), vals (), theNumEntries);
633  if (theNumEntries != 0) {
634  clonedMatrix->insertLocalValues (lrow, linds (0, theNumEntries),
635  vals (0, theNumEntries));
636  }
637  }
638  }
639  }
640  else { // useGlobalIndices
641  clonedMatrix->allocateValues (GlobalIndices,
642  CrsMatrix2::GraphNotYetAllocated);
643  if (this->isGloballyIndexed ()) {
644  ArrayView<const GlobalOrdinal> ginds;
645  ArrayView<const Scalar> vals;
646  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
647  grow <= clonedRowMap->getMaxGlobalIndex ();
648  ++grow) {
649  this->getGlobalRowView (grow, ginds, vals);
650  if (ginds.size () > 0) {
651  clonedMatrix->insertGlobalValues (grow, ginds, vals);
652  }
653  }
654  }
655  else { // this->isLocallyIndexed()
656  Array<GlobalOrdinal> ginds;
657  Array<Scalar> vals;
658  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
659  grow <= clonedRowMap->getMaxGlobalIndex ();
660  ++grow) {
661  size_t theNumEntries = this->getNumEntriesInGlobalRow (grow);
662  if (theNumEntries > static_cast<size_t> (ginds.size ())) {
663  ginds.resize (theNumEntries);
664  }
665  if (theNumEntries > static_cast<size_t> (vals.size ())) {
666  vals.resize (theNumEntries);
667  }
668  this->getGlobalRowCopy (grow, ginds (), vals (), theNumEntries);
669  if (theNumEntries != 0) {
670  clonedMatrix->insertGlobalValues (grow, ginds (0, theNumEntries),
671  vals (0, theNumEntries));
672  }
673  }
674  }
675  }
676 
677  if (fillCompleteClone) {
678  RCP<const Map2> clonedRangeMap;
679  RCP<const Map2> clonedDomainMap;
680  try {
681  if (! this->getRangeMap ().is_null () &&
682  this->getRangeMap () != clonedRowMap) {
683  clonedRangeMap = this->getRangeMap ()->template clone<Node2> (node2);
684  }
685  else {
686  clonedRangeMap = clonedRowMap;
687  }
688  if (! this->getDomainMap ().is_null () &&
689  this->getDomainMap () != clonedRowMap) {
690  clonedDomainMap = this->getDomainMap ()->template clone<Node2> (node2);
691  }
692  else {
693  clonedDomainMap = clonedRowMap;
694  }
695  }
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 ());
703  }
704 
705  RCP<ParameterList> fillparams =
706  params.is_null () ? Teuchos::null : sublist (params, "fillComplete");
707  try {
708  clonedMatrix->fillComplete (clonedDomainMap, clonedRangeMap,
709  fillparams);
710  }
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 ());
718  }
719  }
720  return clonedMatrix;
721  }
722 
724  virtual ~CrsMatrix ();
725 
727 
729 
752  //
798  void
799  insertGlobalValues (const GlobalOrdinal globalRow,
800  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
801  const Teuchos::ArrayView<const Scalar>& vals);
802 
842  void
843  insertLocalValues (const LocalOrdinal localRow,
844  const ArrayView<const LocalOrdinal> &cols,
845  const ArrayView<const Scalar> &vals);
846 
881  LocalOrdinal
882  replaceGlobalValues (const GlobalOrdinal globalRow,
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;
887 
890  LocalOrdinal
891  replaceGlobalValues (const GlobalOrdinal globalRow,
892  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
893  const Teuchos::ArrayView<const Scalar>& vals) const;
894 
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
938  replaceLocalValues (const LocalOrdinal localRow,
939  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
940  const typename UnmanagedView<ImplScalarViewType>::type& inputVals) const
941  {
942  typedef LocalOrdinal LO;
943 
944  if (! isFillActive () || staticGraph_.is_null ()) {
945  // Fill must be active and the graph must exist.
946  return Teuchos::OrdinalTraits<LO>::invalid ();
947  }
948 
949  const RowInfo rowInfo = staticGraph_->getRowInfo (localRow);
950  if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
951  // The input local row is invalid on the calling process,
952  // which means that the calling process summed 0 entries.
953  return static_cast<LO> (0);
954  }
955 
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,
961  curVals,
962  inputInds,
963  inputVals);
964  }
965 
967  LocalOrdinal
968  replaceLocalValues (const LocalOrdinal localRow,
969  const Teuchos::ArrayView<const LocalOrdinal>& cols,
970  const Teuchos::ArrayView<const Scalar>& vals) const;
971 
972  private:
977  static const bool useAtomicUpdatesByDefault =
978 #ifdef KOKKOS_HAVE_SERIAL
979  ! std::is_same<execution_space, Kokkos::Serial>::value;
980 #else
981  true;
982 #endif // KOKKOS_HAVE_SERIAL
983 
984  public:
1019  LocalOrdinal
1020  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1021  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1022  const Teuchos::ArrayView<const Scalar>& vals,
1023  const bool atomic = useAtomicUpdatesByDefault);
1024 
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
1069  sumIntoLocalValues (const LocalOrdinal localRow,
1070  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1071  const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1072  const bool atomic = useAtomicUpdatesByDefault) const
1073  {
1074  typedef LocalOrdinal LO;
1075 
1076  if (! this->isFillActive () || this->staticGraph_.is_null ()) {
1077  // Fill must be active and the graph must exist.
1078  return Teuchos::OrdinalTraits<LO>::invalid ();
1079  }
1080 
1081  const RowInfo rowInfo = this->staticGraph_->getRowInfo (localRow);
1082  if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1083  // The input local row is invalid on the calling process,
1084  // which means that the calling process summed 0 entries.
1085  return static_cast<LO> (0);
1086  }
1087 
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,
1093  curVals,
1094  inputInds,
1095  inputVals,
1096  atomic);
1097  }
1098 
1128  LocalOrdinal
1129  sumIntoLocalValues (const LocalOrdinal localRow,
1130  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1131  const Teuchos::ArrayView<const Scalar>& vals,
1132  const bool atomic = useAtomicUpdatesByDefault) const;
1133 
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
1186  transformLocalValues (const LocalOrdinal localRow,
1187  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1188  const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1189  BinaryFunction f,
1190  const bool atomic = useAtomicUpdatesByDefault) const
1191  {
1192  typedef LocalOrdinal LO;
1193  typedef BinaryFunction BF;
1194 
1195  if (! isFillActive () || staticGraph_.is_null ()) {
1196  // Fill must be active and the "nonconst" graph must exist.
1197  return Teuchos::OrdinalTraits<LO>::invalid ();
1198  }
1199 
1200  const RowInfo rowInfo = staticGraph_->getRowInfo (localRow);
1201  if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1202  // The calling process does not own this row, so it is not
1203  // allowed to modify its values.
1204  return static_cast<LO> (0);
1205  }
1206 
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,
1212  curRowVals,
1213  inputInds,
1214  inputVals,
1215  f, atomic);
1216  }
1217 
1255  template<class BinaryFunction, class InputMemorySpace>
1256  LocalOrdinal
1257  transformGlobalValues (const GlobalOrdinal globalRow,
1258  const Kokkos::View<const GlobalOrdinal*,
1259  InputMemorySpace,
1260  Kokkos::MemoryUnmanaged>& inputInds,
1261  const Kokkos::View<const impl_scalar_type*,
1262  InputMemorySpace,
1263  Kokkos::MemoryUnmanaged>& inputVals,
1264  BinaryFunction f,
1265  const bool atomic = useAtomicUpdatesByDefault) const
1266  {
1267  using Kokkos::MemoryUnmanaged;
1268  using Kokkos::View;
1269  typedef impl_scalar_type ST;
1270  typedef BinaryFunction BF;
1271  typedef device_type DD;
1272  typedef InputMemorySpace ID;
1273 
1274  if (! isFillActive () || staticGraph_.is_null ()) {
1275  // Fill must be active and the "nonconst" graph must exist.
1276  return Teuchos::OrdinalTraits<LocalOrdinal>::invalid ();
1277  }
1278 
1279  const RowInfo rowInfo =
1280  staticGraph_->getRowInfoFromGlobalRowIndex (globalRow);
1281  if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1282  // The calling process does not own this row, so it is not
1283  // allowed to modify its values.
1284  return static_cast<LocalOrdinal> (0);
1285  }
1286  auto curRowVals = this->getRowViewNonConst (rowInfo);
1287 
1288  return staticGraph_->template transformGlobalValues<ST, BF, ID, DD> (rowInfo,
1289  curRowVals,
1290  inputInds,
1291  inputVals,
1292  f, atomic);
1293  }
1294 
1296  void setAllToScalar (const Scalar& alpha);
1297 
1299  void scale (const Scalar& alpha);
1300 
1302 
1309  void
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);
1313 
1315 
1326  void
1327  setAllValues (const Teuchos::ArrayRCP<size_t>& rowPointers,
1328  const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
1329  const Teuchos::ArrayRCP<Scalar>& values);
1330 
1331  void
1332  getAllValues (Teuchos::ArrayRCP<const size_t>& rowPointers,
1333  Teuchos::ArrayRCP<const LocalOrdinal>& columnIndices,
1334  Teuchos::ArrayRCP<const Scalar>& values) const;
1335 
1337 
1339 
1368  void globalAssemble();
1369 
1383  void resumeFill (const RCP<ParameterList>& params = null);
1384 
1418  void
1419  fillComplete (const RCP<const map_type>& domainMap,
1420  const RCP<const map_type>& rangeMap,
1421  const RCP<ParameterList>& params = null);
1422 
1435  void fillComplete (const RCP<ParameterList>& params = null);
1436 
1448  void
1449  expertStaticFillComplete (const RCP<const map_type>& domainMap,
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);
1454 
1464  void
1465  replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
1466 
1548  void
1549  reindexColumns (crs_graph_type* const graph,
1550  const Teuchos::RCP<const map_type>& newColMap,
1551  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
1552  const bool sortEachRow = true);
1553 
1566  void
1567  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
1568  Teuchos::RCP<const import_type>& newImporter);
1569 
1583  virtual void
1584  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
1585 
1587 
1589 
1591  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
1592 
1594  Teuchos::RCP<node_type> getNode () const;
1595 
1597  Teuchos::RCP<const map_type> getRowMap () const;
1598 
1600  Teuchos::RCP<const map_type> getColMap () const;
1601 
1603  Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> > getGraph () const;
1604 
1606  Teuchos::RCP<const crs_graph_type> getCrsGraph () const;
1607 
1609  local_matrix_type getLocalMatrix () const {return lclMatrix_; }
1610 
1631 
1638 
1645  size_t getNodeNumRows() const;
1646 
1650  size_t getNodeNumCols() const;
1651 
1653  GlobalOrdinal getIndexBase() const;
1654 
1657 
1659  size_t getNodeNumEntries() const;
1660 
1662 
1663  size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const;
1664 
1666 
1667  size_t getNumEntriesInLocalRow (LocalOrdinal localRow) const;
1668 
1670 
1673 
1675 
1677  size_t getNodeNumDiags() const;
1678 
1680 
1682  size_t getGlobalMaxNumRowEntries() const;
1683 
1685 
1687  size_t getNodeMaxNumRowEntries() const;
1688 
1690  bool hasColMap() const;
1691 
1693 
1695  bool isLowerTriangular() const;
1696 
1698 
1700  bool isUpperTriangular() const;
1701 
1721  bool isLocallyIndexed() const;
1722 
1742  bool isGloballyIndexed() const;
1743 
1766  bool isFillComplete() const;
1767 
1790  bool isFillActive() const;
1791 
1793 
1799  bool isStorageOptimized () const;
1800 
1802  ProfileType getProfileType () const;
1803 
1805  bool isStaticGraph () const;
1806 
1818  mag_type getFrobeniusNorm () const;
1819 
1822  virtual bool supportsRowViews () const;
1823 
1872  void
1873  getGlobalRowCopy (GlobalOrdinal GlobalRow,
1874  const Teuchos::ArrayView<GlobalOrdinal>& Indices,
1875  const Teuchos::ArrayView<Scalar>& Values,
1876  size_t& NumEntries) const;
1877 
1895  void
1896  getLocalRowCopy (LocalOrdinal localRow,
1897  const Teuchos::ArrayView<LocalOrdinal>& colInds,
1898  const Teuchos::ArrayView<Scalar>& vals,
1899  size_t& numEntries) const;
1900 
1914  void
1915  getGlobalRowView (GlobalOrdinal GlobalRow,
1916  Teuchos::ArrayView<const GlobalOrdinal>& indices,
1917  Teuchos::ArrayView<const Scalar>& values) const;
1918 
1932  void
1933  getLocalRowView (LocalOrdinal LocalRow,
1934  Teuchos::ArrayView<const LocalOrdinal>& indices,
1935  Teuchos::ArrayView<const Scalar>& values) const;
1936 
1943 
1981  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
1982 
2001  void
2003  const Teuchos::ArrayView<const size_t>& offsets) const;
2004 
2005 
2006 
2008  void
2010 
2012  void
2014 
2016 
2018 
2067  template <class DomainScalar, class RangeScalar>
2068  void
2071  Teuchos::ETransp mode,
2072  RangeScalar alpha,
2073  RangeScalar beta) const
2074  {
2075  using Teuchos::NO_TRANS;
2076  // Just like Scalar and impl_scalar_type may differ in CrsMatrix,
2077  // RangeScalar and its corresponding impl_scalar_type may differ in
2078  // MultiVector.
2079  typedef typename MultiVector<RangeScalar, LocalOrdinal, GlobalOrdinal,
2080  Node, classic>::impl_scalar_type range_impl_scalar_type;
2081 #ifdef HAVE_TPETRA_DEBUG
2082  const char tfecfFuncName[] = "localMultiply: ";
2083 #endif // HAVE_TPETRA_DEBUG
2084 
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);
2089 
2090 #ifdef HAVE_TPETRA_DEBUG
2091  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2092  (X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
2093  "X.getNumVectors() = " << X.getNumVectors () << " != Y.getNumVectors() = "
2094  << Y.getNumVectors () << ".");
2095  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2096  (! transpose && X.getLocalLength () != getColMap ()->getNodeNumElements (),
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
2101  (! transpose && Y.getLocalLength () != getRowMap ()->getNodeNumElements (),
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
2106  (transpose && X.getLocalLength () != getRowMap ()->getNodeNumElements (),
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
2112  (transpose && Y.getLocalLength () != getColMap ()->getNodeNumElements (),
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
2123  (! X.isConstantStride () || ! Y.isConstantStride (), std::runtime_error,
2124  "X and Y must be constant stride.");
2125  // If the two pointers are NULL, then they don't alias one
2126  // another, even though they are equal.
2127  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2128  X.getDualView ().d_view.ptr_on_device () == Y.getDualView ().d_view.ptr_on_device () &&
2129  X.getDualView ().d_view.ptr_on_device () != NULL,
2130  std::runtime_error, "X and Y may not alias one another.");
2131 #endif // HAVE_TPETRA_DEBUG
2132 
2133  // Y = alpha*op(M) + beta*Y
2134  if (transpose) {
2135  KokkosSparse::spmv (conjugate ? KokkosSparse::ConjugateTranspose : KokkosSparse::Transpose,
2136  theAlpha,
2137  lclMatrix_,
2138  X.template getLocalView<device_type> (),
2139  theBeta,
2140  Y.template getLocalView<device_type> ());
2141  }
2142  else {
2143  KokkosSparse::spmv (KokkosSparse::NoTranspose,
2144  theAlpha,
2145  lclMatrix_,
2146  X.template getLocalView<device_type> (),
2147  theBeta,
2148  Y.template getLocalView<device_type> ());
2149  }
2150  }
2151 
2176  template <class DomainScalar, class RangeScalar>
2177  void
2181  const RangeScalar& dampingFactor,
2182  const KokkosClassic::ESweepDirection direction) const
2183  {
2184  typedef LocalOrdinal LO;
2185  typedef GlobalOrdinal GO;
2189  typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2190  typedef typename Graph::local_graph_type k_local_graph_type;
2191  typedef typename k_local_graph_type::size_type offset_type;
2192  const char prefix[] = "Tpetra::CrsMatrix::localGaussSeidel: ";
2193 
2194  TEUCHOS_TEST_FOR_EXCEPTION
2195  (! this->isFillComplete (), std::runtime_error,
2196  prefix << "The matrix is not fill complete.");
2197  const size_t lclNumRows = this->getNodeNumRows ();
2198  const size_t numVecs = B.getNumVectors ();
2199  TEUCHOS_TEST_FOR_EXCEPTION
2200  (X.getNumVectors () != numVecs, std::invalid_argument,
2201  prefix << "B.getNumVectors() = " << numVecs << " != "
2202  "X.getNumVectors() = " << X.getNumVectors () << ".");
2203  TEUCHOS_TEST_FOR_EXCEPTION
2204  (B.getLocalLength () != lclNumRows, std::invalid_argument,
2205  prefix << "B.getLocalLength() = " << B.getLocalLength ()
2206  << " != this->getNodeNumRows() = " << lclNumRows << ".");
2207 
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> ();
2211 
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);
2216 
2217  local_matrix_type lclMatrix = this->getLocalMatrix ();
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 ();
2225 
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),
2234  dir.c_str ());
2235  }
2236 
2263  template <class DomainScalar, class RangeScalar>
2264  void
2268  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2269  const RangeScalar& dampingFactor,
2270  const KokkosClassic::ESweepDirection direction) const
2271  {
2272  typedef LocalOrdinal LO;
2273  typedef GlobalOrdinal GO;
2277  typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2278  typedef typename Graph::local_graph_type k_local_graph_type;
2279  typedef typename k_local_graph_type::size_type offset_type;
2280  const char prefix[] = "Tpetra::CrsMatrix::reorderedLocalGaussSeidel: ";
2281 
2282  TEUCHOS_TEST_FOR_EXCEPTION
2283  (! this->isFillComplete (), std::runtime_error,
2284  prefix << "The matrix is not fill complete.");
2285  const size_t lclNumRows = this->getNodeNumRows ();
2286  const size_t numVecs = B.getNumVectors ();
2287  TEUCHOS_TEST_FOR_EXCEPTION
2288  (X.getNumVectors () != numVecs, std::invalid_argument,
2289  prefix << "B.getNumVectors() = " << numVecs << " != "
2290  "X.getNumVectors() = " << X.getNumVectors () << ".");
2291  TEUCHOS_TEST_FOR_EXCEPTION
2292  (B.getLocalLength () != lclNumRows, std::invalid_argument,
2293  prefix << "B.getLocalLength() = " << B.getLocalLength ()
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 << ".");
2300 
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> ();
2304 
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);
2309 
2310  local_matrix_type lclMatrix = this->getLocalMatrix ();
2311  typename Graph::local_graph_type lclGraph = lclMatrix.graph;
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 ();
2318 
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 (),
2324  B_stride[1],
2325  X_lcl.ptr_on_device (),
2326  X_stride[1],
2327  D_lcl.ptr_on_device (),
2328  rowIndices.getRawPtr (),
2329  static_cast<LO> (lclNumRows),
2330  static_cast<impl_scalar_type> (dampingFactor),
2331  dir.c_str ());
2332  }
2333 
2352  template <class DomainScalar, class RangeScalar>
2353  void
2356  Teuchos::ETransp mode) const
2357  {
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 ;
2366 
2367  const char tfecfFuncName[] = "localSolve: ";
2368 
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
2373  (! X.isConstantStride () || ! Y.isConstantStride (), std::invalid_argument,
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.");
2385 
2386  // FIXME (mfh 27 Aug 2014) Tpetra has always made the odd decision
2387  // that if _some_ diagonal entries are missing locally, then it
2388  // assumes that the matrix has an implicitly stored unit diagonal.
2389  // Whether the matrix has an implicit unit diagonal or not should
2390  // be up to the user to decide. What if the graph has no diagonal
2391  // entries, and the user wants it that way? The only reason this
2392  // matters, though, is for the triangular solve, and in that case,
2393  // missing diagonal entries will cause trouble anyway. However,
2394  // it would make sense to warn the user if they ask for a
2395  // triangular solve with an incomplete diagonal. Furthermore,
2396  // this code should only assume an implicitly stored unit diagonal
2397  // if the matrix has _no_ explicitly stored diagonal entries.
2398 
2399  const std::string uplo = isUpperTriangular () ? "U" :
2400  (isLowerTriangular () ? "L" : "N");
2401  const std::string trans = (mode == Teuchos::CONJ_TRANS) ? "C" :
2402  (mode == Teuchos::TRANS ? "T" : "N");
2403  const std::string diag =
2404  (getNodeNumDiags () < getNodeNumRows ()) ? "U" : "N";
2405 
2406  local_matrix_type A_lcl = this->getLocalMatrix ();
2407 
2408  // FIXME (mfh 23 Apr 2015) We currently only have a host,
2409  // sequential kernel for local sparse triangular solve.
2410 
2411  Y.getDualView ().template sync<HMDT> (); // Y is read-only
2412  X.getDualView ().template sync<HMDT> ();
2413  X.getDualView ().template modify<HMDT> (); // we will write to X
2414 
2415  if (X.isConstantStride () && Y.isConstantStride ()) {
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);
2419  }
2420  else {
2421  const size_t numVecs = std::min (X.getNumVectors (), Y.getNumVectors ());
2422  for (size_t j = 0; j < numVecs; ++j) {
2423  auto X_j = X.getVector (j);
2424  auto Y_j = X.getVector (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);
2428  }
2429  }
2430  }
2431 
2434  template <class T>
2435  Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node, classic> >
2436  convert () const;
2437 
2439 
2441 
2452  void
2455  Teuchos::ETransp mode = Teuchos::NO_TRANS,
2456  Scalar alpha = ScalarTraits<Scalar>::one(),
2457  Scalar beta = ScalarTraits<Scalar>::zero()) const;
2458 
2460  bool hasTransposeApply () const;
2461 
2468  Teuchos::RCP<const map_type> getDomainMap () const;
2469 
2476  Teuchos::RCP<const map_type> getRangeMap () const;
2477 
2479 
2481 
2546  void
2550  const Scalar& dampingFactor,
2551  const ESweepDirection direction,
2552  const int numSweeps) const;
2553 
2620  void
2624  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2625  const Scalar& dampingFactor,
2626  const ESweepDirection direction,
2627  const int numSweeps) const;
2628 
2657  void
2661  const Scalar& dampingFactor,
2662  const ESweepDirection direction,
2663  const int numSweeps,
2664  const bool zeroInitialGuess) const;
2665 
2695  void
2699  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2700  const Scalar& dampingFactor,
2701  const ESweepDirection direction,
2702  const int numSweeps,
2703  const bool zeroInitialGuess) const;
2704 
2715  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
2716  add (const Scalar& alpha,
2718  const Scalar& beta,
2719  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
2720  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
2721  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
2722 
2724 
2726 
2728  std::string description () const;
2729 
2731  void
2732  describe (Teuchos::FancyOStream &out,
2733  const Teuchos::EVerbosityLevel verbLevel =
2734  Teuchos::Describable::verbLevel_default) const;
2735 
2737 
2739 
2740  virtual bool
2741  checkSizes (const SrcDistObject& source);
2742 
2743  virtual void
2744  copyAndPermute (const SrcDistObject& source,
2745  size_t numSameIDs,
2746  const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs,
2747  const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs);
2748 
2749  virtual void
2750  packAndPrepare (const SrcDistObject& source,
2751  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
2752  Teuchos::Array<char>& exports,
2753  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
2754  size_t& constantNumPackets,
2755  Distributor& distor);
2756 
2757  private:
2760  void
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,
2765  Distributor& distor,
2766  CombineMode combineMode);
2767 
2768  public:
2778  void
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,
2783  Distributor& distor,
2784  CombineMode combineMode);
2786 
2788 
2906  virtual void
2907  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
2908  Teuchos::Array<char>& exports,
2909  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
2910  size_t& constantNumPackets,
2911  Distributor& distor) const;
2912 
2913  private:
2931  bool
2932  packRow (char* const numEntOut,
2933  char* const valOut,
2934  char* const indOut,
2935  const size_t numEnt,
2936  const LocalOrdinal lclRow) const;
2937 
2960  bool
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,
2968  const Tpetra::CombineMode combineMode);
2969 
2975  void
2976  allocatePackSpace (Teuchos::Array<char>& exports,
2977  size_t& totalNumEntries,
2978  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs) const;
2980 
2981  public:
2983  typename local_matrix_type::values_type getLocalValuesView () const {
2984  return k_values1D_;
2985  }
2986 
2987  private:
2988  // Friend declaration for nonmember function.
2989  template<class CrsMatrixType>
2990  friend Teuchos::RCP<CrsMatrixType>
2991  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
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);
3002 
3003  // Friend declaration for nonmember function.
3004  template<class CrsMatrixType>
3005  friend Teuchos::RCP<CrsMatrixType>
3006  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
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);
3017 
3018  public:
3034  void
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;
3040 
3056  void
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;
3062 
3063 
3064 
3065  private:
3086  void
3087  transferAndFillComplete (Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >& destMatrix,
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;
3092  // We forbid copy construction by declaring this method private
3093  // and not implementing it.
3095 
3096  // We forbid assignment (operator=) by declaring this method
3097  // private and not implementing it.
3100 
3110  void
3111  insertGlobalValuesFiltered (const GlobalOrdinal globalRow,
3112  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3113  const Teuchos::ArrayView<const Scalar>& values);
3114 
3124  void
3125  insertLocalValuesFiltered (const LocalOrdinal localRow,
3126  const Teuchos::ArrayView<const LocalOrdinal>& indices,
3127  const Teuchos::ArrayView<const Scalar>& values);
3128 
3140  void
3141  combineGlobalValues (const GlobalOrdinal globalRowIndex,
3142  const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3143  const Teuchos::ArrayView<const Scalar>& values,
3144  const Tpetra::CombineMode combineMode);
3145 
3157  template<class BinaryFunction>
3158  LocalOrdinal
3159  transformGlobalValues (const GlobalOrdinal globalRow,
3160  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3161  const Teuchos::ArrayView<const Scalar>& values,
3162  BinaryFunction f,
3163  const bool atomic = useAtomicUpdatesByDefault) const
3164  {
3165  using Kokkos::MemoryUnmanaged;
3166  using Kokkos::View;
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;
3172 
3173  // The 'indices' and 'values' arrays come from the user, so we
3174  // assume that they are host data, not device data.
3175  const ST* const rawInputVals =
3176  reinterpret_cast<const ST*> (values.getRawPtr ());
3177  View<const ST*, HD, MemoryUnmanaged> inputValsK (rawInputVals,
3178  values.size ());
3179  View<const GO*, HD, MemoryUnmanaged> inputIndsK (indices.getRawPtr (),
3180  indices.size ());
3181  return this->template transformGlobalValues<BF, HD> (globalRow,
3182  inputIndsK,
3183  inputValsK,
3184  f, atomic);
3185  }
3186 
3187  private:
3194  void
3195  insertNonownedGlobalValues (const GlobalOrdinal globalRow,
3196  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3197  const Teuchos::ArrayView<const Scalar>& values);
3198 
3201 
3202  protected:
3203  // useful typedefs
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;
3210 
3211  // Enums
3212  enum GraphAllocationStatus {
3213  GraphAlreadyAllocated,
3214  GraphNotYetAllocated
3215  };
3216 
3233  void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas);
3234 
3240  void sortEntries();
3241 
3247  void mergeRedundantEntries();
3248 
3256  void clearGlobalConstants();
3257 
3266  void computeGlobalConstants();
3267 
3280  mutable Teuchos::RCP<MV> importMV_;
3281 
3294  mutable Teuchos::RCP<MV> exportMV_;
3295 
3315  Teuchos::RCP<MV>
3316  getColumnMapMultiVector (const MV& X_domainMap,
3317  const bool force = false) const;
3318 
3340  Teuchos::RCP<MV>
3341  getRowMapMultiVector (const MV& Y_rangeMap,
3342  const bool force = false) const;
3343 
3345  void
3346  applyNonTranspose (const MV& X_in,
3347  MV& Y_in,
3348  Scalar alpha,
3349  Scalar beta) const;
3350 
3352  void
3353  applyTranspose (const MV& X_in,
3354  MV& Y_in,
3355  const Teuchos::ETransp mode,
3356  Scalar alpha,
3357  Scalar beta) const;
3358 
3359  // matrix data accessors
3360 
3368  Teuchos::ArrayView<const impl_scalar_type> getView (RowInfo rowinfo) const;
3369 
3381  Teuchos::ArrayView<impl_scalar_type> getViewNonConst (const RowInfo& rowinfo) const;
3382 
3383  private:
3391  Kokkos::View<const impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
3392  getRowView (const RowInfo& rowInfo) const;
3393 
3405  Kokkos::View<impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
3406  getRowViewNonConst (const RowInfo& rowInfo) const;
3407 
3408  protected:
3409 
3415  void fillLocalMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
3416 
3422  void fillLocalGraphAndMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
3423 
3425  void checkInternalState () const;
3426 
3438 
3439  Teuchos::RCP<const Graph> staticGraph_;
3440  Teuchos::RCP< Graph> myGraph_;
3442 
3444  local_matrix_type lclMatrix_;
3445 
3458 
3459  typename local_matrix_type::values_type k_values1D_;
3460  Teuchos::ArrayRCP<Teuchos::Array<impl_scalar_type> > values2D_;
3462 
3473 
3476 
3504  std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
3505  Teuchos::Array<Scalar> > > nonlocals_;
3506 
3512  mutable mag_type frobNorm_;
3513 
3514  public:
3515  // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
3516  // public inner class of CrsMatrix? It looks like it doesn't
3517  // depend on any implementation details of CrsMatrix at all. It
3518  // should really be declared and defined outside of CrsMatrix.
3519  template<class ViewType, class OffsetViewType>
3520  struct pack_functor {
3521  typedef typename ViewType::execution_space execution_space;
3522  ViewType src_;
3523  ViewType dst_;
3524  OffsetViewType src_offset_;
3525  OffsetViewType dst_offset_;
3526  typedef typename OffsetViewType::non_const_value_type scalar_index_type;
3527 
3528  pack_functor (ViewType dst, ViewType src,
3529  OffsetViewType dst_offset, OffsetViewType src_offset) :
3530  src_ (src),
3531  dst_ (dst),
3532  src_offset_ (src_offset),
3533  dst_offset_ (dst_offset)
3534  {}
3535 
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);
3543  }
3544  }
3545  };
3546  }; // class CrsMatrix
3547 
3548 
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)
3562  {
3564  return Teuchos::rcp (new matrix_type (map, maxNumEntriesPerRow,
3565  DynamicProfile, params));
3566  }
3567 
3619  template<class CrsMatrixType>
3620  Teuchos::RCP<CrsMatrixType>
3621  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
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)
3632  {
3633  Teuchos::RCP<CrsMatrixType> destMatrix;
3634  sourceMatrix->importAndFillComplete (destMatrix,importer, domainMap, rangeMap, params);
3635  return destMatrix;
3636  }
3637 
3671  template<class CrsMatrixType>
3672  Teuchos::RCP<CrsMatrixType>
3673  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
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)
3684  {
3685  Teuchos::RCP<CrsMatrixType> destMatrix;
3686  sourceMatrix->exportAndFillComplete (destMatrix,exporter, domainMap, rangeMap, params);
3687  return destMatrix;
3688  }
3689 } // namespace Tpetra
3690 
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&#39; second template parameter; the type of local indices.
void checkInternalState() const
Check that this object&#39;s state is sane; throw if it&#39;s not.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix&#39;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&#39;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&#39;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&#39; 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&#39;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&#39; 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&#39; 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 > &params)
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 > &params=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&#39;s values: this := alpha*this.
void resumeFill(const RCP< ParameterList > &params=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 > &params=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&#39;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 > &params=null) const
Create a deep copy of this CrsMatrix, where the copy may have a different Node type.
Scalar scalar_type
This class&#39; 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&#39;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 > &params=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 > &params=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&#39; 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 > &params=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 > &params) 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&#39;s or matrix&#39;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 > &params=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 > &params=Teuchos::null) const
Import from this to the given destination matrix, and make the result fill complete.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
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.