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  using local_graph_host_type = typename local_graph_device_type::HostMirror;
231 
238 
239 public:
240  // Types used for CrsGraph's storage of local column indices
241  using local_inds_dualv_type =
242  Kokkos::DualView<local_ordinal_type*, device_type>;
243  using local_inds_wdv_type =
245 
246  // Types used for CrsGraph's storage of global column indices
247  using global_inds_dualv_type =
248  Kokkos::DualView<global_ordinal_type*, device_type>;
249  using global_inds_wdv_type =
251 
252 public:
254  using row_ptrs_device_view_type =
255  typename row_graph_type::row_ptrs_device_view_type;
256  using row_ptrs_host_view_type =
257  typename row_graph_type::row_ptrs_host_view_type;
258 
261  typename row_graph_type::local_inds_device_view_type;
262  using local_inds_host_view_type =
263  typename row_graph_type::local_inds_host_view_type;
264  using nonconst_local_inds_host_view_type =
265  typename row_graph_type::nonconst_local_inds_host_view_type;
266 
269  typename row_graph_type::global_inds_device_view_type;
270  using global_inds_host_view_type =
271  typename row_graph_type::global_inds_host_view_type;
272  using nonconst_global_inds_host_view_type =
273  typename row_graph_type::nonconst_global_inds_host_view_type;
274 
275  using offset_device_view_type =
276  typename row_ptrs_device_view_type::non_const_type;
277 
279 
280 
293  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
294  const size_t maxNumEntriesPerRow,
295  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
296 
309  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
310  const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
311  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
312 
326  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
327  const Teuchos::ArrayView<const size_t>& numEntPerRow,
328  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
329 
330 
343 
347  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
348  const Teuchos::RCP<const map_type>& colMap,
349  const size_t maxNumEntriesPerRow,
350  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
351 
366  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
367  const Teuchos::RCP<const map_type>& colMap,
368  const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
369  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
370 
386  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
387  const Teuchos::RCP<const map_type>& colMap,
388  const Teuchos::ArrayView<const size_t>& numEntPerRow,
389  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
390 
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);
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
695  insertGlobalIndices (const global_ordinal_type globalRow,
696  const Teuchos::ArrayView<const global_ordinal_type>& indices);
697 
704  void
705  insertGlobalIndices (const global_ordinal_type globalRow,
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 
902 
904  Teuchos::RCP<const map_type> getRowMap () const override;
905 
907  Teuchos::RCP<const map_type> getColMap () const override;
908 
910  Teuchos::RCP<const map_type> getDomainMap () const override;
911 
913  Teuchos::RCP<const map_type> getRangeMap () const override;
914 
916  Teuchos::RCP<const import_type> getImporter () const override;
917 
919  Teuchos::RCP<const export_type> getExporter () const override;
920 
922 
924  global_size_t getGlobalNumRows() const override;
925 
927 
930  global_size_t getGlobalNumCols () const override;
931 
933  size_t getLocalNumRows () const override;
934 
936 
938  size_t getLocalNumCols () const override;
939 
941  global_ordinal_type getIndexBase () const override;
942 
944 
946  global_size_t getGlobalNumEntries () const override;
947 
957  size_t getLocalNumEntries() const override;
958 
960 
961  size_t
962  getNumEntriesInGlobalRow (global_ordinal_type globalRow) const override;
963 
970  size_t
971  getNumEntriesInLocalRow (local_ordinal_type localRow) const override;
972 
992  size_t getLocalAllocationSize () const;
993 
1001  size_t getNumAllocatedEntriesInGlobalRow (global_ordinal_type globalRow) const;
1002 
1010  size_t getNumAllocatedEntriesInLocalRow (local_ordinal_type localRow) const;
1011 
1025  size_t getGlobalMaxNumRowEntries () const override;
1026 
1031  size_t getLocalMaxNumRowEntries () const override;
1032 
1048  bool hasColMap () const override;
1049 
1050 
1058  bool isLocallyIndexed () const override;
1059 
1067  bool isGloballyIndexed () const override;
1068 
1070  bool isFillComplete () const override;
1071 
1073  bool isFillActive () const;
1074 
1082  bool isSorted () const;
1083 
1085 
1091  bool isStorageOptimized () const;
1092 
1093 
1099  void
1101  nonconst_global_inds_host_view_type &gblColInds,
1102  size_t& numColInds) const override;
1103 
1111  void
1113  nonconst_local_inds_host_view_type &gblColInds,
1114  size_t& numColInds) const override;
1115 
1126  void
1128  const global_ordinal_type gblRow,
1129  global_inds_host_view_type &gblColInds) const override;
1130 
1131 
1134  bool supportsRowViews () const override;
1135 
1136 
1147  void
1148  getLocalRowView (
1149  const LocalOrdinal lclRow,
1150  local_inds_host_view_type &lclColInds) const override;
1151 
1152 
1154 
1156 
1158  std::string description () const override;
1159 
1162  void
1163  describe (Teuchos::FancyOStream& out,
1164  const Teuchos::EVerbosityLevel verbLevel =
1165  Teuchos::Describable::verbLevel_default) const override;
1166 
1168 
1170 
1178 
1179  virtual bool
1180  checkSizes (const SrcDistObject& source) override;
1181 
1182  // clang-format on
1183  using dist_object_type::
1185  // clang-format off
1187 
1188  virtual void
1190  (const SrcDistObject& source,
1191  const size_t numSameIDs,
1192  const Kokkos::DualView<const local_ordinal_type*,
1193  buffer_device_type>& permuteToLIDs,
1194  const Kokkos::DualView<const local_ordinal_type*,
1195  buffer_device_type>& permuteFromLIDs,
1196  const CombineMode CM) override;
1197 
1200 
1201  void
1202  applyCrsPadding(const padding_type& padding,
1203  const bool verbose);
1204 
1205  std::unique_ptr<padding_type>
1206  computeCrsPadding(
1208  node_type>& source,
1209  const size_t numSameIDs,
1210  const Kokkos::DualView<const local_ordinal_type*,
1211  buffer_device_type>& permuteToLIDs,
1212  const Kokkos::DualView<const local_ordinal_type*,
1213  buffer_device_type>& permuteFromLIDs,
1214  const bool verbose) const;
1215 
1216  // This actually modifies imports by sorting it.
1217  std::unique_ptr<padding_type>
1218  computeCrsPaddingForImports(
1219  const Kokkos::DualView<const local_ordinal_type*,
1220  buffer_device_type>& importLIDs,
1221  Kokkos::DualView<packet_type*, buffer_device_type> imports,
1222  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1223  const bool verbose) const;
1224 
1225  std::unique_ptr<padding_type>
1226  computePaddingForCrsMatrixUnpack(
1227  const Kokkos::DualView<const local_ordinal_type*,
1228  buffer_device_type>& importLIDs,
1229  Kokkos::DualView<char*, buffer_device_type> imports,
1230  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1231  const bool verbose) const;
1232 
1233  void
1234  computeCrsPaddingForSameIDs(
1235  padding_type& padding,
1237  node_type>& source,
1238  const local_ordinal_type numSameIDs) const;
1239 
1240  void
1241  computeCrsPaddingForPermutedIDs(
1242  padding_type& padding,
1244  node_type>& source,
1245  const Kokkos::DualView<const local_ordinal_type*,
1246  buffer_device_type>& permuteToLIDs,
1247  const Kokkos::DualView<const local_ordinal_type*,
1248  buffer_device_type>& permuteFromLIDs) const;
1249 
1250  virtual void
1251  packAndPrepare(
1252  const SrcDistObject& source,
1253  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
1254  Kokkos::DualView<packet_type*, buffer_device_type>& exports,
1255  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1256  size_t& constantNumPackets) override;
1257 
1258  // clang-format on
1260  // clang-format off
1264 
1265  virtual void
1266  pack (const Teuchos::ArrayView<const local_ordinal_type>& exportLIDs,
1267  Teuchos::Array<global_ordinal_type>& exports,
1268  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1269  size_t& constantNumPackets) const override;
1270 
1271  void
1272  packFillActive (const Teuchos::ArrayView<const local_ordinal_type>& exportLIDs,
1273  Teuchos::Array<global_ordinal_type>& exports,
1274  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1275  size_t& constantNumPackets) const;
1276 
1277  void
1278  packFillActiveNew (const Kokkos::DualView<const local_ordinal_type*,
1279  buffer_device_type>& exportLIDs,
1280  Kokkos::DualView<packet_type*,
1281  buffer_device_type>& exports,
1282  Kokkos::DualView<size_t*,
1283  buffer_device_type> numPacketsPerLID,
1284  size_t& constantNumPackets) const;
1285 
1286  // clang-format on
1288  // clang-format off
1292 
1293  virtual void
1295  (const Kokkos::DualView<const local_ordinal_type*,
1296  buffer_device_type>& importLIDs,
1297  Kokkos::DualView<packet_type*,
1298  buffer_device_type> imports,
1299  Kokkos::DualView<size_t*,
1300  buffer_device_type> numPacketsPerLID,
1301  const size_t constantNumPackets,
1302  const CombineMode combineMode) override;
1303 
1305 
1307 
1350  void
1351  getLocalDiagOffsets (const Kokkos::View<size_t*, device_type, Kokkos::MemoryUnmanaged>& offsets) const;
1352 
1354  void
1355  getLocalOffRankOffsets (offset_device_view_type& offsets) const;
1356 
1366  void
1367  getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
1368 
1378  void
1379  setAllIndices (const typename local_graph_device_type::row_map_type& rowPointers,
1380  const typename local_graph_device_type::entries_type::non_const_type& columnIndices);
1381 
1391  void
1392  setAllIndices (const Teuchos::ArrayRCP<size_t> & rowPointers,
1393  const Teuchos::ArrayRCP<local_ordinal_type> & columnIndices);
1394 
1397  row_ptrs_host_view_type getLocalRowPtrsHost () const;
1398 
1401  row_ptrs_device_view_type getLocalRowPtrsDevice () const;
1402 
1404  local_inds_host_view_type getLocalIndicesHost () const;
1405 
1408 
1427  void replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
1428 
1448  void
1449  reindexColumns (const Teuchos::RCP<const map_type>& newColMap,
1450  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
1451  const bool sortIndicesInEachRow = true);
1452 
1459  void
1460  replaceDomainMap (const Teuchos::RCP<const map_type>& newDomainMap);
1461 
1475  void
1476  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
1477  const Teuchos::RCP<const import_type>& newImporter);
1478 
1485  void
1486  replaceRangeMap (const Teuchos::RCP<const map_type>& newRangeMap);
1487 
1501  void
1502  replaceRangeMapAndExporter (const Teuchos::RCP<const map_type>& newRangeMap,
1503  const Teuchos::RCP<const export_type>& newExporter);
1504 
1533  virtual void
1534  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
1536 
1537  template<class DestViewType, class SrcViewType,
1538  class DestOffsetViewType, class SrcOffsetViewType >
1539  struct pack_functor {
1540  typedef typename DestViewType::execution_space execution_space;
1541  SrcViewType src;
1542  DestViewType dest;
1543  SrcOffsetViewType src_offset;
1544  DestOffsetViewType dest_offset;
1545  typedef typename DestOffsetViewType::non_const_value_type ScalarIndx;
1546 
1547  pack_functor(DestViewType dest_,
1548  const SrcViewType src_,
1549  DestOffsetViewType dest_offset_,
1550  const SrcOffsetViewType src_offset_):
1551  src(src_),dest(dest_),
1552  src_offset(src_offset_),dest_offset(dest_offset_) {};
1553 
1554  KOKKOS_INLINE_FUNCTION
1555  void operator() (size_t row) const {
1556  ScalarIndx i = src_offset(row);
1557  ScalarIndx j = dest_offset(row);
1558  const ScalarIndx k = dest_offset(row+1);
1559  for(;j<k;j++,i++) {
1560  dest(j) = src(i);
1561  }
1562  }
1563  };
1564 
1565  private:
1566  // Friend declaration for nonmember function.
1567  template<class CrsGraphType>
1568  friend Teuchos::RCP<CrsGraphType>
1569  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1570  const Import<typename CrsGraphType::local_ordinal_type,
1571  typename CrsGraphType::global_ordinal_type,
1572  typename CrsGraphType::node_type>& importer,
1573  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1574  typename CrsGraphType::global_ordinal_type,
1575  typename CrsGraphType::node_type> >& domainMap,
1576  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1577  typename CrsGraphType::global_ordinal_type,
1578  typename CrsGraphType::node_type> >& rangeMap,
1579  const Teuchos::RCP<Teuchos::ParameterList>& params);
1580 
1581  // Friend declaration for nonmember function.
1582  template<class CrsGraphType>
1583  friend Teuchos::RCP<CrsGraphType>
1584  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1585  const Import<typename CrsGraphType::local_ordinal_type,
1586  typename CrsGraphType::global_ordinal_type,
1587  typename CrsGraphType::node_type>& rowImporter,
1588  const Import<typename CrsGraphType::local_ordinal_type,
1589  typename CrsGraphType::global_ordinal_type,
1590  typename CrsGraphType::node_type>& domainImporter,
1591  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1592  typename CrsGraphType::global_ordinal_type,
1593  typename CrsGraphType::node_type> >& domainMap,
1594  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1595  typename CrsGraphType::global_ordinal_type,
1596  typename CrsGraphType::node_type> >& rangeMap,
1597  const Teuchos::RCP<Teuchos::ParameterList>& params);
1598 
1599 
1600  // Friend declaration for nonmember function.
1601  template<class CrsGraphType>
1602  friend Teuchos::RCP<CrsGraphType>
1603  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1604  const Export<typename CrsGraphType::local_ordinal_type,
1605  typename CrsGraphType::global_ordinal_type,
1606  typename CrsGraphType::node_type>& exporter,
1607  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1608  typename CrsGraphType::global_ordinal_type,
1609  typename CrsGraphType::node_type> >& domainMap,
1610  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1611  typename CrsGraphType::global_ordinal_type,
1612  typename CrsGraphType::node_type> >& rangeMap,
1613  const Teuchos::RCP<Teuchos::ParameterList>& params);
1614 
1615  // Friend declaration for nonmember function.
1616  template<class CrsGraphType>
1617  friend Teuchos::RCP<CrsGraphType>
1618  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1619  const Export<typename CrsGraphType::local_ordinal_type,
1620  typename CrsGraphType::global_ordinal_type,
1621  typename CrsGraphType::node_type>& rowExporter,
1622  const Export<typename CrsGraphType::local_ordinal_type,
1623  typename CrsGraphType::global_ordinal_type,
1624  typename CrsGraphType::node_type>& domainExporter,
1625  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1626  typename CrsGraphType::global_ordinal_type,
1627  typename CrsGraphType::node_type> >& domainMap,
1628  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1629  typename CrsGraphType::global_ordinal_type,
1630  typename CrsGraphType::node_type> >& rangeMap,
1631  const Teuchos::RCP<Teuchos::ParameterList>& params);
1632 
1633  public:
1649  void
1650  importAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1651  const import_type& importer,
1652  const Teuchos::RCP<const map_type>& domainMap,
1653  const Teuchos::RCP<const map_type>& rangeMap,
1654  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1655 
1671  void
1672  importAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1673  const import_type& rowImporter,
1674  const import_type& domainImporter,
1675  const Teuchos::RCP<const map_type>& domainMap,
1676  const Teuchos::RCP<const map_type>& rangeMap,
1677  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1678 
1679 
1695  void
1696  exportAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1697  const export_type& exporter,
1698  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1699  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1700  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1701 
1717  void
1718  exportAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1719  const export_type& rowExporter,
1720  const export_type& domainExporter,
1721  const Teuchos::RCP<const map_type>& domainMap,
1722  const Teuchos::RCP<const map_type>& rangeMap,
1723  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1724 
1725 
1726  private:
1747  void
1748  transferAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1749  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, Node>& rowTransfer,
1750  const Teuchos::RCP<const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, Node> > & domainTransfer,
1751  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1752  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1753  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1754 
1755  protected:
1756  // these structs are conveniences, to cut down on the number of
1757  // arguments to some of the methods below.
1758  struct SLocalGlobalViews {
1759  Teuchos::ArrayView<const global_ordinal_type> ginds;
1760  Teuchos::ArrayView<const local_ordinal_type> linds;
1761  };
1762  struct SLocalGlobalNCViews {
1763  Teuchos::ArrayView<global_ordinal_type> ginds;
1764  Teuchos::ArrayView<local_ordinal_type> linds;
1765  };
1766 
1767  bool indicesAreAllocated () const;
1768 
1769  void
1770  allocateIndices(const ELocalGlobal lg, const bool verbose=false);
1771 
1773 
1774 
1784  void makeColMap (Teuchos::Array<int>& remotePIDs);
1785 
1806  std::pair<size_t, std::string>
1807  makeIndicesLocal(const bool verbose=false);
1808 
1817  void
1818  makeImportExport (Teuchos::Array<int>& remotePIDs,
1819  const bool useRemotePIDs);
1820 
1822 
1824 
1859  size_t
1860  insertIndices (RowInfo& rowInfo,
1861  const SLocalGlobalViews& newInds,
1862  const ELocalGlobal lg,
1863  const ELocalGlobal I);
1864 
1874  size_t
1876  const global_ordinal_type inputGblColInds[],
1877  const size_t numInputInds);
1878 
1888  size_t
1889  insertGlobalIndicesImpl (const RowInfo& rowInfo,
1890  const global_ordinal_type inputGblColInds[],
1891  const size_t numInputInds,
1892  std::function<void(const size_t, const size_t, const size_t)> fun =
1893  std::function<void(const size_t, const size_t, const size_t)>());
1894 
1895  void
1896  insertLocalIndicesImpl (const local_ordinal_type lclRow,
1897  const Teuchos::ArrayView<const local_ordinal_type>& gblColInds,
1898  std::function<void(const size_t, const size_t, const size_t)> fun =
1899  std::function<void(const size_t, const size_t, const size_t)>());
1900 
1916  size_t
1917  findGlobalIndices(const RowInfo& rowInfo,
1918  const Teuchos::ArrayView<const global_ordinal_type>& indices,
1919  std::function<void(const size_t, const size_t, const size_t)> fun) const;
1920 
1932  void
1934  const global_ordinal_type gblColInds[],
1935  const local_ordinal_type numGblColInds);
1936 
1948  void
1950  const global_ordinal_type gblColInds[],
1951  const local_ordinal_type numGblColInds);
1952 
1957  static const bool useAtomicUpdatesByDefault =
1958 #ifdef KOKKOS_ENABLE_SERIAL
1959  ! std::is_same<execution_space, Kokkos::Serial>::value;
1960 #else
1961  true;
1962 #endif // KOKKOS_ENABLE_SERIAL
1963 
1965 
1967 
1969  bool isMerged () const;
1970 
1976  void setLocallyModified ();
1977 
1978  private:
1983  void
1984  sortAndMergeAllIndices (const bool sorted, const bool merged);
1985 
1986  // mfh 08 May 2017: I only restore "protected" here for backwards
1987  // compatibility.
1988  protected:
1997  size_t sortAndMergeRowIndices (const RowInfo& rowInfo,
1998  const bool sorted,
1999  const bool merged);
2001 
2011  void
2012  setDomainRangeMaps (const Teuchos::RCP<const map_type>& domainMap,
2013  const Teuchos::RCP<const map_type>& rangeMap);
2014 
2015  void staticAssertions() const;
2016  void clearGlobalConstants();
2017 
2018  public:
2021 
2039  void computeGlobalConstants ();
2040 
2041  bool haveLocalOffRankOffsets() const { return haveLocalOffRankOffsets_;}
2042 
2043  protected:
2063  void computeLocalConstants ();
2064 
2067  RowInfo getRowInfo (const local_ordinal_type myRow) const;
2068 
2081  RowInfo getRowInfoFromGlobalRowIndex (const global_ordinal_type gblRow) const;
2082 
2083  public:
2084 
2093  local_graph_host_type getLocalGraphHost () const;
2094 
2095  protected:
2096 
2097  void fillLocalGraph (const Teuchos::RCP<Teuchos::ParameterList>& params);
2098 
2100  void checkInternalState () const;
2101 
2105  void swap(CrsGraph<local_ordinal_type, global_ordinal_type, Node> & graph);
2106 
2107  // Friend the tester for CrsGraph::swap
2108  friend class Tpetra::crsGraph_Swap_Tester<local_ordinal_type, global_ordinal_type, Node>;
2109 
2110 
2112  Teuchos::RCP<const map_type> rowMap_;
2114  Teuchos::RCP<const map_type> colMap_;
2116  Teuchos::RCP<const map_type> rangeMap_;
2118  Teuchos::RCP<const map_type> domainMap_;
2119 
2126  Teuchos::RCP<const import_type> importer_;
2127 
2133  Teuchos::RCP<const export_type> exporter_;
2134 
2140  Teuchos::OrdinalTraits<size_t>::invalid();
2141 
2146  Teuchos::OrdinalTraits<global_size_t>::invalid();
2147 
2153  Teuchos::OrdinalTraits<global_size_t>::invalid();
2154 
2155  private:
2156  // Replacement for device view k_rowPtrs_
2157  // Device view rowPtrsUnpacked_dev_ takes place of k_rowPtrs_
2158  // Host view rowPtrsUnpacked_host_ takes place of copies and use of getEntryOnHost
2159  // Wish this could be a WrappedDualView, but deep_copies in DualView
2160  // don't work with const data views (e.g., StaticCrsGraph::row_map)
2161  // k_rowPtrs_ is offsets wrt the ALLOCATED indices array, not necessarily
2162  // the ACTUAL compressed indices array.
2163  // When !OptimizedStorage, k_rowPtrs_ may differ from ACTUAL compressed
2164  // indices array. (Karen is skeptical that !OptimizedStorage works)
2165  // When OptimizedStorage, rowPtrsUnpacked_ = k_rowPtrsPacked_
2166 
2167  row_ptrs_device_view_type rowPtrsUnpacked_dev_;
2168  mutable row_ptrs_host_view_type rowPtrsUnpacked_host_;
2169 
2170  // Row offsets into the actual graph local indices
2171  // Device view rowPtrsUnpacked_dev_ takes place of lclGraph_.row_map
2172 
2173  row_ptrs_device_view_type rowPtrsPacked_dev_;
2174  mutable row_ptrs_host_view_type rowPtrsPacked_host_;
2175 
2177  bool packedUnpackedRowPtrsMatch_ = false;
2178 
2179  protected:
2180  void setRowPtrsUnpacked(const row_ptrs_device_view_type &dview) {
2181  packedUnpackedRowPtrsMatch_ = false;
2182  rowPtrsUnpacked_dev_ = dview;
2183  //Make sure stale host rowptrs are not kept
2184  rowPtrsUnpacked_host_ = row_ptrs_host_view_type();
2185  }
2186 
2188  const row_ptrs_device_view_type& getRowPtrsUnpackedDevice() const
2189  {
2190  return rowPtrsUnpacked_dev_;
2191  }
2192 
2194  const row_ptrs_host_view_type& getRowPtrsUnpackedHost() const
2195  {
2196  if(rowPtrsUnpacked_host_.extent(0) != rowPtrsUnpacked_dev_.extent(0))
2197  {
2198  //NOTE: not just using create_mirror_view here, because
2199  //we do want host/device to be in different memory, even if we're using a SharedSpace.
2200  //This is so that reads will never trigger a host-device transfer.
2201  //The exception is when 'device' views are HostSpace, then don't make another copy.
2202  if constexpr(std::is_same_v<typename Node::memory_space, Kokkos::HostSpace>)
2203  {
2204  rowPtrsUnpacked_host_ = rowPtrsUnpacked_dev_;
2205  }
2206  else
2207  {
2208  //Have to make this temporary because rowptrs are const-valued
2209  typename row_ptrs_host_view_type::non_const_type rowPtrsTemp(
2210  Kokkos::view_alloc(Kokkos::WithoutInitializing, "rowPtrsUnpacked_host_"), rowPtrsUnpacked_dev_.extent(0));
2211  Kokkos::deep_copy(rowPtrsTemp, rowPtrsUnpacked_dev_);
2212  rowPtrsUnpacked_host_= rowPtrsTemp;
2213  }
2214  //Also keep packed/unpacked views in sync, if they are known to have the same contents
2215  if(packedUnpackedRowPtrsMatch_)
2216  {
2217  rowPtrsPacked_host_ = rowPtrsUnpacked_host_;
2218  }
2219  }
2220  return rowPtrsUnpacked_host_;
2221  }
2222 
2223  void setRowPtrsPacked(const row_ptrs_device_view_type &dview) {
2224  packedUnpackedRowPtrsMatch_ = false;
2225  rowPtrsPacked_dev_ = dview;
2226  //Make sure stale host rowptrs are not kept
2227  rowPtrsPacked_host_ = row_ptrs_host_view_type();
2228  }
2229 
2231  const row_ptrs_device_view_type& getRowPtrsPackedDevice() const
2232  {
2233  return rowPtrsPacked_dev_;
2234  }
2235 
2237  const row_ptrs_host_view_type& getRowPtrsPackedHost() const
2238  {
2239  if(rowPtrsPacked_host_.extent(0) != rowPtrsPacked_dev_.extent(0))
2240  {
2241  //NOTE: not just using create_mirror_view here, because
2242  //we do want host/device to be in different memory, even if we're using a SharedSpace.
2243  //This is so that reads will never trigger a host-device transfer.
2244  //The exception is when 'device' views are HostSpace, then don't make another copy.
2245  if constexpr(std::is_same_v<typename Node::memory_space, Kokkos::HostSpace>)
2246  {
2247  rowPtrsPacked_host_ = rowPtrsPacked_dev_;
2248  }
2249  else
2250  {
2251  //Have to make this temporary because rowptrs are const-valued
2252  typename row_ptrs_host_view_type::non_const_type rowPtrsTemp(
2253  Kokkos::view_alloc(Kokkos::WithoutInitializing, "rowPtrsPacked_host_"), rowPtrsPacked_dev_.extent(0));
2254  Kokkos::deep_copy(rowPtrsTemp, rowPtrsPacked_dev_);
2255  rowPtrsPacked_host_= rowPtrsTemp;
2256  }
2257  //Also keep packed/unpacked views in sync, if they are known to have the same contents
2258  if(packedUnpackedRowPtrsMatch_)
2259  {
2260  rowPtrsUnpacked_host_ = rowPtrsPacked_host_;
2261  }
2262  }
2263  return rowPtrsPacked_host_;
2264  }
2265 
2266  // There are common cases where both packed and unpacked views are set to the same array.
2267  // Doing this in a single call can reduce dataspace on host, and reduce runtime by
2268  // removing a deep_copy from device to host.
2269 
2270  void setRowPtrs(const row_ptrs_device_view_type &dview) {
2271  packedUnpackedRowPtrsMatch_ = true;
2272  rowPtrsUnpacked_dev_ = dview;
2273  rowPtrsPacked_dev_ = dview;
2274  //Make sure stale host rowptrs are not kept
2275  rowPtrsUnpacked_host_ = row_ptrs_host_view_type();
2276  rowPtrsPacked_host_ = row_ptrs_host_view_type();
2277  }
2278 
2279  //TODO: Make private -- matrix shouldn't access directly the guts of graph
2280 
2295 
2310 
2311  //TODO: Make private -- matrix shouldn't access directly the guts of graph
2312 
2322 
2323  // TODO: Make private -- matrix shouldn't access directly
2325 
2329  typename local_inds_dualv_type::t_host::const_type
2330  getLocalIndsViewHost (const RowInfo& rowinfo) const;
2331 
2335  typename local_inds_dualv_type::t_dev::const_type
2336  getLocalIndsViewDevice (const RowInfo& rowinfo) const;
2337 
2341  typename global_inds_dualv_type::t_host::const_type
2342  getGlobalIndsViewHost (const RowInfo& rowinfo) const;
2343 
2347  typename global_inds_dualv_type::t_dev::const_type
2348  getGlobalIndsViewDevice (const RowInfo& rowinfo) const;
2349 
2353  typename local_inds_dualv_type::t_host
2354  getLocalIndsViewHostNonConst (const RowInfo& rowinfo);
2355 
2356  // FOR NOW...
2357  // KEEP k_numRowEntries_ (though switch from HostMirror to Host)
2358  // KEEP k_numAllocPerRow_ (though perhaps switch from HostMirror to Host)
2359 
2385  typename Kokkos::View<const size_t*, device_type>::HostMirror
2387 
2398 
2400 
2401 
2423 
2431  typedef typename Kokkos::View<size_t*, Kokkos::LayoutLeft, device_type>::HostMirror num_row_entries_type;
2432 
2433  // typedef Kokkos::View<
2434  // size_t*,
2435  // Kokkos::LayoutLeft,
2436  // Kokkos::Device<
2437  // typename Kokkos::View<
2438  // size_t*,
2439  // Kokkos::LayoutLeft,
2440  // device_type>::HostMirror::execution_space,
2441  // Kokkos::HostSpace> > num_row_entries_type;
2442 
2450 
2456  mutable offset_device_view_type k_offRankOffsets_;
2457 
2459 
2470  Details::STORAGE_1D_UNPACKED;
2471 
2472  bool indicesAreAllocated_ = false;
2473  bool indicesAreLocal_ = false;
2474  bool indicesAreGlobal_ = false;
2475  bool fillComplete_ = false;
2476 
2478  bool indicesAreSorted_ = true;
2481  bool noRedundancies_ = true;
2483  bool haveLocalConstants_ = false;
2485  bool haveGlobalConstants_ = false;
2487  mutable bool haveLocalOffRankOffsets_ = false;
2488 
2489  typedef typename std::map<global_ordinal_type, std::vector<global_ordinal_type> > nonlocals_type;
2490 
2492  nonlocals_type nonlocals_;
2493 
2509 
2510  private:
2512  static bool getDebug();
2513 
2516  bool debug_ = getDebug();
2517 
2519  static bool getVerbose();
2520 
2524  bool verbose_ = getVerbose();
2525 
2526  private:
2528  mutable bool need_sync_host_uvm_access = false;
2529 
2531  void set_need_sync_host_uvm_access() {
2532  need_sync_host_uvm_access = true;
2533  }
2534 
2536  void execute_sync_host_uvm_access() const {
2537  if(need_sync_host_uvm_access) {
2538  Kokkos::fence("CrsGraph::execute_sync_host_uvm_access");
2539  need_sync_host_uvm_access = false;
2540  }
2541  }
2542  }; // class CrsGraph
2543 
2551  template <class LocalOrdinal, class GlobalOrdinal, class Node>
2552  Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
2554  const Teuchos::RCP<
2556  size_t maxNumEntriesPerRow = 0,
2557  const Teuchos::RCP<Teuchos::ParameterList>& params =
2558  Teuchos::null)
2559  {
2560  using Teuchos::rcp;
2562  return rcp(new graph_type(map, maxNumEntriesPerRow,
2563  params));
2564  }
2565 
2615  template<class CrsGraphType>
2616  Teuchos::RCP<CrsGraphType>
2617  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2618  const Import<typename CrsGraphType::local_ordinal_type,
2619  typename CrsGraphType::global_ordinal_type,
2620  typename CrsGraphType::node_type>& importer,
2621  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2622  typename CrsGraphType::global_ordinal_type,
2623  typename CrsGraphType::node_type> >& domainMap = Teuchos::null,
2624  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2625  typename CrsGraphType::global_ordinal_type,
2626  typename CrsGraphType::node_type> >& rangeMap = Teuchos::null,
2627  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2628  {
2629  Teuchos::RCP<CrsGraphType> destGraph;
2630  sourceGraph->importAndFillComplete (destGraph,importer,domainMap, rangeMap, params);
2631  return destGraph;
2632  }
2633 
2684  template<class CrsGraphType>
2685  Teuchos::RCP<CrsGraphType>
2686  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2687  const Import<typename CrsGraphType::local_ordinal_type,
2688  typename CrsGraphType::global_ordinal_type,
2689  typename CrsGraphType::node_type>& rowImporter,
2690  const Import<typename CrsGraphType::local_ordinal_type,
2691  typename CrsGraphType::global_ordinal_type,
2692  typename CrsGraphType::node_type>& domainImporter,
2693  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2694  typename CrsGraphType::global_ordinal_type,
2695  typename CrsGraphType::node_type> >& domainMap,
2696  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2697  typename CrsGraphType::global_ordinal_type,
2698  typename CrsGraphType::node_type> >& rangeMap,
2699  const Teuchos::RCP<Teuchos::ParameterList>& params)
2700  {
2701  Teuchos::RCP<CrsGraphType> destGraph;
2702  sourceGraph->importAndFillComplete (destGraph,rowImporter,domainImporter, domainMap, rangeMap, params);
2703  return destGraph;
2704  }
2705 
2739  template<class CrsGraphType>
2740  Teuchos::RCP<CrsGraphType>
2741  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2742  const Export<typename CrsGraphType::local_ordinal_type,
2743  typename CrsGraphType::global_ordinal_type,
2744  typename CrsGraphType::node_type>& exporter,
2745  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2746  typename CrsGraphType::global_ordinal_type,
2747  typename CrsGraphType::node_type> >& domainMap = Teuchos::null,
2748  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2749  typename CrsGraphType::global_ordinal_type,
2750  typename CrsGraphType::node_type> >& rangeMap = Teuchos::null,
2751  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2752  {
2753  Teuchos::RCP<CrsGraphType> destGraph;
2754  sourceGraph->exportAndFillComplete (destGraph,exporter,domainMap, rangeMap, params);
2755  return destGraph;
2756  }
2757 
2791  template<class CrsGraphType>
2792  Teuchos::RCP<CrsGraphType>
2793  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2794  const Export<typename CrsGraphType::local_ordinal_type,
2795  typename CrsGraphType::global_ordinal_type,
2796  typename CrsGraphType::node_type>& rowExporter,
2797  const Export<typename CrsGraphType::local_ordinal_type,
2798  typename CrsGraphType::global_ordinal_type,
2799  typename CrsGraphType::node_type>& domainExporter,
2800  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2801  typename CrsGraphType::global_ordinal_type,
2802  typename CrsGraphType::node_type> >& domainMap,
2803  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2804  typename CrsGraphType::global_ordinal_type,
2805  typename CrsGraphType::node_type> >& rangeMap,
2806  const Teuchos::RCP<Teuchos::ParameterList>& params)
2807  {
2808  Teuchos::RCP<CrsGraphType> destGraph;
2809  sourceGraph->exportAndFillComplete (destGraph,rowExporter,domainExporter,domainMap, rangeMap, params);
2810  return destGraph;
2811  }
2812 
2813 
2814 } // namespace Tpetra
2815 
2816 #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.
Kokkos::View< const size_t *, device_type >::HostMirror k_numAllocPerRow_
The maximum number of entries to allow in each locally owned row, per row.
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.
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.
Kokkos::View< size_t *, Kokkos::LayoutLeft, device_type >::HostMirror num_row_entries_type
Row offsets for &quot;1-D&quot; storage.
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.
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.