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 #ifndef TPETRA_CRSGRAPH_DECL_HPP
11 #define TPETRA_CRSGRAPH_DECL_HPP
12 
15 
16 #include "Tpetra_CrsGraph_fwd.hpp"
17 #include "Tpetra_CrsMatrix_fwd.hpp"
19 #include "Tpetra_DistObject.hpp"
20 #include "Tpetra_Exceptions.hpp"
21 #include "Tpetra_RowGraph.hpp"
22 #include "Tpetra_Util.hpp" // need this here for sort2
23 #include "Tpetra_Details_WrappedDualView.hpp"
24 
25 #include "KokkosSparse_findRelOffset.hpp"
26 #include "Kokkos_DualView.hpp"
27 
28 #include "Teuchos_CommHelpers.hpp"
29 #include "Teuchos_Describable.hpp"
30 #include "Teuchos_OrdinalTraits.hpp"
31 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
32 
33 #include "KokkosSparse_StaticCrsGraph.hpp"
34 
35 #include <functional> // std::function
36 #include <memory>
37 
38 namespace Tpetra {
39 
40 // Forward declaration for CrsGraph::swap() test
41 template <class LocalOrdinal, class GlobalOrdinal, class Node>
42 class crsGraph_Swap_Tester;
43 
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 namespace Details {
46 template <class LocalOrdinal,
47  class GlobalOrdinal>
48 class CrsPadding;
49 } // namespace Details
50 
51 namespace { // (anonymous)
52 
53 template <class ViewType>
54 struct UnmanagedView {
55  static_assert(Kokkos::is_view<ViewType>::value,
56  "ViewType must be a Kokkos::View specialization.");
57  // FIXME (mfh 02 Dec 2015) Right now, this strips away other
58  // memory traits. Christian will add an "AllTraits" enum which is
59  // the enum value of MemoryTraits<T>, that will help us fix this.
60  typedef Kokkos::View<typename ViewType::data_type,
61  typename ViewType::array_layout,
62  typename ViewType::device_type,
63  Kokkos::MemoryUnmanaged>
64  type;
65 };
66 
67 } // namespace
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 : public RowGraph<LocalOrdinal, GlobalOrdinal, Node>,
191  public DistObject<GlobalOrdinal,
192  LocalOrdinal,
193  GlobalOrdinal,
194  Node>,
195  public Teuchos::ParameterListAcceptorDefaultBase {
196  template <class S, class LO, class GO, class N>
197  friend class CrsMatrix;
198  template <class LO2, class GO2, class N2>
199  friend class CrsGraph;
200  template <class LO, class GO, class N>
201  friend class FECrsGraph;
202 
205 
206  public:
208  using local_ordinal_type = LocalOrdinal;
210  using global_ordinal_type = GlobalOrdinal;
212  using device_type = typename Node::device_type;
214  using execution_space = typename device_type::execution_space;
215 
220  using node_type = Node;
221 
224  KokkosSparse::StaticCrsGraph<local_ordinal_type, Kokkos::LayoutLeft,
225  device_type, void, size_t>;
226 
228 #if KOKKOS_VERSION >= 40799
229  using local_graph_host_type = typename local_graph_device_type::host_mirror_type;
230 #else
231  using local_graph_host_type = typename local_graph_device_type::HostMirror;
232 #endif
233 
240 
241  public:
242  // Types used for CrsGraph's storage of local column indices
243  using local_inds_dualv_type =
244  Kokkos::DualView<local_ordinal_type*, device_type>;
245  using local_inds_wdv_type =
247 
248  // Types used for CrsGraph's storage of global column indices
249  using global_inds_dualv_type =
250  Kokkos::DualView<global_ordinal_type*, device_type>;
251  using global_inds_wdv_type =
253 
254  public:
256  using row_ptrs_device_view_type =
257  typename row_graph_type::row_ptrs_device_view_type;
258  using row_ptrs_host_view_type =
259  typename row_graph_type::row_ptrs_host_view_type;
260 
263  typename row_graph_type::local_inds_device_view_type;
264  using local_inds_host_view_type =
265  typename row_graph_type::local_inds_host_view_type;
266  using nonconst_local_inds_host_view_type =
267  typename row_graph_type::nonconst_local_inds_host_view_type;
268 
271  typename row_graph_type::global_inds_device_view_type;
272  using global_inds_host_view_type =
273  typename row_graph_type::global_inds_host_view_type;
274  using nonconst_global_inds_host_view_type =
275  typename row_graph_type::nonconst_global_inds_host_view_type;
276 
277  using offset_device_view_type =
278  typename row_ptrs_device_view_type::non_const_type;
279 
281 
282 
295  CrsGraph(const Teuchos::RCP<const map_type>& rowMap,
296  const size_t maxNumEntriesPerRow,
297  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
298 
311  CrsGraph(const Teuchos::RCP<const map_type>& rowMap,
312  const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
313  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
314 
328  CrsGraph(const Teuchos::RCP<const map_type>& rowMap,
329  const Teuchos::ArrayView<const size_t>& numEntPerRow,
330  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
331 
344 
348  CrsGraph(const Teuchos::RCP<const map_type>& rowMap,
349  const Teuchos::RCP<const map_type>& colMap,
350  const size_t maxNumEntriesPerRow,
351  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
352 
367  CrsGraph(const Teuchos::RCP<const map_type>& rowMap,
368  const Teuchos::RCP<const map_type>& colMap,
369  const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
370  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
371 
387  CrsGraph(const Teuchos::RCP<const map_type>& rowMap,
388  const Teuchos::RCP<const map_type>& colMap,
389  const Teuchos::ArrayView<const size_t>& numEntPerRow,
390  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
391 
404  const Teuchos::RCP<const map_type>& rowMap,
405  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
406 
429  CrsGraph(const Teuchos::RCP<const map_type>& rowMap,
430  const Teuchos::RCP<const map_type>& colMap,
431  const typename local_graph_device_type::row_map_type& rowPointers,
432  const typename local_graph_device_type::entries_type::non_const_type& columnIndices,
433  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
434 
457  CrsGraph(const Teuchos::RCP<const map_type>& rowMap,
458  const Teuchos::RCP<const map_type>& colMap,
459  const Teuchos::ArrayRCP<size_t>& rowPointers,
460  const Teuchos::ArrayRCP<local_ordinal_type>& columnIndices,
461  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
462 
484  CrsGraph(const Teuchos::RCP<const map_type>& rowMap,
485  const Teuchos::RCP<const map_type>& colMap,
486  const local_graph_device_type& lclGraph,
487  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
488 
515  CrsGraph(const local_graph_device_type& lclGraph,
516  const Teuchos::RCP<const map_type>& rowMap,
517  const Teuchos::RCP<const map_type>& colMap,
518  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
519  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
520  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
521 
526  CrsGraph(const local_graph_device_type& lclGraph,
527  const Teuchos::RCP<const map_type>& rowMap,
528  const Teuchos::RCP<const map_type>& colMap,
529  const Teuchos::RCP<const map_type>& domainMap,
530  const Teuchos::RCP<const map_type>& rangeMap,
531  const Teuchos::RCP<const import_type>& importer,
532  const Teuchos::RCP<const export_type>& exporter,
533  const Teuchos::RCP<Teuchos::ParameterList>& params =
534  Teuchos::null);
535 
577  CrsGraph(const row_ptrs_device_view_type& rowPointers,
578  const local_inds_wdv_type& columnIndices,
579  const Teuchos::RCP<const map_type>& rowMap,
580  const Teuchos::RCP<const map_type>& colMap,
581  const Teuchos::RCP<const map_type>& domainMap,
582  const Teuchos::RCP<const map_type>& rangeMap,
583  const Teuchos::RCP<const import_type>& importer,
584  const Teuchos::RCP<const export_type>& exporter,
585  const Teuchos::RCP<Teuchos::ParameterList>& params =
586  Teuchos::null);
587 
590 
593 
596 
599 
609  virtual ~CrsGraph() = default;
610 
638 
656 
658 
660 
662  void
663  setParameterList(const Teuchos::RCP<Teuchos::ParameterList>& params) override;
664 
666  Teuchos::RCP<const Teuchos::ParameterList>
667  getValidParameters() const override;
668 
670 
672 
694  void
696  const Teuchos::ArrayView<const global_ordinal_type>& indices);
697 
704  void
706  const local_ordinal_type numEnt,
707  const global_ordinal_type inds[]);
708 
710 
724  void
725  insertLocalIndices(const local_ordinal_type localRow,
726  const Teuchos::ArrayView<const local_ordinal_type>& indices);
727 
734  void
735  insertLocalIndices(const local_ordinal_type localRow,
736  const local_ordinal_type numEnt,
737  const local_ordinal_type inds[]);
738 
740 
749  void removeLocalIndices(local_ordinal_type localRow);
750 
752 
754 
762  void globalAssemble();
763 
782  void
783  resumeFill(const Teuchos::RCP<Teuchos::ParameterList>& params =
784  Teuchos::null);
785 
823  void
824  fillComplete(const Teuchos::RCP<const map_type>& domainMap,
825  const Teuchos::RCP<const map_type>& rangeMap,
826  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
827 
855  void
856  fillComplete(const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
857 
886  void
887  expertStaticFillComplete(const Teuchos::RCP<const map_type>& domainMap,
888  const Teuchos::RCP<const map_type>& rangeMap,
889  const Teuchos::RCP<const import_type>& importer =
890  Teuchos::null,
891  const Teuchos::RCP<const export_type>& exporter =
892  Teuchos::null,
893  const Teuchos::RCP<Teuchos::ParameterList>& params =
894  Teuchos::null);
896 
898 
900  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const override;
901 
903  Teuchos::RCP<const map_type> getRowMap() const override;
904 
906  Teuchos::RCP<const map_type> getColMap() const override;
907 
909  Teuchos::RCP<const map_type> getDomainMap() const override;
910 
912  Teuchos::RCP<const map_type> getRangeMap() const override;
913 
915  Teuchos::RCP<const import_type> getImporter() const override;
916 
918  Teuchos::RCP<const export_type> getExporter() const override;
919 
921 
923  global_size_t getGlobalNumRows() const override;
924 
926 
929  global_size_t getGlobalNumCols() const override;
930 
932  size_t getLocalNumRows() const override;
933 
935 
937  size_t getLocalNumCols() const override;
938 
940  global_ordinal_type getIndexBase() const override;
941 
943 
945  global_size_t getGlobalNumEntries() const override;
946 
956  size_t getLocalNumEntries() const override;
957 
959 
960  size_t
961  getNumEntriesInGlobalRow(global_ordinal_type globalRow) const override;
962 
969  size_t
970  getNumEntriesInLocalRow(local_ordinal_type localRow) const override;
971 
991  size_t getLocalAllocationSize() const;
992 
1001 
1010 
1024  size_t getGlobalMaxNumRowEntries() const override;
1025 
1030  size_t getLocalMaxNumRowEntries() const override;
1031 
1047  bool hasColMap() const override;
1048 
1056  bool isLocallyIndexed() const override;
1057 
1065  bool isGloballyIndexed() const override;
1066 
1068  bool isFillComplete() const override;
1069 
1071  bool isFillActive() const;
1072 
1080  bool isSorted() const;
1081 
1083 
1089  bool isStorageOptimized() const;
1090 
1096  void
1098  nonconst_global_inds_host_view_type& gblColInds,
1099  size_t& numColInds) const override;
1100 
1108  void
1110  nonconst_local_inds_host_view_type& gblColInds,
1111  size_t& numColInds) const override;
1112 
1123  void
1125  const global_ordinal_type gblRow,
1126  global_inds_host_view_type& gblColInds) const override;
1127 
1130  bool supportsRowViews() const override;
1131 
1142  void
1144  const LocalOrdinal lclRow,
1145  local_inds_host_view_type& lclColInds) const override;
1146 
1148 
1150 
1152  std::string description() const override;
1153 
1156  void
1157  describe(Teuchos::FancyOStream& out,
1158  const Teuchos::EVerbosityLevel verbLevel =
1159  Teuchos::Describable::verbLevel_default) const override;
1160 
1162 
1164 
1172 
1173  virtual bool
1174  checkSizes(const SrcDistObject& source) override;
1175 
1176  using dist_object_type::
1178 
1180  virtual void
1181  copyAndPermute(const SrcDistObject& source,
1182  const size_t numSameIDs,
1183  const Kokkos::DualView<const local_ordinal_type*,
1184  buffer_device_type>& permuteToLIDs,
1185  const Kokkos::DualView<const local_ordinal_type*,
1186  buffer_device_type>& permuteFromLIDs,
1187  const CombineMode CM) override;
1188 
1191 
1192  void
1193  applyCrsPadding(const padding_type& padding,
1194  const bool verbose);
1195 
1196  std::unique_ptr<padding_type>
1197  computeCrsPadding(
1199  node_type>& source,
1200  const size_t numSameIDs,
1201  const Kokkos::DualView<const local_ordinal_type*,
1202  buffer_device_type>& permuteToLIDs,
1203  const Kokkos::DualView<const local_ordinal_type*,
1204  buffer_device_type>& permuteFromLIDs,
1205  const bool verbose) const;
1206 
1207  // This actually modifies imports by sorting it.
1208  std::unique_ptr<padding_type>
1209  computeCrsPaddingForImports(
1210  const Kokkos::DualView<const local_ordinal_type*,
1211  buffer_device_type>& importLIDs,
1212  Kokkos::DualView<packet_type*, buffer_device_type> imports,
1213  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1214  const bool verbose) const;
1215 
1216  std::unique_ptr<padding_type>
1217  computePaddingForCrsMatrixUnpack(
1218  const Kokkos::DualView<const local_ordinal_type*,
1219  buffer_device_type>& importLIDs,
1220  Kokkos::DualView<char*, buffer_device_type> imports,
1221  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1222  const bool verbose) const;
1223 
1224  void
1225  computeCrsPaddingForSameIDs(
1226  padding_type& padding,
1228  node_type>& source,
1229  const local_ordinal_type numSameIDs) const;
1230 
1231  void
1232  computeCrsPaddingForPermutedIDs(
1233  padding_type& padding,
1235  node_type>& source,
1236  const Kokkos::DualView<const local_ordinal_type*,
1237  buffer_device_type>& permuteToLIDs,
1238  const Kokkos::DualView<const local_ordinal_type*,
1239  buffer_device_type>& permuteFromLIDs) const;
1240 
1241  virtual void
1242  packAndPrepare(
1243  const SrcDistObject& source,
1244  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
1245  Kokkos::DualView<packet_type*, buffer_device_type>& exports,
1246  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1247  size_t& constantNumPackets) override;
1248 
1250 
1254  virtual void
1255  pack(const Teuchos::ArrayView<const local_ordinal_type>& exportLIDs,
1256  Teuchos::Array<global_ordinal_type>& exports,
1257  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1258  size_t& constantNumPackets) const override;
1259 
1260  void
1261  packFillActive(const Teuchos::ArrayView<const local_ordinal_type>& exportLIDs,
1262  Teuchos::Array<global_ordinal_type>& exports,
1263  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1264  size_t& constantNumPackets) const;
1265 
1266  void
1267  packFillActiveNew(const Kokkos::DualView<const local_ordinal_type*,
1268  buffer_device_type>& exportLIDs,
1269  Kokkos::DualView<packet_type*,
1270  buffer_device_type>& exports,
1271  Kokkos::DualView<size_t*,
1273  numPacketsPerLID,
1274  size_t& constantNumPackets) const;
1275 
1277 
1281  virtual void
1282  unpackAndCombine(const Kokkos::DualView<const local_ordinal_type*,
1283  buffer_device_type>& importLIDs,
1284  Kokkos::DualView<packet_type*,
1286  imports,
1287  Kokkos::DualView<size_t*,
1289  numPacketsPerLID,
1290  const size_t constantNumPackets,
1291  const CombineMode combineMode) override;
1292 
1294 
1296 
1339  void
1340  getLocalDiagOffsets(const Kokkos::View<size_t*, device_type, Kokkos::MemoryUnmanaged>& offsets) const;
1341 
1343  void
1344  getLocalOffRankOffsets(offset_device_view_type& offsets) const;
1345 
1355  void
1356  getLocalDiagOffsets(Teuchos::ArrayRCP<size_t>& offsets) const;
1357 
1367  void
1368  setAllIndices(const typename local_graph_device_type::row_map_type& rowPointers,
1369  const typename local_graph_device_type::entries_type::non_const_type& columnIndices);
1370 
1380  void
1381  setAllIndices(const Teuchos::ArrayRCP<size_t>& rowPointers,
1382  const Teuchos::ArrayRCP<local_ordinal_type>& columnIndices);
1383 
1386  row_ptrs_host_view_type getLocalRowPtrsHost() const;
1387 
1390  row_ptrs_device_view_type getLocalRowPtrsDevice() const;
1391 
1393  local_inds_host_view_type getLocalIndicesHost() const;
1394 
1397 
1416  void replaceColMap(const Teuchos::RCP<const map_type>& newColMap);
1417 
1437  void
1438  reindexColumns(const Teuchos::RCP<const map_type>& newColMap,
1439  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
1440  const bool sortIndicesInEachRow = true);
1441 
1448  void
1449  replaceDomainMap(const Teuchos::RCP<const map_type>& newDomainMap);
1450 
1464  void
1465  replaceDomainMapAndImporter(const Teuchos::RCP<const map_type>& newDomainMap,
1466  const Teuchos::RCP<const import_type>& newImporter);
1467 
1474  void
1475  replaceRangeMap(const Teuchos::RCP<const map_type>& newRangeMap);
1476 
1490  void
1491  replaceRangeMapAndExporter(const Teuchos::RCP<const map_type>& newRangeMap,
1492  const Teuchos::RCP<const export_type>& newExporter);
1493 
1522  virtual void
1523  removeEmptyProcessesInPlace(const Teuchos::RCP<const map_type>& newMap) override;
1525 
1526  template <class DestViewType, class SrcViewType,
1527  class DestOffsetViewType, class SrcOffsetViewType>
1528  struct pack_functor {
1529  typedef typename DestViewType::execution_space execution_space;
1530  SrcViewType src;
1531  DestViewType dest;
1532  SrcOffsetViewType src_offset;
1533  DestOffsetViewType dest_offset;
1534  typedef typename DestOffsetViewType::non_const_value_type ScalarIndx;
1535 
1536  pack_functor(DestViewType dest_,
1537  const SrcViewType src_,
1538  DestOffsetViewType dest_offset_,
1539  const SrcOffsetViewType src_offset_)
1540  : src(src_)
1541  , dest(dest_)
1542  , src_offset(src_offset_)
1543  , dest_offset(dest_offset_){};
1544 
1545  KOKKOS_INLINE_FUNCTION
1546  void operator()(size_t row) const {
1547  ScalarIndx i = src_offset(row);
1548  ScalarIndx j = dest_offset(row);
1549  const ScalarIndx k = dest_offset(row + 1);
1550  for (; j < k; j++, i++) {
1551  dest(j) = src(i);
1552  }
1553  }
1554  };
1555 
1556  private:
1557  // Friend declaration for nonmember function.
1558  template <class CrsGraphType>
1559  friend Teuchos::RCP<CrsGraphType>
1560  importAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1561  const Import<typename CrsGraphType::local_ordinal_type,
1562  typename CrsGraphType::global_ordinal_type,
1563  typename CrsGraphType::node_type>& importer,
1564  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1565  typename CrsGraphType::global_ordinal_type,
1566  typename CrsGraphType::node_type>>& domainMap,
1567  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1568  typename CrsGraphType::global_ordinal_type,
1569  typename CrsGraphType::node_type>>& rangeMap,
1570  const Teuchos::RCP<Teuchos::ParameterList>& params);
1571 
1572  // Friend declaration for nonmember function.
1573  template <class CrsGraphType>
1574  friend Teuchos::RCP<CrsGraphType>
1575  importAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1576  const Import<typename CrsGraphType::local_ordinal_type,
1577  typename CrsGraphType::global_ordinal_type,
1578  typename CrsGraphType::node_type>& rowImporter,
1579  const Import<typename CrsGraphType::local_ordinal_type,
1580  typename CrsGraphType::global_ordinal_type,
1581  typename CrsGraphType::node_type>& domainImporter,
1582  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1583  typename CrsGraphType::global_ordinal_type,
1584  typename CrsGraphType::node_type>>& domainMap,
1585  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1586  typename CrsGraphType::global_ordinal_type,
1587  typename CrsGraphType::node_type>>& rangeMap,
1588  const Teuchos::RCP<Teuchos::ParameterList>& params);
1589 
1590  // Friend declaration for nonmember function.
1591  template <class CrsGraphType>
1592  friend Teuchos::RCP<CrsGraphType>
1593  exportAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1594  const Export<typename CrsGraphType::local_ordinal_type,
1595  typename CrsGraphType::global_ordinal_type,
1596  typename CrsGraphType::node_type>& exporter,
1597  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1598  typename CrsGraphType::global_ordinal_type,
1599  typename CrsGraphType::node_type>>& domainMap,
1600  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1601  typename CrsGraphType::global_ordinal_type,
1602  typename CrsGraphType::node_type>>& rangeMap,
1603  const Teuchos::RCP<Teuchos::ParameterList>& params);
1604 
1605  // Friend declaration for nonmember function.
1606  template <class CrsGraphType>
1607  friend Teuchos::RCP<CrsGraphType>
1608  exportAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1609  const Export<typename CrsGraphType::local_ordinal_type,
1610  typename CrsGraphType::global_ordinal_type,
1611  typename CrsGraphType::node_type>& rowExporter,
1612  const Export<typename CrsGraphType::local_ordinal_type,
1613  typename CrsGraphType::global_ordinal_type,
1614  typename CrsGraphType::node_type>& domainExporter,
1615  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1616  typename CrsGraphType::global_ordinal_type,
1617  typename CrsGraphType::node_type>>& domainMap,
1618  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1619  typename CrsGraphType::global_ordinal_type,
1620  typename CrsGraphType::node_type>>& rangeMap,
1621  const Teuchos::RCP<Teuchos::ParameterList>& params);
1622 
1623  public:
1639  void
1640  importAndFillComplete(Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node>>& destGraph,
1641  const import_type& importer,
1642  const Teuchos::RCP<const map_type>& domainMap,
1643  const Teuchos::RCP<const map_type>& rangeMap,
1644  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1645 
1661  void
1662  importAndFillComplete(Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node>>& destGraph,
1663  const import_type& rowImporter,
1664  const import_type& domainImporter,
1665  const Teuchos::RCP<const map_type>& domainMap,
1666  const Teuchos::RCP<const map_type>& rangeMap,
1667  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1668 
1684  void
1685  exportAndFillComplete(Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node>>& destGraph,
1686  const export_type& exporter,
1687  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1688  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1689  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1690 
1706  void
1707  exportAndFillComplete(Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node>>& destGraph,
1708  const export_type& rowExporter,
1709  const export_type& domainExporter,
1710  const Teuchos::RCP<const map_type>& domainMap,
1711  const Teuchos::RCP<const map_type>& rangeMap,
1712  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1713 
1714  private:
1735  void
1736  transferAndFillComplete(Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node>>& destGraph,
1737  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, Node>& rowTransfer,
1738  const Teuchos::RCP<const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, Node>>& domainTransfer,
1739  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1740  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1741  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1742 
1743  protected:
1744  // these structs are conveniences, to cut down on the number of
1745  // arguments to some of the methods below.
1746  struct SLocalGlobalViews {
1747  Teuchos::ArrayView<const global_ordinal_type> ginds;
1748  Teuchos::ArrayView<const local_ordinal_type> linds;
1749  };
1750  struct SLocalGlobalNCViews {
1751  Teuchos::ArrayView<global_ordinal_type> ginds;
1752  Teuchos::ArrayView<local_ordinal_type> linds;
1753  };
1754 
1755  bool indicesAreAllocated() const;
1756 
1757  void
1758  allocateIndices(const ELocalGlobal lg, const bool verbose = false);
1759 
1761 
1762 
1772  void makeColMap(Teuchos::Array<int>& remotePIDs);
1773 
1794  std::pair<size_t, std::string>
1795  makeIndicesLocal(const bool verbose = false);
1796 
1805  void
1806  makeImportExport(Teuchos::Array<int>& remotePIDs,
1807  const bool useRemotePIDs);
1808 
1810 
1812 
1847  size_t
1848  insertIndices(RowInfo& rowInfo,
1849  const SLocalGlobalViews& newInds,
1850  const ELocalGlobal lg,
1851  const ELocalGlobal I);
1852 
1862  size_t
1864  const global_ordinal_type inputGblColInds[],
1865  const size_t numInputInds);
1866 
1876  size_t
1877  insertGlobalIndicesImpl(const RowInfo& rowInfo,
1878  const global_ordinal_type inputGblColInds[],
1879  const size_t numInputInds,
1880  std::function<void(const size_t, const size_t, const size_t)> fun =
1881  std::function<void(const size_t, const size_t, const size_t)>());
1882 
1883  void
1884  insertLocalIndicesImpl(const local_ordinal_type lclRow,
1885  const Teuchos::ArrayView<const local_ordinal_type>& gblColInds,
1886  std::function<void(const size_t, const size_t, const size_t)> fun =
1887  std::function<void(const size_t, const size_t, const size_t)>());
1888 
1904  size_t
1905  findGlobalIndices(const RowInfo& rowInfo,
1906  const Teuchos::ArrayView<const global_ordinal_type>& indices,
1907  std::function<void(const size_t, const size_t, const size_t)> fun) const;
1908 
1920  void
1922  const global_ordinal_type gblColInds[],
1923  const local_ordinal_type numGblColInds);
1924 
1936  void
1938  const global_ordinal_type gblColInds[],
1939  const local_ordinal_type numGblColInds);
1940 
1945  static const bool useAtomicUpdatesByDefault =
1946 #ifdef KOKKOS_ENABLE_SERIAL
1947  !std::is_same<execution_space, Kokkos::Serial>::value;
1948 #else
1949  true;
1950 #endif // KOKKOS_ENABLE_SERIAL
1951 
1953 
1955 
1957  bool isMerged() const;
1958 
1964  void setLocallyModified();
1965 
1966  private:
1971  void
1972  sortAndMergeAllIndices(const bool sorted, const bool merged);
1973 
1974  // mfh 08 May 2017: I only restore "protected" here for backwards
1975  // compatibility.
1976  protected:
1985  size_t sortAndMergeRowIndices(const RowInfo& rowInfo,
1986  const bool sorted,
1987  const bool merged);
1989 
1999  void
2000  setDomainRangeMaps(const Teuchos::RCP<const map_type>& domainMap,
2001  const Teuchos::RCP<const map_type>& rangeMap);
2002 
2003  void staticAssertions() const;
2004  void clearGlobalConstants();
2005 
2006  public:
2009 
2027  void computeGlobalConstants();
2028 
2029  bool haveLocalOffRankOffsets() const { return haveLocalOffRankOffsets_; }
2030 
2031  protected:
2051  void computeLocalConstants();
2052 
2055  RowInfo getRowInfo(const local_ordinal_type myRow) const;
2056 
2069  RowInfo getRowInfoFromGlobalRowIndex(const global_ordinal_type gblRow) const;
2070 
2071  public:
2080  local_graph_host_type getLocalGraphHost() const;
2081 
2082  protected:
2083  void fillLocalGraph(const Teuchos::RCP<Teuchos::ParameterList>& params);
2084 
2086  void checkInternalState() const;
2087 
2091  void swap(CrsGraph<local_ordinal_type, global_ordinal_type, Node>& graph);
2092 
2093  // Friend the tester for CrsGraph::swap
2094  friend class Tpetra::crsGraph_Swap_Tester<local_ordinal_type, global_ordinal_type, Node>;
2095 
2097  Teuchos::RCP<const map_type> rowMap_;
2099  Teuchos::RCP<const map_type> colMap_;
2101  Teuchos::RCP<const map_type> rangeMap_;
2103  Teuchos::RCP<const map_type> domainMap_;
2104 
2111  Teuchos::RCP<const import_type> importer_;
2112 
2118  Teuchos::RCP<const export_type> exporter_;
2119 
2125  Teuchos::OrdinalTraits<size_t>::invalid();
2126 
2131  Teuchos::OrdinalTraits<global_size_t>::invalid();
2132 
2138  Teuchos::OrdinalTraits<global_size_t>::invalid();
2139 
2140  private:
2141  // Replacement for device view k_rowPtrs_
2142  // Device view rowPtrsUnpacked_dev_ takes place of k_rowPtrs_
2143  // Host view rowPtrsUnpacked_host_ takes place of copies and use of getEntryOnHost
2144  // Wish this could be a WrappedDualView, but deep_copies in DualView
2145  // don't work with const data views (e.g., StaticCrsGraph::row_map)
2146  // k_rowPtrs_ is offsets wrt the ALLOCATED indices array, not necessarily
2147  // the ACTUAL compressed indices array.
2148  // When !OptimizedStorage, k_rowPtrs_ may differ from ACTUAL compressed
2149  // indices array. (Karen is skeptical that !OptimizedStorage works)
2150  // When OptimizedStorage, rowPtrsUnpacked_ = k_rowPtrsPacked_
2151 
2152  row_ptrs_device_view_type rowPtrsUnpacked_dev_;
2153  mutable row_ptrs_host_view_type rowPtrsUnpacked_host_;
2154 
2155  // Row offsets into the actual graph local indices
2156  // Device view rowPtrsUnpacked_dev_ takes place of lclGraph_.row_map
2157 
2158  row_ptrs_device_view_type rowPtrsPacked_dev_;
2159  mutable row_ptrs_host_view_type rowPtrsPacked_host_;
2160 
2162  bool packedUnpackedRowPtrsMatch_ = false;
2163 
2164  protected:
2165  void setRowPtrsUnpacked(const row_ptrs_device_view_type& dview) {
2166  packedUnpackedRowPtrsMatch_ = false;
2167  rowPtrsUnpacked_dev_ = dview;
2168  // Make sure stale host rowptrs are not kept
2169  rowPtrsUnpacked_host_ = row_ptrs_host_view_type();
2170  }
2171 
2173  const row_ptrs_device_view_type& getRowPtrsUnpackedDevice() const {
2174  return rowPtrsUnpacked_dev_;
2175  }
2176 
2178  const row_ptrs_host_view_type& getRowPtrsUnpackedHost() const {
2179  if (rowPtrsUnpacked_host_.extent(0) != rowPtrsUnpacked_dev_.extent(0)) {
2180  // NOTE: not just using create_mirror_view here, because
2181  // we do want host/device to be in different memory, even if we're using a SharedSpace.
2182  // This is so that reads will never trigger a host-device transfer.
2183  // The exception is when 'device' views are HostSpace, then don't make another copy.
2184  if constexpr (std::is_same_v<typename Node::memory_space, Kokkos::HostSpace>) {
2185  rowPtrsUnpacked_host_ = rowPtrsUnpacked_dev_;
2186  } else {
2187  // Have to make this temporary because rowptrs are const-valued
2188  typename row_ptrs_host_view_type::non_const_type rowPtrsTemp(
2189  Kokkos::view_alloc(Kokkos::WithoutInitializing, "rowPtrsUnpacked_host_"), rowPtrsUnpacked_dev_.extent(0));
2190  Kokkos::deep_copy(rowPtrsTemp, rowPtrsUnpacked_dev_);
2191  rowPtrsUnpacked_host_ = rowPtrsTemp;
2192  }
2193  // Also keep packed/unpacked views in sync, if they are known to have the same contents
2194  if (packedUnpackedRowPtrsMatch_) {
2195  rowPtrsPacked_host_ = rowPtrsUnpacked_host_;
2196  }
2197  }
2198  return rowPtrsUnpacked_host_;
2199  }
2200 
2201  void setRowPtrsPacked(const row_ptrs_device_view_type& dview) {
2202  packedUnpackedRowPtrsMatch_ = false;
2203  rowPtrsPacked_dev_ = dview;
2204  // Make sure stale host rowptrs are not kept
2205  rowPtrsPacked_host_ = row_ptrs_host_view_type();
2206  }
2207 
2209  const row_ptrs_device_view_type& getRowPtrsPackedDevice() const {
2210  return rowPtrsPacked_dev_;
2211  }
2212 
2214  const row_ptrs_host_view_type& getRowPtrsPackedHost() const {
2215  if (rowPtrsPacked_host_.extent(0) != rowPtrsPacked_dev_.extent(0)) {
2216  // NOTE: not just using create_mirror_view here, because
2217  // we do want host/device to be in different memory, even if we're using a SharedSpace.
2218  // This is so that reads will never trigger a host-device transfer.
2219  // The exception is when 'device' views are HostSpace, then don't make another copy.
2220  if constexpr (std::is_same_v<typename Node::memory_space, Kokkos::HostSpace>) {
2221  rowPtrsPacked_host_ = rowPtrsPacked_dev_;
2222  } else {
2223  // Have to make this temporary because rowptrs are const-valued
2224  typename row_ptrs_host_view_type::non_const_type rowPtrsTemp(
2225  Kokkos::view_alloc(Kokkos::WithoutInitializing, "rowPtrsPacked_host_"), rowPtrsPacked_dev_.extent(0));
2226  Kokkos::deep_copy(rowPtrsTemp, rowPtrsPacked_dev_);
2227  rowPtrsPacked_host_ = rowPtrsTemp;
2228  }
2229  // Also keep packed/unpacked views in sync, if they are known to have the same contents
2230  if (packedUnpackedRowPtrsMatch_) {
2231  rowPtrsUnpacked_host_ = rowPtrsPacked_host_;
2232  }
2233  }
2234  return rowPtrsPacked_host_;
2235  }
2236 
2237  // There are common cases where both packed and unpacked views are set to the same array.
2238  // Doing this in a single call can reduce dataspace on host, and reduce runtime by
2239  // removing a deep_copy from device to host.
2240 
2241  void setRowPtrs(const row_ptrs_device_view_type& dview) {
2242  packedUnpackedRowPtrsMatch_ = true;
2243  rowPtrsUnpacked_dev_ = dview;
2244  rowPtrsPacked_dev_ = dview;
2245  // Make sure stale host rowptrs are not kept
2246  rowPtrsUnpacked_host_ = row_ptrs_host_view_type();
2247  rowPtrsPacked_host_ = row_ptrs_host_view_type();
2248  }
2249 
2250  // TODO: Make private -- matrix shouldn't access directly the guts of graph
2251 
2266 
2281 
2282  // TODO: Make private -- matrix shouldn't access directly the guts of graph
2283 
2293 
2294  // TODO: Make private -- matrix shouldn't access directly
2296 
2300  typename local_inds_dualv_type::t_host::const_type
2301  getLocalIndsViewHost(const RowInfo& rowinfo) const;
2302 
2306  typename local_inds_dualv_type::t_dev::const_type
2307  getLocalIndsViewDevice(const RowInfo& rowinfo) const;
2308 
2312  typename global_inds_dualv_type::t_host::const_type
2313  getGlobalIndsViewHost(const RowInfo& rowinfo) const;
2314 
2318  typename global_inds_dualv_type::t_dev::const_type
2319  getGlobalIndsViewDevice(const RowInfo& rowinfo) const;
2320 
2324  typename local_inds_dualv_type::t_host
2325  getLocalIndsViewHostNonConst(const RowInfo& rowinfo);
2326 
2327  // FOR NOW...
2328  // KEEP k_numRowEntries_ (though switch from host_mirror_type to Host)
2329  // KEEP k_numAllocPerRow_ (though perhaps switch from host_mirror_type to Host)
2330 
2356  typename Kokkos::View<const size_t*, device_type>::host_mirror_type
2358 
2369 
2371 
2372 
2394 
2402  typedef typename Kokkos::View<size_t*, Kokkos::LayoutLeft, device_type>::host_mirror_type num_row_entries_type;
2403 
2404  // typedef Kokkos::View<
2405  // size_t*,
2406  // Kokkos::LayoutLeft,
2407  // Kokkos::Device<
2408  // typename Kokkos::View<
2409  // size_t*,
2410  // Kokkos::LayoutLeft,
2411  // device_type>::host_mirror_type::execution_space,
2412  // Kokkos::HostSpace> > num_row_entries_type;
2413 
2421 
2427  mutable offset_device_view_type k_offRankOffsets_;
2428 
2430 
2441  Details::STORAGE_1D_UNPACKED;
2442 
2443  bool indicesAreAllocated_ = false;
2444  bool indicesAreLocal_ = false;
2445  bool indicesAreGlobal_ = false;
2446  bool fillComplete_ = false;
2447 
2449  bool indicesAreSorted_ = true;
2452  bool noRedundancies_ = true;
2454  bool haveLocalConstants_ = false;
2456  bool haveGlobalConstants_ = false;
2458  mutable bool haveLocalOffRankOffsets_ = false;
2459 
2460  typedef typename std::map<global_ordinal_type, std::vector<global_ordinal_type>> nonlocals_type;
2461 
2463  nonlocals_type nonlocals_;
2464 
2480 
2481  private:
2483  static bool getDebug();
2484 
2487  bool debug_ = getDebug();
2488 
2490  static bool getVerbose();
2491 
2495  bool verbose_ = getVerbose();
2496 
2497  private:
2499  mutable bool need_sync_host_uvm_access = false;
2500 
2502  void set_need_sync_host_uvm_access() {
2503  need_sync_host_uvm_access = true;
2504  }
2505 
2507  void execute_sync_host_uvm_access() const {
2508  if (need_sync_host_uvm_access) {
2509  Kokkos::fence("CrsGraph::execute_sync_host_uvm_access");
2510  need_sync_host_uvm_access = false;
2511  }
2512  }
2513 }; // class CrsGraph
2514 
2522 template <class LocalOrdinal, class GlobalOrdinal, class Node>
2523 Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node>>
2525  const Teuchos::RCP<
2527  size_t maxNumEntriesPerRow = 0,
2528  const Teuchos::RCP<Teuchos::ParameterList>& params =
2529  Teuchos::null) {
2530  using Teuchos::rcp;
2532  return rcp(new graph_type(map, maxNumEntriesPerRow,
2533  params));
2534 }
2535 
2585 template <class CrsGraphType>
2586 Teuchos::RCP<CrsGraphType>
2587 importAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2588  const Import<typename CrsGraphType::local_ordinal_type,
2589  typename CrsGraphType::global_ordinal_type,
2590  typename CrsGraphType::node_type>& importer,
2591  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2592  typename CrsGraphType::global_ordinal_type,
2593  typename CrsGraphType::node_type>>& domainMap = Teuchos::null,
2594  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2595  typename CrsGraphType::global_ordinal_type,
2596  typename CrsGraphType::node_type>>& rangeMap = Teuchos::null,
2597  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
2598  Teuchos::RCP<CrsGraphType> destGraph;
2599  sourceGraph->importAndFillComplete(destGraph, importer, domainMap, rangeMap, params);
2600  return destGraph;
2601 }
2602 
2653 template <class CrsGraphType>
2654 Teuchos::RCP<CrsGraphType>
2655 importAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2656  const Import<typename CrsGraphType::local_ordinal_type,
2657  typename CrsGraphType::global_ordinal_type,
2658  typename CrsGraphType::node_type>& rowImporter,
2659  const Import<typename CrsGraphType::local_ordinal_type,
2660  typename CrsGraphType::global_ordinal_type,
2661  typename CrsGraphType::node_type>& domainImporter,
2662  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2663  typename CrsGraphType::global_ordinal_type,
2664  typename CrsGraphType::node_type>>& domainMap,
2665  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2666  typename CrsGraphType::global_ordinal_type,
2667  typename CrsGraphType::node_type>>& rangeMap,
2668  const Teuchos::RCP<Teuchos::ParameterList>& params) {
2669  Teuchos::RCP<CrsGraphType> destGraph;
2670  sourceGraph->importAndFillComplete(destGraph, rowImporter, domainImporter, domainMap, rangeMap, params);
2671  return destGraph;
2672 }
2673 
2707 template <class CrsGraphType>
2708 Teuchos::RCP<CrsGraphType>
2709 exportAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2710  const Export<typename CrsGraphType::local_ordinal_type,
2711  typename CrsGraphType::global_ordinal_type,
2712  typename CrsGraphType::node_type>& exporter,
2713  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2714  typename CrsGraphType::global_ordinal_type,
2715  typename CrsGraphType::node_type>>& domainMap = Teuchos::null,
2716  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2717  typename CrsGraphType::global_ordinal_type,
2718  typename CrsGraphType::node_type>>& rangeMap = Teuchos::null,
2719  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
2720  Teuchos::RCP<CrsGraphType> destGraph;
2721  sourceGraph->exportAndFillComplete(destGraph, exporter, domainMap, rangeMap, params);
2722  return destGraph;
2723 }
2724 
2758 template <class CrsGraphType>
2759 Teuchos::RCP<CrsGraphType>
2760 exportAndFillCompleteCrsGraph(const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2761  const Export<typename CrsGraphType::local_ordinal_type,
2762  typename CrsGraphType::global_ordinal_type,
2763  typename CrsGraphType::node_type>& rowExporter,
2764  const Export<typename CrsGraphType::local_ordinal_type,
2765  typename CrsGraphType::global_ordinal_type,
2766  typename CrsGraphType::node_type>& domainExporter,
2767  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2768  typename CrsGraphType::global_ordinal_type,
2769  typename CrsGraphType::node_type>>& domainMap,
2770  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2771  typename CrsGraphType::global_ordinal_type,
2772  typename CrsGraphType::node_type>>& rangeMap,
2773  const Teuchos::RCP<Teuchos::ParameterList>& params) {
2774  Teuchos::RCP<CrsGraphType> destGraph;
2775  sourceGraph->exportAndFillComplete(destGraph, rowExporter, domainExporter, domainMap, rangeMap, params);
2776  return destGraph;
2777 }
2778 
2779 } // namespace Tpetra
2780 
2781 #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.
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
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().
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.
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.
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.
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.
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.
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.
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().
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.
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.