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 Kokkos::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 
1966 
1987 
1994 
2001  size_t getNodeNumRows() const;
2002 
2006  size_t getNodeNumCols() const;
2007 
2009  GlobalOrdinal getIndexBase() const;
2010 
2013 
2015  size_t getNodeNumEntries() const;
2016 
2018 
2019  size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const;
2020 
2022 
2023  size_t getNumEntriesInLocalRow (LocalOrdinal localRow) const;
2024 
2026 
2029 
2031 
2033  size_t getNodeNumDiags() const;
2034 
2036 
2038  size_t getGlobalMaxNumRowEntries() const;
2039 
2041 
2043  size_t getNodeMaxNumRowEntries() const;
2044 
2046  bool hasColMap() const;
2047 
2049 
2051  bool isLowerTriangular() const;
2052 
2054 
2056  bool isUpperTriangular() const;
2057 
2077  bool isLocallyIndexed() const;
2078 
2098  bool isGloballyIndexed() const;
2099 
2122  bool isFillComplete() const;
2123 
2146  bool isFillActive() const;
2147 
2149 
2155  bool isStorageOptimized () const;
2156 
2158  ProfileType getProfileType () const;
2159 
2161  bool isStaticGraph () const;
2162 
2174  mag_type getFrobeniusNorm () const;
2175 
2178  virtual bool supportsRowViews () const;
2179 
2228  void
2229  getGlobalRowCopy (GlobalOrdinal GlobalRow,
2230  const Teuchos::ArrayView<GlobalOrdinal>& Indices,
2231  const Teuchos::ArrayView<Scalar>& Values,
2232  size_t& NumEntries) const;
2233 
2251  void
2252  getLocalRowCopy (LocalOrdinal localRow,
2253  const Teuchos::ArrayView<LocalOrdinal>& colInds,
2254  const Teuchos::ArrayView<Scalar>& vals,
2255  size_t& numEntries) const;
2256 
2270  void
2271  getGlobalRowView (GlobalOrdinal GlobalRow,
2272  Teuchos::ArrayView<const GlobalOrdinal>& indices,
2273  Teuchos::ArrayView<const Scalar>& values) const;
2274 
2288  void
2289  getLocalRowView (LocalOrdinal LocalRow,
2290  Teuchos::ArrayView<const LocalOrdinal>& indices,
2291  Teuchos::ArrayView<const Scalar>& values) const;
2292 
2319  LocalOrdinal
2320  getLocalRowViewRaw (const LocalOrdinal lclRow,
2321  LocalOrdinal& numEnt,
2322  const LocalOrdinal*& lclColInds,
2323  const Scalar*& vals) const;
2324 
2350  LocalOrdinal
2351  getLocalRowView (const LocalOrdinal lclRow,
2352  LocalOrdinal& numEnt,
2353  const impl_scalar_type*& val,
2354  const LocalOrdinal*& ind) const;
2355 
2363  template<class OutputScalarType>
2364  typename std::enable_if<! std::is_same<OutputScalarType, impl_scalar_type>::value &&
2365  std::is_convertible<impl_scalar_type, OutputScalarType>::value,
2366  LocalOrdinal>::type
2367  getLocalRowView (const LocalOrdinal lclRow,
2368  LocalOrdinal& numEnt,
2369  const OutputScalarType*& val,
2370  const LocalOrdinal*& ind) const
2371  {
2372  const impl_scalar_type* valTmp = NULL;
2373  const LocalOrdinal err = this->getLocalRowView (lclRow, numEnt, valTmp, ind);
2374  // Cast is legitimate because impl_scalar_type is convertible to
2375  // OutputScalarType.
2376  val = reinterpret_cast<const OutputScalarType*> (valTmp);
2377  return err;
2378  }
2379 
2385  void
2387 
2431  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
2432 
2454  void
2456  const Kokkos::View<const size_t*, device_type,
2457  Kokkos::MemoryUnmanaged>& offsets) const;
2458 
2481  void
2483  const Teuchos::ArrayView<const size_t>& offsets) const;
2484 
2486  void
2488 
2490  void
2492 
2494 
2496 
2545  template <class DomainScalar, class RangeScalar>
2546  void
2549  Teuchos::ETransp mode,
2550  RangeScalar alpha,
2551  RangeScalar beta) const
2552  {
2553  using Teuchos::NO_TRANS;
2554  // Just like Scalar and impl_scalar_type may differ in CrsMatrix,
2555  // RangeScalar and its corresponding impl_scalar_type may differ in
2556  // MultiVector.
2557  typedef typename MultiVector<RangeScalar, LocalOrdinal, GlobalOrdinal,
2558  Node, classic>::impl_scalar_type range_impl_scalar_type;
2559 #ifdef HAVE_TPETRA_DEBUG
2560  const char tfecfFuncName[] = "localMultiply: ";
2561 #endif // HAVE_TPETRA_DEBUG
2562 
2563  const range_impl_scalar_type theAlpha = static_cast<range_impl_scalar_type> (alpha);
2564  const range_impl_scalar_type theBeta = static_cast<range_impl_scalar_type> (beta);
2565  const bool conjugate = (mode == Teuchos::CONJ_TRANS);
2566  const bool transpose = (mode != Teuchos::NO_TRANS);
2567  auto X_lcl = X.template getLocalView<device_type> ();
2568  auto Y_lcl = Y.template getLocalView<device_type> ();
2569 
2570 #ifdef HAVE_TPETRA_DEBUG
2571  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2572  (X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
2573  "X.getNumVectors() = " << X.getNumVectors () << " != Y.getNumVectors() = "
2574  << Y.getNumVectors () << ".");
2575  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2576  (! transpose && X.getLocalLength () != getColMap ()->getNodeNumElements (),
2577  std::runtime_error, "NO_TRANS case: X has the wrong number of local rows. "
2578  "X.getLocalLength() = " << X.getLocalLength () << " != getColMap()->"
2579  "getNodeNumElements() = " << getColMap ()->getNodeNumElements () << ".");
2580  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2581  (! transpose && Y.getLocalLength () != getRowMap ()->getNodeNumElements (),
2582  std::runtime_error, "NO_TRANS case: Y has the wrong number of local rows. "
2583  "Y.getLocalLength() = " << Y.getLocalLength () << " != getRowMap()->"
2584  "getNodeNumElements() = " << getRowMap ()->getNodeNumElements () << ".");
2585  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2586  (transpose && X.getLocalLength () != getRowMap ()->getNodeNumElements (),
2587  std::runtime_error, "TRANS or CONJ_TRANS case: X has the wrong number of "
2588  "local rows. X.getLocalLength() = " << X.getLocalLength () << " != "
2589  "getRowMap()->getNodeNumElements() = "
2590  << getRowMap ()->getNodeNumElements () << ".");
2591  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2592  (transpose && Y.getLocalLength () != getColMap ()->getNodeNumElements (),
2593  std::runtime_error, "TRANS or CONJ_TRANS case: X has the wrong number of "
2594  "local rows. Y.getLocalLength() = " << Y.getLocalLength () << " != "
2595  "getColMap()->getNodeNumElements() = "
2596  << getColMap ()->getNodeNumElements () << ".");
2597  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2598  (! isFillComplete (), std::runtime_error, "The matrix is not fill "
2599  "complete. You must call fillComplete() (possibly with domain and range "
2600  "Map arguments) without an intervening resumeFill() call before you may "
2601  "call this method.");
2602  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2603  (! X.isConstantStride () || ! Y.isConstantStride (), std::runtime_error,
2604  "X and Y must be constant stride.");
2605  // If the two pointers are NULL, then they don't alias one
2606  // another, even though they are equal.
2607  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2608  X_lcl.ptr_on_device () == Y_lcl.ptr_on_device () &&
2609  X_lcl.ptr_on_device () != NULL,
2610  std::runtime_error, "X and Y may not alias one another.");
2611 #endif // HAVE_TPETRA_DEBUG
2612 
2613  // Y = alpha*op(M) + beta*Y
2614  if (transpose) {
2615  KokkosSparse::spmv (conjugate ? KokkosSparse::ConjugateTranspose : KokkosSparse::Transpose,
2616  theAlpha,
2617  lclMatrix_,
2618  X.template getLocalView<device_type> (),
2619  theBeta,
2620  Y.template getLocalView<device_type> ());
2621  }
2622  else {
2623  KokkosSparse::spmv (KokkosSparse::NoTranspose,
2624  theAlpha,
2625  lclMatrix_,
2626  X.template getLocalView<device_type> (),
2627  theBeta,
2628  Y.template getLocalView<device_type> ());
2629  }
2630  }
2631 
2656  template <class DomainScalar, class RangeScalar>
2657  void
2661  const RangeScalar& dampingFactor,
2662  const KokkosClassic::ESweepDirection direction) const
2663  {
2664  typedef LocalOrdinal LO;
2665  typedef GlobalOrdinal GO;
2669  typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2670  typedef typename Graph::local_graph_type k_local_graph_type;
2671  typedef typename k_local_graph_type::size_type offset_type;
2672  const char prefix[] = "Tpetra::CrsMatrix::localGaussSeidel: ";
2673 
2674  TEUCHOS_TEST_FOR_EXCEPTION
2675  (! this->isFillComplete (), std::runtime_error,
2676  prefix << "The matrix is not fill complete.");
2677  const size_t lclNumRows = this->getNodeNumRows ();
2678  const size_t numVecs = B.getNumVectors ();
2679  TEUCHOS_TEST_FOR_EXCEPTION
2680  (X.getNumVectors () != numVecs, std::invalid_argument,
2681  prefix << "B.getNumVectors() = " << numVecs << " != "
2682  "X.getNumVectors() = " << X.getNumVectors () << ".");
2683  TEUCHOS_TEST_FOR_EXCEPTION
2684  (B.getLocalLength () != lclNumRows, std::invalid_argument,
2685  prefix << "B.getLocalLength() = " << B.getLocalLength ()
2686  << " != this->getNodeNumRows() = " << lclNumRows << ".");
2687 
2688  typename DMV::dual_view_type::t_host B_lcl = B.template getLocalView<HMDT> ();
2689  typename RMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
2690  typename MMV::dual_view_type::t_host D_lcl = D.template getLocalView<HMDT> ();
2691 
2692  offset_type B_stride[8], X_stride[8], D_stride[8];
2693  B_lcl.stride (B_stride);
2694  X_lcl.stride (X_stride);
2695  D_lcl.stride (D_stride);
2696 
2697  local_matrix_type lclMatrix = this->getLocalMatrix ();
2698  k_local_graph_type lclGraph = lclMatrix.graph;
2699  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
2700  typename local_matrix_type::index_type ind = lclGraph.entries;
2701  typename local_matrix_type::values_type val = lclMatrix.values;
2702  const offset_type* const ptrRaw = ptr.ptr_on_device ();
2703  const LO* const indRaw = ind.ptr_on_device ();
2704  const impl_scalar_type* const valRaw = val.ptr_on_device ();
2705 
2706  const std::string dir ((direction == KokkosClassic::Forward) ? "F" : "B");
2707  KokkosSparse::Impl::Sequential::gaussSeidel (static_cast<LO> (lclNumRows),
2708  static_cast<LO> (numVecs),
2709  ptrRaw, indRaw, valRaw,
2710  B_lcl.ptr_on_device (), B_stride[1],
2711  X_lcl.ptr_on_device (), X_stride[1],
2712  D_lcl.ptr_on_device (),
2713  static_cast<impl_scalar_type> (dampingFactor),
2714  dir.c_str ());
2715  }
2716 
2743  template <class DomainScalar, class RangeScalar>
2744  void
2748  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
2749  const RangeScalar& dampingFactor,
2750  const KokkosClassic::ESweepDirection direction) const
2751  {
2752  typedef LocalOrdinal LO;
2753  typedef GlobalOrdinal GO;
2757  typedef typename DMV::dual_view_type::host_mirror_space HMDT ;
2758  typedef typename Graph::local_graph_type k_local_graph_type;
2759  typedef typename k_local_graph_type::size_type offset_type;
2760  const char prefix[] = "Tpetra::CrsMatrix::reorderedLocalGaussSeidel: ";
2761 
2762  TEUCHOS_TEST_FOR_EXCEPTION
2763  (! this->isFillComplete (), std::runtime_error,
2764  prefix << "The matrix is not fill complete.");
2765  const size_t lclNumRows = this->getNodeNumRows ();
2766  const size_t numVecs = B.getNumVectors ();
2767  TEUCHOS_TEST_FOR_EXCEPTION
2768  (X.getNumVectors () != numVecs, std::invalid_argument,
2769  prefix << "B.getNumVectors() = " << numVecs << " != "
2770  "X.getNumVectors() = " << X.getNumVectors () << ".");
2771  TEUCHOS_TEST_FOR_EXCEPTION
2772  (B.getLocalLength () != lclNumRows, std::invalid_argument,
2773  prefix << "B.getLocalLength() = " << B.getLocalLength ()
2774  << " != this->getNodeNumRows() = " << lclNumRows << ".");
2775  TEUCHOS_TEST_FOR_EXCEPTION
2776  (static_cast<size_t> (rowIndices.size ()) < lclNumRows,
2777  std::invalid_argument, prefix << "rowIndices.size() = "
2778  << rowIndices.size () << " < this->getNodeNumRows() = "
2779  << lclNumRows << ".");
2780 
2781  typename DMV::dual_view_type::t_host B_lcl = B.template getLocalView<HMDT> ();
2782  typename RMV::dual_view_type::t_host X_lcl = X.template getLocalView<HMDT> ();
2783  typename MMV::dual_view_type::t_host D_lcl = D.template getLocalView<HMDT> ();
2784 
2785  offset_type B_stride[8], X_stride[8], D_stride[8];
2786  B_lcl.stride (B_stride);
2787  X_lcl.stride (X_stride);
2788  D_lcl.stride (D_stride);
2789 
2790  local_matrix_type lclMatrix = this->getLocalMatrix ();
2791  typename Graph::local_graph_type lclGraph = lclMatrix.graph;
2792  typename local_matrix_type::index_type ind = lclGraph.entries;
2793  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
2794  typename local_matrix_type::values_type val = lclMatrix.values;
2795  const offset_type* const ptrRaw = ptr.ptr_on_device ();
2796  const LO* const indRaw = ind.ptr_on_device ();
2797  const impl_scalar_type* const valRaw = val.ptr_on_device ();
2798 
2799  const std::string dir = (direction == KokkosClassic::Forward) ? "F" : "B";
2800  KokkosSparse::Impl::Sequential::reorderedGaussSeidel (static_cast<LO> (lclNumRows),
2801  static_cast<LO> (numVecs),
2802  ptrRaw, indRaw, valRaw,
2803  B_lcl.ptr_on_device (),
2804  B_stride[1],
2805  X_lcl.ptr_on_device (),
2806  X_stride[1],
2807  D_lcl.ptr_on_device (),
2808  rowIndices.getRawPtr (),
2809  static_cast<LO> (lclNumRows),
2810  static_cast<impl_scalar_type> (dampingFactor),
2811  dir.c_str ());
2812  }
2813 
2832  template <class DomainScalar, class RangeScalar>
2833  void
2836  Teuchos::ETransp mode) const
2837  {
2838  using Teuchos::CONJ_TRANS;
2839  using Teuchos::NO_TRANS;
2840  using Teuchos::TRANS;
2841  const char tfecfFuncName[] = "localSolve: ";
2842 
2843  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2844  (! isFillComplete (), std::runtime_error,
2845  "The matrix is not fill complete.");
2846  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2847  (! X.isConstantStride () || ! Y.isConstantStride (), std::invalid_argument,
2848  "X and Y must be constant stride.");
2849 
2850  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2851  ( getNodeNumRows()>0 && ! isUpperTriangular () && ! isLowerTriangular (), std::runtime_error,
2852  "The matrix is neither upper triangular or lower triangular. "
2853  "You may only call this method if the matrix is triangular. "
2854  "Remember that this is a local (per MPI process) property, and that "
2855  "Tpetra only knows how to do a local (per process) triangular solve.");
2856 
2857  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2858  (STS::isComplex && mode == TRANS, std::logic_error, "This method does "
2859  "not currently support non-conjugated transposed solve (mode == "
2860  "Teuchos::TRANS) for complex scalar types.");
2861 
2862  // FIXME (mfh 19 May 2016) This makes some Ifpack2 tests fail.
2863  //
2864  // TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC
2865  // (Y.template need_sync<device_type> () && !
2866  // Y.template need_sync<Kokkos::HostSpace> (), std::runtime_error,
2867  // "Y must be sync'd to device memory before you may call this method.");
2868 
2869  // FIXME (mfh 27 Aug 2014) Tpetra has always made the odd decision
2870  // that if _some_ diagonal entries are missing locally, then it
2871  // assumes that the matrix has an implicitly stored unit diagonal.
2872  // Whether the matrix has an implicit unit diagonal or not should
2873  // be up to the user to decide. What if the graph has no diagonal
2874  // entries, and the user wants it that way? The only reason this
2875  // matters, though, is for the triangular solve, and in that case,
2876  // missing diagonal entries will cause trouble anyway. However,
2877  // it would make sense to warn the user if they ask for a
2878  // triangular solve with an incomplete diagonal. Furthermore,
2879  // this code should only assume an implicitly stored unit diagonal
2880  // if the matrix has _no_ explicitly stored diagonal entries.
2881 
2882  const std::string uplo = isUpperTriangular () ? "U" :
2883  (isLowerTriangular () ? "L" : "N");
2884  const std::string trans = (mode == Teuchos::CONJ_TRANS) ? "C" :
2885  (mode == Teuchos::TRANS ? "T" : "N");
2886  const std::string diag =
2887  (getNodeNumDiags () < getNodeNumRows ()) ? "U" : "N";
2888 
2889  local_matrix_type A_lcl = this->getLocalMatrix ();
2890  X.template modify<device_type> (); // we will write to X
2891 
2892  if (X.isConstantStride () && Y.isConstantStride ()) {
2893  auto X_lcl = X.template getLocalView<device_type> ();
2894  auto Y_lcl = Y.template getLocalView<device_type> ();
2895  KokkosSparse::trsv (uplo.c_str (), trans.c_str (), diag.c_str (),
2896  A_lcl, Y_lcl, X_lcl);
2897  }
2898  else {
2899  const size_t numVecs = std::min (X.getNumVectors (), Y.getNumVectors ());
2900  for (size_t j = 0; j < numVecs; ++j) {
2901  auto X_j = X.getVector (j);
2902  auto Y_j = X.getVector (j);
2903  auto X_lcl = X_j->template getLocalView<device_type> ();
2904  auto Y_lcl = Y_j->template getLocalView<device_type> ();
2905  KokkosSparse::trsv (uplo.c_str (), trans.c_str (),
2906  diag.c_str (), A_lcl, Y_lcl, X_lcl);
2907  }
2908  }
2909  }
2910 
2913  template <class T>
2914  Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node, classic> >
2915  convert () const;
2916 
2918 
2920 
2931  void
2934  Teuchos::ETransp mode = Teuchos::NO_TRANS,
2935  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
2936  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
2937 
2939  bool hasTransposeApply () const;
2940 
2947  Teuchos::RCP<const map_type> getDomainMap () const;
2948 
2955  Teuchos::RCP<const map_type> getRangeMap () const;
2956 
2958 
2960 
3025  void
3029  const Scalar& dampingFactor,
3030  const ESweepDirection direction,
3031  const int numSweeps) const;
3032 
3099  void
3103  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
3104  const Scalar& dampingFactor,
3105  const ESweepDirection direction,
3106  const int numSweeps) const;
3107 
3136  void
3140  const Scalar& dampingFactor,
3141  const ESweepDirection direction,
3142  const int numSweeps,
3143  const bool zeroInitialGuess) const;
3144 
3174  void
3178  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
3179  const Scalar& dampingFactor,
3180  const ESweepDirection direction,
3181  const int numSweeps,
3182  const bool zeroInitialGuess) const;
3183 
3194  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3195  add (const Scalar& alpha,
3197  const Scalar& beta,
3198  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
3199  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
3200  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3201 
3203 
3205 
3207  std::string description () const;
3208 
3210  void
3211  describe (Teuchos::FancyOStream &out,
3212  const Teuchos::EVerbosityLevel verbLevel =
3213  Teuchos::Describable::verbLevel_default) const;
3214 
3216 
3218 
3219  virtual bool
3220  checkSizes (const SrcDistObject& source);
3221 
3222  virtual void
3223  copyAndPermute (const SrcDistObject& source,
3224  size_t numSameIDs,
3225  const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs,
3226  const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs);
3227 
3228  virtual void
3229  packAndPrepare (const SrcDistObject& source,
3230  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
3231  Teuchos::Array<char>& exports,
3232  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
3233  size_t& constantNumPackets,
3234  Distributor& distor);
3235 
3236  private:
3239  void
3240  unpackAndCombineImpl (const Teuchos::ArrayView<const LocalOrdinal>& importLIDs,
3241  const Teuchos::ArrayView<const char>& imports,
3242  const Teuchos::ArrayView<const size_t>& numPacketsPerLID,
3243  size_t constantNumPackets,
3244  Distributor& distor,
3245  CombineMode combineMode);
3246 
3247  public:
3257  void
3258  unpackAndCombine (const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
3259  const Teuchos::ArrayView<const char> &imports,
3260  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
3261  size_t constantNumPackets,
3262  Distributor& distor,
3263  CombineMode combineMode);
3265 
3267 
3385  virtual void
3386  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
3387  Teuchos::Array<char>& exports,
3388  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
3389  size_t& constantNumPackets,
3390  Distributor& distor) const;
3391 
3392  private:
3410  bool
3411  packRow (char* const numEntOut,
3412  char* const valOut,
3413  char* const indOut,
3414  const size_t numEnt,
3415  const LocalOrdinal lclRow) const;
3416 
3439  bool
3440  unpackRow (Scalar* const valInTmp,
3441  GlobalOrdinal* const indInTmp,
3442  const size_t tmpNumEnt,
3443  const char* const valIn,
3444  const char* const indIn,
3445  const size_t numEnt,
3446  const LocalOrdinal lclRow,
3447  const Tpetra::CombineMode combineMode);
3448 
3454  void
3455  allocatePackSpace (Teuchos::Array<char>& exports,
3456  size_t& totalNumEntries,
3457  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs) const;
3459 
3460  public:
3462  typename local_matrix_type::values_type getLocalValuesView () const {
3463  return k_values1D_;
3464  }
3465 
3466  private:
3467  // Friend declaration for nonmember function.
3468  template<class CrsMatrixType>
3469  friend Teuchos::RCP<CrsMatrixType>
3470  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3471  const Import<typename CrsMatrixType::local_ordinal_type,
3472  typename CrsMatrixType::global_ordinal_type,
3473  typename CrsMatrixType::node_type>& importer,
3474  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3475  typename CrsMatrixType::global_ordinal_type,
3476  typename CrsMatrixType::node_type> >& domainMap,
3477  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3478  typename CrsMatrixType::global_ordinal_type,
3479  typename CrsMatrixType::node_type> >& rangeMap,
3480  const Teuchos::RCP<Teuchos::ParameterList>& params);
3481 
3482  // Friend declaration for nonmember function.
3483  template<class CrsMatrixType>
3484  friend Teuchos::RCP<CrsMatrixType>
3485  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3486  const Import<typename CrsMatrixType::local_ordinal_type,
3487  typename CrsMatrixType::global_ordinal_type,
3488  typename CrsMatrixType::node_type>& rowImporter,
3489  const Import<typename CrsMatrixType::local_ordinal_type,
3490  typename CrsMatrixType::global_ordinal_type,
3491  typename CrsMatrixType::node_type>& domainImporter,
3492  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3493  typename CrsMatrixType::global_ordinal_type,
3494  typename CrsMatrixType::node_type> >& domainMap,
3495  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3496  typename CrsMatrixType::global_ordinal_type,
3497  typename CrsMatrixType::node_type> >& rangeMap,
3498  const Teuchos::RCP<Teuchos::ParameterList>& params);
3499 
3500 
3501  // Friend declaration for nonmember function.
3502  template<class CrsMatrixType>
3503  friend Teuchos::RCP<CrsMatrixType>
3504  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3505  const Export<typename CrsMatrixType::local_ordinal_type,
3506  typename CrsMatrixType::global_ordinal_type,
3507  typename CrsMatrixType::node_type>& exporter,
3508  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3509  typename CrsMatrixType::global_ordinal_type,
3510  typename CrsMatrixType::node_type> >& domainMap,
3511  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3512  typename CrsMatrixType::global_ordinal_type,
3513  typename CrsMatrixType::node_type> >& rangeMap,
3514  const Teuchos::RCP<Teuchos::ParameterList>& params);
3515 
3516  // Friend declaration for nonmember function.
3517  template<class CrsMatrixType>
3518  friend Teuchos::RCP<CrsMatrixType>
3519  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
3520  const Export<typename CrsMatrixType::local_ordinal_type,
3521  typename CrsMatrixType::global_ordinal_type,
3522  typename CrsMatrixType::node_type>& rowExporter,
3523  const Export<typename CrsMatrixType::local_ordinal_type,
3524  typename CrsMatrixType::global_ordinal_type,
3525  typename CrsMatrixType::node_type>& domainExporter,
3526  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3527  typename CrsMatrixType::global_ordinal_type,
3528  typename CrsMatrixType::node_type> >& domainMap,
3529  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
3530  typename CrsMatrixType::global_ordinal_type,
3531  typename CrsMatrixType::node_type> >& rangeMap,
3532  const Teuchos::RCP<Teuchos::ParameterList>& params);
3533 
3534  public:
3550  void
3552  const import_type& importer,
3553  const Teuchos::RCP<const map_type>& domainMap,
3554  const Teuchos::RCP<const map_type>& rangeMap,
3555  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3556 
3572  void
3574  const import_type& rowImporter,
3575  const import_type& domainImporter,
3576  const Teuchos::RCP<const map_type>& domainMap,
3577  const Teuchos::RCP<const map_type>& rangeMap,
3578  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3579 
3580 
3596  void
3598  const export_type& exporter,
3599  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3600  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3601  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3602 
3618  void
3620  const export_type& rowExporter,
3621  const export_type& domainExporter,
3622  const Teuchos::RCP<const map_type>& domainMap,
3623  const Teuchos::RCP<const map_type>& rangeMap,
3624  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
3625 
3626 
3627  private:
3648  void
3649  transferAndFillComplete (Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >& destMatrix,
3650  const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
3651  const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > & domainTransfer,
3652  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
3653  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
3654  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
3655  // We forbid copy construction by declaring this method private
3656  // and not implementing it.
3658 
3659  // We forbid assignment (operator=) by declaring this method
3660  // private and not implementing it.
3663 
3673  void
3674  insertGlobalValuesFiltered (const GlobalOrdinal globalRow,
3675  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3676  const Teuchos::ArrayView<const Scalar>& values);
3677 
3687  void
3688  insertLocalValuesFiltered (const LocalOrdinal localRow,
3689  const Teuchos::ArrayView<const LocalOrdinal>& indices,
3690  const Teuchos::ArrayView<const Scalar>& values);
3691 
3703  void
3704  combineGlobalValues (const GlobalOrdinal globalRowIndex,
3705  const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
3706  const Teuchos::ArrayView<const Scalar>& values,
3707  const Tpetra::CombineMode combineMode);
3708 
3720  template<class BinaryFunction>
3721  LocalOrdinal
3722  transformGlobalValues (const GlobalOrdinal globalRow,
3723  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3724  const Teuchos::ArrayView<const Scalar>& values,
3725  BinaryFunction f,
3726  const bool atomic = useAtomicUpdatesByDefault) const
3727  {
3728  using Kokkos::MemoryUnmanaged;
3729  using Kokkos::View;
3730  typedef impl_scalar_type ST;
3731  typedef BinaryFunction BF;
3732  typedef GlobalOrdinal GO;
3733  typedef device_type DD;
3734  typedef typename View<GO*, DD>::HostMirror::device_type HD;
3735 
3736  // The 'indices' and 'values' arrays come from the user, so we
3737  // assume that they are host data, not device data.
3738  const ST* const rawInputVals =
3739  reinterpret_cast<const ST*> (values.getRawPtr ());
3740  View<const ST*, HD, MemoryUnmanaged> inputValsK (rawInputVals,
3741  values.size ());
3742  View<const GO*, HD, MemoryUnmanaged> inputIndsK (indices.getRawPtr (),
3743  indices.size ());
3744  return this->template transformGlobalValues<BF, HD> (globalRow,
3745  inputIndsK,
3746  inputValsK,
3747  f, atomic);
3748  }
3749 
3750  private:
3757  void
3758  insertNonownedGlobalValues (const GlobalOrdinal globalRow,
3759  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
3760  const Teuchos::ArrayView<const Scalar>& values);
3761 
3763  typedef DistObject<char, LocalOrdinal, GlobalOrdinal, Node, classic> dist_object_type;
3764 
3765  protected:
3766  // useful typedefs
3767  typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
3768  typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
3769  typedef Kokkos::Details::ArithTraits<mag_type> STM;
3770  typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> MV;
3771  typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> V;
3772  typedef crs_graph_type Graph;
3773 
3774  // Enums
3775  enum GraphAllocationStatus {
3776  GraphAlreadyAllocated,
3777  GraphNotYetAllocated
3778  };
3779 
3796  void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas);
3797 
3803  void sortEntries();
3804 
3810  void mergeRedundantEntries();
3811 
3819  void clearGlobalConstants();
3820 
3829  void computeGlobalConstants();
3830 
3843  mutable Teuchos::RCP<MV> importMV_;
3844 
3857  mutable Teuchos::RCP<MV> exportMV_;
3858 
3878  Teuchos::RCP<MV>
3879  getColumnMapMultiVector (const MV& X_domainMap,
3880  const bool force = false) const;
3881 
3903  Teuchos::RCP<MV>
3904  getRowMapMultiVector (const MV& Y_rangeMap,
3905  const bool force = false) const;
3906 
3908  void
3909  applyNonTranspose (const MV& X_in,
3910  MV& Y_in,
3911  Scalar alpha,
3912  Scalar beta) const;
3913 
3915  void
3916  applyTranspose (const MV& X_in,
3917  MV& Y_in,
3918  const Teuchos::ETransp mode,
3919  Scalar alpha,
3920  Scalar beta) const;
3921 
3922  // matrix data accessors
3923 
3942  LocalOrdinal
3943  getViewRawConst (const impl_scalar_type*& vals,
3944  LocalOrdinal& numEnt,
3945  const RowInfo& rowinfo) const;
3946 
3965  LocalOrdinal
3966  getViewRaw (impl_scalar_type*& vals,
3967  LocalOrdinal& numEnt,
3968  const RowInfo& rowinfo) const;
3969 
3977  Teuchos::ArrayView<const impl_scalar_type> getView (RowInfo rowinfo) const;
3978 
3990  Teuchos::ArrayView<impl_scalar_type> getViewNonConst (const RowInfo& rowinfo) const;
3991 
3992  private:
4000  Kokkos::View<const impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
4001  getRowView (const RowInfo& rowInfo) const;
4002 
4014  Kokkos::View<impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
4015  getRowViewNonConst (const RowInfo& rowInfo) const;
4016 
4017  protected:
4018 
4024  void fillLocalMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4025 
4031  void fillLocalGraphAndMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4032 
4034  void checkInternalState () const;
4035 
4047 
4048  Teuchos::RCP<const Graph> staticGraph_;
4049  Teuchos::RCP< Graph> myGraph_;
4051 
4054 
4067 
4068  typename local_matrix_type::values_type k_values1D_;
4069  Teuchos::ArrayRCP<Teuchos::Array<impl_scalar_type> > values2D_;
4071 
4082 
4085 
4113  std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
4114  Teuchos::Array<Scalar> > > nonlocals_;
4115 
4122 
4123  public:
4124  // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
4125  // public inner class of CrsMatrix? It looks like it doesn't
4126  // depend on any implementation details of CrsMatrix at all. It
4127  // should really be declared and defined outside of CrsMatrix.
4128  template<class ViewType, class OffsetViewType>
4129  struct pack_functor {
4130  typedef typename ViewType::execution_space execution_space;
4131  ViewType src_;
4132  ViewType dst_;
4133  OffsetViewType src_offset_;
4134  OffsetViewType dst_offset_;
4135  typedef typename OffsetViewType::non_const_value_type scalar_index_type;
4136 
4137  pack_functor (ViewType dst, ViewType src,
4138  OffsetViewType dst_offset, OffsetViewType src_offset) :
4139  src_ (src),
4140  dst_ (dst),
4141  src_offset_ (src_offset),
4142  dst_offset_ (dst_offset)
4143  {}
4144 
4145  KOKKOS_INLINE_FUNCTION
4146  void operator () (const LocalOrdinal row) const {
4147  scalar_index_type srcPos = src_offset_(row);
4148  const scalar_index_type dstEnd = dst_offset_(row+1);
4149  scalar_index_type dstPos = dst_offset_(row);
4150  for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
4151  dst_(dstPos) = src_(srcPos);
4152  }
4153  }
4154  };
4155  }; // class CrsMatrix
4156 
4157 
4166  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, const bool classic = Node::classic>
4167  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, classic> >
4169  size_t maxNumEntriesPerRow = 0,
4170  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4171  {
4173  return Teuchos::rcp (new matrix_type (map, maxNumEntriesPerRow,
4174  DynamicProfile, params));
4175  }
4176 
4228  template<class CrsMatrixType>
4229  Teuchos::RCP<CrsMatrixType>
4230  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4231  const Import<typename CrsMatrixType::local_ordinal_type,
4232  typename CrsMatrixType::global_ordinal_type,
4233  typename CrsMatrixType::node_type>& importer,
4234  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4235  typename CrsMatrixType::global_ordinal_type,
4236  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
4237  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4238  typename CrsMatrixType::global_ordinal_type,
4239  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
4240  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4241  {
4242  Teuchos::RCP<CrsMatrixType> destMatrix;
4243  sourceMatrix->importAndFillComplete (destMatrix,importer,domainMap, rangeMap, params);
4244  return destMatrix;
4245  }
4246 
4300  template<class CrsMatrixType>
4301  Teuchos::RCP<CrsMatrixType>
4302  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4303  const Import<typename CrsMatrixType::local_ordinal_type,
4304  typename CrsMatrixType::global_ordinal_type,
4305  typename CrsMatrixType::node_type>& rowImporter,
4306  const Import<typename CrsMatrixType::local_ordinal_type,
4307  typename CrsMatrixType::global_ordinal_type,
4308  typename CrsMatrixType::node_type>& domainImporter,
4309  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4310  typename CrsMatrixType::global_ordinal_type,
4311  typename CrsMatrixType::node_type> >& domainMap,
4312  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4313  typename CrsMatrixType::global_ordinal_type,
4314  typename CrsMatrixType::node_type> >& rangeMap,
4315  const Teuchos::RCP<Teuchos::ParameterList>& params)
4316  {
4317  Teuchos::RCP<CrsMatrixType> destMatrix;
4318  sourceMatrix->importAndFillComplete (destMatrix,rowImporter,domainImporter, domainMap, rangeMap, params);
4319  return destMatrix;
4320  }
4321 
4355  template<class CrsMatrixType>
4356  Teuchos::RCP<CrsMatrixType>
4357  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4358  const Export<typename CrsMatrixType::local_ordinal_type,
4359  typename CrsMatrixType::global_ordinal_type,
4360  typename CrsMatrixType::node_type>& exporter,
4361  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4362  typename CrsMatrixType::global_ordinal_type,
4363  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
4364  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4365  typename CrsMatrixType::global_ordinal_type,
4366  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
4367  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4368  {
4369  Teuchos::RCP<CrsMatrixType> destMatrix;
4370  sourceMatrix->exportAndFillComplete (destMatrix,exporter,domainMap, rangeMap, params);
4371  return destMatrix;
4372  }
4373 
4407  template<class CrsMatrixType>
4408  Teuchos::RCP<CrsMatrixType>
4409  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4410  const Export<typename CrsMatrixType::local_ordinal_type,
4411  typename CrsMatrixType::global_ordinal_type,
4412  typename CrsMatrixType::node_type>& rowExporter,
4413  const Export<typename CrsMatrixType::local_ordinal_type,
4414  typename CrsMatrixType::global_ordinal_type,
4415  typename CrsMatrixType::node_type>& domainExporter,
4416  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4417  typename CrsMatrixType::global_ordinal_type,
4418  typename CrsMatrixType::node_type> >& domainMap,
4419  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4420  typename CrsMatrixType::global_ordinal_type,
4421  typename CrsMatrixType::node_type> >& rangeMap,
4422  const Teuchos::RCP<Teuchos::ParameterList>& params)
4423  {
4424  Teuchos::RCP<CrsMatrixType> destMatrix;
4425  sourceMatrix->exportAndFillComplete (destMatrix,rowExporter,domainExporter,domainMap, rangeMap, params);
4426  return destMatrix;
4427  }
4428 } // namespace Tpetra
4429 
4437 #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...
Kokkos::CrsMatrix< impl_scalar_type, LocalOrdinal, execution_space, void, typename local_graph_type::size_type > local_matrix_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
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.
void sortEntries()
Sort the entries of each row by their column indices.
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 mergeRedundantEntries()
Merge entries in each row with the same column 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 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.
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.
Describes a parallel distribution of objects over processes.
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, classic > > createCrsMatrix(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Non-member function to create an empty CrsMatrix given a row map and a non-zero profile.
void 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().
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.
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< 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.