Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_CrsGraph_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // clang-format off
11 #ifndef TPETRA_CRSGRAPH_DECL_HPP
12 #define TPETRA_CRSGRAPH_DECL_HPP
13 
16 
17 #include "Tpetra_CrsGraph_fwd.hpp"
18 #include "Tpetra_CrsMatrix_fwd.hpp"
20 #include "Tpetra_DistObject.hpp"
21 #include "Tpetra_Exceptions.hpp"
22 #include "Tpetra_RowGraph.hpp"
23 #include "Tpetra_Util.hpp" // need this here for sort2
24 #include "Tpetra_Details_WrappedDualView.hpp"
25 
26 #include "KokkosSparse_findRelOffset.hpp"
27 #include "Kokkos_DualView.hpp"
28 
29 #include "Teuchos_CommHelpers.hpp"
30 #include "Teuchos_Describable.hpp"
31 #include "Teuchos_OrdinalTraits.hpp"
32 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
33 
34 #include "KokkosSparse_StaticCrsGraph.hpp"
35 
36 #include <functional> // std::function
37 #include <memory>
38 
39 namespace Tpetra {
40 
41 
42  // Forward declaration for CrsGraph::swap() test
43  template<class LocalOrdinal, class GlobalOrdinal, class Node> class crsGraph_Swap_Tester;
44 
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
46  namespace Details {
47  template<class LocalOrdinal,
48  class GlobalOrdinal>
49  class CrsPadding;
50  } // namespace Details
51 
52  namespace { // (anonymous)
53 
54  template<class ViewType>
55  struct UnmanagedView {
56  static_assert (Kokkos::is_view<ViewType>::value,
57  "ViewType must be a Kokkos::View specialization.");
58  // FIXME (mfh 02 Dec 2015) Right now, this strips away other
59  // memory traits. Christian will add an "AllTraits" enum which is
60  // the enum value of MemoryTraits<T>, that will help us fix this.
61  typedef Kokkos::View<typename ViewType::data_type,
62  typename ViewType::array_layout,
63  typename ViewType::device_type,
64  Kokkos::MemoryUnmanaged> type;
65  };
66 
67  } // namespace (anonymous)
68 #endif // DOXYGEN_SHOULD_SKIP_THIS
69 
78  struct RowInfo {
79  size_t localRow;
80  size_t allocSize;
81  size_t numEntries;
82  size_t offset1D;
83  };
84 
85  enum ELocalGlobal {
86  LocalIndices,
87  GlobalIndices
88  };
89 
90  namespace Details {
122  STORAGE_1D_UNPACKED, //<! 1-D "unpacked" storage
123  STORAGE_1D_PACKED, //<! 1-D "packed" storage
124  STORAGE_UB //<! Invalid value; upper bound on enum values
125  };
126 
127  } // namespace Details
128 
187  template <class LocalOrdinal,
188  class GlobalOrdinal,
189  class Node>
190  class CrsGraph :
191  public RowGraph<LocalOrdinal, GlobalOrdinal, Node>,
192  public DistObject<GlobalOrdinal,
193  LocalOrdinal,
194  GlobalOrdinal,
195  Node>,
196  public Teuchos::ParameterListAcceptorDefaultBase
197  {
198  template <class S, class LO, class GO, class N>
199  friend class CrsMatrix;
200  template <class LO2, class GO2, class N2>
201  friend class CrsGraph;
202  template <class LO, class GO, class N>
203  friend class FECrsGraph;
204 
207 
208  public:
210  using local_ordinal_type = LocalOrdinal;
212  using global_ordinal_type = GlobalOrdinal;
214  using device_type = typename Node::device_type;
216  using execution_space = typename device_type::execution_space;
217 
222  using node_type = Node;
223 
226  KokkosSparse::StaticCrsGraph<local_ordinal_type, Kokkos::LayoutLeft,
227  device_type, void, size_t>;
228 
230 #if KOKKOS_VERSION >= 40799
231  using local_graph_host_type = typename local_graph_device_type::host_mirror_type;
232 #else
233  using local_graph_host_type = typename local_graph_device_type::HostMirror;
234 #endif
235 
242 
243 public:
244  // Types used for CrsGraph's storage of local column indices
245  using local_inds_dualv_type =
246  Kokkos::DualView<local_ordinal_type*, device_type>;
247  using local_inds_wdv_type =
249 
250  // Types used for CrsGraph's storage of global column indices
251  using global_inds_dualv_type =
252  Kokkos::DualView<global_ordinal_type*, device_type>;
253  using global_inds_wdv_type =
255 
256 public:
258  using row_ptrs_device_view_type =
259  typename row_graph_type::row_ptrs_device_view_type;
260  using row_ptrs_host_view_type =
261  typename row_graph_type::row_ptrs_host_view_type;
262 
265  typename row_graph_type::local_inds_device_view_type;
266  using local_inds_host_view_type =
267  typename row_graph_type::local_inds_host_view_type;
268  using nonconst_local_inds_host_view_type =
269  typename row_graph_type::nonconst_local_inds_host_view_type;
270 
273  typename row_graph_type::global_inds_device_view_type;
274  using global_inds_host_view_type =
275  typename row_graph_type::global_inds_host_view_type;
276  using nonconst_global_inds_host_view_type =
277  typename row_graph_type::nonconst_global_inds_host_view_type;
278 
279  using offset_device_view_type =
280  typename row_ptrs_device_view_type::non_const_type;
281 
283 
284 
297  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
298  const size_t maxNumEntriesPerRow,
299  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
300 
313  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
314  const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
315  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
316 
330  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
331  const Teuchos::ArrayView<const size_t>& numEntPerRow,
332  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
333 
334 
347 
351  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
352  const Teuchos::RCP<const map_type>& colMap,
353  const size_t maxNumEntriesPerRow,
354  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
355 
370  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
371  const Teuchos::RCP<const map_type>& colMap,
372  const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
373  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
374 
390  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
391  const Teuchos::RCP<const map_type>& colMap,
392  const Teuchos::ArrayView<const size_t>& numEntPerRow,
393  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
394 
395 
408  const Teuchos::RCP<const map_type>& rowMap,
409  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
410 
433  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
434  const Teuchos::RCP<const map_type>& colMap,
435  const typename local_graph_device_type::row_map_type& rowPointers,
436  const typename local_graph_device_type::entries_type::non_const_type& columnIndices,
437  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
438 
461  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
462  const Teuchos::RCP<const map_type>& colMap,
463  const Teuchos::ArrayRCP<size_t>& rowPointers,
464  const Teuchos::ArrayRCP<local_ordinal_type>& columnIndices,
465  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
466 
488  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
489  const Teuchos::RCP<const map_type>& colMap,
490  const local_graph_device_type& lclGraph,
491  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
492 
519  CrsGraph (const local_graph_device_type& lclGraph,
520  const Teuchos::RCP<const map_type>& rowMap,
521  const Teuchos::RCP<const map_type>& colMap,
522  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
523  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
524  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
525 
530  CrsGraph (const local_graph_device_type& lclGraph,
531  const Teuchos::RCP<const map_type>& rowMap,
532  const Teuchos::RCP<const map_type>& colMap,
533  const Teuchos::RCP<const map_type>& domainMap,
534  const Teuchos::RCP<const map_type>& rangeMap,
535  const Teuchos::RCP<const import_type>& importer,
536  const Teuchos::RCP<const export_type>& exporter,
537  const Teuchos::RCP<Teuchos::ParameterList>& params =
538  Teuchos::null);
539 
581  CrsGraph (const row_ptrs_device_view_type& rowPointers,
582  const local_inds_wdv_type& columnIndices,
583  const Teuchos::RCP<const map_type>& rowMap,
584  const Teuchos::RCP<const map_type>& colMap,
585  const Teuchos::RCP<const map_type>& domainMap,
586  const Teuchos::RCP<const map_type>& rangeMap,
587  const Teuchos::RCP<const import_type>& importer,
588  const Teuchos::RCP<const export_type>& exporter,
589  const Teuchos::RCP<Teuchos::ParameterList>& params =
590  Teuchos::null);
591 
594 
597 
600 
603 
613  virtual ~CrsGraph () = default;
614 
642 
660 
662 
664 
666  void
667  setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& params) override;
668 
670  Teuchos::RCP<const Teuchos::ParameterList>
671  getValidParameters () const override;
672 
674 
676 
698  void
699  insertGlobalIndices (const global_ordinal_type globalRow,
700  const Teuchos::ArrayView<const global_ordinal_type>& indices);
701 
708  void
709  insertGlobalIndices (const global_ordinal_type globalRow,
710  const local_ordinal_type numEnt,
711  const global_ordinal_type inds[]);
712 
714 
728  void
729  insertLocalIndices (const local_ordinal_type localRow,
730  const Teuchos::ArrayView<const local_ordinal_type>& indices);
731 
738  void
739  insertLocalIndices (const local_ordinal_type localRow,
740  const local_ordinal_type numEnt,
741  const local_ordinal_type inds[]);
742 
744 
753  void removeLocalIndices (local_ordinal_type localRow);
754 
756 
758 
766  void globalAssemble ();
767 
786  void
787  resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params =
788  Teuchos::null);
789 
827  void
828  fillComplete (const Teuchos::RCP<const map_type>& domainMap,
829  const Teuchos::RCP<const map_type>& rangeMap,
830  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
831 
859  void
860  fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
861 
890  void
891  expertStaticFillComplete (const Teuchos::RCP<const map_type>& domainMap,
892  const Teuchos::RCP<const map_type>& rangeMap,
893  const Teuchos::RCP<const import_type>& importer =
894  Teuchos::null,
895  const Teuchos::RCP<const export_type>& exporter =
896  Teuchos::null,
897  const Teuchos::RCP<Teuchos::ParameterList>& params =
898  Teuchos::null);
900 
902 
904  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const override;
905 
906 
908  Teuchos::RCP<const map_type> getRowMap () const override;
909 
911  Teuchos::RCP<const map_type> getColMap () const override;
912 
914  Teuchos::RCP<const map_type> getDomainMap () const override;
915 
917  Teuchos::RCP<const map_type> getRangeMap () const override;
918 
920  Teuchos::RCP<const import_type> getImporter () const override;
921 
923  Teuchos::RCP<const export_type> getExporter () const override;
924 
926 
928  global_size_t getGlobalNumRows() const override;
929 
931 
934  global_size_t getGlobalNumCols () const override;
935 
937  size_t getLocalNumRows () const override;
938 
940 
942  size_t getLocalNumCols () const override;
943 
945  global_ordinal_type getIndexBase () const override;
946 
948 
950  global_size_t getGlobalNumEntries () const override;
951 
961  size_t getLocalNumEntries() const override;
962 
964 
965  size_t
966  getNumEntriesInGlobalRow (global_ordinal_type globalRow) const override;
967 
974  size_t
975  getNumEntriesInLocalRow (local_ordinal_type localRow) const override;
976 
996  size_t getLocalAllocationSize () const;
997 
1005  size_t getNumAllocatedEntriesInGlobalRow (global_ordinal_type globalRow) const;
1006 
1014  size_t getNumAllocatedEntriesInLocalRow (local_ordinal_type localRow) const;
1015 
1029  size_t getGlobalMaxNumRowEntries () const override;
1030 
1035  size_t getLocalMaxNumRowEntries () const override;
1036 
1052  bool hasColMap () const override;
1053 
1054 
1062  bool isLocallyIndexed () const override;
1063 
1071  bool isGloballyIndexed () const override;
1072 
1074  bool isFillComplete () const override;
1075 
1077  bool isFillActive () const;
1078 
1086  bool isSorted () const;
1087 
1089 
1095  bool isStorageOptimized () const;
1096 
1097 
1103  void
1105  nonconst_global_inds_host_view_type &gblColInds,
1106  size_t& numColInds) const override;
1107 
1115  void
1117  nonconst_local_inds_host_view_type &gblColInds,
1118  size_t& numColInds) const override;
1119 
1130  void
1132  const global_ordinal_type gblRow,
1133  global_inds_host_view_type &gblColInds) const override;
1134 
1135 
1138  bool supportsRowViews () const override;
1139 
1140 
1151  void
1152  getLocalRowView (
1153  const LocalOrdinal lclRow,
1154  local_inds_host_view_type &lclColInds) const override;
1155 
1156 
1158 
1160 
1162  std::string description () const override;
1163 
1166  void
1167  describe (Teuchos::FancyOStream& out,
1168  const Teuchos::EVerbosityLevel verbLevel =
1169  Teuchos::Describable::verbLevel_default) const override;
1170 
1172 
1174 
1182 
1183  virtual bool
1184  checkSizes (const SrcDistObject& source) override;
1185 
1186  // clang-format on
1187  using dist_object_type::
1189  // clang-format off
1191 
1192  virtual void
1194  (const SrcDistObject& source,
1195  const size_t numSameIDs,
1196  const Kokkos::DualView<const local_ordinal_type*,
1197  buffer_device_type>& permuteToLIDs,
1198  const Kokkos::DualView<const local_ordinal_type*,
1199  buffer_device_type>& permuteFromLIDs,
1200  const CombineMode CM) override;
1201 
1204 
1205  void
1206  applyCrsPadding(const padding_type& padding,
1207  const bool verbose);
1208 
1209  std::unique_ptr<padding_type>
1210  computeCrsPadding(
1212  node_type>& source,
1213  const size_t numSameIDs,
1214  const Kokkos::DualView<const local_ordinal_type*,
1215  buffer_device_type>& permuteToLIDs,
1216  const Kokkos::DualView<const local_ordinal_type*,
1217  buffer_device_type>& permuteFromLIDs,
1218  const bool verbose) const;
1219 
1220  // This actually modifies imports by sorting it.
1221  std::unique_ptr<padding_type>
1222  computeCrsPaddingForImports(
1223  const Kokkos::DualView<const local_ordinal_type*,
1224  buffer_device_type>& importLIDs,
1225  Kokkos::DualView<packet_type*, buffer_device_type> imports,
1226  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1227  const bool verbose) const;
1228 
1229  std::unique_ptr<padding_type>
1230  computePaddingForCrsMatrixUnpack(
1231  const Kokkos::DualView<const local_ordinal_type*,
1232  buffer_device_type>& importLIDs,
1233  Kokkos::DualView<char*, buffer_device_type> imports,
1234  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1235  const bool verbose) const;
1236 
1237  void
1238  computeCrsPaddingForSameIDs(
1239  padding_type& padding,
1241  node_type>& source,
1242  const local_ordinal_type numSameIDs) const;
1243 
1244  void
1245  computeCrsPaddingForPermutedIDs(
1246  padding_type& padding,
1248  node_type>& source,
1249  const Kokkos::DualView<const local_ordinal_type*,
1250  buffer_device_type>& permuteToLIDs,
1251  const Kokkos::DualView<const local_ordinal_type*,
1252  buffer_device_type>& permuteFromLIDs) const;
1253 
1254  virtual void
1255  packAndPrepare(
1256  const SrcDistObject& source,
1257  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
1258  Kokkos::DualView<packet_type*, buffer_device_type>& exports,
1259  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1260  size_t& constantNumPackets) override;
1261 
1262  // clang-format on
1264  // clang-format off
1268 
1269  virtual void
1270  pack (const Teuchos::ArrayView<const local_ordinal_type>& exportLIDs,
1271  Teuchos::Array<global_ordinal_type>& exports,
1272  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1273  size_t& constantNumPackets) const override;
1274 
1275  void
1276  packFillActive (const Teuchos::ArrayView<const local_ordinal_type>& exportLIDs,
1277  Teuchos::Array<global_ordinal_type>& exports,
1278  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1279  size_t& constantNumPackets) const;
1280 
1281  void
1282  packFillActiveNew (const Kokkos::DualView<const local_ordinal_type*,
1283  buffer_device_type>& exportLIDs,
1284  Kokkos::DualView<packet_type*,
1285  buffer_device_type>& exports,
1286  Kokkos::DualView<size_t*,
1287  buffer_device_type> numPacketsPerLID,
1288  size_t& constantNumPackets) const;
1289 
1290  // clang-format on
1292  // clang-format off
1296 
1297  virtual void
1299  (const Kokkos::DualView<const local_ordinal_type*,
1300  buffer_device_type>& importLIDs,
1301  Kokkos::DualView<packet_type*,
1302  buffer_device_type> imports,
1303  Kokkos::DualView<size_t*,
1304  buffer_device_type> numPacketsPerLID,
1305  const size_t constantNumPackets,
1306  const CombineMode combineMode) override;
1307 
1309 
1311 
1354  void
1355  getLocalDiagOffsets (const Kokkos::View<size_t*, device_type, Kokkos::MemoryUnmanaged>& offsets) const;
1356 
1358  void
1359  getLocalOffRankOffsets (offset_device_view_type& offsets) const;
1360 
1370  void
1371  getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
1372 
1382  void
1383  setAllIndices (const typename local_graph_device_type::row_map_type& rowPointers,
1384  const typename local_graph_device_type::entries_type::non_const_type& columnIndices);
1385 
1395  void
1396  setAllIndices (const Teuchos::ArrayRCP<size_t> & rowPointers,
1397  const Teuchos::ArrayRCP<local_ordinal_type> & columnIndices);
1398 
1401  row_ptrs_host_view_type getLocalRowPtrsHost () const;
1402 
1405  row_ptrs_device_view_type getLocalRowPtrsDevice () const;
1406 
1408  local_inds_host_view_type getLocalIndicesHost () const;
1409 
1412 
1431  void replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
1432 
1452  void
1453  reindexColumns (const Teuchos::RCP<const map_type>& newColMap,
1454  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
1455  const bool sortIndicesInEachRow = true);
1456 
1463  void
1464  replaceDomainMap (const Teuchos::RCP<const map_type>& newDomainMap);
1465 
1479  void
1480  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
1481  const Teuchos::RCP<const import_type>& newImporter);
1482 
1489  void
1490  replaceRangeMap (const Teuchos::RCP<const map_type>& newRangeMap);
1491 
1505  void
1506  replaceRangeMapAndExporter (const Teuchos::RCP<const map_type>& newRangeMap,
1507  const Teuchos::RCP<const export_type>& newExporter);
1508 
1537  virtual void
1538  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
1540 
1541  template<class DestViewType, class SrcViewType,
1542  class DestOffsetViewType, class SrcOffsetViewType >
1543  struct pack_functor {
1544  typedef typename DestViewType::execution_space execution_space;
1545  SrcViewType src;
1546  DestViewType dest;
1547  SrcOffsetViewType src_offset;
1548  DestOffsetViewType dest_offset;
1549  typedef typename DestOffsetViewType::non_const_value_type ScalarIndx;
1550 
1551  pack_functor(DestViewType dest_,
1552  const SrcViewType src_,
1553  DestOffsetViewType dest_offset_,
1554  const SrcOffsetViewType src_offset_):
1555  src(src_),dest(dest_),
1556  src_offset(src_offset_),dest_offset(dest_offset_) {};
1557 
1558  KOKKOS_INLINE_FUNCTION
1559  void operator() (size_t row) const {
1560  ScalarIndx i = src_offset(row);
1561  ScalarIndx j = dest_offset(row);
1562  const ScalarIndx k = dest_offset(row+1);
1563  for(;j<k;j++,i++) {
1564  dest(j) = src(i);
1565  }
1566  }
1567  };
1568 
1569  private:
1570  // Friend declaration for nonmember function.
1571  template<class CrsGraphType>
1572  friend Teuchos::RCP<CrsGraphType>
1573  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1574  const Import<typename CrsGraphType::local_ordinal_type,
1575  typename CrsGraphType::global_ordinal_type,
1576  typename CrsGraphType::node_type>& importer,
1577  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1578  typename CrsGraphType::global_ordinal_type,
1579  typename CrsGraphType::node_type> >& domainMap,
1580  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1581  typename CrsGraphType::global_ordinal_type,
1582  typename CrsGraphType::node_type> >& rangeMap,
1583  const Teuchos::RCP<Teuchos::ParameterList>& params);
1584 
1585  // Friend declaration for nonmember function.
1586  template<class CrsGraphType>
1587  friend Teuchos::RCP<CrsGraphType>
1588  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1589  const Import<typename CrsGraphType::local_ordinal_type,
1590  typename CrsGraphType::global_ordinal_type,
1591  typename CrsGraphType::node_type>& rowImporter,
1592  const Import<typename CrsGraphType::local_ordinal_type,
1593  typename CrsGraphType::global_ordinal_type,
1594  typename CrsGraphType::node_type>& domainImporter,
1595  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1596  typename CrsGraphType::global_ordinal_type,
1597  typename CrsGraphType::node_type> >& domainMap,
1598  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1599  typename CrsGraphType::global_ordinal_type,
1600  typename CrsGraphType::node_type> >& rangeMap,
1601  const Teuchos::RCP<Teuchos::ParameterList>& params);
1602 
1603 
1604  // Friend declaration for nonmember function.
1605  template<class CrsGraphType>
1606  friend Teuchos::RCP<CrsGraphType>
1607  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1608  const Export<typename CrsGraphType::local_ordinal_type,
1609  typename CrsGraphType::global_ordinal_type,
1610  typename CrsGraphType::node_type>& exporter,
1611  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1612  typename CrsGraphType::global_ordinal_type,
1613  typename CrsGraphType::node_type> >& domainMap,
1614  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1615  typename CrsGraphType::global_ordinal_type,
1616  typename CrsGraphType::node_type> >& rangeMap,
1617  const Teuchos::RCP<Teuchos::ParameterList>& params);
1618 
1619  // Friend declaration for nonmember function.
1620  template<class CrsGraphType>
1621  friend Teuchos::RCP<CrsGraphType>
1622  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1623  const Export<typename CrsGraphType::local_ordinal_type,
1624  typename CrsGraphType::global_ordinal_type,
1625  typename CrsGraphType::node_type>& rowExporter,
1626  const Export<typename CrsGraphType::local_ordinal_type,
1627  typename CrsGraphType::global_ordinal_type,
1628  typename CrsGraphType::node_type>& domainExporter,
1629  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1630  typename CrsGraphType::global_ordinal_type,
1631  typename CrsGraphType::node_type> >& domainMap,
1632  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1633  typename CrsGraphType::global_ordinal_type,
1634  typename CrsGraphType::node_type> >& rangeMap,
1635  const Teuchos::RCP<Teuchos::ParameterList>& params);
1636 
1637  public:
1653  void
1654  importAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1655  const import_type& importer,
1656  const Teuchos::RCP<const map_type>& domainMap,
1657  const Teuchos::RCP<const map_type>& rangeMap,
1658  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1659 
1675  void
1676  importAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1677  const import_type& rowImporter,
1678  const import_type& domainImporter,
1679  const Teuchos::RCP<const map_type>& domainMap,
1680  const Teuchos::RCP<const map_type>& rangeMap,
1681  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1682 
1683 
1699  void
1700  exportAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1701  const export_type& exporter,
1702  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1703  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1704  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1705 
1721  void
1722  exportAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1723  const export_type& rowExporter,
1724  const export_type& domainExporter,
1725  const Teuchos::RCP<const map_type>& domainMap,
1726  const Teuchos::RCP<const map_type>& rangeMap,
1727  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1728 
1729 
1730  private:
1751  void
1752  transferAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1753  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, Node>& rowTransfer,
1754  const Teuchos::RCP<const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, Node> > & domainTransfer,
1755  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1756  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1757  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1758 
1759  protected:
1760  // these structs are conveniences, to cut down on the number of
1761  // arguments to some of the methods below.
1762  struct SLocalGlobalViews {
1763  Teuchos::ArrayView<const global_ordinal_type> ginds;
1764  Teuchos::ArrayView<const local_ordinal_type> linds;
1765  };
1766  struct SLocalGlobalNCViews {
1767  Teuchos::ArrayView<global_ordinal_type> ginds;
1768  Teuchos::ArrayView<local_ordinal_type> linds;
1769  };
1770 
1771  bool indicesAreAllocated () const;
1772 
1773  void
1774  allocateIndices(const ELocalGlobal lg, const bool verbose=false);
1775 
1777 
1778 
1788  void makeColMap (Teuchos::Array<int>& remotePIDs);
1789 
1810  std::pair<size_t, std::string>
1811  makeIndicesLocal(const bool verbose=false);
1812 
1821  void
1822  makeImportExport (Teuchos::Array<int>& remotePIDs,
1823  const bool useRemotePIDs);
1824 
1826 
1828 
1863  size_t
1864  insertIndices (RowInfo& rowInfo,
1865  const SLocalGlobalViews& newInds,
1866  const ELocalGlobal lg,
1867  const ELocalGlobal I);
1868 
1878  size_t
1880  const global_ordinal_type inputGblColInds[],
1881  const size_t numInputInds);
1882 
1892  size_t
1893  insertGlobalIndicesImpl (const RowInfo& rowInfo,
1894  const global_ordinal_type inputGblColInds[],
1895  const size_t numInputInds,
1896  std::function<void(const size_t, const size_t, const size_t)> fun =
1897  std::function<void(const size_t, const size_t, const size_t)>());
1898 
1899  void
1900  insertLocalIndicesImpl (const local_ordinal_type lclRow,
1901  const Teuchos::ArrayView<const local_ordinal_type>& gblColInds,
1902  std::function<void(const size_t, const size_t, const size_t)> fun =
1903  std::function<void(const size_t, const size_t, const size_t)>());
1904 
1920  size_t
1921  findGlobalIndices(const RowInfo& rowInfo,
1922  const Teuchos::ArrayView<const global_ordinal_type>& indices,
1923  std::function<void(const size_t, const size_t, const size_t)> fun) const;
1924 
1936  void
1938  const global_ordinal_type gblColInds[],
1939  const local_ordinal_type numGblColInds);
1940 
1952  void
1954  const global_ordinal_type gblColInds[],
1955  const local_ordinal_type numGblColInds);
1956 
1961  static const bool useAtomicUpdatesByDefault =
1962 #ifdef KOKKOS_ENABLE_SERIAL
1963  ! std::is_same<execution_space, Kokkos::Serial>::value;
1964 #else
1965  true;
1966 #endif // KOKKOS_ENABLE_SERIAL
1967 
1969 
1971 
1973  bool isMerged () const;
1974 
1980  void setLocallyModified ();
1981 
1982  private:
1987  void
1988  sortAndMergeAllIndices (const bool sorted, const bool merged);
1989 
1990  // mfh 08 May 2017: I only restore "protected" here for backwards
1991  // compatibility.
1992  protected:
2001  size_t sortAndMergeRowIndices (const RowInfo& rowInfo,
2002  const bool sorted,
2003  const bool merged);
2005 
2015  void
2016  setDomainRangeMaps (const Teuchos::RCP<const map_type>& domainMap,
2017  const Teuchos::RCP<const map_type>& rangeMap);
2018 
2019  void staticAssertions() const;
2020  void clearGlobalConstants();
2021 
2022  public:
2025 
2043  void computeGlobalConstants ();
2044 
2045  bool haveLocalOffRankOffsets() const { return haveLocalOffRankOffsets_;}
2046 
2047  protected:
2067  void computeLocalConstants ();
2068 
2071  RowInfo getRowInfo (const local_ordinal_type myRow) const;
2072 
2085  RowInfo getRowInfoFromGlobalRowIndex (const global_ordinal_type gblRow) const;
2086 
2087  public:
2088 
2097  local_graph_host_type getLocalGraphHost () const;
2098 
2099  protected:
2100 
2101  void fillLocalGraph (const Teuchos::RCP<Teuchos::ParameterList>& params);
2102 
2104  void checkInternalState () const;
2105 
2109  void swap(CrsGraph<local_ordinal_type, global_ordinal_type, Node> & graph);
2110 
2111  // Friend the tester for CrsGraph::swap
2112  friend class Tpetra::crsGraph_Swap_Tester<local_ordinal_type, global_ordinal_type, Node>;
2113 
2114 
2116  Teuchos::RCP<const map_type> rowMap_;
2118  Teuchos::RCP<const map_type> colMap_;
2120  Teuchos::RCP<const map_type> rangeMap_;
2122  Teuchos::RCP<const map_type> domainMap_;
2123 
2130  Teuchos::RCP<const import_type> importer_;
2131 
2137  Teuchos::RCP<const export_type> exporter_;
2138 
2144  Teuchos::OrdinalTraits<size_t>::invalid();
2145 
2150  Teuchos::OrdinalTraits<global_size_t>::invalid();
2151 
2157  Teuchos::OrdinalTraits<global_size_t>::invalid();
2158 
2159  private:
2160  // Replacement for device view k_rowPtrs_
2161  // Device view rowPtrsUnpacked_dev_ takes place of k_rowPtrs_
2162  // Host view rowPtrsUnpacked_host_ takes place of copies and use of getEntryOnHost
2163  // Wish this could be a WrappedDualView, but deep_copies in DualView
2164  // don't work with const data views (e.g., StaticCrsGraph::row_map)
2165  // k_rowPtrs_ is offsets wrt the ALLOCATED indices array, not necessarily
2166  // the ACTUAL compressed indices array.
2167  // When !OptimizedStorage, k_rowPtrs_ may differ from ACTUAL compressed
2168  // indices array. (Karen is skeptical that !OptimizedStorage works)
2169  // When OptimizedStorage, rowPtrsUnpacked_ = k_rowPtrsPacked_
2170 
2171  row_ptrs_device_view_type rowPtrsUnpacked_dev_;
2172  mutable row_ptrs_host_view_type rowPtrsUnpacked_host_;
2173 
2174  // Row offsets into the actual graph local indices
2175  // Device view rowPtrsUnpacked_dev_ takes place of lclGraph_.row_map
2176 
2177  row_ptrs_device_view_type rowPtrsPacked_dev_;
2178  mutable row_ptrs_host_view_type rowPtrsPacked_host_;
2179 
2181  bool packedUnpackedRowPtrsMatch_ = false;
2182 
2183  protected:
2184  void setRowPtrsUnpacked(const row_ptrs_device_view_type &dview) {
2185  packedUnpackedRowPtrsMatch_ = false;
2186  rowPtrsUnpacked_dev_ = dview;
2187  //Make sure stale host rowptrs are not kept
2188  rowPtrsUnpacked_host_ = row_ptrs_host_view_type();
2189  }
2190 
2192  const row_ptrs_device_view_type& getRowPtrsUnpackedDevice() const
2193  {
2194  return rowPtrsUnpacked_dev_;
2195  }
2196 
2198  const row_ptrs_host_view_type& getRowPtrsUnpackedHost() const
2199  {
2200  if(rowPtrsUnpacked_host_.extent(0) != rowPtrsUnpacked_dev_.extent(0))
2201  {
2202  //NOTE: not just using create_mirror_view here, because
2203  //we do want host/device to be in different memory, even if we're using a SharedSpace.
2204  //This is so that reads will never trigger a host-device transfer.
2205  //The exception is when 'device' views are HostSpace, then don't make another copy.
2206  if constexpr(std::is_same_v<typename Node::memory_space, Kokkos::HostSpace>)
2207  {
2208  rowPtrsUnpacked_host_ = rowPtrsUnpacked_dev_;
2209  }
2210  else
2211  {
2212  //Have to make this temporary because rowptrs are const-valued
2213  typename row_ptrs_host_view_type::non_const_type rowPtrsTemp(
2214  Kokkos::view_alloc(Kokkos::WithoutInitializing, "rowPtrsUnpacked_host_"), rowPtrsUnpacked_dev_.extent(0));
2215  Kokkos::deep_copy(rowPtrsTemp, rowPtrsUnpacked_dev_);
2216  rowPtrsUnpacked_host_= rowPtrsTemp;
2217  }
2218  //Also keep packed/unpacked views in sync, if they are known to have the same contents
2219  if(packedUnpackedRowPtrsMatch_)
2220  {
2221  rowPtrsPacked_host_ = rowPtrsUnpacked_host_;
2222  }
2223  }
2224  return rowPtrsUnpacked_host_;
2225  }
2226 
2227  void setRowPtrsPacked(const row_ptrs_device_view_type &dview) {
2228  packedUnpackedRowPtrsMatch_ = false;
2229  rowPtrsPacked_dev_ = dview;
2230  //Make sure stale host rowptrs are not kept
2231  rowPtrsPacked_host_ = row_ptrs_host_view_type();
2232  }
2233 
2235  const row_ptrs_device_view_type& getRowPtrsPackedDevice() const
2236  {
2237  return rowPtrsPacked_dev_;
2238  }
2239 
2241  const row_ptrs_host_view_type& getRowPtrsPackedHost() const
2242  {
2243  if(rowPtrsPacked_host_.extent(0) != rowPtrsPacked_dev_.extent(0))
2244  {
2245  //NOTE: not just using create_mirror_view here, because
2246  //we do want host/device to be in different memory, even if we're using a SharedSpace.
2247  //This is so that reads will never trigger a host-device transfer.
2248  //The exception is when 'device' views are HostSpace, then don't make another copy.
2249  if constexpr(std::is_same_v<typename Node::memory_space, Kokkos::HostSpace>)
2250  {
2251  rowPtrsPacked_host_ = rowPtrsPacked_dev_;
2252  }
2253  else
2254  {
2255  //Have to make this temporary because rowptrs are const-valued
2256  typename row_ptrs_host_view_type::non_const_type rowPtrsTemp(
2257  Kokkos::view_alloc(Kokkos::WithoutInitializing, "rowPtrsPacked_host_"), rowPtrsPacked_dev_.extent(0));
2258  Kokkos::deep_copy(rowPtrsTemp, rowPtrsPacked_dev_);
2259  rowPtrsPacked_host_= rowPtrsTemp;
2260  }
2261  //Also keep packed/unpacked views in sync, if they are known to have the same contents
2262  if(packedUnpackedRowPtrsMatch_)
2263  {
2264  rowPtrsUnpacked_host_ = rowPtrsPacked_host_;
2265  }
2266  }
2267  return rowPtrsPacked_host_;
2268  }
2269 
2270  // There are common cases where both packed and unpacked views are set to the same array.
2271  // Doing this in a single call can reduce dataspace on host, and reduce runtime by
2272  // removing a deep_copy from device to host.
2273 
2274  void setRowPtrs(const row_ptrs_device_view_type &dview) {
2275  packedUnpackedRowPtrsMatch_ = true;
2276  rowPtrsUnpacked_dev_ = dview;
2277  rowPtrsPacked_dev_ = dview;
2278  //Make sure stale host rowptrs are not kept
2279  rowPtrsUnpacked_host_ = row_ptrs_host_view_type();
2280  rowPtrsPacked_host_ = row_ptrs_host_view_type();
2281  }
2282 
2283  //TODO: Make private -- matrix shouldn't access directly the guts of graph
2284 
2299 
2314 
2315  //TODO: Make private -- matrix shouldn't access directly the guts of graph
2316 
2326 
2327  // TODO: Make private -- matrix shouldn't access directly
2329 
2333  typename local_inds_dualv_type::t_host::const_type
2334  getLocalIndsViewHost (const RowInfo& rowinfo) const;
2335 
2339  typename local_inds_dualv_type::t_dev::const_type
2340  getLocalIndsViewDevice (const RowInfo& rowinfo) const;
2341 
2345  typename global_inds_dualv_type::t_host::const_type
2346  getGlobalIndsViewHost (const RowInfo& rowinfo) const;
2347 
2351  typename global_inds_dualv_type::t_dev::const_type
2352  getGlobalIndsViewDevice (const RowInfo& rowinfo) const;
2353 
2357  typename local_inds_dualv_type::t_host
2358  getLocalIndsViewHostNonConst (const RowInfo& rowinfo);
2359 
2360  // FOR NOW...
2361  // KEEP k_numRowEntries_ (though switch from host_mirror_type to Host)
2362  // KEEP k_numAllocPerRow_ (though perhaps switch from host_mirror_type to Host)
2363 
2389  typename Kokkos::View<const size_t*, device_type>::host_mirror_type
2391 
2402 
2404 
2405 
2427 
2435  typedef typename Kokkos::View<size_t*, Kokkos::LayoutLeft, device_type>::host_mirror_type num_row_entries_type;
2436 
2437  // typedef Kokkos::View<
2438  // size_t*,
2439  // Kokkos::LayoutLeft,
2440  // Kokkos::Device<
2441  // typename Kokkos::View<
2442  // size_t*,
2443  // Kokkos::LayoutLeft,
2444  // device_type>::host_mirror_type::execution_space,
2445  // Kokkos::HostSpace> > num_row_entries_type;
2446 
2454 
2460  mutable offset_device_view_type k_offRankOffsets_;
2461 
2463 
2474  Details::STORAGE_1D_UNPACKED;
2475 
2476  bool indicesAreAllocated_ = false;
2477  bool indicesAreLocal_ = false;
2478  bool indicesAreGlobal_ = false;
2479  bool fillComplete_ = false;
2480 
2482  bool indicesAreSorted_ = true;
2485  bool noRedundancies_ = true;
2487  bool haveLocalConstants_ = false;
2489  bool haveGlobalConstants_ = false;
2491  mutable bool haveLocalOffRankOffsets_ = false;
2492 
2493  typedef typename std::map<global_ordinal_type, std::vector<global_ordinal_type> > nonlocals_type;
2494 
2496  nonlocals_type nonlocals_;
2497 
2513 
2514  private:
2516  static bool getDebug();
2517 
2520  bool debug_ = getDebug();
2521 
2523  static bool getVerbose();
2524 
2528  bool verbose_ = getVerbose();
2529 
2530  private:
2532  mutable bool need_sync_host_uvm_access = false;
2533 
2535  void set_need_sync_host_uvm_access() {
2536  need_sync_host_uvm_access = true;
2537  }
2538 
2540  void execute_sync_host_uvm_access() const {
2541  if(need_sync_host_uvm_access) {
2542  Kokkos::fence("CrsGraph::execute_sync_host_uvm_access");
2543  need_sync_host_uvm_access = false;
2544  }
2545  }
2546  }; // class CrsGraph
2547 
2555  template <class LocalOrdinal, class GlobalOrdinal, class Node>
2556  Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
2558  const Teuchos::RCP<
2560  size_t maxNumEntriesPerRow = 0,
2561  const Teuchos::RCP<Teuchos::ParameterList>& params =
2562  Teuchos::null)
2563  {
2564  using Teuchos::rcp;
2566  return rcp(new graph_type(map, maxNumEntriesPerRow,
2567  params));
2568  }
2569 
2619  template<class CrsGraphType>
2620  Teuchos::RCP<CrsGraphType>
2621  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2622  const Import<typename CrsGraphType::local_ordinal_type,
2623  typename CrsGraphType::global_ordinal_type,
2624  typename CrsGraphType::node_type>& importer,
2625  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2626  typename CrsGraphType::global_ordinal_type,
2627  typename CrsGraphType::node_type> >& domainMap = Teuchos::null,
2628  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2629  typename CrsGraphType::global_ordinal_type,
2630  typename CrsGraphType::node_type> >& rangeMap = Teuchos::null,
2631  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2632  {
2633  Teuchos::RCP<CrsGraphType> destGraph;
2634  sourceGraph->importAndFillComplete (destGraph,importer,domainMap, rangeMap, params);
2635  return destGraph;
2636  }
2637 
2688  template<class CrsGraphType>
2689  Teuchos::RCP<CrsGraphType>
2690  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2691  const Import<typename CrsGraphType::local_ordinal_type,
2692  typename CrsGraphType::global_ordinal_type,
2693  typename CrsGraphType::node_type>& rowImporter,
2694  const Import<typename CrsGraphType::local_ordinal_type,
2695  typename CrsGraphType::global_ordinal_type,
2696  typename CrsGraphType::node_type>& domainImporter,
2697  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2698  typename CrsGraphType::global_ordinal_type,
2699  typename CrsGraphType::node_type> >& domainMap,
2700  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2701  typename CrsGraphType::global_ordinal_type,
2702  typename CrsGraphType::node_type> >& rangeMap,
2703  const Teuchos::RCP<Teuchos::ParameterList>& params)
2704  {
2705  Teuchos::RCP<CrsGraphType> destGraph;
2706  sourceGraph->importAndFillComplete (destGraph,rowImporter,domainImporter, domainMap, rangeMap, params);
2707  return destGraph;
2708  }
2709 
2743  template<class CrsGraphType>
2744  Teuchos::RCP<CrsGraphType>
2745  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2746  const Export<typename CrsGraphType::local_ordinal_type,
2747  typename CrsGraphType::global_ordinal_type,
2748  typename CrsGraphType::node_type>& exporter,
2749  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2750  typename CrsGraphType::global_ordinal_type,
2751  typename CrsGraphType::node_type> >& domainMap = Teuchos::null,
2752  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2753  typename CrsGraphType::global_ordinal_type,
2754  typename CrsGraphType::node_type> >& rangeMap = Teuchos::null,
2755  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2756  {
2757  Teuchos::RCP<CrsGraphType> destGraph;
2758  sourceGraph->exportAndFillComplete (destGraph,exporter,domainMap, rangeMap, params);
2759  return destGraph;
2760  }
2761 
2795  template<class CrsGraphType>
2796  Teuchos::RCP<CrsGraphType>
2797  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2798  const Export<typename CrsGraphType::local_ordinal_type,
2799  typename CrsGraphType::global_ordinal_type,
2800  typename CrsGraphType::node_type>& rowExporter,
2801  const Export<typename CrsGraphType::local_ordinal_type,
2802  typename CrsGraphType::global_ordinal_type,
2803  typename CrsGraphType::node_type>& domainExporter,
2804  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2805  typename CrsGraphType::global_ordinal_type,
2806  typename CrsGraphType::node_type> >& domainMap,
2807  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2808  typename CrsGraphType::global_ordinal_type,
2809  typename CrsGraphType::node_type> >& rangeMap,
2810  const Teuchos::RCP<Teuchos::ParameterList>& params)
2811  {
2812  Teuchos::RCP<CrsGraphType> destGraph;
2813  sourceGraph->exportAndFillComplete (destGraph,rowExporter,domainExporter,domainMap, rangeMap, params);
2814  return destGraph;
2815  }
2816 
2817 
2818 } // namespace Tpetra
2819 
2820 #endif // TPETRA_CRSGRAPH_DECL_HPP
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
void setDomainRangeMaps(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap)
void setAllIndices(const typename local_graph_device_type::row_map_type &rowPointers, const typename local_graph_device_type::entries_type::non_const_type &columnIndices)
Set the graph&#39;s data directly, using 1-D storage.
Teuchos::RCP< const map_type > getRowMap() const override
Returns the Map that describes the row distribution in this graph.
offset_device_view_type k_offRankOffsets_
The offsets for off-rank entries.
size_t nodeMaxNumRowEntries_
Local maximum of the number of entries in each row.
bool indicesAreSorted_
Whether the graph&#39;s indices are sorted in each row, on this process.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
KokkosSparse::StaticCrsGraph< local_ordinal_type, Kokkos::LayoutLeft, device_type, void, size_t > local_graph_device_type
The type of the part of the sparse graph on each MPI process.
::Tpetra::Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization used by this class.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
Teuchos::RCP< const map_type > rangeMap_
The Map describing the range of the (matrix corresponding to the) graph.
Teuchos::RCP< const map_type > getColMap() const override
Returns the Map that describes the column distribution in this graph.
local_inds_host_view_type getLocalIndicesHost() const
Get a host view of the packed column indicies.
GO global_ordinal_type
The type of the graph&#39;s global indices.
local_inds_dualv_type::t_host::const_type getLocalIndsViewHost(const RowInfo &rowinfo) const
Get a const, locally indexed view of the locally owned row myRow, such that rowinfo = getRowInfo(myRo...
An abstract interface for graphs accessed by rows.
void getLocalOffRankOffsets(offset_device_view_type &offsets) const
Get offsets of the off-rank entries in the graph.
void insertGlobalIndicesFiltered(const local_ordinal_type lclRow, const global_ordinal_type gblColInds[], const local_ordinal_type numGblColInds)
Like insertGlobalIndices(), but with column Map filtering.
local_inds_dualv_type::t_host getLocalIndsViewHostNonConst(const RowInfo &rowinfo)
Get a ReadWrite locally indexed view of the locally owned row myRow, such that rowinfo = getRowInfo(m...
bool sortGhostsAssociatedWithEachProcessor_
Whether to require makeColMap() (and therefore fillComplete()) to order column Map GIDs associated wi...
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM)
Perform copies and permutations that are local to the calling (MPI) process.
size_t insertGlobalIndicesImpl(const local_ordinal_type lclRow, const global_ordinal_type inputGblColInds[], const size_t numInputInds)
Insert global indices, using an input local row index.
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Resume fill operations.
bool haveGlobalConstants_
Whether all processes have computed global constants.
size_t getLocalNumRows() const override
Returns the number of graph rows owned on the calling node.
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 graph that already has data, via setAllIndices().
Teuchos::RCP< const import_type > getImporter() const override
Returns the importer associated with this graph.
void getLocalDiagOffsets(const Kokkos::View< size_t *, device_type, Kokkos::MemoryUnmanaged > &offsets) const
Get offsets of the diagonal entries in the graph.
void insertGlobalIndices(const global_ordinal_type globalRow, const Teuchos::ArrayView< const global_ordinal_type > &indices)
Insert global indices into the graph.
size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override
Get the number of entries in the given row (local index).
size_t getLocalAllocationSize() const
The local number of indices allocated for the graph, over all rows on the calling (MPI) process...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Default parameter list suitable for validation.
void computeLocalConstants()
Compute local constants, if they have not yet been computed.
typename row_graph_type::local_inds_device_view_type local_inds_device_view_type
The Kokkos::View type for views of local ordinals on device and host.
bool isIdenticalTo(const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph) const
Create a cloned CrsGraph for a different Node type.
bool isMerged() const
Whether duplicate column indices in each row have been merged.
virtual bool checkSizes(const SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
Forward declaration of Tpetra::BlockCrsMatrix.
Teuchos::RCP< const map_type > getDomainMap() const override
Returns the Map associated with the domain of this graph.
size_t getGlobalMaxNumRowEntries() const override
Maximum number of entries in any row of the graph, over all processes in the graph&#39;s communicator...
virtual ~CrsGraph()=default
Destructor (virtual for memory safety of derived classes).
bool noRedundancies_
Whether the graph&#39;s indices are non-redundant (merged) in each row, on this process.
global_inds_dualv_type::t_dev::const_type getGlobalIndsViewDevice(const RowInfo &rowinfo) const
Get a const, globally indexed view of the locally owned row myRow, such that rowinfo = getRowInfo(myR...
void replaceRangeMap(const Teuchos::RCP< const map_type > &newRangeMap)
Replace the current Range Map with the given objects.
row_ptrs_device_view_type getLocalRowPtrsDevice() const
Get a device view of the packed row offsets.
virtual void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< packet_type *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode combineMode)
Perform any unpacking and combining after communication.
global_inds_dualv_type::t_host::const_type getGlobalIndsViewHost(const RowInfo &rowinfo) const
Get a const, globally indexed view of the locally owned row myRow, such that rowinfo = getRowInfo(myR...
const row_ptrs_host_view_type & getRowPtrsPackedHost() const
Get the packed row pointers on host. Lazily make a copy from device.
Kokkos::View< size_t *, Kokkos::LayoutLeft, device_type >::host_mirror_type num_row_entries_type
Row offsets for &quot;1-D&quot; storage.
size_t getNumAllocatedEntriesInGlobalRow(global_ordinal_type globalRow) const
Current number of allocated entries in the given row on the calling (MPI) process, using a global row index.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
local_inds_wdv_type lclIndsUnpacked_wdv
Local ordinals of column indices for all rows Valid when isLocallyIndexed is true If OptimizedStorage...
void replaceRangeMapAndExporter(const Teuchos::RCP< const map_type > &newRangeMap, const Teuchos::RCP< const export_type > &newExporter)
Replace the current Range Map and Export with the given parameters.
bool hasColMap() const override
Whether the graph has a column Map.
bool isGloballyIndexed() const override
Whether the graph&#39;s column indices are stored as global indices.
void exportAndFillComplete(Teuchos::RCP< CrsGraph< local_ordinal_type, global_ordinal_type, Node > > &destGraph, 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 graph, and make the result fill complete.
virtual void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< packet_type *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode combineMode) override
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
bool isStorageOptimized() const
Returns true if storage has been optimized.
bool haveLocalConstants_
Whether this process has computed local constants.
size_t findGlobalIndices(const RowInfo &rowInfo, const Teuchos::ArrayView< const global_ordinal_type > &indices, std::function< void(const size_t, const size_t, const size_t)> fun) const
Finds indices in the given row.
std::string description() const override
Return a one-line human-readable description of this object.
void makeColMap(Teuchos::Array< int > &remotePIDs)
Make and set the graph&#39;s column Map.
Teuchos::RCP< const export_type > getExporter() const override
Returns the exporter associated with this graph.
std::pair< size_t, std::string > makeIndicesLocal(const bool verbose=false)
Convert column indices from global to local.
size_t global_size_t
Global size_t object.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap) override
Remove processes owning zero rows from the Maps and their communicator.
node_type node_type
This class&#39; Kokkos Node type.
void reindexColumns(const Teuchos::RCP< const map_type > &newColMap, const Teuchos::RCP< const import_type > &newImport=Teuchos::null, const bool sortIndicesInEachRow=true)
Reindex the column indices in place, and replace the column Map. Optionally, replace the Import objec...
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
Teuchos::RCP< CrsGraphType > importAndFillCompleteCrsGraph(const Teuchos::RCP< const CrsGraphType > &sourceGraph, const Import< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > &importer, const Teuchos::RCP< const Map< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsGraph constructor that fuses Import and fillComplete().
void makeImportExport(Teuchos::Array< int > &remotePIDs, const bool useRemotePIDs)
Make the Import and Export objects, if needed.
size_t sortAndMergeRowIndices(const RowInfo &rowInfo, const bool sorted, const bool merged)
Sort and merge duplicate column indices in the given row.
void insertLocalIndices(const local_ordinal_type localRow, const Teuchos::ArrayView< const local_ordinal_type > &indices)
Insert local indices into the graph.
bool isSorted() const
Whether graph indices in all rows are known to be sorted.
void getLocalRowCopy(local_ordinal_type gblRow, nonconst_local_inds_host_view_type &gblColInds, size_t &numColInds) const override
Get a copy of the given row, using local indices.
Teuchos::RCP< const map_type > rowMap_
The Map describing the distribution of rows of the graph.
Teuchos::RCP< const import_type > importer_
The Import from the domain Map to the column Map.
num_row_entries_type k_numRowEntries_
The number of local entries in each locally owned row.
local_inds_device_view_type getLocalIndicesDevice() const
Get a device view of the packed column indicies.
Teuchos::RCP< const map_type > domainMap_
The Map describing the domain of the (matrix corresponding to the) graph.
global_size_t getGlobalNumRows() const override
Returns the number of global rows in the graph.
void setLocallyModified()
Report that we made a local modification to its structure.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
virtual void packAndPrepare(const SrcDistObject &source, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< packet_type *, buffer_device_type > &exports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, size_t &constantNumPackets)
Pack data and metadata for communication (sends).
void checkInternalState() const
Throw an exception if the internal state is not consistent.
Keep track of how much more space a CrsGraph or CrsMatrix needs, when the graph or matrix is the targ...
CombineMode
Rule for combining data in an Import or Export.
Teuchos::RCP< const export_type > exporter_
The Export from the row Map to the range Map.
void insertGlobalIndicesIntoNonownedRows(const global_ordinal_type gblRow, const global_ordinal_type gblColInds[], const local_ordinal_type numGblColInds)
Implementation of insertGlobalIndices for nonowned rows.
bool isFillComplete() const override
Whether fillComplete() has been called and the graph is in compute mode.
size_t getNumAllocatedEntriesInLocalRow(local_ordinal_type localRow) const
Current number of allocated entries in the given row on the calling (MPI) process, using a local row index.
void swap(CrsGraph< local_ordinal_type, global_ordinal_type, Node > &graph)
Swaps the data from *this with the data and maps from graph.
void globalAssemble()
Communicate nonlocal contributions to other processes.
typename device_type::execution_space execution_space
This class&#39; Kokkos execution space.
RowInfo getRowInfoFromGlobalRowIndex(const global_ordinal_type gblRow) const
Get information about the locally owned row with global index gblRow.
Forward declaration of Tpetra::CrsMatrix.
size_t getLocalNumCols() const override
Returns the number of columns connected to the locally owned rows of this graph.
size_t getLocalNumEntries() const override
The local number of entries in the graph.
Abstract base class for objects that can be the source of an Import or Export operation.
void removeLocalIndices(local_ordinal_type localRow)
Remove all graph indices from the specified local row.
LO local_ordinal_type
The type of the graph&#39;s local indices.
global_size_t globalNumEntries_
Global number of entries in the graph.
global_inds_wdv_type gblInds_wdv
Global ordinals of column indices for all rows.
local_inds_dualv_type::t_dev::const_type getLocalIndsViewDevice(const RowInfo &rowinfo) const
Get a const, locally indexed view of the locally owned row myRow, such that rowinfo = getRowInfo(myRo...
Teuchos::RCP< const map_type > getRangeMap() const override
Returns the Map associated with the domain of this graph.
virtual void pack(const Teuchos::ArrayView< const local_ordinal_type > &exportLIDs, Teuchos::Array< global_ordinal_type > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets) const override
row_ptrs_host_view_type getLocalRowPtrsHost() const
Get a host view of the packed row offsets.
const row_ptrs_host_view_type & getRowPtrsUnpackedHost() const
Get the unpacked row pointers on host. Lazily make a copy from device.
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the graph&#39;s current column Map with the given Map.
global_size_t getGlobalNumCols() const override
Returns the number of global columns in the graph.
size_t getLocalMaxNumRowEntries() const override
Maximum number of entries in any row of the graph, on this process.
RowInfo getRowInfo(const local_ordinal_type myRow) const
Get information about the locally owned row with local index myRow.
void replaceDomainMapAndImporter(const Teuchos::RCP< const map_type > &newDomainMap, const Teuchos::RCP< const import_type > &newImporter)
Replace the current domain Map and Import with the given parameters.
typename row_graph_type::global_inds_device_view_type global_inds_device_view_type
The Kokkos::View type for views of global ordinals on device and host.
bool supportsRowViews() const override
Whether this class implements getLocalRowView() and getGlobalRowView() (it does). ...
typename dist_object_type::buffer_device_type buffer_device_type
Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > createCrsGraph(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map, size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember function to create an empty CrsGraph given a row Map and the max number of entries allowed ...
local_inds_wdv_type lclIndsPacked_wdv
Local ordinals of column indices for all rows Valid when isLocallyIndexed is true Built during fillCo...
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
Details::EStorageStatus storageStatus_
Status of the graph&#39;s storage, when not in a fill-complete state.
const row_ptrs_device_view_type & getRowPtrsPackedDevice() const
Get the packed row pointers on device.
const row_ptrs_device_view_type & getRowPtrsUnpackedDevice() const
Get the unpacked row pointers on device.
CrsGraph & operator=(const CrsGraph< local_ordinal_type, global_ordinal_type, node_type > &)=default
Assignment operator (default).
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the given list of parameters (must be nonnull).
size_t getNumEntriesInGlobalRow(global_ordinal_type globalRow) const override
Returns the current number of entries on this node in the specified global row.
void fillComplete(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Tell the graph that you are done changing its structure.
void getLocalRowView(const LocalOrdinal lclRow, local_inds_host_view_type &lclColInds) const override
Get a const view of the given local row&#39;s local column indices.
typename node_type::device_type device_type
This class&#39; Kokkos device type.
bool isLocallyIndexed() const override
Whether the graph&#39;s column indices are stored as local indices.
::Tpetra::Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization used by this class.
Stand-alone utility functions and macros.
bool isFillActive() const
Whether resumeFill() has been called and the graph is in edit mode.
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM) override
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
Returns the communicator.
Kokkos::View< const size_t *, device_type >::host_mirror_type k_numAllocPerRow_
The maximum number of entries to allow in each locally owned row, per row.
void importAndFillComplete(Teuchos::RCP< CrsGraph< local_ordinal_type, global_ordinal_type, Node > > &destGraph, 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 graph, and make the result fill complete.
global_size_t globalMaxNumRowEntries_
Global maximum of the number of entries in each row.
static const bool useAtomicUpdatesByDefault
Whether transformLocalValues should use atomic updates by default.
size_t insertIndices(RowInfo &rowInfo, const SLocalGlobalViews &newInds, const ELocalGlobal lg, const ELocalGlobal I)
Insert indices into the given row.
global_size_t getGlobalNumEntries() const override
Returns the global number of entries in the graph.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
size_t numAllocForAllRows_
The maximum number of entries to allow in each locally owned row.
local_graph_device_type getLocalGraphDevice() const
Get the local graph.
Base class for distributed Tpetra objects that support data redistribution.
void getGlobalRowView(const global_ordinal_type gblRow, global_inds_host_view_type &gblColInds) const override
Get a const view of the given global row&#39;s global column indices.
global_ordinal_type packet_type
Type of each entry of the DistObject communication buffer.
Teuchos::RCP< const map_type > colMap_
The Map describing the distribution of columns of the graph.
global_ordinal_type getIndexBase() const override
Returns the index base for global indices for this graph.
typename local_graph_device_type::HostMirror local_graph_host_type
The type of the part of the sparse graph on each MPI process.
void replaceDomainMap(const Teuchos::RCP< const map_type > &newDomainMap)
Replace the current domain Map with the given objects.
EStorageStatus
Status of the graph&#39;s or matrix&#39;s storage, when not in a fill-complete state.
Forward declaration of Tpetra::CrsGraph.
Teuchos::RCP< CrsGraphType > exportAndFillCompleteCrsGraph(const Teuchos::RCP< const CrsGraphType > &sourceGraph, const Export< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > &exporter, const Teuchos::RCP< const Map< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Nonmember CrsGraph constructor that fuses Export and fillComplete().
nonlocals_type nonlocals_
Nonlocal data given to insertGlobalIndices.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const override
Print this object to the given output stream with the given verbosity level.
void computeGlobalConstants()
Compute global constants, if they have not yet been computed.
void getGlobalRowCopy(global_ordinal_type gblRow, nonconst_global_inds_host_view_type &gblColInds, size_t &numColInds) const override
Get a copy of the given row, using global indices.