Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 // ************************************************************************
38 // @HEADER
39 
40 #ifndef TPETRA_CRSMATRIX_DECL_HPP
41 #define TPETRA_CRSMATRIX_DECL_HPP
42 
50 
51 #include "Tpetra_CrsMatrix_fwd.hpp"
52 #include "Tpetra_LocalCrsMatrixOperator_fwd.hpp"
53 #include "Tpetra_RowMatrix_decl.hpp"
54 #include "Tpetra_Exceptions.hpp"
55 #include "Tpetra_DistObject.hpp"
56 #include "Tpetra_CrsGraph.hpp"
57 #include "Tpetra_Vector.hpp"
59 #include "KokkosSparse_CrsMatrix.hpp"
60 
61 // localGaussSeidel and reorderedLocalGaussSeidel are templated on
62 // DomainScalar and RangeScalar, so we have to include this header
63 // file here, rather than in the _def header file, so that we can get
64 // the interfaces to the corresponding local computational kernels.
65 #include "KokkosSparse_sor_sequential_impl.hpp"
66 
67 #include <memory> // std::shared_ptr
68 
69 namespace Tpetra {
70 
71  // Forward declaration for CrsMatrix::swap() test
72  template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> class crsMatrix_Swap_Tester;
73 
125  template<class CrsMatrixType>
126  Teuchos::RCP<CrsMatrixType>
127  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
128  const Import<typename CrsMatrixType::local_ordinal_type,
129  typename CrsMatrixType::global_ordinal_type,
130  typename CrsMatrixType::node_type>& importer,
131  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
132  typename CrsMatrixType::global_ordinal_type,
133  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
134  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
135  typename CrsMatrixType::global_ordinal_type,
136  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
137  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
138 
192  template<class CrsMatrixType>
193  Teuchos::RCP<CrsMatrixType>
194  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
195  const Import<typename CrsMatrixType::local_ordinal_type,
196  typename CrsMatrixType::global_ordinal_type,
197  typename CrsMatrixType::node_type>& rowImporter,
198  const Import<typename CrsMatrixType::local_ordinal_type,
199  typename CrsMatrixType::global_ordinal_type,
200  typename CrsMatrixType::node_type>& domainImporter,
201  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
202  typename CrsMatrixType::global_ordinal_type,
203  typename CrsMatrixType::node_type> >& domainMap,
204  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
205  typename CrsMatrixType::global_ordinal_type,
206  typename CrsMatrixType::node_type> >& rangeMap,
207  const Teuchos::RCP<Teuchos::ParameterList>& params);
208 
242  template<class CrsMatrixType>
243  Teuchos::RCP<CrsMatrixType>
244  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
245  const Export<typename CrsMatrixType::local_ordinal_type,
246  typename CrsMatrixType::global_ordinal_type,
247  typename CrsMatrixType::node_type>& exporter,
248  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
249  typename CrsMatrixType::global_ordinal_type,
250  typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
251  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
252  typename CrsMatrixType::global_ordinal_type,
253  typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
254  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
255 
289  template<class CrsMatrixType>
290  Teuchos::RCP<CrsMatrixType>
291  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
292  const Export<typename CrsMatrixType::local_ordinal_type,
293  typename CrsMatrixType::global_ordinal_type,
294  typename CrsMatrixType::node_type>& rowExporter,
295  const Export<typename CrsMatrixType::local_ordinal_type,
296  typename CrsMatrixType::global_ordinal_type,
297  typename CrsMatrixType::node_type>& domainExporter,
298  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
299  typename CrsMatrixType::global_ordinal_type,
300  typename CrsMatrixType::node_type> >& domainMap,
301  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
302  typename CrsMatrixType::global_ordinal_type,
303  typename CrsMatrixType::node_type> >& rangeMap,
304  const Teuchos::RCP<Teuchos::ParameterList>& params);
305 
419  template <class Scalar,
420  class LocalOrdinal,
421  class GlobalOrdinal,
422  class Node>
423  class CrsMatrix :
424  public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
425  public DistObject<char, LocalOrdinal, GlobalOrdinal, Node>
426 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
427  , public ::Tpetra::Details::HasDeprecatedMethods2630_WarningThisClassIsNotForUsers
428 #endif // TPETRA_ENABLE_DEPRECATED_CODE
429  {
430  public:
432 
433 
435  using scalar_type = Scalar;
445  using impl_scalar_type = typename Kokkos::ArithTraits<Scalar>::val_type;
447  using local_ordinal_type = LocalOrdinal;
449  using global_ordinal_type = GlobalOrdinal;
451  using device_type = typename Node::device_type;
453  using execution_space = typename device_type::execution_space;
454 
459  using node_type = Node;
460 
466  using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
467 
470 
473 
476 
479 
482 
485  using local_matrix_type =
486  KokkosSparse::CrsMatrix<impl_scalar_type,
489  void,
490  typename local_graph_type::size_type>;
491 
492 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
493  typedef typename local_matrix_type::row_map_type t_RowPtrs TPETRA_DEPRECATED;
496  typedef typename local_matrix_type::row_map_type::non_const_type t_RowPtrsNC TPETRA_DEPRECATED;
498  typedef typename local_graph_type::entries_type::non_const_type t_LocalOrdinal_1D TPETRA_DEPRECATED;
500  typedef typename local_matrix_type::values_type t_ValuesType TPETRA_DEPRECATED;
502  typedef local_matrix_type k_local_matrix_type TPETRA_DEPRECATED;
503 #endif // TPETRA_ENABLE_DEPRECATED_CODE
504 
506 
508 
510  CrsMatrix (const CrsMatrix<Scalar, LocalOrdinal,
511  GlobalOrdinal, Node>&) = default;
512 
514  CrsMatrix (CrsMatrix<Scalar, LocalOrdinal,
515  GlobalOrdinal, Node>&&) = default;
516 
518  CrsMatrix&
519  operator= (const CrsMatrix<Scalar, LocalOrdinal,
520  GlobalOrdinal, Node>&) = default;
521 
523  CrsMatrix&
524  operator= (CrsMatrix<Scalar, LocalOrdinal,
525  GlobalOrdinal, Node>&&) = default;
526 
544  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
545  const size_t maxNumEntriesPerRow,
546  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
547  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
548 
566  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
567  const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
568  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
569  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
570 
571 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
572  TPETRA_DEPRECATED
574  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
575  const Teuchos::ArrayRCP<const size_t>& numEntPerRowToAlloc,
576  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
577  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
578 #endif // TPETRA_ENABLE_DEPRECATED_CODE
579 
602  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
603  const Teuchos::RCP<const map_type>& colMap,
604  const size_t maxNumEntPerRow,
605  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
606  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
607 
630  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
631  const Teuchos::RCP<const map_type>& colMap,
632  const Teuchos::ArrayView<const size_t>& numEntPerRowToAlloc,
633  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
634  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
635 
636 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
637  TPETRA_DEPRECATED
639  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
640  const Teuchos::RCP<const map_type>& colMap,
641  const Teuchos::ArrayRCP<const size_t>& numEntPerRowToAlloc,
642  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
643  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
644 #endif // TPETRA_ENABLE_DEPRECATED_CODE
645 
670  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
671  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
672 
701  explicit CrsMatrix (const Teuchos::RCP<const crs_graph_type>& graph,
702  const typename local_matrix_type::values_type& values,
703  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
704 
728  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
729  const Teuchos::RCP<const map_type>& colMap,
730  const typename local_matrix_type::row_map_type& rowPointers,
731  const typename local_graph_type::entries_type::non_const_type& columnIndices,
732  const typename local_matrix_type::values_type& values,
733  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
734 
758  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
759  const Teuchos::RCP<const map_type>& colMap,
760  const Teuchos::ArrayRCP<size_t>& rowPointers,
761  const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
762  const Teuchos::ArrayRCP<Scalar>& values,
763  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
764 
785  CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
786  const Teuchos::RCP<const map_type>& colMap,
787  const local_matrix_type& lclMatrix,
788  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
789 
816  CrsMatrix (const local_matrix_type& lclMatrix,
817  const Teuchos::RCP<const map_type>& rowMap,
818  const Teuchos::RCP<const map_type>& colMap,
819  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
820  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
821  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
822 
824  CrsMatrix (const local_matrix_type& lclMatrix,
825  const Teuchos::RCP<const map_type>& rowMap,
826  const Teuchos::RCP<const map_type>& colMap,
827  const Teuchos::RCP<const map_type>& domainMap,
828  const Teuchos::RCP<const map_type>& rangeMap,
829  const Teuchos::RCP<const import_type>& importer,
830  const Teuchos::RCP<const export_type>& exporter,
831  const Teuchos::RCP<Teuchos::ParameterList>& params =
832  Teuchos::null);
833 
835  // This function in 'Copy' mode is only guaranteed to work correctly for matrices
836  // which are fillComplete.
838  const Teuchos::DataAccess copyOrView);
839 
849  virtual ~CrsMatrix () = default;
850 
851  // This friend declaration makes the clone() method work.
852  template <class S2, class LO2, class GO2, class N2>
853  friend class CrsMatrix;
854 
855 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
856  template <class Node2>
881  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node2> > TPETRA_DEPRECATED
882  clone (const Teuchos::RCP<Node2>& node2,
883  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const
884  {
885  using Teuchos::Array;
886  using Teuchos::ArrayRCP;
887  using Teuchos::ArrayView;
888  using Teuchos::null;
889  using Teuchos::ParameterList;
890  using Teuchos::RCP;
891  using Teuchos::rcp;
892  using Teuchos::sublist;
895  const char tfecfFuncName[] = "clone";
896 
897  // Get parameter values. Set them initially to their default values.
898  bool fillCompleteClone = true;
899  bool useLocalIndices = this->hasColMap ();
900  ProfileType pftype = StaticProfile;
901  if (! params.is_null ()) {
902  fillCompleteClone = params->get ("fillComplete clone", fillCompleteClone);
903  useLocalIndices = params->get ("Locally indexed clone", useLocalIndices);
904 
905  bool staticProfileClone = true;
906  staticProfileClone = params->get ("Static profile clone", staticProfileClone);
907  pftype = staticProfileClone ? StaticProfile : ProfileType(StaticProfile+1) /*DynamicProfile*/;
908  }
909 
910  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
911  ! this->hasColMap () && useLocalIndices, std::runtime_error,
912  ": You requested that the returned clone have local indices, but the "
913  "the source matrix does not have a column Map yet.");
914 
915  RCP<const Map2> clonedRowMap = this->getRowMap ()->template clone<Node2> (node2);
916 
917  // Get an upper bound on the number of entries per row.
918  RCP<CrsMatrix2> clonedMatrix;
919  ArrayRCP<const size_t> numEntriesPerRow;
920  size_t numEntriesForAll = 0;
921  bool boundSameForAllLocalRows = false;
922  staticGraph_->getNumEntriesPerLocalRowUpperBound (numEntriesPerRow,
923  numEntriesForAll,
924  boundSameForAllLocalRows);
925  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
926  numEntriesForAll != 0 &&
927  static_cast<size_t> (numEntriesPerRow.size ()) != 0,
928  std::logic_error, ": getNumEntriesPerLocalRowUpperBound returned a "
929  "nonzero numEntriesForAll = " << numEntriesForAll << " , as well as a "
930  "numEntriesPerRow array of nonzero length " << numEntriesPerRow.size ()
931  << ". This should never happen. Please report this bug to the Tpetra "
932  "developers.");
933  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
934  numEntriesForAll != 0 && ! boundSameForAllLocalRows,
935  std::logic_error, ": getNumEntriesPerLocalRowUpperBound returned a "
936  "nonzero numEntriesForAll = " << numEntriesForAll << " , but claims "
937  "(via its third output value) that the upper bound is not the same for "
938  "all rows. This should never happen. Please report this bug to the "
939  "Tpetra developers.");
940  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
941  numEntriesPerRow.size () != 0 && boundSameForAllLocalRows,
942  std::logic_error, ": getNumEntriesPerLocalRowUpperBound returned a "
943  "numEntriesPerRow array of nonzero length " << numEntriesPerRow.size ()
944  << ", but claims (via its third output value) that the upper bound is "
945  "not the same for all rows. This should never happen. Please report "
946  "this bug to the Tpetra developers.");
947 
948  RCP<ParameterList> matParams =
949  params.is_null () ? null : sublist (params,"CrsMatrix");
950  if (useLocalIndices) {
951  RCP<const Map2> clonedColMap =
952  this->getColMap ()->template clone<Node2> (node2);
953  if (numEntriesPerRow.is_null ()) {
954  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, clonedColMap,
955  numEntriesForAll, pftype,
956  matParams));
957  }
958  else {
959  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, clonedColMap,
960  numEntriesPerRow (), pftype,
961  matParams));
962  }
963  }
964  else {
965  if (numEntriesPerRow.is_null ()) {
966  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap, numEntriesForAll,
967  pftype, matParams));
968  }
969  else {
970  clonedMatrix = rcp (new CrsMatrix2 (clonedRowMap,
971  numEntriesPerRow (),
972  pftype, matParams));
973  }
974  }
975  // done with these
976  numEntriesPerRow = Teuchos::null;
977  numEntriesForAll = 0;
978 
979  if (useLocalIndices) {
980  clonedMatrix->allocateValues (LocalIndices,
981  CrsMatrix2::GraphNotYetAllocated);
982  if (this->isLocallyIndexed ()) {
983  ArrayView<const LocalOrdinal> linds;
984  ArrayView<const Scalar> vals;
985  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
986  lrow <= clonedRowMap->getMaxLocalIndex ();
987  ++lrow) {
988  this->getLocalRowView (lrow, linds, vals);
989  if (linds.size ()) {
990  clonedMatrix->insertLocalValues (lrow, linds, vals);
991  }
992  }
993  }
994  else { // this->isGloballyIndexed()
995  Array<LocalOrdinal> linds;
996  Array<Scalar> vals;
997  for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex ();
998  lrow <= clonedRowMap->getMaxLocalIndex ();
999  ++lrow) {
1000  size_t theNumEntries = this->getNumEntriesInLocalRow (lrow);
1001  if (theNumEntries > static_cast<size_t> (linds.size ())) {
1002  linds.resize (theNumEntries);
1003  }
1004  if (theNumEntries > static_cast<size_t> (vals.size ())) {
1005  vals.resize (theNumEntries);
1006  }
1007  this->getLocalRowCopy (clonedRowMap->getGlobalElement (lrow),
1008  linds (), vals (), theNumEntries);
1009  if (theNumEntries != 0) {
1010  clonedMatrix->insertLocalValues (lrow, linds (0, theNumEntries),
1011  vals (0, theNumEntries));
1012  }
1013  }
1014  }
1015  }
1016  else { // useGlobalIndices
1017  clonedMatrix->allocateValues (GlobalIndices,
1018  CrsMatrix2::GraphNotYetAllocated);
1019  if (this->isGloballyIndexed ()) {
1020  ArrayView<const GlobalOrdinal> ginds;
1021  ArrayView<const Scalar> vals;
1022  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
1023  grow <= clonedRowMap->getMaxGlobalIndex ();
1024  ++grow) {
1025  this->getGlobalRowView (grow, ginds, vals);
1026  if (ginds.size () > 0) {
1027  clonedMatrix->insertGlobalValues (grow, ginds, vals);
1028  }
1029  }
1030  }
1031  else { // this->isLocallyIndexed()
1032  Array<GlobalOrdinal> ginds;
1033  Array<Scalar> vals;
1034  for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex ();
1035  grow <= clonedRowMap->getMaxGlobalIndex ();
1036  ++grow) {
1037  size_t theNumEntries = this->getNumEntriesInGlobalRow (grow);
1038  if (theNumEntries > static_cast<size_t> (ginds.size ())) {
1039  ginds.resize (theNumEntries);
1040  }
1041  if (theNumEntries > static_cast<size_t> (vals.size ())) {
1042  vals.resize (theNumEntries);
1043  }
1044  this->getGlobalRowCopy (grow, ginds (), vals (), theNumEntries);
1045  if (theNumEntries != 0) {
1046  clonedMatrix->insertGlobalValues (grow, ginds (0, theNumEntries),
1047  vals (0, theNumEntries));
1048  }
1049  }
1050  }
1051  }
1052 
1053  if (fillCompleteClone) {
1054  RCP<const Map2> clonedRangeMap;
1055  RCP<const Map2> clonedDomainMap;
1056  try {
1057  if (! this->getRangeMap ().is_null () &&
1058  this->getRangeMap () != clonedRowMap) {
1059  clonedRangeMap = this->getRangeMap ()->template clone<Node2> (node2);
1060  }
1061  else {
1062  clonedRangeMap = clonedRowMap;
1063  }
1064  if (! this->getDomainMap ().is_null () &&
1065  this->getDomainMap () != clonedRowMap) {
1066  clonedDomainMap = this->getDomainMap ()->template clone<Node2> (node2);
1067  }
1068  else {
1069  clonedDomainMap = clonedRowMap;
1070  }
1071  }
1072  catch (std::exception &e) {
1073  const bool caughtExceptionOnClone = true;
1074  TEUCHOS_TEST_FOR_EXCEPTION
1075  (caughtExceptionOnClone, std::runtime_error,
1076  Teuchos::typeName (*this) << "::clone: Caught the following "
1077  "exception while cloning range and domain Maps on a clone of "
1078  "type " << Teuchos::typeName (*clonedMatrix) << ": " << e.what ());
1079  }
1080 
1081  RCP<ParameterList> fillparams =
1082  params.is_null () ? Teuchos::null : sublist (params, "fillComplete");
1083  try {
1084  clonedMatrix->fillComplete (clonedDomainMap, clonedRangeMap,
1085  fillparams);
1086  }
1087  catch (std::exception &e) {
1088  const bool caughtExceptionOnClone = true;
1089  TEUCHOS_TEST_FOR_EXCEPTION(
1090  caughtExceptionOnClone, std::runtime_error,
1091  Teuchos::typeName (*this) << "::clone: Caught the following "
1092  "exception while calling fillComplete() on a clone of type "
1093  << Teuchos::typeName (*clonedMatrix) << ": " << e.what ());
1094  }
1095  }
1096  return clonedMatrix;
1097  }
1098 #endif
1099 
1100  public:
1102 
1104 
1128  //
1174  void
1175  insertGlobalValues (const GlobalOrdinal globalRow,
1176  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1177  const Teuchos::ArrayView<const Scalar>& vals);
1178 
1193  void
1194  insertGlobalValues (const GlobalOrdinal globalRow,
1195  const LocalOrdinal numEnt,
1196  const Scalar vals[],
1197  const GlobalOrdinal inds[]);
1198 
1239  void
1240  insertLocalValues (const LocalOrdinal localRow,
1241  const Teuchos::ArrayView<const LocalOrdinal> &cols,
1242  const Teuchos::ArrayView<const Scalar> &vals);
1243 
1258  void
1259  insertLocalValues (const LocalOrdinal localRow,
1260  const LocalOrdinal numEnt,
1261  const Scalar vals[],
1262  const LocalOrdinal cols[]);
1263 
1264  private:
1275  LocalOrdinal
1276  replaceGlobalValuesImpl (impl_scalar_type rowVals[],
1277  const crs_graph_type& graph,
1278  const RowInfo& rowInfo,
1279  const GlobalOrdinal inds[],
1280  const impl_scalar_type newVals[],
1281  const LocalOrdinal numElts) const;
1282 
1283  public:
1320  template<class GlobalIndicesViewType,
1321  class ImplScalarViewType>
1322  LocalOrdinal
1323  replaceGlobalValues (const GlobalOrdinal globalRow,
1324  const typename UnmanagedView<GlobalIndicesViewType>::type& inputInds,
1325  const typename UnmanagedView<ImplScalarViewType>::type& inputVals) const
1326  {
1327  // We use static_assert here to check the template parameters,
1328  // rather than std::enable_if (e.g., on the return value, to
1329  // enable compilation only if the template parameters match the
1330  // desired attributes). This turns obscure link errors into
1331  // clear compilation errors. It also makes the return value a
1332  // lot easier to see.
1333  static_assert (Kokkos::is_view<GlobalIndicesViewType>::value,
1334  "First template parameter GlobalIndicesViewType must be "
1335  "a Kokkos::View.");
1336  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1337  "Second template parameter ImplScalarViewType must be a "
1338  "Kokkos::View.");
1339  static_assert (static_cast<int> (GlobalIndicesViewType::rank) == 1,
1340  "First template parameter GlobalIndicesViewType must "
1341  "have rank 1.");
1342  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1343  "Second template parameter ImplScalarViewType must have "
1344  "rank 1.");
1345  static_assert (std::is_same<
1346  typename GlobalIndicesViewType::non_const_value_type,
1347  global_ordinal_type>::value,
1348  "First template parameter GlobalIndicesViewType must "
1349  "contain values of type global_ordinal_type.");
1350  static_assert (std::is_same<
1351  typename ImplScalarViewType::non_const_value_type,
1352  impl_scalar_type>::value,
1353  "Second template parameter ImplScalarViewType must "
1354  "contain values of type impl_scalar_type.");
1355  typedef LocalOrdinal LO;
1356  const LO numInputEnt = inputInds.extent (0);
1357  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1358  return Teuchos::OrdinalTraits<LO>::invalid ();
1359  }
1360  const Scalar* const inVals =
1361  reinterpret_cast<const Scalar*> (inputVals.data ());
1362  return this->replaceGlobalValues (globalRow, numInputEnt, inVals,
1363  inputInds.data ());
1364  }
1365 
1369  LocalOrdinal
1370  replaceGlobalValues (const GlobalOrdinal globalRow,
1371  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1372  const Teuchos::ArrayView<const Scalar>& vals) const;
1373 
1389  LocalOrdinal
1390  replaceGlobalValues (const GlobalOrdinal globalRow,
1391  const LocalOrdinal numEnt,
1392  const Scalar vals[],
1393  const GlobalOrdinal cols[]) const;
1394 
1395  private:
1406  LocalOrdinal
1407  replaceLocalValuesImpl (impl_scalar_type rowVals[],
1408  const crs_graph_type& graph,
1409  const RowInfo& rowInfo,
1410  const LocalOrdinal inds[],
1411  const impl_scalar_type newVals[],
1412  const LocalOrdinal numElts) const;
1413 
1414  public:
1450  template<class LocalIndicesViewType,
1451  class ImplScalarViewType>
1452  LocalOrdinal
1453  replaceLocalValues (const LocalOrdinal localRow,
1454  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1455  const typename UnmanagedView<ImplScalarViewType>::type& inputVals) const
1456  {
1457  // We use static_assert here to check the template parameters,
1458  // rather than std::enable_if (e.g., on the return value, to
1459  // enable compilation only if the template parameters match the
1460  // desired attributes). This turns obscure link errors into
1461  // clear compilation errors. It also makes the return value a
1462  // lot easier to see.
1463  static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1464  "First template parameter LocalIndicesViewType must be "
1465  "a Kokkos::View.");
1466  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1467  "Second template parameter ImplScalarViewType must be a "
1468  "Kokkos::View.");
1469  static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1470  "First template parameter LocalIndicesViewType must "
1471  "have rank 1.");
1472  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1473  "Second template parameter ImplScalarViewType must have "
1474  "rank 1.");
1475  static_assert (std::is_same<
1476  typename LocalIndicesViewType::non_const_value_type,
1477  local_ordinal_type>::value,
1478  "First template parameter LocalIndicesViewType must "
1479  "contain values of type local_ordinal_type.");
1480  static_assert (std::is_same<
1481  typename ImplScalarViewType::non_const_value_type,
1482  impl_scalar_type>::value,
1483  "Second template parameter ImplScalarViewType must "
1484  "contain values of type impl_scalar_type.");
1485 
1486  typedef LocalOrdinal LO;
1487  const LO numInputEnt = inputInds.extent (0);
1488  if (numInputEnt != inputVals.extent (0)) {
1489  return Teuchos::OrdinalTraits<LO>::invalid ();
1490  }
1491  const Scalar* const inVals =
1492  reinterpret_cast<const Scalar*> (inputVals.data ());
1493  return this->replaceLocalValues (localRow, numInputEnt,
1494  inVals, inputInds.data ());
1495  }
1496 
1500  LocalOrdinal
1501  replaceLocalValues (const LocalOrdinal localRow,
1502  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1503  const Teuchos::ArrayView<const Scalar>& vals) const;
1504 
1522  LocalOrdinal
1523  replaceLocalValues (const LocalOrdinal localRow,
1524  const LocalOrdinal numEnt,
1525  const Scalar inputVals[],
1526  const LocalOrdinal inputCols[]) const;
1527 
1528  private:
1533  static const bool useAtomicUpdatesByDefault =
1534 #ifdef KOKKOS_ENABLE_SERIAL
1535  ! std::is_same<execution_space, Kokkos::Serial>::value;
1536 #else
1537  true;
1538 #endif // KOKKOS_ENABLE_SERIAL
1539 
1563  LocalOrdinal
1564  sumIntoGlobalValuesImpl (impl_scalar_type rowVals[],
1565  const crs_graph_type& graph,
1566  const RowInfo& rowInfo,
1567  const GlobalOrdinal inds[],
1568  const impl_scalar_type newVals[],
1569  const LocalOrdinal numElts,
1570  const bool atomic = useAtomicUpdatesByDefault) const;
1571 
1572  public:
1609  LocalOrdinal
1610  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1611  const Teuchos::ArrayView<const GlobalOrdinal>& cols,
1612  const Teuchos::ArrayView<const Scalar>& vals,
1613  const bool atomic = useAtomicUpdatesByDefault);
1614 
1637  LocalOrdinal
1638  sumIntoGlobalValues (const GlobalOrdinal globalRow,
1639  const LocalOrdinal numEnt,
1640  const Scalar vals[],
1641  const GlobalOrdinal cols[],
1642  const bool atomic = useAtomicUpdatesByDefault);
1643 
1644  private:
1657  LocalOrdinal
1658  sumIntoLocalValuesImpl (impl_scalar_type rowVals[],
1659  const crs_graph_type& graph,
1660  const RowInfo& rowInfo,
1661  const LocalOrdinal inds[],
1662  const impl_scalar_type newVals[],
1663  const LocalOrdinal numElts,
1664  const bool atomic = useAtomicUpdatesByDefault) const;
1665 
1666  public:
1703  template<class LocalIndicesViewType,
1704  class ImplScalarViewType>
1705  LocalOrdinal
1706  sumIntoLocalValues (const LocalOrdinal localRow,
1707  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
1708  const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
1709  const bool atomic = useAtomicUpdatesByDefault) const
1710  {
1711  // We use static_assert here to check the template parameters,
1712  // rather than std::enable_if (e.g., on the return value, to
1713  // enable compilation only if the template parameters match the
1714  // desired attributes). This turns obscure link errors into
1715  // clear compilation errors. It also makes the return value a
1716  // lot easier to see.
1717  static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
1718  "First template parameter LocalIndicesViewType must be "
1719  "a Kokkos::View.");
1720  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
1721  "Second template parameter ImplScalarViewType must be a "
1722  "Kokkos::View.");
1723  static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
1724  "First template parameter LocalIndicesViewType must "
1725  "have rank 1.");
1726  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
1727  "Second template parameter ImplScalarViewType must have "
1728  "rank 1.");
1729  static_assert (std::is_same<
1730  typename LocalIndicesViewType::non_const_value_type,
1731  local_ordinal_type>::value,
1732  "First template parameter LocalIndicesViewType must "
1733  "contain values of type local_ordinal_type.");
1734  static_assert (std::is_same<
1735  typename ImplScalarViewType::non_const_value_type,
1736  impl_scalar_type>::value,
1737  "Second template parameter ImplScalarViewType must "
1738  "contain values of type impl_scalar_type.");
1739  typedef LocalOrdinal LO;
1740  const LO numInputEnt = inputInds.extent (0);
1741  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
1742  return Teuchos::OrdinalTraits<LO>::invalid ();
1743  }
1744  return this->sumIntoLocalValues (localRow,
1745  numInputEnt,
1746  reinterpret_cast<const Scalar*> (inputVals.data ()),
1747  inputInds.data (),
1748  atomic);
1749  }
1750 
1780  LocalOrdinal
1781  sumIntoLocalValues (const LocalOrdinal localRow,
1782  const Teuchos::ArrayView<const LocalOrdinal>& cols,
1783  const Teuchos::ArrayView<const Scalar>& vals,
1784  const bool atomic = useAtomicUpdatesByDefault) const;
1785 
1807  LocalOrdinal
1808  sumIntoLocalValues (const LocalOrdinal localRow,
1809  const LocalOrdinal numEnt,
1810  const Scalar vals[],
1811  const LocalOrdinal cols[],
1812  const bool atomic = useAtomicUpdatesByDefault) const;
1813 
1814  private:
1845  LocalOrdinal
1846  transformLocalValues (impl_scalar_type rowVals[],
1847  const crs_graph_type& graph,
1848  const RowInfo& rowInfo,
1849  const LocalOrdinal inds[],
1850  const impl_scalar_type newVals[],
1851  const LocalOrdinal numElts,
1852  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1853  const bool atomic = useAtomicUpdatesByDefault) const;
1854 
1885  LocalOrdinal
1886  transformGlobalValues (impl_scalar_type rowVals[],
1887  const crs_graph_type& graph,
1888  const RowInfo& rowInfo,
1889  const GlobalOrdinal inds[],
1890  const impl_scalar_type newVals[],
1891  const LocalOrdinal numElts,
1892  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1893  const bool atomic = useAtomicUpdatesByDefault) const;
1894 
1921  LocalOrdinal
1922  transformLocalValues (const LocalOrdinal lclRow,
1923  const LocalOrdinal numInputEnt,
1924  const impl_scalar_type inputVals[],
1925  const LocalOrdinal inputCols[],
1926  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1927  const bool atomic = useAtomicUpdatesByDefault) const;
1928 
1955  LocalOrdinal
1956  transformGlobalValues (const GlobalOrdinal gblRow,
1957  const LocalOrdinal numInputEnt,
1958  const impl_scalar_type inputVals[],
1959  const GlobalOrdinal inputCols[],
1960  std::function<impl_scalar_type (const impl_scalar_type&, const impl_scalar_type&) > f,
1961  const bool atomic = useAtomicUpdatesByDefault) const;
1962 
1963  public:
2007  template<class LocalIndicesViewType,
2008  class ImplScalarViewType,
2009  class BinaryFunction>
2010  LocalOrdinal
2011  transformLocalValues (const LocalOrdinal lclRow,
2012  const typename UnmanagedView<LocalIndicesViewType>::type& inputInds,
2013  const typename UnmanagedView<ImplScalarViewType>::type& inputVals,
2014  BinaryFunction f,
2015  const bool atomic = useAtomicUpdatesByDefault) const
2016  {
2017  // We use static_assert here to check the template parameters,
2018  // rather than std::enable_if (e.g., on the return value, to
2019  // enable compilation only if the template parameters match the
2020  // desired attributes). This turns obscure link errors into
2021  // clear compilation errors. It also makes the return value a
2022  // lot easier to see.
2023  static_assert (Kokkos::is_view<LocalIndicesViewType>::value,
2024  "First template parameter LocalIndicesViewType must be "
2025  "a Kokkos::View.");
2026  static_assert (Kokkos::is_view<ImplScalarViewType>::value,
2027  "Second template parameter ImplScalarViewType must be a "
2028  "Kokkos::View.");
2029  static_assert (static_cast<int> (LocalIndicesViewType::rank) == 1,
2030  "First template parameter LocalIndicesViewType must "
2031  "have rank 1.");
2032  static_assert (static_cast<int> (ImplScalarViewType::rank) == 1,
2033  "Second template parameter ImplScalarViewType must have "
2034  "rank 1.");
2035  static_assert (std::is_same<
2036  typename LocalIndicesViewType::non_const_value_type,
2037  local_ordinal_type>::value,
2038  "First template parameter LocalIndicesViewType must "
2039  "contain values of type local_ordinal_type.");
2040  static_assert (std::is_same<
2041  typename ImplScalarViewType::non_const_value_type,
2042  impl_scalar_type>::value,
2043  "Second template parameter ImplScalarViewType must "
2044  "contain values of type impl_scalar_type.");
2045  typedef LocalOrdinal LO;
2046  const LO numInputEnt = inputInds.extent (0);
2047  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
2048  return Teuchos::OrdinalTraits<LO>::invalid ();
2049  }
2050  return this->transformLocalValues (lclRow,
2051  numInputEnt,
2052  inputVals.data (),
2053  inputInds.data (),
2054  f,
2055  atomic);
2056  }
2057 
2099  template<class BinaryFunction, class InputMemorySpace>
2100  LocalOrdinal
2101  transformGlobalValues (const GlobalOrdinal gblRow,
2102  const Kokkos::View<const GlobalOrdinal*,
2103  InputMemorySpace,
2104  Kokkos::MemoryUnmanaged>& inputInds,
2105  const Kokkos::View<const impl_scalar_type*,
2106  InputMemorySpace,
2107  Kokkos::MemoryUnmanaged>& inputVals,
2108  BinaryFunction f,
2109  const bool atomic = useAtomicUpdatesByDefault) const
2110  {
2111  typedef LocalOrdinal LO;
2112  const LO numInputEnt = inputInds.extent (0);
2113  if (static_cast<LO> (inputVals.extent (0)) != numInputEnt) {
2114  return Teuchos::OrdinalTraits<LO>::invalid ();
2115  }
2116  return this->transformGlobalValues (gblRow,
2117  numInputEnt,
2118  inputVals.data (),
2119  inputInds.data (),
2120  f,
2121  atomic);
2122  }
2123 
2125  void setAllToScalar (const Scalar& alpha);
2126 
2128  void scale (const Scalar& alpha);
2129 
2153  void
2154  setAllValues (const typename local_matrix_type::row_map_type& ptr,
2155  const typename local_graph_type::entries_type::non_const_type& ind,
2156  const typename local_matrix_type::values_type& val);
2157 
2181  void
2182  setAllValues (const Teuchos::ArrayRCP<size_t>& ptr,
2183  const Teuchos::ArrayRCP<LocalOrdinal>& ind,
2184  const Teuchos::ArrayRCP<Scalar>& val);
2185 
2186  void
2187  getAllValues (Teuchos::ArrayRCP<const size_t>& rowPointers,
2188  Teuchos::ArrayRCP<const LocalOrdinal>& columnIndices,
2189  Teuchos::ArrayRCP<const Scalar>& values) const;
2190 
2192 
2194 
2223  void globalAssemble();
2224 
2238  void resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2239 
2297  void
2298  fillComplete (const Teuchos::RCP<const map_type>& domainMap,
2299  const Teuchos::RCP<const map_type>& rangeMap,
2300  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2301 
2328  void
2329  fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2330 
2357  void
2358  expertStaticFillComplete (const Teuchos::RCP<const map_type>& domainMap,
2359  const Teuchos::RCP<const map_type>& rangeMap,
2360  const Teuchos::RCP<const import_type>& importer = Teuchos::null,
2361  const Teuchos::RCP<const export_type>& exporter = Teuchos::null,
2362  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
2363 
2373  void
2374  replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
2375 
2457  void
2458  reindexColumns (crs_graph_type* const graph,
2459  const Teuchos::RCP<const map_type>& newColMap,
2460  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
2461  const bool sortEachRow = true);
2462 
2475  void
2476  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
2477  Teuchos::RCP<const import_type>& newImporter);
2478 
2492  virtual void
2493  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
2494 
2496 
2498 
2500  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const override;
2501 
2502 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2503  TPETRA_DEPRECATED Teuchos::RCP<node_type> getNode () const override;
2505 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2506 
2508  Teuchos::RCP<const map_type> getRowMap () const override;
2509 
2511  Teuchos::RCP<const map_type> getColMap () const override;
2512 
2514  Teuchos::RCP<const RowGraph<LocalOrdinal, GlobalOrdinal, Node> >
2515  getGraph () const override;
2516 
2518  Teuchos::RCP<const crs_graph_type> getCrsGraph () const;
2519 
2520  private:
2531  const crs_graph_type& getCrsGraphRef () const;
2532 
2533  public:
2544 
2564  global_size_t getGlobalNumRows() const override;
2565 
2571  global_size_t getGlobalNumCols() const override;
2572 
2579  size_t getNodeNumRows() const override;
2580 
2584  size_t getNodeNumCols() const override;
2585 
2587  GlobalOrdinal getIndexBase() const override;
2588 
2590  global_size_t getGlobalNumEntries() const override;
2591 
2593  size_t getNodeNumEntries() const override;
2594 
2601  size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const override;
2602 
2609  size_t getNumEntriesInLocalRow (local_ordinal_type localRow) const override;
2610 
2618  size_t getGlobalMaxNumRowEntries () const override;
2619 
2627  size_t getNodeMaxNumRowEntries () const override;
2628 
2630  bool hasColMap () const override;
2631 
2632 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2633  global_size_t TPETRA_DEPRECATED getGlobalNumDiags () const override;
2641 
2649  size_t TPETRA_DEPRECATED getNodeNumDiags () const override;
2650 
2662  global_size_t getGlobalNumDiagsImpl () const override;
2663 
2675  size_t getNodeNumDiagsImpl () const override;
2676 
2687  bool TPETRA_DEPRECATED isLowerTriangular () const override;
2688 
2699  bool TPETRA_DEPRECATED isUpperTriangular () const override;
2700 
2712  bool isLowerTriangularImpl () const override;
2713 
2725  bool isUpperTriangularImpl () const override;
2726 #endif // TPETRA_ENABLE_DEPRECATED_CODE
2727 
2748  bool isLocallyIndexed() const override;
2749 
2770  bool isGloballyIndexed() const override;
2771 
2794  bool isFillComplete() const override;
2795 
2818  bool isFillActive() const;
2819 
2821 
2827  bool isStorageOptimized () const;
2828 
2830  ProfileType getProfileType () const;
2831 
2833  bool isStaticGraph () const;
2834 
2846  mag_type getFrobeniusNorm () const override;
2847 
2850  virtual bool supportsRowViews () const override;
2851 
2900  void
2901  getGlobalRowCopy (GlobalOrdinal GlobalRow,
2902  const Teuchos::ArrayView<GlobalOrdinal>& Indices,
2903  const Teuchos::ArrayView<Scalar>& Values,
2904  size_t& NumEntries) const override;
2905 
2921  void
2922  getLocalRowCopy (LocalOrdinal localRow,
2923  const Teuchos::ArrayView<LocalOrdinal>& colInds,
2924  const Teuchos::ArrayView<Scalar>& vals,
2925  size_t& numEntries) const override;
2926 
2939  void
2940  getGlobalRowView (GlobalOrdinal GlobalRow,
2941  Teuchos::ArrayView<const GlobalOrdinal>& indices,
2942  Teuchos::ArrayView<const Scalar>& values) const override;
2943 
2956  void
2957  getLocalRowView (LocalOrdinal LocalRow,
2958  Teuchos::ArrayView<const LocalOrdinal>& indices,
2959  Teuchos::ArrayView<const Scalar>& values) const override;
2960 
2985  LocalOrdinal
2986  getLocalRowViewRaw (const LocalOrdinal lclRow,
2987  LocalOrdinal& numEnt,
2988  const LocalOrdinal*& lclColInds,
2989  const Scalar*& vals) const override;
2990 
3014  LocalOrdinal
3015  getLocalRowView (const LocalOrdinal lclRow,
3016  LocalOrdinal& numEnt,
3017  const impl_scalar_type*& val,
3018  const LocalOrdinal*& ind) const;
3019 
3027  template<class OutputScalarType>
3028  typename std::enable_if<! std::is_same<OutputScalarType, impl_scalar_type>::value &&
3029  std::is_convertible<impl_scalar_type, OutputScalarType>::value,
3030  LocalOrdinal>::type
3031  getLocalRowView (const LocalOrdinal lclRow,
3032  LocalOrdinal& numEnt,
3033  const OutputScalarType*& val,
3034  const LocalOrdinal*& ind) const
3035  {
3036  const impl_scalar_type* valTmp = NULL;
3037  const LocalOrdinal err = this->getLocalRowView (lclRow, numEnt, valTmp, ind);
3038  // Cast is legitimate because impl_scalar_type is convertible to
3039  // OutputScalarType.
3040  val = reinterpret_cast<const OutputScalarType*> (valTmp);
3041  return err;
3042  }
3043 
3050  void
3052 
3096  void getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
3097 
3119  void
3121  const Kokkos::View<const size_t*, device_type,
3122  Kokkos::MemoryUnmanaged>& offsets) const;
3123 
3146  void
3148  const Teuchos::ArrayView<const size_t>& offsets) const;
3149 
3154  void
3156 
3161  void
3163 
3165 
3167 
3229  void
3232  const Teuchos::ETransp mode = Teuchos::NO_TRANS,
3233  const Scalar& alpha = Teuchos::ScalarTraits<Scalar>::one (),
3234  const Scalar& beta = Teuchos::ScalarTraits<Scalar>::zero ()) const;
3235 
3260  template <class DomainScalar, class RangeScalar>
3261  void
3265  const RangeScalar& dampingFactor,
3266  const ESweepDirection direction) const
3267  {
3268  typedef LocalOrdinal LO;
3269  typedef GlobalOrdinal GO;
3272  typedef typename Node::device_type::memory_space dev_mem_space;
3273  typedef typename MMV::dual_view_type::t_host::device_type host_mem_space;
3274  typedef typename Graph::local_graph_type k_local_graph_type;
3275  typedef typename k_local_graph_type::size_type offset_type;
3276  const char prefix[] = "Tpetra::CrsMatrix::localGaussSeidel: ";
3277 
3278  TEUCHOS_TEST_FOR_EXCEPTION
3279  (! this->isFillComplete (), std::runtime_error,
3280  prefix << "The matrix is not fill complete.");
3281  const size_t lclNumRows = this->getNodeNumRows ();
3282  const size_t numVecs = B.getNumVectors ();
3283  TEUCHOS_TEST_FOR_EXCEPTION
3284  (X.getNumVectors () != numVecs, std::invalid_argument,
3285  prefix << "B.getNumVectors() = " << numVecs << " != "
3286  "X.getNumVectors() = " << X.getNumVectors () << ".");
3287  TEUCHOS_TEST_FOR_EXCEPTION
3288  (B.getLocalLength () != lclNumRows, std::invalid_argument,
3289  prefix << "B.getLocalLength() = " << B.getLocalLength ()
3290  << " != this->getNodeNumRows() = " << lclNumRows << ".");
3291 
3292  // mfh 28 Aug 2017: The current local Gauss-Seidel kernel only
3293  // runs on host. (See comments below.) Thus, we need to access
3294  // the host versions of these data.
3295  const_cast<DMV&> (B).sync_host ();
3296  X.sync_host ();
3297  X.modify_host ();
3298  const_cast<MMV&> (D).sync_host ();
3299 
3300  auto B_lcl = B.template getLocalView<host_mem_space> ();
3301  auto X_lcl = X.template getLocalView<host_mem_space> ();
3302  auto D_lcl = D.template getLocalView<host_mem_space> ();
3303 
3304  offset_type B_stride[8], X_stride[8], D_stride[8];
3305  B_lcl.stride (B_stride);
3306  X_lcl.stride (X_stride);
3307  D_lcl.stride (D_stride);
3308 
3309  local_matrix_type lclMatrix = this->getLocalMatrix ();
3310  k_local_graph_type lclGraph = lclMatrix.graph;
3311  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
3312  typename local_matrix_type::index_type ind = lclGraph.entries;
3313  typename local_matrix_type::values_type val = lclMatrix.values;
3314  const offset_type* const ptrRaw = ptr.data ();
3315  const LO* const indRaw = ind.data ();
3316  const impl_scalar_type* const valRaw = val.data ();
3317 
3318  const std::string dir ((direction == Forward) ? "F" : "B");
3319  // NOTE (mfh 28 Aug 2017) This assumes UVM. We can't get around
3320  // that on GPUs without using a GPU-based sparse triangular
3321  // solve to implement Gauss-Seidel. This exists in cuSPARSE,
3322  // but we would need to implement a wrapper with a fall-back
3323  // algorithm for unsupported Scalar and LO types.
3324  KokkosSparse::Impl::Sequential::gaussSeidel (static_cast<LO> (lclNumRows),
3325  static_cast<LO> (numVecs),
3326  ptrRaw, indRaw, valRaw,
3327  B_lcl.data (), B_stride[1],
3328  X_lcl.data (), X_stride[1],
3329  D_lcl.data (),
3330  static_cast<impl_scalar_type> (dampingFactor),
3331  dir.c_str ());
3332  const_cast<DMV&> (B).template sync<dev_mem_space> ();
3333  X.template sync<dev_mem_space> ();
3334  const_cast<MMV&> (D).template sync<dev_mem_space> ();
3335  }
3336 
3363  template <class DomainScalar, class RangeScalar>
3364  void
3368  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
3369  const RangeScalar& dampingFactor,
3370  const ESweepDirection direction) const
3371  {
3372  typedef LocalOrdinal LO;
3373  typedef GlobalOrdinal GO;
3376  typedef typename Node::device_type::memory_space dev_mem_space;
3377  typedef typename MMV::dual_view_type::t_host::device_type host_mem_space;
3378  typedef typename Graph::local_graph_type k_local_graph_type;
3379  typedef typename k_local_graph_type::size_type offset_type;
3380  const char prefix[] = "Tpetra::CrsMatrix::reorderedLocalGaussSeidel: ";
3381 
3382  TEUCHOS_TEST_FOR_EXCEPTION
3383  (! this->isFillComplete (), std::runtime_error,
3384  prefix << "The matrix is not fill complete.");
3385  const size_t lclNumRows = this->getNodeNumRows ();
3386  const size_t numVecs = B.getNumVectors ();
3387  TEUCHOS_TEST_FOR_EXCEPTION
3388  (X.getNumVectors () != numVecs, std::invalid_argument,
3389  prefix << "B.getNumVectors() = " << numVecs << " != "
3390  "X.getNumVectors() = " << X.getNumVectors () << ".");
3391  TEUCHOS_TEST_FOR_EXCEPTION
3392  (B.getLocalLength () != lclNumRows, std::invalid_argument,
3393  prefix << "B.getLocalLength() = " << B.getLocalLength ()
3394  << " != this->getNodeNumRows() = " << lclNumRows << ".");
3395  TEUCHOS_TEST_FOR_EXCEPTION
3396  (static_cast<size_t> (rowIndices.size ()) < lclNumRows,
3397  std::invalid_argument, prefix << "rowIndices.size() = "
3398  << rowIndices.size () << " < this->getNodeNumRows() = "
3399  << lclNumRows << ".");
3400 
3401  // mfh 28 Aug 2017: The current local Gauss-Seidel kernel only
3402  // runs on host. (See comments below.) Thus, we need to access
3403  // the host versions of these data.
3404  const_cast<DMV&> (B).sync_host ();
3405  X.sync_host ();
3406  X.modify_host ();
3407  const_cast<MMV&> (D).sync_host ();
3408 
3409  auto B_lcl = B.template getLocalView<host_mem_space> ();
3410  auto X_lcl = X.template getLocalView<host_mem_space> ();
3411  auto D_lcl = D.template getLocalView<host_mem_space> ();
3412 
3413  offset_type B_stride[8], X_stride[8], D_stride[8];
3414  B_lcl.stride (B_stride);
3415  X_lcl.stride (X_stride);
3416  D_lcl.stride (D_stride);
3417 
3418  local_matrix_type lclMatrix = this->getLocalMatrix ();
3419  typename Graph::local_graph_type lclGraph = lclMatrix.graph;
3420  typename local_matrix_type::index_type ind = lclGraph.entries;
3421  typename local_matrix_type::row_map_type ptr = lclGraph.row_map;
3422  typename local_matrix_type::values_type val = lclMatrix.values;
3423  const offset_type* const ptrRaw = ptr.data ();
3424  const LO* const indRaw = ind.data ();
3425  const impl_scalar_type* const valRaw = val.data ();
3426 
3427  const std::string dir = (direction == Forward) ? "F" : "B";
3428  // NOTE (mfh 28 Aug 2017) This assumes UVM. We can't get around
3429  // that on GPUs without using a GPU-based sparse triangular
3430  // solve to implement Gauss-Seidel, and also handling the
3431  // permutations correctly.
3432  KokkosSparse::Impl::Sequential::reorderedGaussSeidel (static_cast<LO> (lclNumRows),
3433  static_cast<LO> (numVecs),
3434  ptrRaw, indRaw, valRaw,
3435  B_lcl.data (),
3436  B_stride[1],
3437  X_lcl.data (),
3438  X_stride[1],
3439  D_lcl.data (),
3440  rowIndices.getRawPtr (),
3441  static_cast<LO> (lclNumRows),
3442  static_cast<impl_scalar_type> (dampingFactor),
3443  dir.c_str ());
3444  const_cast<DMV&> (B).template sync<dev_mem_space> ();
3445  X.template sync<dev_mem_space> ();
3446  const_cast<MMV&> (D).template sync<dev_mem_space> ();
3447  }
3448 
3451  template <class T>
3452  Teuchos::RCP<CrsMatrix<T, LocalOrdinal, GlobalOrdinal, Node> >
3453  convert () const;
3454 
3456 
3458 
3469  void
3472  Teuchos::ETransp mode = Teuchos::NO_TRANS,
3473  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
3474  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const override;
3475 
3478  bool hasTransposeApply () const override;
3479 
3486  Teuchos::RCP<const map_type> getDomainMap () const override;
3487 
3494  Teuchos::RCP<const map_type> getRangeMap () const override;
3495 
3497 
3499 
3564  void
3568  const Scalar& dampingFactor,
3569  const ESweepDirection direction,
3570  const int numSweeps) const;
3571 
3638  void
3642  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
3643  const Scalar& dampingFactor,
3644  const ESweepDirection direction,
3645  const int numSweeps) const;
3646 
3675  void
3679  const Scalar& dampingFactor,
3680  const ESweepDirection direction,
3681  const int numSweeps,
3682  const bool zeroInitialGuess) const;
3683 
3713  void
3717  const Teuchos::ArrayView<LocalOrdinal>& rowIndices,
3718  const Scalar& dampingFactor,
3719  const ESweepDirection direction,
3720  const int numSweeps,
3721  const bool zeroInitialGuess) const;
3722 
3733  virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
3734  add (const Scalar& alpha,
3736  const Scalar& beta,
3737  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap,
3738  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap,
3739  const Teuchos::RCP<Teuchos::ParameterList>& params) const override;
3740 
3742 
3744 
3746  std::string description () const override;
3747 
3750  void
3751  describe (Teuchos::FancyOStream& out,
3752  const Teuchos::EVerbosityLevel verbLevel =
3753  Teuchos::Describable::verbLevel_default) const override;
3754 
3756 
3758 
3763  typedef typename DistObject<Scalar, LocalOrdinal, GlobalOrdinal,
3765 
3766  virtual bool
3767  checkSizes (const SrcDistObject& source) override;
3768 
3769  void
3770  applyCrsPadding(const Kokkos::UnorderedMap<LocalOrdinal, size_t, device_type>& padding);
3771 
3772  private:
3773  void
3774  copyAndPermuteImpl (const RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& source,
3775  const size_t numSameIDs,
3776  const LocalOrdinal permuteToLIDs[],
3777  const LocalOrdinal permuteFromLIDs[],
3778  const size_t numPermutes);
3779  protected:
3780  virtual void
3781 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
3782  copyAndPermuteNew
3783 #else // TPETRA_ENABLE_DEPRECATED_CODE
3784  copyAndPermute
3785 #endif // TPETRA_ENABLE_DEPRECATED_CODE
3786  (const SrcDistObject& source,
3787  const size_t numSameIDs,
3788  const Kokkos::DualView<
3789  const local_ordinal_type*,
3790  buffer_device_type>& permuteToLIDs,
3791  const Kokkos::DualView<
3792  const local_ordinal_type*,
3793  buffer_device_type>& permuteFromLIDs) override;
3794 
3795  virtual void
3796 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
3797  packAndPrepareNew
3798 #else // TPETRA_ENABLE_DEPRECATED_CODE
3799  packAndPrepare
3800 #endif // TPETRA_ENABLE_DEPRECATED_CODE
3801  (const SrcDistObject& source,
3802  const Kokkos::DualView<
3803  const local_ordinal_type*,
3804  buffer_device_type>& exportLIDs,
3805  Kokkos::DualView<char*, buffer_device_type>& exports,
3806  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3807  size_t& constantNumPackets,
3808  Distributor& distor) override;
3809 
3810  private:
3813  void
3814  unpackAndCombineImpl (const Kokkos::DualView<const local_ordinal_type*,
3815  buffer_device_type>& importLIDs,
3816  const Kokkos::DualView<const char*,
3817  buffer_device_type>& imports,
3818  const Kokkos::DualView<const size_t*,
3819  buffer_device_type>& numPacketsPerLID,
3820  const size_t constantNumPackets,
3821  Distributor& distor,
3822  const CombineMode combineMode,
3823  const bool atomic = useAtomicUpdatesByDefault);
3824 
3827  void
3828  unpackAndCombineImplNonStatic (const Kokkos::DualView<const local_ordinal_type*,
3829  buffer_device_type>& importLIDs,
3830  const Kokkos::DualView<const char*,
3831  buffer_device_type>& imports,
3832  const Kokkos::DualView<const size_t*,
3833  buffer_device_type>& numPacketsPerLID,
3834  const size_t constantNumPackets,
3835  Distributor& distor,
3836  const CombineMode combineMode);
3837 
3838  public:
3848  void
3849 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
3850  unpackAndCombineNew
3851 #else // TPETRA_ENABLE_DEPRECATED_CODE
3853 #endif // TPETRA_ENABLE_DEPRECATED_CODE
3854  (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& importLIDs,
3855  Kokkos::DualView<char*, buffer_device_type> imports,
3856  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
3857  const size_t constantNumPackets,
3858  Distributor& distor,
3859  const CombineMode CM) override;
3860 
3968  void
3969  packNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3970  Kokkos::DualView<char*, buffer_device_type>& exports,
3971  const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3972  size_t& constantNumPackets,
3973  Distributor& dist) const;
3974 
3975  private:
3982  void
3983  packNonStaticNew (const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
3984  Kokkos::DualView<char*, buffer_device_type>& exports,
3985  const Kokkos::DualView<size_t*, buffer_device_type>& numPacketsPerLID,
3986  size_t& constantNumPackets,
3987  Distributor& distor) const;
3988 
4018  size_t
4019  packRow (char exports[],
4020  const size_t offset,
4021  const size_t numEnt,
4022  const GlobalOrdinal gidsIn[],
4023  const impl_scalar_type valsIn[],
4024  const size_t numBytesPerValue) const;
4025 
4049  bool
4050  packRowStatic (char* const numEntOut,
4051  char* const valOut,
4052  char* const indOut,
4053  const size_t numEnt,
4054  const LocalOrdinal lclRow) const;
4055 
4081  size_t
4082  unpackRow (GlobalOrdinal gidsOut[],
4083  impl_scalar_type valsOut[],
4084  const char imports[],
4085  const size_t offset,
4086  const size_t numBytes,
4087  const size_t numEnt,
4088  const size_t numBytesPerValue);
4089 
4098  void
4099  allocatePackSpaceNew (Kokkos::DualView<char*, buffer_device_type>& exports,
4100  size_t& totalNumEntries,
4101  const Kokkos::DualView<const local_ordinal_type*,
4102  buffer_device_type>& exportLIDs) const;
4104 
4105  public:
4107  typename local_matrix_type::values_type getLocalValuesView () const {
4108  return k_values1D_;
4109  }
4110 
4111  private:
4112  // Friend declaration for nonmember function.
4113  template<class CrsMatrixType>
4114  friend Teuchos::RCP<CrsMatrixType>
4115  Tpetra::importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4116  const Import<typename CrsMatrixType::local_ordinal_type,
4117  typename CrsMatrixType::global_ordinal_type,
4118  typename CrsMatrixType::node_type>& importer,
4119  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4120  typename CrsMatrixType::global_ordinal_type,
4121  typename CrsMatrixType::node_type> >& domainMap,
4122  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4123  typename CrsMatrixType::global_ordinal_type,
4124  typename CrsMatrixType::node_type> >& rangeMap,
4125  const Teuchos::RCP<Teuchos::ParameterList>& params);
4126 
4127  // Friend declaration for nonmember function.
4128  template<class CrsMatrixType>
4129  friend Teuchos::RCP<CrsMatrixType>
4130  Tpetra::importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4131  const Import<typename CrsMatrixType::local_ordinal_type,
4132  typename CrsMatrixType::global_ordinal_type,
4133  typename CrsMatrixType::node_type>& rowImporter,
4134  const Import<typename CrsMatrixType::local_ordinal_type,
4135  typename CrsMatrixType::global_ordinal_type,
4136  typename CrsMatrixType::node_type>& domainImporter,
4137  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4138  typename CrsMatrixType::global_ordinal_type,
4139  typename CrsMatrixType::node_type> >& domainMap,
4140  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4141  typename CrsMatrixType::global_ordinal_type,
4142  typename CrsMatrixType::node_type> >& rangeMap,
4143  const Teuchos::RCP<Teuchos::ParameterList>& params);
4144 
4145 
4146  // Friend declaration for nonmember function.
4147  template<class CrsMatrixType>
4148  friend Teuchos::RCP<CrsMatrixType>
4149  Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4150  const Export<typename CrsMatrixType::local_ordinal_type,
4151  typename CrsMatrixType::global_ordinal_type,
4152  typename CrsMatrixType::node_type>& exporter,
4153  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4154  typename CrsMatrixType::global_ordinal_type,
4155  typename CrsMatrixType::node_type> >& domainMap,
4156  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4157  typename CrsMatrixType::global_ordinal_type,
4158  typename CrsMatrixType::node_type> >& rangeMap,
4159  const Teuchos::RCP<Teuchos::ParameterList>& params);
4160 
4161  // Friend declaration for nonmember function.
4162  template<class CrsMatrixType>
4163  friend Teuchos::RCP<CrsMatrixType>
4164  Tpetra::exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4165  const Export<typename CrsMatrixType::local_ordinal_type,
4166  typename CrsMatrixType::global_ordinal_type,
4167  typename CrsMatrixType::node_type>& rowExporter,
4168  const Export<typename CrsMatrixType::local_ordinal_type,
4169  typename CrsMatrixType::global_ordinal_type,
4170  typename CrsMatrixType::node_type>& domainExporter,
4171  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4172  typename CrsMatrixType::global_ordinal_type,
4173  typename CrsMatrixType::node_type> >& domainMap,
4174  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4175  typename CrsMatrixType::global_ordinal_type,
4176  typename CrsMatrixType::node_type> >& rangeMap,
4177  const Teuchos::RCP<Teuchos::ParameterList>& params);
4178 
4179  public:
4195  void
4197  const import_type& importer,
4198  const Teuchos::RCP<const map_type>& domainMap,
4199  const Teuchos::RCP<const map_type>& rangeMap,
4200  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
4201 
4217  void
4219  const import_type& rowImporter,
4220  const import_type& domainImporter,
4221  const Teuchos::RCP<const map_type>& domainMap,
4222  const Teuchos::RCP<const map_type>& rangeMap,
4223  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
4224 
4225 
4241  void
4243  const export_type& exporter,
4244  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
4245  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
4246  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
4247 
4263  void
4265  const export_type& rowExporter,
4266  const export_type& domainExporter,
4267  const Teuchos::RCP<const map_type>& domainMap,
4268  const Teuchos::RCP<const map_type>& rangeMap,
4269  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
4270 
4271 
4272  private:
4293  void
4294  transferAndFillComplete (Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& destMatrix,
4295  const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node>& rowTransfer,
4296  const Teuchos::RCP<const ::Tpetra::Details::Transfer<LocalOrdinal, GlobalOrdinal, Node> > & domainTransfer,
4297  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
4298  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
4299  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
4300 
4312  void
4313  insertGlobalValuesImpl (crs_graph_type& graph,
4314  RowInfo& rowInfo,
4315  const GlobalOrdinal gblColInds[],
4316  const impl_scalar_type vals[],
4317  const size_t numInputEnt);
4318 
4328  void
4329  insertGlobalValuesFiltered (const GlobalOrdinal globalRow,
4330  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
4331  const Teuchos::ArrayView<const Scalar>& values);
4332 
4344  void
4345  combineGlobalValues (const GlobalOrdinal globalRowIndex,
4346  const Teuchos::ArrayView<const GlobalOrdinal>& columnIndices,
4347  const Teuchos::ArrayView<const Scalar>& values,
4348  const Tpetra::CombineMode combineMode);
4349 
4367  LocalOrdinal
4368  combineGlobalValuesRaw (const LocalOrdinal lclRow,
4369  const LocalOrdinal numEnt,
4370  const impl_scalar_type vals[],
4371  const GlobalOrdinal cols[],
4372  const Tpetra::CombineMode combineMode);
4373 
4385  template<class BinaryFunction>
4386  LocalOrdinal
4387  transformGlobalValues (const GlobalOrdinal globalRow,
4388  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
4389  const Teuchos::ArrayView<const Scalar>& values,
4390  BinaryFunction f,
4391  const bool atomic = useAtomicUpdatesByDefault) const
4392  {
4393  typedef impl_scalar_type IST;
4394  typedef LocalOrdinal LO;
4395  typedef GlobalOrdinal GO;
4396 
4397  const LO numInputEnt = static_cast<LO> (indices.size ());
4398  if (static_cast<LO> (values.size ()) != numInputEnt) {
4399  return Teuchos::OrdinalTraits<LO>::invalid ();
4400  }
4401 
4402  const GO* const inputCols = indices.getRawPtr ();
4403  const IST* const inputVals =
4404  reinterpret_cast<const IST*> (values.getRawPtr ());
4405  return this->transformGlobalValues (globalRow, numInputEnt, inputVals,
4406  inputCols, f, atomic);
4407  }
4408 
4415  void
4416  insertNonownedGlobalValues (const GlobalOrdinal globalRow,
4417  const Teuchos::ArrayView<const GlobalOrdinal>& indices,
4418  const Teuchos::ArrayView<const Scalar>& values);
4419 
4462  void
4463  insertIndicesAndValues (crs_graph_type& graph,
4464  RowInfo& rowInfo,
4465  const typename crs_graph_type::SLocalGlobalViews& newInds,
4466  const Teuchos::ArrayView<impl_scalar_type>& oldRowVals,
4467  const Teuchos::ArrayView<const impl_scalar_type>& newRowVals,
4468  const ELocalGlobal lg,
4469  const ELocalGlobal I);
4470 
4472  typedef DistObject<char, LocalOrdinal, GlobalOrdinal, Node> dist_object_type;
4473 
4474  protected:
4475  // useful typedefs
4476  typedef Teuchos::OrdinalTraits<LocalOrdinal> OTL;
4477  typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
4478  typedef Kokkos::Details::ArithTraits<mag_type> STM;
4479  typedef MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> MV;
4480  typedef Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> V;
4481  typedef crs_graph_type Graph;
4482 
4483  // Enums
4484  enum GraphAllocationStatus {
4485  GraphAlreadyAllocated,
4486  GraphNotYetAllocated
4487  };
4488 
4489  private:
4493  Teuchos::ArrayRCP<Teuchos::Array<impl_scalar_type> >
4494  allocateValues2D ();
4495 
4496  protected:
4513  void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas);
4514 
4524  size_t
4526  const RowInfo& rowInfo);
4527 
4542  void
4543  sortAndMergeIndicesAndValues (const bool sorted,
4544  const bool merged);
4545 
4553  void clearGlobalConstants();
4554 
4562  public:
4564  void computeGlobalConstants();
4566  bool haveGlobalConstants() const;
4567  protected:
4580  mutable Teuchos::RCP<MV> importMV_;
4581 
4594  mutable Teuchos::RCP<MV> exportMV_;
4595 
4615  Teuchos::RCP<MV>
4616  getColumnMapMultiVector (const MV& X_domainMap,
4617  const bool force = false) const;
4618 
4640  Teuchos::RCP<MV>
4641  getRowMapMultiVector (const MV& Y_rangeMap,
4642  const bool force = false) const;
4643 
4645  void
4646  applyNonTranspose (const MV& X_in,
4647  MV& Y_in,
4648  Scalar alpha,
4649  Scalar beta) const;
4650 
4652  void
4653  applyTranspose (const MV& X_in,
4654  MV& Y_in,
4655  const Teuchos::ETransp mode,
4656  Scalar alpha,
4657  Scalar beta) const;
4658 
4659  // matrix data accessors
4660 
4679  LocalOrdinal
4680  getViewRawConst (const impl_scalar_type*& vals,
4681  LocalOrdinal& numEnt,
4682  const RowInfo& rowinfo) const;
4683 
4702  LocalOrdinal
4703  getViewRaw (impl_scalar_type*& vals,
4704  LocalOrdinal& numEnt,
4705  const RowInfo& rowinfo) const;
4706 
4714  Teuchos::ArrayView<const impl_scalar_type> getView (RowInfo rowinfo) const;
4715 
4727  Teuchos::ArrayView<impl_scalar_type>
4728  getViewNonConst (const RowInfo& rowinfo) const;
4729 
4730  private:
4738  Kokkos::View<const impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
4739  getRowView (const RowInfo& rowInfo) const;
4740 
4752  Kokkos::View<impl_scalar_type*, execution_space, Kokkos::MemoryUnmanaged>
4753  getRowViewNonConst (const RowInfo& rowInfo) const;
4754 
4755 
4756  protected:
4757 
4758  // Friend the tester for CrsMatrix::swap
4759  friend class Tpetra::crsMatrix_Swap_Tester<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
4760 
4765 
4766 
4767  protected:
4768 
4774  void fillLocalMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4775 
4781  void fillLocalGraphAndMatrix (const Teuchos::RCP<Teuchos::ParameterList>& params);
4782 
4784  void checkInternalState () const;
4785 
4797 
4798  Teuchos::RCP<const Graph> staticGraph_;
4799  Teuchos::RCP< Graph> myGraph_;
4801 
4802  using local_multiply_op_type =
4804  scalar_type,
4805  device_type>;
4807  std::shared_ptr<local_multiply_op_type> lclMatrix_;
4808 
4821 
4822  typename local_matrix_type::values_type k_values1D_;
4823  Teuchos::ArrayRCP<Teuchos::Array<impl_scalar_type> > values2D_;
4825 
4836 
4839 
4867  std::map<GlobalOrdinal, std::pair<Teuchos::Array<GlobalOrdinal>,
4868  Teuchos::Array<Scalar> > > nonlocals_;
4869 
4876 
4877  public:
4878  // FIXME (mfh 24 Feb 2014) Is it _really_ necessary to make this a
4879  // public inner class of CrsMatrix? It looks like it doesn't
4880  // depend on any implementation details of CrsMatrix at all. It
4881  // should really be declared and defined outside of CrsMatrix.
4882  template<class ViewType, class OffsetViewType>
4883  struct pack_functor {
4884  typedef typename ViewType::execution_space execution_space;
4885  ViewType src_;
4886  ViewType dst_;
4887  OffsetViewType src_offset_;
4888  OffsetViewType dst_offset_;
4889  typedef typename OffsetViewType::non_const_value_type scalar_index_type;
4890 
4891  pack_functor (ViewType dst, ViewType src,
4892  OffsetViewType dst_offset, OffsetViewType src_offset) :
4893  src_ (src),
4894  dst_ (dst),
4895  src_offset_ (src_offset),
4896  dst_offset_ (dst_offset)
4897  {}
4898 
4899  KOKKOS_INLINE_FUNCTION
4900  void operator () (const LocalOrdinal row) const {
4901  scalar_index_type srcPos = src_offset_(row);
4902  const scalar_index_type dstEnd = dst_offset_(row+1);
4903  scalar_index_type dstPos = dst_offset_(row);
4904  for ( ; dstPos < dstEnd; ++dstPos, ++srcPos) {
4905  dst_(dstPos) = src_(srcPos);
4906  }
4907  }
4908  };
4909  }; // class CrsMatrix
4910 
4919  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
4920  Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
4922  size_t maxNumEntriesPerRow = 0,
4923  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
4924  {
4926  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE;
4927  return Teuchos::rcp (new matrix_type (map, maxNumEntriesPerRow, pftype, params));
4928  }
4929 
4930  template<class CrsMatrixType>
4931  Teuchos::RCP<CrsMatrixType>
4932  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4933  const Import<typename CrsMatrixType::local_ordinal_type,
4934  typename CrsMatrixType::global_ordinal_type,
4935  typename CrsMatrixType::node_type>& importer,
4936  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4937  typename CrsMatrixType::global_ordinal_type,
4938  typename CrsMatrixType::node_type> >& domainMap,
4939  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4940  typename CrsMatrixType::global_ordinal_type,
4941  typename CrsMatrixType::node_type> >& rangeMap,
4942  const Teuchos::RCP<Teuchos::ParameterList>& params)
4943  {
4944  Teuchos::RCP<CrsMatrixType> destMatrix;
4945  sourceMatrix->importAndFillComplete (destMatrix, importer, domainMap, rangeMap, params);
4946  return destMatrix;
4947  }
4948 
4949  template<class CrsMatrixType>
4950  Teuchos::RCP<CrsMatrixType>
4951  importAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4952  const Import<typename CrsMatrixType::local_ordinal_type,
4953  typename CrsMatrixType::global_ordinal_type,
4954  typename CrsMatrixType::node_type>& rowImporter,
4955  const Import<typename CrsMatrixType::local_ordinal_type,
4956  typename CrsMatrixType::global_ordinal_type,
4957  typename CrsMatrixType::node_type>& domainImporter,
4958  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4959  typename CrsMatrixType::global_ordinal_type,
4960  typename CrsMatrixType::node_type> >& domainMap,
4961  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4962  typename CrsMatrixType::global_ordinal_type,
4963  typename CrsMatrixType::node_type> >& rangeMap,
4964  const Teuchos::RCP<Teuchos::ParameterList>& params)
4965  {
4966  Teuchos::RCP<CrsMatrixType> destMatrix;
4967  sourceMatrix->importAndFillComplete (destMatrix, rowImporter, domainImporter, domainMap, rangeMap, params);
4968  return destMatrix;
4969  }
4970 
4971  template<class CrsMatrixType>
4972  Teuchos::RCP<CrsMatrixType>
4973  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4974  const Export<typename CrsMatrixType::local_ordinal_type,
4975  typename CrsMatrixType::global_ordinal_type,
4976  typename CrsMatrixType::node_type>& exporter,
4977  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4978  typename CrsMatrixType::global_ordinal_type,
4979  typename CrsMatrixType::node_type> >& domainMap,
4980  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
4981  typename CrsMatrixType::global_ordinal_type,
4982  typename CrsMatrixType::node_type> >& rangeMap,
4983  const Teuchos::RCP<Teuchos::ParameterList>& params)
4984  {
4985  Teuchos::RCP<CrsMatrixType> destMatrix;
4986  sourceMatrix->exportAndFillComplete (destMatrix, exporter, domainMap, rangeMap, params);
4987  return destMatrix;
4988  }
4989 
4990  template<class CrsMatrixType>
4991  Teuchos::RCP<CrsMatrixType>
4992  exportAndFillCompleteCrsMatrix (const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
4993  const Export<typename CrsMatrixType::local_ordinal_type,
4994  typename CrsMatrixType::global_ordinal_type,
4995  typename CrsMatrixType::node_type>& rowExporter,
4996  const Export<typename CrsMatrixType::local_ordinal_type,
4997  typename CrsMatrixType::global_ordinal_type,
4998  typename CrsMatrixType::node_type>& domainExporter,
4999  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
5000  typename CrsMatrixType::global_ordinal_type,
5001  typename CrsMatrixType::node_type> >& domainMap,
5002  const Teuchos::RCP<const Map<typename CrsMatrixType::local_ordinal_type,
5003  typename CrsMatrixType::global_ordinal_type,
5004  typename CrsMatrixType::node_type> >& rangeMap,
5005  const Teuchos::RCP<Teuchos::ParameterList>& params)
5006  {
5007  Teuchos::RCP<CrsMatrixType> destMatrix;
5008  sourceMatrix->exportAndFillComplete (destMatrix, rowExporter, domainExporter, domainMap, rangeMap, params);
5009  return destMatrix;
5010  }
5011 } // namespace Tpetra
5012 
5020 #endif // TPETRA_CRSMATRIX_DECL_HPP
CrsMatrix & operator=(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &)=default
Copy assignment.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
bool hasColMap() const override
Whether the matrix has a well-defined column Map.
global_size_t getGlobalNumCols() const override
The number of global columns in the matrix.
void checkInternalState() const
Check that this object&#39;s state is sane; throw if it&#39;s not.
Abstract interface for local operators (e.g., matrices and preconditioners).
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
size_t getNodeNumCols() const override
The number of columns connected to the locally owned rows of this matrix.
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().
CrsGraph< LocalOrdinal, GlobalOrdinal, Node > crs_graph_type
The CrsGraph specialization suitable for this CrsMatrix specialization.
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the matrix&#39;s column Map with the given Map.
virtual bool supportsRowViews() const override
Return true if getLocalRowView() and getGlobalRowView() are valid for this object.
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 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.
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...
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 map_type > getRangeMap() const override
The range Map of this matrix.
global_size_t getGlobalNumRows() const override
Number of global elements in the row map of this matrix.
std::map< GlobalOrdinal, std::pair< Teuchos::Array< GlobalOrdinal >, Teuchos::Array< Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
void sortAndMergeIndicesAndValues(const bool sorted, const bool merged)
Sort and merge duplicate local column indices in all rows on the calling process, along with their co...
typename device_type::execution_space execution_space
The Kokkos execution space.
void getLocalRowCopy(LocalOrdinal localRow, const Teuchos::ArrayView< LocalOrdinal > &colInds, const Teuchos::ArrayView< Scalar > &vals, size_t &numEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row...
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Type of a norm result.
size_t getNumVectors() const
Number of columns in the multivector.
size_t getLocalLength() const
Local number of rows on the calling process.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to alpha.
One or more distributed dense vectors.
size_t getNodeNumEntries() const override
The local number of entries in this matrix.
void scale(const Scalar &alpha)
Scale the matrix&#39;s values: this := alpha*this.
size_t getNodeNumRows() const override
The number of matrix rows owned by the calling process.
void fillLocalGraphAndMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local graph and matrix.
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Resume operations that may change the values or structure of the matrix.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the left with the given Vector.
GlobalOrdinal global_ordinal_type
The type of each global index in the matrix.
Declaration and generic definition of traits class that tells Tpetra::CrsMatrix how to pack and unpac...
virtual ~CrsMatrix()=default
Destructor (virtual for memory safety of derived classes).
void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< char *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, Distributor &distor, const CombineMode CM) override
Unpack the imported column indices and values, and combine into matrix.
void reindexColumns(crs_graph_type *const graph, const Teuchos::RCP< const map_type > &newColMap, const Teuchos::RCP< const import_type > &newImport=Teuchos::null, const bool sortEachRow=true)
Reindex the column indices in place, and replace the column Map. Optionally, replace the Import objec...
Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization suitable for this CrsMatrix specialization.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const Teuchos::ArrayView< GlobalOrdinal > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const override
Fill given arrays with a deep copy of the locally owned entries of the matrix in a given row...
Teuchos::RCP< const crs_graph_type > getCrsGraph() const
This matrix&#39;s graph, as a CrsGraph.
size_t getGlobalMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, over all processes in the matrix&#39;s communicator...
void applyNonTranspose(const MV &X_in, MV &Y_in, Scalar alpha, Scalar beta) const
Special case of apply() for mode == Teuchos::NO_TRANS.
Teuchos::RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Return another CrsMatrix with the same entries, but converted to a different Scalar type T...
Scalar scalar_type
The type of each entry in the matrix.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
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.
void swap(CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &matrix)
Swaps the data from *this with the data and maps from crsMatrix.
void fillLocalMatrix(const Teuchos::RCP< Teuchos::ParameterList > &params)
Fill data into the local matrix.
void globalAssemble()
Communicate nonlocal contributions to other processes.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const override
Get a copy of the diagonal entries of the matrix.
std::shared_ptr< local_multiply_op_type > lclMatrix_
The local sparse matrix, wrapped in a multiply operator.
void gaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
&quot;Hybrid&quot; Jacobi + (Gauss-Seidel or SOR) on .
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > 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.
bool isFillActive() const
Whether the matrix is not fill complete.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply() and gaussSeidel().
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
size_t global_size_t
Global size_t object.
bool hasTransposeApply() const override
Whether apply() allows applying the transpose or conjugate transpose.
void clearGlobalConstants()
Clear matrix properties that require collectives.
void gaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of gaussSeidel(), with fewer requirements on X.
LocalOrdinal getLocalRowViewRaw(const LocalOrdinal lclRow, LocalOrdinal &numEnt, const LocalOrdinal *&lclColInds, const Scalar *&vals) const override
Get a constant, nonpersisting, locally indexed view of the given row of the matrix, using &quot;raw&quot; pointers instead of Teuchos::ArrayView.
LocalOrdinal transformLocalValues(const LocalOrdinal lclRow, 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...
void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas)
Allocate values (and optionally indices) using the Node.
void exportAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &destMatrix, const export_type &exporter, const Teuchos::RCP< const map_type > &domainMap=Teuchos::null, const Teuchos::RCP< const map_type > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Export from this to the given destination matrix, and make the result fill complete.
bool isFillComplete() const override
Whether the matrix is fill complete.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
The communicator over which the matrix is distributed.
void sync_host()
Synchronize to Host.
void importAndFillComplete(Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &destMatrix, const import_type &importer, const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Import from this to the given destination matrix, and make the result fill complete.
void packNew(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< char *, buffer_device_type > &exports, const Kokkos::DualView< size_t *, buffer_device_type > &numPacketsPerLID, size_t &constantNumPackets, Distributor &dist) const
Pack this object&#39;s data for an Import or Export.
void reorderedGaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &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.
ESweepDirection
Sweep direction for Gauss-Seidel or Successive Over-Relaxation (SOR).
GlobalOrdinal getIndexBase() const override
The index base for global indices for this matrix.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
typename crs_graph_type::local_graph_type local_graph_type
The part of the sparse matrix&#39;s graph on each MPI process.
Kokkos::StaticCrsGraph< local_ordinal_type, Kokkos::LayoutLeft, execution_space > local_graph_type
The type of the part of the sparse graph on each MPI process.
Node node_type
This class&#39; Kokkos Node type.
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
Sets up and executes a communication plan for a Tpetra DistObject.
mag_type frobNorm_
Cached Frobenius norm of the (global) matrix.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const override
Print this object with the given verbosity level to the given output stream.
Teuchos::RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const override
This matrix&#39;s graph, as a RowGraph.
CombineMode
Rule for combining data in an Import or Export.
DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node >::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
CrsGraphType::global_ordinal_type getGlobalNumDiags(const CrsGraphType &G)
Number of populated diagonal entries in the given sparse graph, over all processes in the graph&#39;s (MP...
bool isGloballyIndexed() const override
Whether the matrix is globally indexed on the calling process.
Forward declaration of Tpetra::CrsMatrix.
LocalOrdinal sumIntoGlobalValues(const GlobalOrdinal globalRow, const Teuchos::ArrayView< const GlobalOrdinal > &cols, const Teuchos::ArrayView< const Scalar > &vals, const bool atomic=useAtomicUpdatesByDefault)
Sum into one or more sparse matrix entries, using global indices.
void localGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const RangeScalar &dampingFactor, const ESweepDirection direction) const
Gauss-Seidel or SOR on .
bool fillComplete_
Whether the matrix is fill complete.
virtual Teuchos::RCP< RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > add(const Scalar &alpha, const RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params) const override
Implementation of RowMatrix::add: return alpha*A + beta*this.
Abstract base class for objects that can be the source of an Import or Export operation.
typename Node::device_type device_type
The Kokkos device type.
size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override
Number of entries in the sparse matrix in the given local row, on the calling (MPI) process...
Teuchos::RCP< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
std::string description() const override
A one-line description of this object.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const override
Compute a sparse matrix-MultiVector multiply.
void computeGlobalConstants()
Compute matrix properties that require collectives.
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 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 modify_host()
Mark data as modified on the host side.
local_matrix_type::values_type getLocalValuesView() const
Get the Kokkos local values.
ProfileType getProfileType() const
Returns true if the matrix was allocated with static data structures.
void getGlobalRowView(GlobalOrdinal GlobalRow, Teuchos::ArrayView< const GlobalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const override
Get a constant, nonpersisting view of a row of this matrix, using global row and column indices...
LocalOrdinal transformGlobalValues(const GlobalOrdinal gblRow, const Kokkos::View< const GlobalOrdinal *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputInds, const Kokkos::View< const impl_scalar_type *, InputMemorySpace, Kokkos::MemoryUnmanaged > &inputVals, BinaryFunction f, const bool atomic=useAtomicUpdatesByDefault) const
Transform CrsMatrix entries in place, using global indices to select the entries in the row to transf...
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap) override
Remove processes owning zero rows from the Maps and their communicator.
virtual bool checkSizes(const SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
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.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
A parallel distribution of indices over processes.
Teuchos::RCP< const map_type > getDomainMap() const override
The domain Map of this matrix.
Teuchos::ArrayView< const impl_scalar_type > getView(RowInfo rowinfo) const
Constant view of all entries (including extra space) in the given row.
KokkosSparse::CrsMatrix< impl_scalar_type, local_ordinal_type, 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...
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.
A read-only, row-oriented interface to a sparse matrix.
local_matrix_type getLocalMatrix() const
The local sparse matrix.
void getLocalRowView(LocalOrdinal LocalRow, Teuchos::ArrayView< const LocalOrdinal > &indices, Teuchos::ArrayView< const Scalar > &values) const override
Get a constant, nonpersisting view of a row of this matrix, using local row and column indices...
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x) override
Scale the matrix on the right with the given Vector.
size_t getNodeMaxNumRowEntries() const override
Maximum number of entries in any row of the matrix, on this process.
A distributed dense vector.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &importer, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
void applyTranspose(const MV &X_in, MV &Y_in, const Teuchos::ETransp mode, Scalar alpha, Scalar beta) const
Special case of apply() for mode != Teuchos::NO_TRANS.
void 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.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const override
Number of entries in the sparse matrix in the given global row, on the calling (MPI) process...
size_t mergeRowIndicesAndValues(crs_graph_type &graph, const RowInfo &rowInfo)
Merge duplicate row indices in the given row, along with their corresponding values.
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.
bool isLocallyIndexed() const override
Whether the matrix is locally indexed on the calling process.
Teuchos::RCP< const map_type > getColMap() const override
The Map that describes the column distribution in this matrix.
void reorderedGaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
Reordered &quot;Hybrid&quot; Jacobi + (Gauss-Seidel or SOR) on .
Teuchos::ArrayView< impl_scalar_type > getViewNonConst(const RowInfo &rowinfo) const
Nonconst view of all entries (including extra space) in the given row.
Base class for distributed Tpetra objects that support data redistribution.
LocalOrdinal local_ordinal_type
The type of each local index in the matrix.
EStorageStatus
Status of the graph&#39;s or matrix&#39;s storage, when not in a fill-complete state.
mag_type getFrobeniusNorm() const override
Compute and return the Frobenius norm of the matrix.
::Tpetra::Details::EStorageStatus storageStatus_
Status of the matrix&#39;s storage, when not in a fill-complete state.
void localApply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, const Teuchos::ETransp mode=Teuchos::NO_TRANS, const Scalar &alpha=Teuchos::ScalarTraits< Scalar >::one(), const Scalar &beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Compute the local part of a sparse matrix-(Multi)Vector multiply.
void reorderedLocalGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Teuchos::ArrayView< LocalOrdinal > &rowIndices, const RangeScalar &dampingFactor, const ESweepDirection direction) const
Reordered Gauss-Seidel or SOR on .
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.
bool isStorageOptimized() const
Returns true if storage has been optimized.
Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization suitable for this CrsMatrix specialization.
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
Teuchos::RCP< const map_type > getRowMap() const override
The Map that describes the row distribution in this matrix.
global_size_t getGlobalNumEntries() const override
The global number of entries in this matrix.