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 // localMultiply is templated on DomainScalar and RangeScalar, so we
61 // have to include this header file here, rather than in the _def
62 // header file, so that we can get KokkosSparse::spmv.
63 #include "Kokkos_Sparse.hpp"
64 // localGaussSeidel and reorderedLocalGaussSeidel are templated on
65 // DomainScalar and RangeScalar, so we have to include this header
66 // file here, rather than in the _def header file, so that we can get
67 // the interfaces to the corresponding local computational kernels.
68 #include "Kokkos_Sparse_impl_sor.hpp"
69 
70 
71 namespace Tpetra {
185  template <class Scalar = ::Tpetra::Details::DefaultTypes::scalar_type,
187  class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
189  const bool classic = Node::classic>
190  class CrsMatrix :
191  public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
192  public DistObject<char, LocalOrdinal, GlobalOrdinal, Node, classic>
193  {
194  public:
196 
197 
200  typedef Scalar scalar_type;
210  typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
212  typedef LocalOrdinal local_ordinal_type;
214  typedef GlobalOrdinal global_ordinal_type;
216  typedef Node node_type;
217 
219  typedef typename Node::device_type device_type;
221  typedef typename device_type::execution_space execution_space;
222 
228  typedef typename Kokkos::Details::ArithTraits<impl_scalar_type>::mag_type mag_type;
229 
232 
235 
238 
241 
244 
247  typedef KokkosSparse::CrsMatrix<impl_scalar_type, LocalOrdinal, execution_space, void,
248  typename local_graph_type::size_type> local_matrix_type;
249 
251  typedef typename local_matrix_type::row_map_type t_RowPtrs TPETRA_DEPRECATED;
253  typedef typename local_matrix_type::row_map_type::non_const_type t_RowPtrsNC TPETRA_DEPRECATED;
255  typedef typename local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D TPETRA_DEPRECATED;
257  typedef typename local_matrix_type::values_type t_ValuesType TPETRA_DEPRECATED;
258 
260  typedef local_matrix_type k_local_matrix_type TPETRA_DEPRECATED;
261 
263 
265 
283  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
284  size_t maxNumEntriesPerRow,
285  ProfileType pftype = DynamicProfile,
286  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
287 
305  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
306  const Teuchos::ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
307  ProfileType pftype = DynamicProfile,
308  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
309 
332  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
333  const Teuchos::RCP<const map_type>& colMap,
334  size_t maxNumEntriesPerRow,
335  ProfileType pftype = DynamicProfile,
336  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
337 
360  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
361  const Teuchos::RCP<const map_type>& colMap,
362  const Teuchos::ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
363  ProfileType pftype = DynamicProfile,
364  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
365 
390  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
391  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
392 
416  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
417  const Teuchos::RCP<const map_type>& colMap,
418  const typename local_matrix_type::row_map_type& rowPointers,
419  const typename local_graph_type::entries_type::non_const_type& columnIndices,
420  const typename local_matrix_type::values_type& values,
421  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
422 
446  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
447  const Teuchos::RCP<const map_type>& colMap,
448  const Teuchos::ArrayRCP<size_t>& rowPointers,
449  const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
450  const Teuchos::ArrayRCP<Scalar>& values,
451  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
452 
473  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
474  const Teuchos::RCP<const map_type>& colMap,
475  const local_matrix_type& lclMatrix,
476  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
477 
478  // This friend declaration makes the clone() method work.
479  template <class S2, class LO2, class GO2, class N2, const bool isClassic>
480  friend class CrsMatrix;
481 
506  template <class Node2>
507  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node2, Node2::classic> >
508  clone (const Teuchos::RCP<Node2>& node2,
509  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const
510  {
511  using Teuchos::Array;
512  using Teuchos::ArrayRCP;
513  using Teuchos::ArrayView;
514  using Teuchos::null;
515  using Teuchos::ParameterList;
516  using Teuchos::RCP;
517  using Teuchos::rcp;
518  using Teuchos::sublist;
521  const char tfecfFuncName[] = "clone";
522 
523  // Get parameter values. Set them initially to their default values.
524  bool fillCompleteClone = true;
525  bool useLocalIndices = this->hasColMap ();
526  ProfileType pftype = StaticProfile;
527  if (! params.is_null ()) {
528  fillCompleteClone = params->get ("fillComplete clone", fillCompleteClone);
529  useLocalIndices = params->get ("Locally indexed clone", useLocalIndices);
530 
531  bool staticProfileClone = true;
532  staticProfileClone = params->get ("Static profile clone", staticProfileClone);
533  pftype = staticProfileClone ? StaticProfile : DynamicProfile;
534  }
535 
536  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
537  ! this->hasColMap () && useLocalIndices, std::runtime_error,
538  ": You requested that the returned clone have local indices, but the "
539  "the source matrix does not have a column Map yet.");
540 
541  RCP<const Map2> clonedRowMap = this->getRowMap ()->template clone<Node2> (node2);
542 
543  // Get an upper bound on the number of entries per row.
544  RCP<CrsMatrix2> clonedMatrix;
545  ArrayRCP<const size_t> numEntriesPerRow;
546  size_t numEntriesForAll = 0;
547  bool boundSameForAllLocalRows = false;
548  staticGraph_->getNumEntriesPerLocalRowUpperBound (numEntriesPerRow,
549  numEntriesForAll,
550  boundSameForAllLocalRows);
551  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
552  numEntriesForAll != 0 &&
553  static_cast<size_t> (numEntriesPerRow.size ()) != 0,
554  std::logic_error, ": getNumEntriesPerLocalRowUpperBound returned a "
555  "nonzero numEntriesForAll = " << numEntriesForAll << " , as well as a "
556  "numEntriesPerRow array of nonzero length " << numEntriesPerRow.size ()
557  << ". This should never happen. Please report this bug to the Tpetra "
558  "developers.");
559  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
560  numEntriesForAll != 0 && ! boundSameForAllLocalRows,
561  std::logic_error, ": getNumEntriesPerLocalRowUpperBound returned a "
562  "nonzero numEntriesForAll = " << numEntriesForAll << " , but claims "
563  "(via its third output value) that the upper bound is not the same for "
564  "all rows. This should never happen. Please report this bug to the "
565  "Tpetra developers.");
566  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
567  numEntriesPerRow.size () != 0 && boundSameForAllLocalRows,
568  std::logic_error, ": getNumEntriesPerLocalRowUpperBound returned a "
569  "numEntriesPerRow array of nonzero length " << numEntriesPerRow.size ()
570  << ", but claims (via its third output value) that the upper bound is "
571  "not the same for all rows. This should never happen. Please report "
572  "this bug to the Tpetra developers.");
573 
574  RCP<ParameterList> matParams =
575  params.is_null () ? null : sublist (params,"CrsMatrix");
576  if (useLocalIndices) {
577  RCP<const Map2> clonedColMap =
578  this->getColMap ()->template clone<Node2> (node2);
579  if (numEntriesPerRow.is_null ()) {
580  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, clonedColMap,
581  numEntriesForAll, pftype,
582  matParams));
583  }
584  else {
585  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, clonedColMap,
586  numEntriesPerRow, pftype,
587  matParams));
588  }
589  }
590  else {
591  if (numEntriesPerRow.is_null ()) {
592  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, numEntriesForAll,
593  pftype, matParams));
594  }
595  else {
596  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, numEntriesPerRow,
597  pftype, matParams));
598  }
599  }
600  // done with these
601  numEntriesPerRow = Teuchos::null;
602  numEntriesForAll = 0;
603 
604  if (useLocalIndices) {
605  clonedMatrix->allocateValues (LocalIndices,
606  CrsMatrix2::GraphNotYetAllocated);
607  if (this->isLocallyIndexed ()) {
608  ArrayView<const LocalOrdinal> linds;
609  ArrayView<const Scalar> vals;
610  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
611  lrow <= clonedRowMap->getMaxLocalIndex ();
612  ++lrow) {
613  this->getLocalRowView (lrow, linds, vals);
614  if (linds.size ()) {
615  clonedMatrix->insertLocalValues (lrow, linds, vals);
616  }
617  }
618  }
619  else { // this->isGloballyIndexed()
620  Array<LocalOrdinal> linds;
621  Array<Scalar> vals;
622  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
623  lrow <= clonedRowMap->getMaxLocalIndex ();
624  ++lrow) {
625  size_t theNumEntries = this->getNumEntriesInLocalRow (lrow);
626  if (theNumEntries > static_cast<size_t> (linds.size ())) {
627  linds.resize (theNumEntries);
628  }
629  if (theNumEntries > static_cast<size_t> (vals.size ())) {
630  vals.resize (theNumEntries);
631  }
632  this->getLocalRowCopy (clonedRowMap->getGlobalElement (lrow),
633  linds (), vals (), theNumEntries);
634  if (theNumEntries != 0) {
635  clonedMatrix->insertLocalValues (lrow, linds (0, theNumEntries),
636  vals (0, theNumEntries));
637  }
638  }
639  }
640  }
641  else { // useGlobalIndices
642  clonedMatrix->allocateValues (GlobalIndices,
643  CrsMatrix2::GraphNotYetAllocated);
644  if (this->isGloballyIndexed ()) {
645  ArrayView<const GlobalOrdinal> ginds;
646  ArrayView<const Scalar> vals;
647  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
648  grow <= clonedRowMap->getMaxGlobalIndex ();
649  ++grow) {
650  this->getGlobalRowView (grow, ginds, vals);
651  if (ginds.size () > 0) {
652  clonedMatrix->insertGlobalValues (grow, ginds, vals);
653  }
654  }
655  }
656  else { // this->isLocallyIndexed()
657  Array<GlobalOrdinal> ginds;
658  Array<Scalar> vals;
659  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
660  grow <= clonedRowMap->getMaxGlobalIndex ();
661  ++grow) {
662  size_t theNumEntries = this->getNumEntriesInGlobalRow (grow);
663  if (theNumEntries > static_cast<size_t> (ginds.size ())) {
664  ginds.resize (theNumEntries);
665  }
666  if (theNumEntries > static_cast<size_t> (vals.size ())) {
667  vals.resize (theNumEntries);
668  }
669  this->getGlobalRowCopy (grow, ginds (), vals (), theNumEntries);
670  if (theNumEntries != 0) {
671  clonedMatrix->insertGlobalValues (grow, ginds (0, theNumEntries),
672  vals (0, theNumEntries));
673  }
674  }
675  }
676  }
677 
678  if (fillCompleteClone) {
679  RCP<const Map2> clonedRangeMap;
680  RCP<const Map2> clonedDomainMap;
681  try {
682  if (! this->getRangeMap ().is_null () &&
683  this->getRangeMap () != clonedRowMap) {
684  clonedRangeMap = this->getRangeMap ()->template clone<Node2> (node2);
685  }
686  else {
687  clonedRangeMap = clonedRowMap;
688  }
689  if (! this->getDomainMap ().is_null () &&
690  this->getDomainMap () != clonedRowMap) {
691  clonedDomainMap = this->getDomainMap ()->template clone<Node2> (node2);
692  }
693  else {
694  clonedDomainMap = clonedRowMap;
695  }
696  }
697  catch (std::exception &e) {
698  const bool caughtExceptionOnClone = true;
699  TEUCHOS_TEST_FOR_EXCEPTION
700  (caughtExceptionOnClone, std::runtime_error,
701  Teuchos::typeName (*this) << "::clone: Caught the following "
702  "exception while cloning range and domain Maps on a clone of "
703  "type " << Teuchos::typeName (*clonedMatrix) << ": " << e.what ());
704  }
705 
706  RCP<ParameterList> fillparams =
707  params.is_null () ? Teuchos::null : sublist (params, "fillComplete");
708  try {
709  clonedMatrix->fillComplete (clonedDomainMap, clonedRangeMap,
710  fillparams);
711  }
712  catch (std::exception &e) {
713  const bool caughtExceptionOnClone = true;
714  TEUCHOS_TEST_FOR_EXCEPTION(
715  caughtExceptionOnClone, std::runtime_error,
716  Teuchos::typeName (*this) << "::clone: Caught the following "
717  "exception while calling fillComplete() on a clone of type "
718  << Teuchos::typeName (*clonedMatrix) << ": " << e.what ());
719  }
720  }
721  return clonedMatrix;
722  }
723 
725  virtual ~CrsMatrix ();
726 
728 
730 
754  //
800  void
801  insertGlobalValues (const GlobalOrdinal globalRow,
802  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
803  const Teuchos::ArrayView<const Scalar>& vals);
804 
819  void
820  insertGlobalValues (const GlobalOrdinal globalRow,
821  const LocalOrdinal numEnt,
822  const Scalar vals[],
823  const GlobalOrdinal inds[]);
824 
865  void
866  insertLocalValues (const LocalOrdinal localRow,
867  const Teuchos::ArrayView<const LocalOrdinal> &cols,
868  const Teuchos::ArrayView<const Scalar> &vals);
869 
884  void
885  insertLocalValues (const LocalOrdinal localRow,
886  const LocalOrdinal numEnt,
887  const Scalar vals[],
888  const LocalOrdinal cols[]);
889 
926  template<class GlobalIndicesViewType,
927  class ImplScalarViewType>
928  LocalOrdinal
929  replaceGlobalValues (const GlobalOrdinal globalRow,
930  const typename UnmanagedView<GlobalIndicesViewType>::type& inputInds,
931  const typename UnmanagedView<ImplScalarViewType>::type& inputVals) const
932  {
933  // We use static_assert here to check the template parameters,
934  // rather than std::enable_if (e.g., on the return value, to
935  // enable compilation only if the template parameters match the
936  // desired attributes). This turns obscure link errors into
937  // clear compilation errors. It also makes the return value a
938  // lot easier to see.
939  static_assert (Kokkos::is_view<GlobalIndicesViewType>::value,
940  "First template parameter GlobalIndicesViewType must be "
941  "a Kokkos::View.");
942  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
943  "Second template parameter ImplScalarViewType must be a "
944  "Kokkos::View.");
945  static_assert (static_cast<int> (GlobalIndicesViewType::rank) == 1,
946  "First template parameter GlobalIndicesViewType must "
947  "have rank 1.");
948  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
949  "Second template parameter ImplScalarViewType must have "
950  "rank 1.");
951  static_assert (std::is_same<
952  typename GlobalIndicesViewType::non_const_value_type,
953  global_ordinal_type>::value,
954  "First template parameter GlobalIndicesViewType must "
955  "contain values of type global_ordinal_type.");
956  static_assert (std::is_same<
957  typename ImplScalarViewType::non_const_value_type,
958  impl_scalar_type>::value,
959  "Second template parameter ImplScalarViewType must "
960  "contain values of type impl_scalar_type.");
961 
962  typedef LocalOrdinal LO;
963  typedef ImplScalarViewType ISVT;
964  typedef GlobalIndicesViewType GIVT;
965 
966  if (! isFillActive () || staticGraph_.is_null ()) {
967  // Fill must be active and the graph must exist.
968  return Teuchos::OrdinalTraits<LO>::invalid ();
969  }
970  const RowInfo rowInfo = staticGraph_->getRowInfoFromGlobalRowIndex (globalRow);
971  if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
972  // The input local row is invalid on the calling process,
973  // which means that the calling process summed 0 entries.
974  return static_cast<LO> (0);
975  }
976 
977  auto curVals = this->getRowViewNonConst (rowInfo);
978  // output scalar view type
979  typedef typename std::decay<decltype (curVals)>::type OSVT;
980  return staticGraph_->template replaceGlobalValues<OSVT, GIVT, ISVT> (rowInfo,
981  curVals,
982  inputInds,
983  inputVals);
984  }
985 
989  LocalOrdinal
990  replaceGlobalValues (const GlobalOrdinal globalRow,
991  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
992  const Teuchos::ArrayView<const Scalar>& vals) const;
993 
1009  LocalOrdinal
1010  replaceGlobalValues (const GlobalOrdinal globalRow,
1011  const LocalOrdinal numEnt,
1012  const Scalar vals[],
1013  const GlobalOrdinal cols[]) const;
1014 
1050  template<class LocalIndicesViewType,
1051  class ImplScalarViewType>
1052  LocalOrdinal
1053  replaceLocalValues (const LocalOrdinal localRow,
1054  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1055  const typename UnmanagedView<ImplScalarViewType>::type& inputVals) const
1056  {
1057  // We use static_assert here to check the template parameters,
1058  // rather than std::enable_if (e.g., on the return value, to
1059  // enable compilation only if the template parameters match the
1060  // desired attributes). This turns obscure link errors into
1061  // clear compilation errors. It also makes the return value a
1062  // lot easier to see.
1063  static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1064  "First template parameter LocalIndicesViewType must be "
1065  "a Kokkos::View.");
1066  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1067  "Second template parameter ImplScalarViewType must be a "
1068  "Kokkos::View.");
1069  static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1070  "First template parameter LocalIndicesViewType must "
1071  "have rank 1.");
1072  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1073  "Second template parameter ImplScalarViewType must have "
1074  "rank 1.");
1075  static_assert (std::is_same<
1076  typename LocalIndicesViewType::non_const_value_type,
1077  local_ordinal_type>::value,
1078  "First template parameter LocalIndicesViewType must "
1079  "contain values of type local_ordinal_type.");
1080  static_assert (std::is_same<
1081  typename ImplScalarViewType::non_const_value_type,
1082  impl_scalar_type>::value,
1083  "Second template parameter ImplScalarViewType must "
1084  "contain values of type impl_scalar_type.");
1085 
1086  typedef LocalOrdinal LO;
1087 
1088  if (! isFillActive () || staticGraph_.is_null ()) {
1089  // Fill must be active and the graph must exist.
1090  return Teuchos::OrdinalTraits<LO>::invalid ();
1091  }
1092 
1093  const RowInfo rowInfo = staticGraph_->getRowInfo (localRow);
1094  if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1095  // The input local row is invalid on the calling process,
1096  // which means that the calling process summed 0 entries.
1097  return static_cast<LO> (0);
1098  }
1099 
1100  auto curVals = this->getRowViewNonConst (rowInfo);
1101  typedef typename std::decay<decltype (curVals) >::type OSVT;
1102  typedef typename UnmanagedView<LocalIndicesViewType>::type LIVT;
1103  typedef typename UnmanagedView<ImplScalarViewType>::type ISVT;
1104  return staticGraph_->template replaceLocalValues<OSVT, LIVT, ISVT> (rowInfo,
1105  curVals,
1106  inputInds,
1107  inputVals);
1108  }
1109 
1113  LocalOrdinal
1114  replaceLocalValues (const LocalOrdinal localRow,
1115  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1116  const Teuchos::ArrayView<const Scalar>& vals) const;
1117 
1135  LocalOrdinal
1136  replaceLocalValues (const LocalOrdinal localRow,
1137  const LocalOrdinal numEnt,
1138  const Scalar inputVals[],
1139  const LocalOrdinal inputCols[]) const;
1140 
1141  private:
1146  static const bool useAtomicUpdatesByDefault =
1147 #ifdef KOKKOS_HAVE_SERIAL
1148  ! std::is_same<execution_space, Kokkos::Serial>::value;
1149 #else
1150  true;
1151 #endif // KOKKOS_HAVE_SERIAL
1152 
1153  public:
1190  LocalOrdinal
1191  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1192  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1193  const Teuchos::ArrayView<const Scalar>& vals,
1194  const bool atomic = useAtomicUpdatesByDefault);
1195 
1218  LocalOrdinal
1219  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1220  const LocalOrdinal numEnt,
1221  const Scalar vals[],
1222  const GlobalOrdinal cols[],
1223  const bool atomic = useAtomicUpdatesByDefault);
1224 
1261  template<class LocalIndicesViewType,
1262  class ImplScalarViewType>
1263  LocalOrdinal
1264  sumIntoLocalValues (const LocalOrdinal localRow,
1265  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1266  const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1267  const bool atomic = useAtomicUpdatesByDefault) const
1268  {
1269  // We use static_assert here to check the template parameters,
1270  // rather than std::enable_if (e.g., on the return value, to
1271  // enable compilation only if the template parameters match the
1272  // desired attributes). This turns obscure link errors into
1273  // clear compilation errors. It also makes the return value a
1274  // lot easier to see.
1275  static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1276  "First template parameter LocalIndicesViewType must be "
1277  "a Kokkos::View.");
1278  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1279  "Second template parameter ImplScalarViewType must be a "
1280  "Kokkos::View.");
1281  static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1282  "First template parameter LocalIndicesViewType must "
1283  "have rank 1.");
1284  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1285  "Second template parameter ImplScalarViewType must have "
1286  "rank 1.");
1287  static_assert (std::is_same<
1288  typename LocalIndicesViewType::non_const_value_type,
1289  local_ordinal_type>::value,
1290  "First template parameter LocalIndicesViewType must "
1291  "contain values of type local_ordinal_type.");
1292  static_assert (std::is_same<
1293  typename ImplScalarViewType::non_const_value_type,
1294  impl_scalar_type>::value,
1295  "Second template parameter ImplScalarViewType must "
1296  "contain values of type impl_scalar_type.");
1297 
1298  typedef LocalOrdinal LO;
1299 
1300  if (! this->isFillActive () || this->staticGraph_.is_null ()) {
1301  // Fill must be active and the graph must exist.
1302  return Teuchos::OrdinalTraits<LO>::invalid ();
1303  }
1304 
1305  const RowInfo rowInfo = this->staticGraph_->getRowInfo (localRow);
1306  if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1307  // The input local row is invalid on the calling process,
1308  // which means that the calling process summed 0 entries.
1309  return static_cast<LO> (0);
1310  }
1311 
1312  auto curVals = this->getRowViewNonConst (rowInfo);
1313  typedef typename std::remove_const<typename std::remove_reference<decltype (curVals)>::type>::type OSVT;
1314  typedef typename UnmanagedView<LocalIndicesViewType>::type LIVT;
1315  typedef typename UnmanagedView<ImplScalarViewType>::type ISVT;
1316  return staticGraph_->template sumIntoLocalValues<OSVT, LIVT, ISVT> (rowInfo,
1317  curVals,
1318  inputInds,
1319  inputVals,
1320  atomic);
1321  }
1322 
1352  LocalOrdinal
1353  sumIntoLocalValues (const LocalOrdinal localRow,
1354  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1355  const Teuchos::ArrayView<const Scalar>& vals,
1356  const bool atomic = useAtomicUpdatesByDefault) const;
1357 
1379  LocalOrdinal
1380  sumIntoLocalValues (const LocalOrdinal localRow,
1381  const LocalOrdinal numEnt,
1382  const Scalar vals[],
1383  const LocalOrdinal cols[],
1384  const bool atomic = useAtomicUpdatesByDefault) const;
1385 
1429  template<class LocalIndicesViewType,
1430  class ImplScalarViewType,
1431  class BinaryFunction>
1432  LocalOrdinal
1433  transformLocalValues (const LocalOrdinal localRow,
1434  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1435  const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1436  BinaryFunction f,
1437  const bool atomic = useAtomicUpdatesByDefault) const
1438  {
1439  // We use static_assert here to check the template parameters,
1440  // rather than std::enable_if (e.g., on the return value, to
1441  // enable compilation only if the template parameters match the
1442  // desired attributes). This turns obscure link errors into
1443  // clear compilation errors. It also makes the return value a
1444  // lot easier to see.
1445  static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1446  "First template parameter LocalIndicesViewType must be "
1447  "a Kokkos::View.");
1448  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1449  "Second template parameter ImplScalarViewType must be a "
1450  "Kokkos::View.");
1451  static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1452  "First template parameter LocalIndicesViewType must "
1453  "have rank 1.");
1454  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1455  "Second template parameter ImplScalarViewType must have "
1456  "rank 1.");
1457  static_assert (std::is_same<
1458  typename LocalIndicesViewType::non_const_value_type,
1459  local_ordinal_type>::value,
1460  "First template parameter LocalIndicesViewType must "
1461  "contain values of type local_ordinal_type.");
1462  static_assert (std::is_same<
1463  typename ImplScalarViewType::non_const_value_type,
1464  impl_scalar_type>::value,
1465  "Second template parameter ImplScalarViewType must "
1466  "contain values of type impl_scalar_type.");
1467 
1468  typedef LocalOrdinal LO;
1469  typedef BinaryFunction BF;
1470 
1471  if (! isFillActive () || staticGraph_.is_null ()) {
1472  // Fill must be active and the "nonconst" graph must exist.
1473  return Teuchos::OrdinalTraits<LO>::invalid ();
1474  }
1475 
1476  const RowInfo rowInfo = staticGraph_->getRowInfo (localRow);
1477  if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1478  // The calling process does not own this row, so it is not
1479  // allowed to modify its values.
1480  return static_cast<LO> (0);
1481  }
1482 
1483  auto curRowVals = this->getRowViewNonConst (rowInfo);
1484  typedef typename std::decay<decltype (curRowVals) >::type OSVT;
1485  typedef typename UnmanagedView<LocalIndicesViewType>::type LIVT;
1486  typedef typename UnmanagedView<ImplScalarViewType>::type ISVT;
1487  return staticGraph_->template transformLocalValues<OSVT, LIVT, ISVT, BF> (rowInfo,
1488  curRowVals,
1489  inputInds,
1490  inputVals,
1491  f, atomic);
1492  }
1493 
1531  template<class BinaryFunction, class InputMemorySpace>
1532  LocalOrdinal
1533  transformGlobalValues (const GlobalOrdinal globalRow,
1534  const Kokkos::View<const GlobalOrdinal*,
1535  InputMemorySpace,
1536  Kokkos::MemoryUnmanaged>& inputInds,
1537  const Kokkos::View<const impl_scalar_type*,
1538  InputMemorySpace,
1539  Kokkos::MemoryUnmanaged>& inputVals,
1540  BinaryFunction f,
1541  const bool atomic = useAtomicUpdatesByDefault) const
1542  {
1543  using Kokkos::MemoryUnmanaged;
1544  using Kokkos::View;
1545  typedef impl_scalar_type ST;
1546  typedef BinaryFunction BF;
1547  typedef device_type DD;
1548  typedef InputMemorySpace ID;
1549 
1550  if (! isFillActive () || staticGraph_.is_null ()) {
1551  // Fill must be active and the "nonconst" graph must exist.
1552  return Teuchos::OrdinalTraits<LocalOrdinal>::invalid ();
1553  }
1554 
1555  const RowInfo rowInfo =
1556  staticGraph_->getRowInfoFromGlobalRowIndex (globalRow);
1557  if (rowInfo.localRow == Teuchos::OrdinalTraits<size_t>::invalid ()) {
1558  // The calling process does not own this row, so it is not
1559  // allowed to modify its values.
1560  return static_cast<LocalOrdinal> (0);
1561  }
1562  auto curRowVals = this->getRowViewNonConst (rowInfo);
1563 
1564  return staticGraph_->template transformGlobalValues<ST, BF, ID, DD> (rowInfo,
1565  curRowVals,
1566  inputInds,
1567  inputVals,
1568  f, atomic);
1569  }
1570 
1572  void setAllToScalar (const Scalar& alpha);
1573 
1575  void scale (const Scalar& alpha);
1576 
1600  void
1601  setAllValues (const typename local_matrix_type::row_map_type& ptr,
1602  const typename local_graph_type::entries_type::non_const_type& ind,
1603  const typename local_matrix_type::values_type& val);
1604 
1628  void
1629  setAllValues (const Teuchos::ArrayRCP<size_t>& ptr,
1630  const Teuchos::ArrayRCP<LocalOrdinal>& ind,
1631  const Teuchos::ArrayRCP<Scalar>& val);
1632 
1633  void
1634  getAllValues (Teuchos::ArrayRCP<const size_t>& rowPointers,
1635  Teuchos::ArrayRCP<const LocalOrdinal>& columnIndices,
1636  Teuchos::ArrayRCP<const Scalar>& values) const;
1637 
1639 
1641 
1670  void globalAssemble();
1671 
1685  void resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1686 
1744  void
1745  fillComplete (const Teuchos::RCP<const map_type>& domainMap,
1746  const Teuchos::RCP<const map_type>& rangeMap,
1747  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1748 
1775  void
1776  fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1777 
1804  void
1805  expertStaticFillComplete (const Teuchos::RCP<const map_type>& domainMap,
1806  const Teuchos::RCP<const map_type>& rangeMap,
1807  const Teuchos::RCP<const import_type>& importer = Teuchos::null,
1808  const Teuchos::RCP<const export_type>& exporter = Teuchos::null,
1809  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1810 
1820  void
1821  replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
1822 
1904  void
1905  reindexColumns (crs_graph_type* const graph,
1906  const Teuchos::RCP<const map_type>& newColMap,
1907  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
1908  const bool sortEachRow = true);
1909 
1922  void
1923  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
1924  Teuchos::RCP<const import_type>& newImporter);
1925 
1939  virtual void
1940  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap);
1941 
1943 
1945 
1947  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
1948 
1950  Teuchos::RCP<node_type> getNode () const;
1951 
1953  Teuchos::RCP<const map_type> getRowMap () const;
1954 
1956  Teuchos::RCP<const map_type> getColMap () const;
1957 
1959  Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> > getGraph () const;
1960 
1962  Teuchos::RCP<const crs_graph_type> getCrsGraph () const;
1963 
1964  private:
1975  const crs_graph_type& getCrsGraphRef () const;
1976 
1977  public:
1987  local_matrix_type getLocalMatrix () const {return lclMatrix_; }
1988 
2009 
2016 
2023  size_t getNodeNumRows() const;
2024 
2028  size_t getNodeNumCols() const;
2029 
2031  GlobalOrdinal getIndexBase() const;
2032 
2035 
2037  size_t getNodeNumEntries() const;
2038 
2040 
2041  size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const;
2042 
2044 
2045  size_t getNumEntriesInLocalRow (LocalOrdinal localRow) const;
2046 
2048 
2051 
2053 
2055  size_t getNodeNumDiags() const;
2056 
2058 
2060  size_t getGlobalMaxNumRowEntries() const;
2061 
2063 
2065  size_t getNodeMaxNumRowEntries() const;
2066 
2068  bool hasColMap() const;
2069 
2071 
2073  bool isLowerTriangular() const;
2074 
2076 
2078  bool isUpperTriangular() const;
2079 
2099  bool isLocallyIndexed() const;
2100 
2120  bool isGloballyIndexed() const;
2121 
2144  bool isFillComplete() const;
2145 
2168  bool isFillActive() const;
2169 
2171 
2177  bool isStorageOptimized () const;
2178 
2180  ProfileType getProfileType () const;
2181 
2183  bool isStaticGraph () const;
2184 
2196  mag_type getFrobeniusNorm () const;
2197 
2200  virtual bool supportsRowViews () const;
2201 
2250  void
2251  getGlobalRowCopy (GlobalOrdinal GlobalRow,
2252  const Teuchos::ArrayView<GlobalOrdinal>& Indices,
2253  const Teuchos::ArrayView<Scalar>& Values,
2254  size_t& NumEntries) const;
2255 
2273  void
2274  getLocalRowCopy (LocalOrdinal localRow,
2275  const Teuchos::ArrayView<LocalOrdinal>& colInds,
2276  const Teuchos::ArrayView<Scalar>& vals,
2277  size_t& numEntries) const;
2278 
2292  void
2293  getGlobalRowView (GlobalOrdinal GlobalRow,
2294  Teuchos::ArrayView<const GlobalOrdinal>& indices,
2295  Teuchos::ArrayView<const Scalar>& values) const;
2296 
2310  void
2311  getLocalRowView (LocalOrdinal LocalRow,
2312  Teuchos::ArrayView<const LocalOrdinal>& indices,
2313  Teuchos::ArrayView<const Scalar>& values) const;
2314 
2341  LocalOrdinal
2342  getLocalRowViewRaw (const LocalOrdinal lclRow,
2343  LocalOrdinal& numEnt,
2344  const LocalOrdinal*& lclColInds,
2345  const Scalar*& vals) const;
2346 
2372  LocalOrdinal
2373  getLocalRowView (const LocalOrdinal lclRow,
2374  LocalOrdinal& numEnt,
2375  const impl_scalar_type*& val,
2376  const LocalOrdinal*& ind) const;
2377 
2385  template<class OutputScalarType>
2386  typename std::enable_if<! std::is_same<OutputScalarType, impl_scalar_type>::value &&
2387  std::is_convertible<impl_scalar_type, OutputScalarType>::value,
2388  LocalOrdinal>::type
2389  getLocalRowView (const LocalOrdinal lclRow,
2390  LocalOrdinal& numEnt,
2391  const OutputScalarType*& val,
2392  const LocalOrdinal*& ind) const
2393  {
2394  const impl_scalar_type* valTmp = NULL;
2395  const LocalOrdinal err = this->getLocalRowView (lclRow, numEnt, valTmp, ind);
2396  // Cast is legitimate because impl_scalar_type is convertible to
2397  // OutputScalarType.
2398  val = reinterpret_cast<const OutputScalarType*> (valTmp);
2399  return err;
2400  }
2401 
2408  void
2410 
2454  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
2455 
2477  void
2479  const Kokkos::View<const size_t*, device_type,
2480  Kokkos::MemoryUnmanaged>& offsets) const;
2481 
2504  void
2506  const Teuchos::ArrayView<const size_t>& offsets) const;
2507 
2509  void
2511 
2513  void
2515 
2517 
2519 
2568  template <class DomainScalar, class RangeScalar>
2569  void
2572  Teuchos::ETransp mode,
2573  RangeScalar alpha,
2574  RangeScalar beta) const
2575  {
2576  using Teuchos::NO_TRANS;
2577  // Just like Scalar and impl_scalar_type may differ in CrsMatrix,
2578  // RangeScalar and its corresponding impl_scalar_type may differ in
2579  // MultiVector.
2580  typedef typename MultiVector<RangeScalar, LocalOrdinal, GlobalOrdinal,
2581  Node, classic>::impl_scalar_type range_impl_scalar_type;
2582 #ifdef HAVE_TPETRA_DEBUG
2583  const char tfecfFuncName[] = "localMultiply: ";
2584 #endif // HAVE_TPETRA_DEBUG
2585 
2586  const range_impl_scalar_type theAlpha = static_cast<range_impl_scalar_type> (alpha);
2587  const range_impl_scalar_type theBeta = static_cast<range_impl_scalar_type> (beta);
2588  const bool conjugate = (mode == Teuchos::CONJ_TRANS);
2589  const bool transpose = (mode != Teuchos::NO_TRANS);
2590  auto X_lcl = X.template getLocalView<device_type> ();
2591  auto Y_lcl = Y.template getLocalView<device_type> ();
2592 
2593 #ifdef HAVE_TPETRA_DEBUG
2594  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2595  (X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
2596  "X.getNumVectors() = " << X.getNumVectors () << " != Y.getNumVectors() = "
2597  << Y.getNumVectors () << ".");
2598  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2599  (! transpose && X.getLocalLength () != getColMap ()->getNodeNumElements (),
2600  std::runtime_error, "NO_TRANS case: X has the wrong number of local rows. "
2601  "X.getLocalLength() = " << X.getLocalLength () << " != getColMap()->"
2602  "getNodeNumElements() = " << getColMap ()->getNodeNumElements () << ".");
2603  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2604  (! transpose && Y.getLocalLength () != getRowMap ()->getNodeNumElements (),
2605  std::runtime_error, "NO_TRANS case: Y has the wrong number of local rows. "
2606  "Y.getLocalLength() = " << Y.getLocalLength () << " != getRowMap()->"
2607  "getNodeNumElements() = " << getRowMap ()->getNodeNumElements () << ".");
2608  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2609  (transpose && X.getLocalLength () != getRowMap ()->getNodeNumElements (),
2610  std::runtime_error, "TRANS or CONJ_TRANS case: X has the wrong number of "
2611  "local rows. X.getLocalLength() = " << X.getLocalLength () << " != "
2612  "getRowMap()->getNodeNumElements() = "
2613  << getRowMap ()->getNodeNumElements () << ".");
2614  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2615  (transpose && Y.getLocalLength () != getColMap ()->getNodeNumElements (),
2616  std::runtime_error, "TRANS or CONJ_TRANS case: X has the wrong number of "
2617  "local rows. Y.getLocalLength() = " << Y.getLocalLength () << " != "
2618  "getColMap()->getNodeNumElements() = "
2619  << getColMap ()->getNodeNumElements () << ".");
2620  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2621  (! isFillComplete (), std::runtime_error, "The matrix is not fill "
2622  "complete. You must call fillComplete() (possibly with domain and range "
2623  "Map arguments) without an intervening resumeFill() call before you may "
2624  "call this method.");
2625  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2626  (! X.isConstantStride () || ! Y.isConstantStride (), std::runtime_error,
2627  "X and Y must be constant stride.");
2628  // If the two pointers are NULL, then they don't alias one
2629  // another, even though they are equal.
2630  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2631  X_lcl.ptr_on_device () == Y_lcl.ptr_on_device () &&
2632  X_lcl.ptr_on_device () != NULL,
2633  std::runtime_error, "X and Y may not alias one another.");
2634 #endif // HAVE_TPETRA_DEBUG
2635 
2636  // Y = alpha*op(M) + beta*Y
2637  if (transpose) {
2638  KokkosSparse::spmv (conjugate ? KokkosSparse::ConjugateTranspose : KokkosSparse::Transpose,
2639  theAlpha,
2640  lclMatrix_,
2641  X.template getLocalView<device_type> (),
2642  theBeta,
2643  Y.template getLocalView<device_type> ());
2644  }
2645  else {
2646  KokkosSparse::spmv (KokkosSparse::NoTranspose,
2647  theAlpha,
2648  lclMatrix_,
2649  X.template getLocalView<device_type> (),
2650  theBeta,
2651  Y.template getLocalView<device_type> ());
2652  }
2653  }
2654 
2655  private:
2656 
2687  void
2690  const Teuchos::ETransp mode = Teuchos::NO_TRANS,
2691  const Scalar& alpha = Teuchos::ScalarTraits<Scalar>::one (),
2692  const Scalar& beta = Teuchos::ScalarTraits<Scalar>::zero ()) const;
2693 
2694  public:
2695 
2720  template <class DomainScalar, class RangeScalar>
2721  void
2725  const RangeScalar& dampingFactor,
2726  const KokkosClassic::ESweepDirection direction) const
2727  {
2728  typedef LocalOrdinal LO;
2729  typedef GlobalOrdinal GO;
2733  typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2734  typedef typename Graph::local_graph_type k_local_graph_type;
2735  typedef typename k_local_graph_type::size_type offset_type;
2736  const char prefix[] = "Tpetra::CrsMatrix::localGaussSeidel: ";
2737 
2738  TEUCHOS_TEST_FOR_EXCEPTION
2739  (! this->isFillComplete (), std::runtime_error,
2740  prefix << "The matrix is not fill complete.");
2741  const size_t lclNumRows = this->getNodeNumRows ();
2742  const size_t numVecs = B.getNumVectors ();
2743  TEUCHOS_TEST_FOR_EXCEPTION
2744  (X.getNumVectors () != numVecs, std::invalid_argument,
2745  prefix << "B.getNumVectors() = " << numVecs << " != "
2746  "X.getNumVectors() = " << X.getNumVectors () << ".");
2747  TEUCHOS_TEST_FOR_EXCEPTION
2748  (B.getLocalLength () != lclNumRows, std::invalid_argument,
2749  prefix << "B.getLocalLength() = " << B.getLocalLength ()
2750  << " != this->getNodeNumRows() = " << lclNumRows << ".");
2751 
2752  typename DMV::dual_view_type::t_host B_lcl = B.template getLocalView<HMDT> ();
2753  typename RMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
2754  typename MMV::dual_view_type::t_host D_lcl = D.template getLocalView<HMDT> ();
2755 
2756  offset_type B_stride[8], X_stride[8], D_stride[8];
2757  B_lcl.stride (B_stride);
2758  X_lcl.stride (X_stride);
2759  D_lcl.stride (D_stride);
2760 
2761  local_matrix_type lclMatrix = this->getLocalMatrix ();
2762  k_local_graph_type lclGraph = lclMatrix.graph;
2763  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
2764  typename local_matrix_type::index_type ind = lclGraph.entries;
2765  typename local_matrix_type::values_type val = lclMatrix.values;
2766  const offset_type* const ptrRaw = ptr.ptr_on_device ();
2767  const LO* const indRaw = ind.ptr_on_device ();
2768  const impl_scalar_type* const valRaw = val.ptr_on_device ();
2769 
2770  const std::string dir ((direction == KokkosClassic::Forward) ? "F" : "B");
2771  KokkosSparse::Impl::Sequential::gaussSeidel (static_cast<LO> (lclNumRows),
2772  static_cast<LO> (numVecs),
2773  ptrRaw, indRaw, valRaw,
2774  B_lcl.ptr_on_device (), B_stride[1],
2775  X_lcl.ptr_on_device (), X_stride[1],
2776  D_lcl.ptr_on_device (),
2777  static_cast<impl_scalar_type> (dampingFactor),
2778  dir.c_str ());
2779  }
2780 
2807  template <class DomainScalar, class RangeScalar>
2808  void
2812  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2813  const RangeScalar& dampingFactor,
2814  const KokkosClassic::ESweepDirection direction) const
2815  {
2816  typedef LocalOrdinal LO;
2817  typedef GlobalOrdinal GO;
2821  typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2822  typedef typename Graph::local_graph_type k_local_graph_type;
2823  typedef typename k_local_graph_type::size_type offset_type;
2824  const char prefix[] = "Tpetra::CrsMatrix::reorderedLocalGaussSeidel: ";
2825 
2826  TEUCHOS_TEST_FOR_EXCEPTION
2827  (! this->isFillComplete (), std::runtime_error,
2828  prefix << "The matrix is not fill complete.");
2829  const size_t lclNumRows = this->getNodeNumRows ();
2830  const size_t numVecs = B.getNumVectors ();
2831  TEUCHOS_TEST_FOR_EXCEPTION
2832  (X.getNumVectors () != numVecs, std::invalid_argument,
2833  prefix << "B.getNumVectors() = " << numVecs << " != "
2834  "X.getNumVectors() = " << X.getNumVectors () << ".");
2835  TEUCHOS_TEST_FOR_EXCEPTION
2836  (B.getLocalLength () != lclNumRows, std::invalid_argument,
2837  prefix << "B.getLocalLength() = " << B.getLocalLength ()
2838  << " != this->getNodeNumRows() = " << lclNumRows << ".");
2839  TEUCHOS_TEST_FOR_EXCEPTION
2840  (static_cast<size_t> (rowIndices.size ()) < lclNumRows,
2841  std::invalid_argument, prefix << "rowIndices.size() = "
2842  << rowIndices.size () << " < this->getNodeNumRows() = "
2843  << lclNumRows << ".");
2844 
2845  typename DMV::dual_view_type::t_host B_lcl = B.template getLocalView<HMDT> ();
2846  typename RMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
2847  typename MMV::dual_view_type::t_host D_lcl = D.template getLocalView<HMDT> ();
2848 
2849  offset_type B_stride[8], X_stride[8], D_stride[8];
2850  B_lcl.stride (B_stride);
2851  X_lcl.stride (X_stride);
2852  D_lcl.stride (D_stride);
2853 
2854  local_matrix_type lclMatrix = this->getLocalMatrix ();
2855  typename Graph::local_graph_type lclGraph = lclMatrix.graph;
2856  typename local_matrix_type::index_type ind = lclGraph.entries;
2857  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
2858  typename local_matrix_type::values_type val = lclMatrix.values;
2859  const offset_type* const ptrRaw = ptr.ptr_on_device ();
2860  const LO* const indRaw = ind.ptr_on_device ();
2861  const impl_scalar_type* const valRaw = val.ptr_on_device ();
2862 
2863  const std::string dir = (direction == KokkosClassic::Forward) ? "F" : "B";
2864  KokkosSparse::Impl::Sequential::reorderedGaussSeidel (static_cast<LO> (lclNumRows),
2865  static_cast<LO> (numVecs),
2866  ptrRaw, indRaw, valRaw,
2867  B_lcl.ptr_on_device (),
2868  B_stride[1],
2869  X_lcl.ptr_on_device (),
2870  X_stride[1],
2871  D_lcl.ptr_on_device (),
2872  rowIndices.getRawPtr (),
2873  static_cast<LO> (lclNumRows),
2874  static_cast<impl_scalar_type> (dampingFactor),
2875  dir.c_str ());
2876  }
2877 
2896  template <class DomainScalar, class RangeScalar>
2897  void
2900  Teuchos::ETransp mode) const
2901  {
2902  using Teuchos::CONJ_TRANS;
2903  using Teuchos::NO_TRANS;
2904  using Teuchos::TRANS;
2905  const char tfecfFuncName[] = "localSolve: ";
2906 
2907  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2908  (! isFillComplete (), std::runtime_error,
2909  "The matrix is not fill complete.");
2910  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2911  (! X.isConstantStride () || ! Y.isConstantStride (), std::invalid_argument,
2912  "X and Y must be constant stride.");
2913 
2914  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2915  ( getNodeNumRows()>0 && ! isUpperTriangular () && ! isLowerTriangular (), std::runtime_error,
2916  "The matrix is neither upper triangular or lower triangular. "
2917  "You may only call this method if the matrix is triangular. "
2918  "Remember that this is a local (per MPI process) property, and that "
2919  "Tpetra only knows how to do a local (per process) triangular solve.");
2920 
2921  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2922  (STS::isComplex && mode == TRANS, std::logic_error, "This method does "
2923  "not currently support non-conjugated transposed solve (mode == "
2924  "Teuchos::TRANS) for complex scalar types.");
2925 
2926  // FIXME (mfh 19 May 2016) This makes some Ifpack2 tests fail.
2927  //
2928  // TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2929  // (Y.template need_sync<device_type> () && !
2930  // Y.template need_sync<Kokkos::HostSpace> (), std::runtime_error,
2931  // "Y must be sync'd to device memory before you may call this method.");
2932 
2933  // FIXME (mfh 27 Aug 2014) Tpetra has always made the odd decision
2934  // that if _some_ diagonal entries are missing locally, then it
2935  // assumes that the matrix has an implicitly stored unit diagonal.
2936  // Whether the matrix has an implicit unit diagonal or not should
2937  // be up to the user to decide. What if the graph has no diagonal
2938  // entries, and the user wants it that way? The only reason this
2939  // matters, though, is for the triangular solve, and in that case,
2940  // missing diagonal entries will cause trouble anyway. However,
2941  // it would make sense to warn the user if they ask for a
2942  // triangular solve with an incomplete diagonal. Furthermore,
2943  // this code should only assume an implicitly stored unit diagonal
2944  // if the matrix has _no_ explicitly stored diagonal entries.
2945 
2946  const std::string uplo = isUpperTriangular () ? "U" :
2947  (isLowerTriangular () ? "L" : "N");
2948  const std::string trans = (mode == Teuchos::CONJ_TRANS) ? "C" :
2949  (mode == Teuchos::TRANS ? "T" : "N");
2950  const std::string diag =
2951  (getNodeNumDiags () < getNodeNumRows ()) ? "U" : "N";
2952 
2953  local_matrix_type A_lcl = this->getLocalMatrix ();
2954  X.template modify<device_type> (); // we will write to X
2955 
2956  if (X.isConstantStride () && Y.isConstantStride ()) {
2957  auto X_lcl = X.template getLocalView<device_type> ();
2958  auto Y_lcl = Y.template getLocalView<device_type> ();
2959  KokkosSparse::trsv (uplo.c_str (), trans.c_str (), diag.c_str (),
2960  A_lcl, Y_lcl, X_lcl);
2961  }
2962  else {
2963  const size_t numVecs = std::min (X.getNumVectors (), Y.getNumVectors ());
2964  for (size_t j = 0; j < numVecs; ++j) {
2965  auto X_j = X.getVector (j);
2966  auto Y_j = X.getVector (j);
2967  auto X_lcl = X_j->template getLocalView<device_type> ();
2968  auto Y_lcl = Y_j->template getLocalView<device_type> ();
2969  KokkosSparse::trsv (uplo.c_str (), trans.c_str (),
2970  diag.c_str (), A_lcl, Y_lcl, X_lcl);
2971  }
2972  }
2973  }
2974 
2977  template <class T>
2978  Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node, classic> >
2979  convert () const;
2980 
2982 
2984 
2995  void
2998  Teuchos::ETransp mode = Teuchos::NO_TRANS,
2999  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
3000  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
3001 
3003  bool hasTransposeApply () const;
3004 
3011  Teuchos::RCP<const map_type> getDomainMap () const;
3012 
3019  Teuchos::RCP<const map_type> getRangeMap () const;
3020 
3022 
3024 
3089  void
3093  const Scalar& dampingFactor,
3094  const ESweepDirection direction,
3095  const int numSweeps) const;
3096 
3163  void
3167  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
3168  const Scalar& dampingFactor,
3169  const ESweepDirection direction,
3170  const int numSweeps) const;
3171 
3200  void
3204  const Scalar& dampingFactor,
3205  const ESweepDirection direction,
3206  const int numSweeps,
3207  const bool zeroInitialGuess) const;
3208 
3238  void
3242  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
3243  const Scalar& dampingFactor,
3244  const ESweepDirection direction,
3245  const int numSweeps,
3246  const bool zeroInitialGuess) const;
3247 
3258  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3259  add (const Scalar& alpha,
3261  const Scalar& beta,
3262  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
3263  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
3264  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3265 
3267 
3269 
3271  std::string description () const;
3272 
3274  void
3275  describe (Teuchos::FancyOStream &out,
3276  const Teuchos::EVerbosityLevel verbLevel =
3277  Teuchos::Describable::verbLevel_default) const;
3278 
3280 
3282 
3283  virtual bool
3284  checkSizes (const SrcDistObject& source);
3285 
3286  virtual void
3287  copyAndPermute (const SrcDistObject& source,
3288  size_t numSameIDs,
3289  const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs,
3290  const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs);
3291 
3292  virtual void
3293  packAndPrepare (const SrcDistObject& source,
3294  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
3295  Teuchos::Array<char>& exports,
3296  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
3297  size_t& constantNumPackets,
3298  Distributor& distor);
3299 
3300  private:
3303  void
3304  unpackAndCombineImpl (const Teuchos::ArrayView<const LocalOrdinal>& importLIDs,
3305  const Teuchos::ArrayView<const char>& imports,
3306  const Teuchos::ArrayView<const size_t>& numPacketsPerLID,
3307  size_t constantNumPackets,
3308  Distributor& distor,
3309  CombineMode combineMode,
3310  const bool atomic = useAtomicUpdatesByDefault);
3311  void
3312  unpackAndCombineImplNonStatic (
3313  const Teuchos::ArrayView<const LocalOrdinal>& importLIDs,
3314  const Teuchos::ArrayView<const char>& imports,
3315  const Teuchos::ArrayView<const size_t>& numPacketsPerLID,
3316  size_t constantNumPackets,
3317  Distributor& distor,
3318  CombineMode combineMode);
3319 
3320  public:
3330  void
3331  unpackAndCombine (const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
3332  const Teuchos::ArrayView<const char> &imports,
3333  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
3334  size_t constantNumPackets,
3335  Distributor& distor,
3336  CombineMode combineMode);
3338 
3340 
3458  virtual void
3459  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
3460  Teuchos::Array<char>& exports,
3461  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
3462  size_t& constantNumPackets,
3463  Distributor& distor) const;
3464  void
3465  packNonStatic (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
3466  Teuchos::Array<char>& exports,
3467  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
3468  size_t& constantNumPackets,
3469  Distributor& distor) const;
3470 
3471  private:
3489  bool
3490  packRow (char* const numEntOut,
3491  char* const valOut,
3492  char* const indOut,
3493  const size_t numEnt,
3494  const LocalOrdinal lclRow) const;
3495 
3519  bool
3520  packRowStatic (char* const numEntOut,
3521  char* const valOut,
3522  char* const indOut,
3523  const size_t numEnt,
3524  const LocalOrdinal lclRow) const;
3525 
3548  bool
3549  unpackRow (impl_scalar_type* const valInTmp,
3550  GlobalOrdinal* const indInTmp,
3551  const size_t tmpNumEnt,
3552  const char* const valIn,
3553  const char* const indIn,
3554  const size_t numEnt,
3555  const LocalOrdinal lclRow,
3556  const Tpetra::CombineMode combineMode);
3557 
3563  void
3564  allocatePackSpace (Teuchos::Array<char>& exports,
3565  size_t& totalNumEntries,
3566  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs) const;
3568 
3569  public:
3571  typename local_matrix_type::values_type getLocalValuesView () const {
3572  return k_values1D_;
3573  }
3574 
3575  private:
3576  // Friend declaration for nonmember function.
3577  template<class CrsMatrixType>
3578  friend Teuchos::RCP<CrsMatrixType>
3579  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3580  const Import<typename CrsMatrixType::local_ordinal_type,
3581  typename CrsMatrixType::global_ordinal_type,
3582  typename CrsMatrixType::node_type>& importer,
3583  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3584  typename CrsMatrixType::global_ordinal_type,
3585  typename CrsMatrixType::node_type> >& domainMap,
3586  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3587  typename CrsMatrixType::global_ordinal_type,
3588  typename CrsMatrixType::node_type> >& rangeMap,
3589  const Teuchos::RCP<Teuchos::ParameterList>& params);
3590 
3591  // Friend declaration for nonmember function.
3592  template<class CrsMatrixType>
3593  friend Teuchos::RCP<CrsMatrixType>
3594  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3595  const Import<typename CrsMatrixType::local_ordinal_type,
3596  typename CrsMatrixType::global_ordinal_type,
3597  typename CrsMatrixType::node_type>& rowImporter,
3598  const Import<typename CrsMatrixType::local_ordinal_type,
3599  typename CrsMatrixType::global_ordinal_type,
3600  typename CrsMatrixType::node_type>& domainImporter,
3601  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3602  typename CrsMatrixType::global_ordinal_type,
3603  typename CrsMatrixType::node_type> >& domainMap,
3604  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3605  typename CrsMatrixType::global_ordinal_type,
3606  typename CrsMatrixType::node_type> >& rangeMap,
3607  const Teuchos::RCP<Teuchos::ParameterList>& params);
3608 
3609 
3610  // Friend declaration for nonmember function.
3611  template<class CrsMatrixType>
3612  friend Teuchos::RCP<CrsMatrixType>
3613  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3614  const Export<typename CrsMatrixType::local_ordinal_type,
3615  typename CrsMatrixType::global_ordinal_type,
3616  typename CrsMatrixType::node_type>& exporter,
3617  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3618  typename CrsMatrixType::global_ordinal_type,
3619  typename CrsMatrixType::node_type> >& domainMap,
3620  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3621  typename CrsMatrixType::global_ordinal_type,
3622  typename CrsMatrixType::node_type> >& rangeMap,
3623  const Teuchos::RCP<Teuchos::ParameterList>& params);
3624 
3625  // Friend declaration for nonmember function.
3626  template<class CrsMatrixType>
3627  friend Teuchos::RCP<CrsMatrixType>
3628  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3629  const Export<typename CrsMatrixType::local_ordinal_type,
3630  typename CrsMatrixType::global_ordinal_type,
3631  typename CrsMatrixType::node_type>& rowExporter,
3632  const Export<typename CrsMatrixType::local_ordinal_type,
3633  typename CrsMatrixType::global_ordinal_type,
3634  typename CrsMatrixType::node_type>& domainExporter,
3635  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3636  typename CrsMatrixType::global_ordinal_type,
3637  typename CrsMatrixType::node_type> >& domainMap,
3638  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3639  typename CrsMatrixType::global_ordinal_type,
3640  typename CrsMatrixType::node_type> >& rangeMap,
3641  const Teuchos::RCP<Teuchos::ParameterList>& params);
3642 
3643  public:
3659  void
3661  const import_type& importer,
3662  const Teuchos::RCP<const map_type>& domainMap,
3663  const Teuchos::RCP<const map_type>& rangeMap,
3664  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3665 
3681  void
3683  const import_type& rowImporter,
3684  const import_type& domainImporter,
3685  const Teuchos::RCP<const map_type>& domainMap,
3686  const Teuchos::RCP<const map_type>& rangeMap,
3687  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3688 
3689 
3705  void
3707  const export_type& exporter,
3708  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3709  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3710  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3711 
3727  void
3729  const export_type& rowExporter,
3730  const export_type& domainExporter,
3731  const Teuchos::RCP<const map_type>& domainMap,
3732  const Teuchos::RCP<const map_type>& rangeMap,
3733  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3734 
3735 
3736  private:
3757  void
3758  transferAndFillComplete (Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >& destMatrix,
3759  const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3760  const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > & domainTransfer,
3761  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3762  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3763  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3764  // We forbid copy construction by declaring this method private
3765  // and not implementing it.
3767 
3768  // We forbid assignment (operator=) by declaring this method
3769  // private and not implementing it.
3772 
3782  void
3783  insertGlobalValuesFiltered (const GlobalOrdinal globalRow,
3784  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3785  const Teuchos::ArrayView<const Scalar>& values);
3786 
3796  void
3797  insertLocalValuesFiltered (const LocalOrdinal localRow,
3798  const Teuchos::ArrayView<const LocalOrdinal>& indices,
3799  const Teuchos::ArrayView<const Scalar>& values);
3800 
3812  void
3813  combineGlobalValues (const GlobalOrdinal globalRowIndex,
3814  const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3815  const Teuchos::ArrayView<const Scalar>& values,
3816  const Tpetra::CombineMode combineMode);
3817 
3835  LocalOrdinal
3836  combineGlobalValuesRaw (const LocalOrdinal lclRow,
3837  const LocalOrdinal numEnt,
3838  const impl_scalar_type vals[],
3839  const GlobalOrdinal cols[],
3840  const Tpetra::CombineMode combineMode);
3841 
3853  template<class BinaryFunction>
3854  LocalOrdinal
3855  transformGlobalValues (const GlobalOrdinal globalRow,
3856  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3857  const Teuchos::ArrayView<const Scalar>& values,
3858  BinaryFunction f,
3859  const bool atomic = useAtomicUpdatesByDefault) const
3860  {
3861  using Kokkos::MemoryUnmanaged;
3862  using Kokkos::View;
3863  typedef impl_scalar_type ST;
3864  typedef BinaryFunction BF;
3865  typedef GlobalOrdinal GO;
3866  typedef device_type DD;
3867  typedef typename View<GO*, DD>::HostMirror::device_type HD;
3868 
3869  // The 'indices' and 'values' arrays come from the user, so we
3870  // assume that they are host data, not device data.
3871  const ST* const rawInputVals =
3872  reinterpret_cast<const ST*> (values.getRawPtr ());
3873  View<const ST*, HD, MemoryUnmanaged> inputValsK (rawInputVals,
3874  values.size ());
3875  View<const GO*, HD, MemoryUnmanaged> inputIndsK (indices.getRawPtr (),
3876  indices.size ());
3877  return this->template transformGlobalValues<BF, HD> (globalRow,
3878  inputIndsK,
3879  inputValsK,
3880  f, atomic);
3881  }
3882 
3883  private:
3890  void
3891  insertNonownedGlobalValues (const GlobalOrdinal globalRow,
3892  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3893  const Teuchos::ArrayView<const Scalar>& values);
3894 
3897 
3898  protected:
3899  // useful typedefs
3900  typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
3901  typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
3902  typedef Kokkos::Details::ArithTraits<mag_type> STM;
3905  typedef crs_graph_type Graph;
3906 
3907  // Enums
3908  enum GraphAllocationStatus {
3909  GraphAlreadyAllocated,
3910  GraphNotYetAllocated
3911  };
3912 
3929  void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas);
3930 
3940  size_t
3941  mergeRowIndicesAndValues (crs_graph_type& graph,
3942  const RowInfo& rowInfo);
3943 
3958  void
3959  sortAndMergeIndicesAndValues (const bool sorted,
3960  const bool merged);
3961 
3969  void clearGlobalConstants();
3970 
3979  void computeGlobalConstants();
3980 
3981  public:
3983  bool haveGlobalConstants() const;
3984  protected:
3997  mutable Teuchos::RCP<MV> importMV_;
3998 
4011  mutable Teuchos::RCP<MV> exportMV_;
4012 
4032  Teuchos::RCP<MV>
4033  getColumnMapMultiVector (const MV& X_domainMap,
4034  const bool force = false) const;
4035 
4057  Teuchos::RCP<MV>
4058  getRowMapMultiVector (const MV& Y_rangeMap,
4059  const bool force = false) const;
4060 
4062  void
4063  applyNonTranspose (const MV& X_in,
4064  MV& Y_in,
4065  Scalar alpha,
4066  Scalar beta) const;
4067 
4069  void
4070  applyTranspose (const MV& X_in,
4071  MV& Y_in,
4072  const Teuchos::ETransp mode,
4073  Scalar alpha,
4074  Scalar beta) const;
4075 
4076  // matrix data accessors
4077 
4096  LocalOrdinal
4097  getViewRawConst (const impl_scalar_type*& vals,
4098  LocalOrdinal& numEnt,
4099  const RowInfo& rowinfo) const;
4100 
4119  LocalOrdinal
4120  getViewRaw (impl_scalar_type*& vals,
4121  LocalOrdinal& numEnt,
4122  const RowInfo& rowinfo) const;
4123 
4131  Teuchos::ArrayView<const impl_scalar_type> getView (RowInfo rowinfo) const;
4132 
4144  Teuchos::ArrayView<impl_scalar_type> getViewNonConst (const RowInfo& rowinfo) const;
4145 
4146  private:
4154  Kokkos::View<const impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
4155  getRowView (const RowInfo& rowInfo) const;
4156 
4168  Kokkos::View<impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
4169  getRowViewNonConst (const RowInfo& rowInfo) const;
4170 
4171  protected:
4172 
4178  void fillLocalMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4179 
4185  void fillLocalGraphAndMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4186 
4188  void checkInternalState () const;
4189 
4201 
4202  Teuchos::RCP<const Graph> staticGraph_;
4203  Teuchos::RCP< Graph> myGraph_;
4205 
4207  local_matrix_type lclMatrix_;
4208 
4221 
4222  typename local_matrix_type::values_type k_values1D_;
4223  Teuchos::ArrayRCP<Teuchos::Array<impl_scalar_type> > values2D_;
4225 
4236 
4239 
4267  std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
4268  Teuchos::Array<Scalar> > > nonlocals_;
4269 
4275  mutable mag_type frobNorm_;
4276 
4277  public:
4278  // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
4279  // public inner class of CrsMatrix? It looks like it doesn't
4280  // depend on any implementation details of CrsMatrix at all. It
4281  // should really be declared and defined outside of CrsMatrix.
4282  template<class ViewType, class OffsetViewType>
4283  struct pack_functor {
4284  typedef typename ViewType::execution_space execution_space;
4285  ViewType src_;
4286  ViewType dst_;
4287  OffsetViewType src_offset_;
4288  OffsetViewType dst_offset_;
4289  typedef typename OffsetViewType::non_const_value_type scalar_index_type;
4290 
4291  pack_functor (ViewType dst, ViewType src,
4292  OffsetViewType dst_offset, OffsetViewType src_offset) :
4293  src_ (src),
4294  dst_ (dst),
4295  src_offset_ (src_offset),
4296  dst_offset_ (dst_offset)
4297  {}
4298 
4299  KOKKOS_INLINE_FUNCTION
4300  void operator () (const LocalOrdinal row) const {
4301  scalar_index_type srcPos = src_offset_(row);
4302  const scalar_index_type dstEnd = dst_offset_(row+1);
4303  scalar_index_type dstPos = dst_offset_(row);
4304  for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
4305  dst_(dstPos) = src_(srcPos);
4306  }
4307  }
4308  };
4309  }; // class CrsMatrix
4310 
4311 
4320  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic = Node::classic>
4321  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
4323  size_t maxNumEntriesPerRow = 0,
4324  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4325  {
4327  return Teuchos::rcp (new matrix_type (map, maxNumEntriesPerRow,
4328  DynamicProfile, params));
4329  }
4330 
4382  template<class CrsMatrixType>
4383  Teuchos::RCP<CrsMatrixType>
4384  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4385  const Import<typename CrsMatrixType::local_ordinal_type,
4386  typename CrsMatrixType::global_ordinal_type,
4387  typename CrsMatrixType::node_type>& importer,
4388  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4389  typename CrsMatrixType::global_ordinal_type,
4390  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
4391  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4392  typename CrsMatrixType::global_ordinal_type,
4393  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
4394  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4395  {
4396  Teuchos::RCP<CrsMatrixType> destMatrix;
4397  sourceMatrix->importAndFillComplete (destMatrix,importer,domainMap, rangeMap, params);
4398  return destMatrix;
4399  }
4400 
4454  template<class CrsMatrixType>
4455  Teuchos::RCP<CrsMatrixType>
4456  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4457  const Import<typename CrsMatrixType::local_ordinal_type,
4458  typename CrsMatrixType::global_ordinal_type,
4459  typename CrsMatrixType::node_type>& rowImporter,
4460  const Import<typename CrsMatrixType::local_ordinal_type,
4461  typename CrsMatrixType::global_ordinal_type,
4462  typename CrsMatrixType::node_type>& domainImporter,
4463  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4464  typename CrsMatrixType::global_ordinal_type,
4465  typename CrsMatrixType::node_type> >& domainMap,
4466  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4467  typename CrsMatrixType::global_ordinal_type,
4468  typename CrsMatrixType::node_type> >& rangeMap,
4469  const Teuchos::RCP<Teuchos::ParameterList>& params)
4470  {
4471  Teuchos::RCP<CrsMatrixType> destMatrix;
4472  sourceMatrix->importAndFillComplete (destMatrix,rowImporter,domainImporter, domainMap, rangeMap, params);
4473  return destMatrix;
4474  }
4475 
4509  template<class CrsMatrixType>
4510  Teuchos::RCP<CrsMatrixType>
4511  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4512  const Export<typename CrsMatrixType::local_ordinal_type,
4513  typename CrsMatrixType::global_ordinal_type,
4514  typename CrsMatrixType::node_type>& exporter,
4515  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4516  typename CrsMatrixType::global_ordinal_type,
4517  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
4518  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4519  typename CrsMatrixType::global_ordinal_type,
4520  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
4521  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4522  {
4523  Teuchos::RCP<CrsMatrixType> destMatrix;
4524  sourceMatrix->exportAndFillComplete (destMatrix,exporter,domainMap, rangeMap, params);
4525  return destMatrix;
4526  }
4527 
4561  template<class CrsMatrixType>
4562  Teuchos::RCP<CrsMatrixType>
4563  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4564  const Export<typename CrsMatrixType::local_ordinal_type,
4565  typename CrsMatrixType::global_ordinal_type,
4566  typename CrsMatrixType::node_type>& rowExporter,
4567  const Export<typename CrsMatrixType::local_ordinal_type,
4568  typename CrsMatrixType::global_ordinal_type,
4569  typename CrsMatrixType::node_type>& domainExporter,
4570  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4571  typename CrsMatrixType::global_ordinal_type,
4572  typename CrsMatrixType::node_type> >& domainMap,
4573  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4574  typename CrsMatrixType::global_ordinal_type,
4575  typename CrsMatrixType::node_type> >& rangeMap,
4576  const Teuchos::RCP<Teuchos::ParameterList>& params)
4577  {
4578  Teuchos::RCP<CrsMatrixType> destMatrix;
4579  sourceMatrix->exportAndFillComplete (destMatrix,rowExporter,domainExporter,domainMap, rangeMap, params);
4580  return destMatrix;
4581  }
4582 } // namespace Tpetra
4583 
4591 #endif // TPETRA_CRSMATRIX_DECL_HPP
ProfileType getProfileType() const
Returns true if the matrix was allocated with static data structures.
LocalOrdinal replaceGlobalValues(const GlobalOrdinal globalRow, const typename UnmanagedView< GlobalIndicesViewType >::type &inputInds, const typename UnmanagedView< ImplScalarViewType >::type &inputVals) const
Replace one or more entries&#39; values, using global indices.
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...
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.
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.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
std::string description() const
A one-line description of this object.
mag_type getFrobeniusNorm() const
Compute and return the Frobenius norm of the matrix.
LocalOrdinal local_ordinal_type
This class&#39; second template parameter; the type of local indices.
size_t getNodeNumEntries() const
The local number of entries in this matrix.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
LocalOrdinal 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.
LocalOrdinal 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.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
This matrix&#39;s graph, as a RowGraph.
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
bool isFillActive() const
Whether the matrix is not fill complete.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
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 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.
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Resume operations that may change the values or structure of the matrix.
Teuchos::ArrayView< const impl_scalar_type > getView(RowInfo rowinfo) const
Constant view of all entries (including extra space) in the given row.
global_size_t getGlobalNumEntries() const
The global number of entries in this matrix.
local_matrix_type getLocalMatrix() const
The local sparse matrix.
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.
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.
Teuchos::ArrayView< impl_scalar_type > getViewNonConst(const RowInfo &rowinfo) const
Nonconst view of all entries (including extra space) in the given row.
size_t getNodeNumCols() const
The number of columns connected to the locally owned rows of this matrix.
Teuchos::RCP< const map_type > getRowMap() const
The Map that describes the row distribution in this matrix.
bool hasColMap() const
Indicates whether the matrix has a well-defined column map.
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 .
One or more distributed dense vectors.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
Teuchos::RCP< node_type > getNode() const
The Kokkos Node instance.
GlobalOrdinal global_ordinal_type
This class&#39; third template parameter; the type of global indices.
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.
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.
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
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.
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=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Compute a sparse matrix-MultiVector multiply.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &rowImporter, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &domainImporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the matrix&#39;s column Map with the given Map.
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...
virtual bool checkSizes(const SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
Node node_type
This class&#39; fourth template parameter; the Kokkos device type.
bool fillComplete_
Whether the matrix is fill complete.
bool isLowerTriangular() const
Indicates whether the matrix is lower triangular.
Node::device_type device_type
The Kokkos device type.
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.
virtual bool supportsRowViews() const
Return true if getLocalRowView() and getGlobalRowView() are valid for this object.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > &diag) const
Get a copy of the diagonal entries of the matrix.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap)
Remove processes owning zero rows from the Maps and their communicator.
device_type::execution_space execution_space
The Kokkos execution space.
mag_type frobNorm_
Cached Frobenius norm of the (global) matrix.
void insertGlobalValues(const GlobalOrdinal globalRow, const Teuchos::ArrayView< const GlobalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using global column indices.
void 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 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.
global_size_t getGlobalNumCols() const
The number of global columns in the matrix.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
void applyTranspose(const MV &X_in, MV &Y_in, const Teuchos::ETransp mode, Scalar alpha, Scalar beta) const
Special case of apply() for mode != Teuchos::NO_TRANS.
size_t getLocalLength() const
Local number of rows on the calling process.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
local_matrix_type::values_type t_ValuesType TPETRA_DEPRECATED
DEPRECATED; use local_matrix_type::values_type instead.
bool isFillComplete() const
Whether the matrix is fill complete.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
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.
local_matrix_type::values_type getLocalValuesView() const
Get the Kokkos local values.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
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.
void scale(const Scalar &alpha)
Scale the matrix&#39;s values: this := alpha*this.
LocalOrdinal 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...
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node2, Node2::classic > > clone(const Teuchos::RCP< Node2 > &node2, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Create a deep copy of this CrsMatrix, where the copy may have a different Node type.
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.
Sets up and executes a communication plan for a Tpetra DistObject.
bool isStorageOptimized() const
Returns true if storage has been optimized.
CombineMode
Rule for combining data in an Import or Export.
void setAllValues(const typename local_matrix_type::row_map_type &ptr, const typename local_graph_type::entries_type::non_const_type &ind, const typename local_matrix_type::values_type &val)
Set the local matrix using three (compressed sparse row) arrays.
LocalOrdinal getLocalRowViewRaw(const LocalOrdinal lclRow, LocalOrdinal &numEnt, const LocalOrdinal *&lclColInds, const Scalar *&vals) const
Get a constant, nonpersisting, locally indexed view of the given row of the matrix, using "raw" pointers instead of Teuchos::ArrayView.
bool isUpperTriangular() const
Indicates whether the matrix is upper triangular.
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
KokkosSparse::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...
virtual ~CrsMatrix()
Destructor.
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...
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.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
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.
LocalOrdinal getViewRaw(impl_scalar_type *&vals, LocalOrdinal &numEnt, const RowInfo &rowinfo) const
Nonconst pointer to all entries (including extra space) in the given row.
void fillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Tell the matrix that you are done changing its structure or values, and that you are ready to do comp...
void computeGlobalConstants()
Compute matrix properties that require collectives.
bool hasTransposeApply() const
Whether apply() allows applying the transpose or conjugate transpose.
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 .
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 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...
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...
Kokkos::Details::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
size_t getNodeNumRows() const
The number of matrix rows owned by the calling process.
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().
void checkInternalState() const
Check that this object&#39;s state is sane; throw if it&#39;s not.
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.
local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D TPETRA_DEPRECATED
DEPRECATED; use local_graph_type::entries_type::non_const_type instead.
A parallel distribution of indices over processes.
void applyNonTranspose(const MV &X_in, MV &Y_in, Scalar alpha, Scalar beta) const
Special case of apply() for mode == Teuchos::NO_TRANS.
size_t getNumVectors() const
Number of columns in the multivector.
A read-only, row-oriented interface to a sparse matrix.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
std::map< GlobalOrdinal, std::pair< Teuchos::Array< GlobalOrdinal >, Teuchos::Array< Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
size_t mergeRowIndicesAndValues(crs_graph_type &graph, const RowInfo &rowInfo)
Merge duplicate row indices in the given row, along with their corresponding values.
A distributed dense vector.
bool isGloballyIndexed() const
Whether the matrix is globally indexed on the calling process.
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &rowExporter, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &domainExporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
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< 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 insertLocalValues(const LocalOrdinal localRow, const Teuchos::ArrayView< const LocalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using local column indices.
Teuchos::RCP< const map_type > getColMap() const
The Map that describes the column distribution in this matrix.
Teuchos::RCP< const map_type > getDomainMap() const
The domain Map of this matrix.
void sortAndMergeIndicesAndValues(const bool sorted, const bool merged)
Sort and merge duplicate local column indices in all rows on the calling process, along with their co...
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.
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.
Teuchos::RCP< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
Map< LocalOrdinal, GlobalOrdinal, Node > map_type
The Map specialization suitable for this CrsMatrix specialization.
Teuchos::RCP< const map_type > getRangeMap() const
The range Map of this matrix.
Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization suitable for this CrsMatrix specialization.
void expertStaticFillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< const import_type > &importer=Teuchos::null, const Teuchos::RCP< const export_type > &exporter=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Perform a fillComplete on a matrix that already has data.
Base class for distributed Tpetra objects that support data redistribution.
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.
std::enable_if<! std::is_same< OutputScalarType, impl_scalar_type >::value &&std::is_convertible< impl_scalar_type, OutputScalarType >::value, LocalOrdinal >::type getLocalRowView(const LocalOrdinal lclRow, LocalOrdinal &numEnt, const OutputScalarType *&val, const LocalOrdinal *&ind) const
Get a constant, nonpersisting view of a row of this matrix, using local row and column indices...
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix&#39;s graph, as a CrsGraph.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
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 .
void clearGlobalConstants()
Clear matrix properties that require collectives.
EStorageStatus
Status of the graph&#39;s or matrix&#39;s storage, when not in a fill-complete state.
LocalOrdinal getViewRawConst(const impl_scalar_type *&vals, LocalOrdinal &numEnt, const RowInfo &rowinfo) const
Const pointer to all entries (including extra space) in the given row.
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.
bool isLocallyIndexed() const
Whether the matrix is locally indexed on the calling process.
local_matrix_type lclMatrix_
The local sparse matrix.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local graph and matrix.
GlobalOrdinal getIndexBase() const
The index base for global indices for this matrix.