Tpetra parallel linear algebra  Version of the Day
Tpetra_CrsGraph_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // ************************************************************************
38 // @HEADER
39 
40 #ifndef TPETRA_CRSGRAPH_DECL_HPP
41 #define TPETRA_CRSGRAPH_DECL_HPP
42 
45 
46 #include "Tpetra_CrsGraph_fwd.hpp"
47 #include "Tpetra_CrsMatrix_fwd.hpp"
49 #include "Tpetra_DistObject.hpp"
50 #include "Tpetra_Exceptions.hpp"
51 #include "Tpetra_RowGraph.hpp"
52 #include "Tpetra_Util.hpp" // need this here for sort2
53 #include "Tpetra_Details_WrappedDualView.hpp"
54 
55 #include "KokkosSparse_findRelOffset.hpp"
56 #include "Kokkos_DualView.hpp"
57 #include "Kokkos_StaticCrsGraph.hpp"
58 
59 #include "Teuchos_CommHelpers.hpp"
60 #include "Teuchos_Describable.hpp"
61 #include "Teuchos_OrdinalTraits.hpp"
62 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
63 
64 #include <functional> // std::function
65 #include <memory>
66 
67 namespace Tpetra {
68 
69 
70  // Forward declaration for CrsGraph::swap() test
71  template<class LocalOrdinal, class GlobalOrdinal, class Node> class crsGraph_Swap_Tester;
72 
73 #ifndef DOXYGEN_SHOULD_SKIP_THIS
74  namespace Details {
75  template<class LocalOrdinal,
76  class GlobalOrdinal>
77  class CrsPadding;
78  } // namespace Details
79 
80  namespace { // (anonymous)
81 
82  template<class ViewType>
83  struct UnmanagedView {
84  static_assert (Kokkos::is_view<ViewType>::value,
85  "ViewType must be a Kokkos::View specialization.");
86  // FIXME (mfh 02 Dec 2015) Right now, this strips away other
87  // memory traits. Christian will add an "AllTraits" enum which is
88  // the enum value of MemoryTraits<T>, that will help us fix this.
89  typedef Kokkos::View<typename ViewType::data_type,
90  typename ViewType::array_layout,
91  typename ViewType::device_type,
92  Kokkos::MemoryUnmanaged> type;
93  };
94 
95  } // namespace (anonymous)
96 #endif // DOXYGEN_SHOULD_SKIP_THIS
97 
106  struct RowInfo {
107  size_t localRow;
108  size_t allocSize;
109  size_t numEntries;
110  size_t offset1D;
111  };
112 
113  enum ELocalGlobal {
114  LocalIndices,
115  GlobalIndices
116  };
117 
118  namespace Details {
150  STORAGE_1D_UNPACKED, //<! 1-D "unpacked" storage
151  STORAGE_1D_PACKED, //<! 1-D "packed" storage
152  STORAGE_UB //<! Invalid value; upper bound on enum values
153  };
154 
155  } // namespace Details
156 
215  template <class LocalOrdinal,
216  class GlobalOrdinal,
217  class Node>
218  class CrsGraph :
219  public RowGraph<LocalOrdinal, GlobalOrdinal, Node>,
220  public DistObject<GlobalOrdinal,
221  LocalOrdinal,
222  GlobalOrdinal,
223  Node>,
224  public Teuchos::ParameterListAcceptorDefaultBase
225  {
226  template <class S, class LO, class GO, class N>
227  friend class CrsMatrix;
228  template <class LO2, class GO2, class N2>
229  friend class CrsGraph;
230  template <class LO, class GO, class N>
231  friend class FECrsGraph;
232 
235 
236  public:
238  using local_ordinal_type = LocalOrdinal;
240  using global_ordinal_type = GlobalOrdinal;
242  using device_type = typename Node::device_type;
244  using execution_space = typename device_type::execution_space;
245 
250  using node_type = Node;
251 
254  Kokkos::StaticCrsGraph<local_ordinal_type, Kokkos::LayoutLeft,
255  device_type, void, size_t>;
256 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
257  using local_graph_type = local_graph_device_type;
258 #endif
259 
261  using local_graph_host_type = typename local_graph_device_type::HostMirror;
262 
269 
270 protected:
271  // Types used for CrsGraph's storage of local column indices
272  using local_inds_dualv_type =
273  Kokkos::DualView<local_ordinal_type*, device_type>;
274  using local_inds_wdv_type =
275  Details::WrappedDualView<local_inds_dualv_type>;
276 
277  // Types used for CrsGraph's storage of global column indices
278  using global_inds_dualv_type =
279  Kokkos::DualView<global_ordinal_type*, device_type>;
280  using global_inds_wdv_type =
281  Details::WrappedDualView<global_inds_dualv_type>;
282 
283 public:
285  using row_ptrs_device_view_type =
286  typename row_graph_type::row_ptrs_device_view_type;
287  using row_ptrs_host_view_type =
288  typename row_graph_type::row_ptrs_host_view_type;
289 
292  typename row_graph_type::local_inds_device_view_type;
293  using local_inds_host_view_type =
294  typename row_graph_type::local_inds_host_view_type;
295  using nonconst_local_inds_host_view_type =
296  typename row_graph_type::nonconst_local_inds_host_view_type;
297 
300  typename row_graph_type::global_inds_device_view_type;
301  using global_inds_host_view_type =
302  typename row_graph_type::global_inds_host_view_type;
303  using nonconst_global_inds_host_view_type =
304  typename row_graph_type::nonconst_global_inds_host_view_type;
305 
306  using offset_device_view_type =
307  typename row_ptrs_device_view_type::non_const_type;
308 
309 
310 //KDDKDD INROW using local_inds_host_view_type =
311 //KDDKDD INROW typename local_inds_dualv_type::t_host::const_type;
312 
313 //KDDKDD INROW using global_inds_host_view_type =
314 //KDDKDD INROW typename global_inds_dualv_type::t_host::const_type;
315 
317 //KDDKDD INROW using local_inds_device_view_type =
318 //KDDKDD INROW typename local_inds_dualv_type::t_dev::const_type;
319 
321 //KDDKDD INROW using global_inds_device_view_type =
322 //KDDKDD INROW typename global_inds_dualv_type::t_dev::const_type;
323 
325 
326 
341  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
342  const size_t maxNumEntriesPerRow,
343  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
344  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
345 
360  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
361  const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
362  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
363  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
364 
380  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
381  const Teuchos::ArrayView<const size_t>& numEntPerRow,
382  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
383  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
384 
385 
404  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
405  const Teuchos::RCP<const map_type>& colMap,
406  const size_t maxNumEntriesPerRow,
407  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
408  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
409 
426  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
427  const Teuchos::RCP<const map_type>& colMap,
428  const Kokkos::DualView<const size_t*, device_type>& numEntPerRow,
429  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
430  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
431 
449  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
450  const Teuchos::RCP<const map_type>& colMap,
451  const Teuchos::ArrayView<const size_t>& numEntPerRow,
452  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE,
453  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
454 
455 
468  const Teuchos::RCP<const map_type>& rowMap,
469  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
470 
493  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
494  const Teuchos::RCP<const map_type>& colMap,
495  const typename local_graph_device_type::row_map_type& rowPointers,
496  const typename local_graph_device_type::entries_type::non_const_type& columnIndices,
497  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
498 
521  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
522  const Teuchos::RCP<const map_type>& colMap,
523  const Teuchos::ArrayRCP<size_t>& rowPointers,
524  const Teuchos::ArrayRCP<local_ordinal_type>& columnIndices,
525  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
526 
548  CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
549  const Teuchos::RCP<const map_type>& colMap,
550  const local_graph_device_type& lclGraph,
551  const Teuchos::RCP<Teuchos::ParameterList>& params);
552 
579  CrsGraph (const local_graph_device_type& lclGraph,
580  const Teuchos::RCP<const map_type>& rowMap,
581  const Teuchos::RCP<const map_type>& colMap,
582  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
583  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
584  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
585 
590  CrsGraph (const local_graph_device_type& lclGraph,
591  const Teuchos::RCP<const map_type>& rowMap,
592  const Teuchos::RCP<const map_type>& colMap,
593  const Teuchos::RCP<const map_type>& domainMap,
594  const Teuchos::RCP<const map_type>& rangeMap,
595  const Teuchos::RCP<const import_type>& importer,
596  const Teuchos::RCP<const export_type>& exporter,
597  const Teuchos::RCP<Teuchos::ParameterList>& params =
598  Teuchos::null);
599 
602 
605 
608 
611 
621  virtual ~CrsGraph () = default;
622 
650 
668 
670 
672 
674  void
675  setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& params) override;
676 
678  Teuchos::RCP<const Teuchos::ParameterList>
679  getValidParameters () const override;
680 
682 
684 
706  void
707  insertGlobalIndices (const global_ordinal_type globalRow,
708  const Teuchos::ArrayView<const global_ordinal_type>& indices);
709 
716  void
717  insertGlobalIndices (const global_ordinal_type globalRow,
718  const local_ordinal_type numEnt,
719  const global_ordinal_type inds[]);
720 
722 
736  void
737  insertLocalIndices (const local_ordinal_type localRow,
738  const Teuchos::ArrayView<const local_ordinal_type>& indices);
739 
746  void
747  insertLocalIndices (const local_ordinal_type localRow,
748  const local_ordinal_type numEnt,
749  const local_ordinal_type inds[]);
750 
752 
761  void removeLocalIndices (local_ordinal_type localRow);
762 
764 
766 
774  void globalAssemble ();
775 
794  void
795  resumeFill (const Teuchos::RCP<Teuchos::ParameterList>& params =
796  Teuchos::null);
797 
835  void
836  fillComplete (const Teuchos::RCP<const map_type>& domainMap,
837  const Teuchos::RCP<const map_type>& rangeMap,
838  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
839 
867  void
868  fillComplete (const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
869 
898  void
899  expertStaticFillComplete (const Teuchos::RCP<const map_type>& domainMap,
900  const Teuchos::RCP<const map_type>& rangeMap,
901  const Teuchos::RCP<const import_type>& importer =
902  Teuchos::null,
903  const Teuchos::RCP<const export_type>& exporter =
904  Teuchos::null,
905  const Teuchos::RCP<Teuchos::ParameterList>& params =
906  Teuchos::null);
908 
910 
912  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const override;
913 
914 
916  Teuchos::RCP<const map_type> getRowMap () const override;
917 
919  Teuchos::RCP<const map_type> getColMap () const override;
920 
922  Teuchos::RCP<const map_type> getDomainMap () const override;
923 
925  Teuchos::RCP<const map_type> getRangeMap () const override;
926 
928  Teuchos::RCP<const import_type> getImporter () const override;
929 
931  Teuchos::RCP<const export_type> getExporter () const override;
932 
934 
936  global_size_t getGlobalNumRows() const override;
937 
939 
942  global_size_t getGlobalNumCols () const override;
943 
945  size_t getNodeNumRows () const override;
946 
948 
950  size_t getNodeNumCols () const override;
951 
953  global_ordinal_type getIndexBase () const override;
954 
956 
958  global_size_t getGlobalNumEntries () const override;
959 
969  size_t getNodeNumEntries() const override;
970 
972 
973  size_t
974  getNumEntriesInGlobalRow (global_ordinal_type globalRow) const override;
975 
982  size_t
983  getNumEntriesInLocalRow (local_ordinal_type localRow) const override;
984 
1004  size_t getNodeAllocationSize () const;
1005 
1013  size_t getNumAllocatedEntriesInGlobalRow (global_ordinal_type globalRow) const;
1014 
1022  size_t getNumAllocatedEntriesInLocalRow (local_ordinal_type localRow) const;
1023 
1037  size_t getGlobalMaxNumRowEntries () const override;
1038 
1043  size_t getNodeMaxNumRowEntries () const override;
1044 
1060  bool hasColMap () const override;
1061 
1062 
1070  bool isLocallyIndexed () const override;
1071 
1079  bool isGloballyIndexed () const override;
1080 
1082  bool isFillComplete () const override;
1083 
1085  bool isFillActive () const;
1086 
1094  bool isSorted () const;
1095 
1097 
1103  bool isStorageOptimized () const;
1104 
1106  ProfileType getProfileType () const;
1107 
1113  void
1115  nonconst_global_inds_host_view_type &gblColInds,
1116  size_t& numColInds) const override;
1117 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
1118  void
1120  const Teuchos::ArrayView<global_ordinal_type>& gblColInds,
1121  size_t& numColInds) const override;
1122 #endif
1130  void
1132  nonconst_local_inds_host_view_type &gblColInds,
1133  size_t& numColInds) const override;
1134 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
1135  void
1137  const Teuchos::ArrayView<local_ordinal_type>& lclColInds,
1138  size_t& numColInds) const override;
1139 #endif
1140 
1141 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
1152  void
1153  getGlobalRowView (const global_ordinal_type gblRow,
1154  Teuchos::ArrayView<const global_ordinal_type>& gblColInds) const override;
1155 #endif // TPETRA_ENABLE_DEPRECATED_CODE
1156 
1167  void
1169  const global_ordinal_type gblRow,
1170  global_inds_host_view_type &gblColInds) const override;
1171 
1172 
1175  bool supportsRowViews () const override;
1176 
1177 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
1188  void
1189  getLocalRowView (const local_ordinal_type lclRow,
1190  Teuchos::ArrayView<const local_ordinal_type>& lclColInds) const override;
1191 #endif // TPETRA_ENABLE_DEPRECATED_CODE
1192 
1203  void
1204  getLocalRowView (
1205  const LocalOrdinal lclRow,
1206  local_inds_host_view_type &lclColInds) const override;
1207 
1208 
1210 
1212 
1214  std::string description () const override;
1215 
1218  void
1219  describe (Teuchos::FancyOStream& out,
1220  const Teuchos::EVerbosityLevel verbLevel =
1221  Teuchos::Describable::verbLevel_default) const override;
1222 
1224 
1226 
1234 
1235  virtual bool
1236  checkSizes (const SrcDistObject& source) override;
1237 
1238  virtual void
1239  copyAndPermute
1240  (const SrcDistObject& source,
1241  const size_t numSameIDs,
1242  const Kokkos::DualView<const local_ordinal_type*,
1243  buffer_device_type>& permuteToLIDs,
1244  const Kokkos::DualView<const local_ordinal_type*,
1245  buffer_device_type>& permuteFromLIDs,
1246  const CombineMode CM) override;
1247 
1250 
1251  void
1252  applyCrsPadding(const padding_type& padding,
1253  const bool verbose);
1254 
1255  std::unique_ptr<padding_type>
1256  computeCrsPadding(
1258  node_type>& source,
1259  const size_t numSameIDs,
1260  const Kokkos::DualView<const local_ordinal_type*,
1261  buffer_device_type>& permuteToLIDs,
1262  const Kokkos::DualView<const local_ordinal_type*,
1263  buffer_device_type>& permuteFromLIDs,
1264  const bool verbose) const;
1265 
1266  // This actually modifies imports by sorting it.
1267  std::unique_ptr<padding_type>
1268  computeCrsPaddingForImports(
1269  const Kokkos::DualView<const local_ordinal_type*,
1270  buffer_device_type>& importLIDs,
1271  Kokkos::DualView<packet_type*, buffer_device_type> imports,
1272  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1273  const bool verbose) const;
1274 
1275  std::unique_ptr<padding_type>
1276  computePaddingForCrsMatrixUnpack(
1277  const Kokkos::DualView<const local_ordinal_type*,
1278  buffer_device_type>& importLIDs,
1279  Kokkos::DualView<char*, buffer_device_type> imports,
1280  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1281  const bool verbose) const;
1282 
1283  void
1284  computeCrsPaddingForSameIDs(
1285  padding_type& padding,
1287  node_type>& source,
1288  const local_ordinal_type numSameIDs) const;
1289 
1290  void
1291  computeCrsPaddingForPermutedIDs(
1292  padding_type& padding,
1294  node_type>& source,
1295  const Kokkos::DualView<const local_ordinal_type*,
1296  buffer_device_type>& permuteToLIDs,
1297  const Kokkos::DualView<const local_ordinal_type*,
1298  buffer_device_type>& permuteFromLIDs) const;
1299 
1300  virtual void
1301  packAndPrepare(
1302  const SrcDistObject& source,
1303  const Kokkos::DualView<const local_ordinal_type*, buffer_device_type>& exportLIDs,
1304  Kokkos::DualView<packet_type*, buffer_device_type>& exports,
1305  Kokkos::DualView<size_t*, buffer_device_type> numPacketsPerLID,
1306  size_t& constantNumPackets) override;
1307 
1308  virtual void
1309  pack (const Teuchos::ArrayView<const local_ordinal_type>& exportLIDs,
1310  Teuchos::Array<global_ordinal_type>& exports,
1311  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1312  size_t& constantNumPackets) const override;
1313 
1314  void
1315  packFillActive (const Teuchos::ArrayView<const local_ordinal_type>& exportLIDs,
1316  Teuchos::Array<global_ordinal_type>& exports,
1317  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1318  size_t& constantNumPackets) const;
1319 
1320  void
1321  packFillActiveNew (const Kokkos::DualView<const local_ordinal_type*,
1322  buffer_device_type>& exportLIDs,
1323  Kokkos::DualView<packet_type*,
1324  buffer_device_type>& exports,
1325  Kokkos::DualView<size_t*,
1326  buffer_device_type> numPacketsPerLID,
1327  size_t& constantNumPackets) const;
1328 
1329  virtual void
1330  unpackAndCombine
1331  (const Kokkos::DualView<const local_ordinal_type*,
1332  buffer_device_type>& importLIDs,
1333  Kokkos::DualView<packet_type*,
1334  buffer_device_type> imports,
1335  Kokkos::DualView<size_t*,
1336  buffer_device_type> numPacketsPerLID,
1337  const size_t constantNumPackets,
1338  const CombineMode combineMode) override;
1339 
1341 
1343 
1386  void
1387  getLocalDiagOffsets (const Kokkos::View<size_t*, device_type, Kokkos::MemoryUnmanaged>& offsets) const;
1388 
1390  void
1391  getLocalOffRankOffsets (offset_device_view_type& offsets) const;
1392 
1402  void
1403  getLocalDiagOffsets (Teuchos::ArrayRCP<size_t>& offsets) const;
1404 
1427  //TPETRA_DEPRECATED
1428  void
1429  getNumEntriesPerLocalRowUpperBound (Teuchos::ArrayRCP<const size_t>& boundPerLocalRow,
1430  size_t& boundForAllLocalRows,
1431  bool& boundSameForAllLocalRows) const;
1432 
1442  void
1443  setAllIndices (const typename local_graph_device_type::row_map_type& rowPointers,
1444  const typename local_graph_device_type::entries_type::non_const_type& columnIndices);
1445 
1455  void
1456  setAllIndices (const Teuchos::ArrayRCP<size_t> & rowPointers,
1457  const Teuchos::ArrayRCP<local_ordinal_type> & columnIndices);
1458 
1466  Teuchos::ArrayRCP<const size_t> getNodeRowPtrs () const;
1467 
1469 
1471  Teuchos::ArrayRCP<const local_ordinal_type> getNodePackedIndices () const;
1472 
1491  void replaceColMap (const Teuchos::RCP<const map_type>& newColMap);
1492 
1512  void
1513  reindexColumns (const Teuchos::RCP<const map_type>& newColMap,
1514  const Teuchos::RCP<const import_type>& newImport = Teuchos::null,
1515  const bool sortIndicesInEachRow = true);
1516 
1523  void
1524  replaceDomainMap (const Teuchos::RCP<const map_type>& newDomainMap);
1525 
1539  void
1540  replaceDomainMapAndImporter (const Teuchos::RCP<const map_type>& newDomainMap,
1541  const Teuchos::RCP<const import_type>& newImporter);
1542 
1549  void
1550  replaceRangeMap (const Teuchos::RCP<const map_type>& newRangeMap);
1551 
1565  void
1566  replaceRangeMapAndExporter (const Teuchos::RCP<const map_type>& newRangeMap,
1567  const Teuchos::RCP<const export_type>& newExporter);
1568 
1597  virtual void
1598  removeEmptyProcessesInPlace (const Teuchos::RCP<const map_type>& newMap) override;
1600 
1601  template<class DestViewType, class SrcViewType,
1602  class DestOffsetViewType, class SrcOffsetViewType >
1603  struct pack_functor {
1604  typedef typename DestViewType::execution_space execution_space;
1605  SrcViewType src;
1606  DestViewType dest;
1607  SrcOffsetViewType src_offset;
1608  DestOffsetViewType dest_offset;
1609  typedef typename DestOffsetViewType::non_const_value_type ScalarIndx;
1610 
1611  pack_functor(DestViewType dest_,
1612  const SrcViewType src_,
1613  DestOffsetViewType dest_offset_,
1614  const SrcOffsetViewType src_offset_):
1615  src(src_),dest(dest_),
1616  src_offset(src_offset_),dest_offset(dest_offset_) {};
1617 
1618  KOKKOS_INLINE_FUNCTION
1619  void operator() (size_t row) const {
1620  ScalarIndx i = src_offset(row);
1621  ScalarIndx j = dest_offset(row);
1622  const ScalarIndx k = dest_offset(row+1);
1623  for(;j<k;j++,i++) {
1624  dest(j) = src(i);
1625  }
1626  }
1627  };
1628 
1629  private:
1630  // Friend declaration for nonmember function.
1631  template<class CrsGraphType>
1632  friend Teuchos::RCP<CrsGraphType>
1633  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1634  const Import<typename CrsGraphType::local_ordinal_type,
1635  typename CrsGraphType::global_ordinal_type,
1636  typename CrsGraphType::node_type>& importer,
1637  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1638  typename CrsGraphType::global_ordinal_type,
1639  typename CrsGraphType::node_type> >& domainMap,
1640  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1641  typename CrsGraphType::global_ordinal_type,
1642  typename CrsGraphType::node_type> >& rangeMap,
1643  const Teuchos::RCP<Teuchos::ParameterList>& params);
1644 
1645  // Friend declaration for nonmember function.
1646  template<class CrsGraphType>
1647  friend Teuchos::RCP<CrsGraphType>
1648  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1649  const Import<typename CrsGraphType::local_ordinal_type,
1650  typename CrsGraphType::global_ordinal_type,
1651  typename CrsGraphType::node_type>& rowImporter,
1652  const Import<typename CrsGraphType::local_ordinal_type,
1653  typename CrsGraphType::global_ordinal_type,
1654  typename CrsGraphType::node_type>& domainImporter,
1655  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1656  typename CrsGraphType::global_ordinal_type,
1657  typename CrsGraphType::node_type> >& domainMap,
1658  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1659  typename CrsGraphType::global_ordinal_type,
1660  typename CrsGraphType::node_type> >& rangeMap,
1661  const Teuchos::RCP<Teuchos::ParameterList>& params);
1662 
1663 
1664  // Friend declaration for nonmember function.
1665  template<class CrsGraphType>
1666  friend Teuchos::RCP<CrsGraphType>
1667  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1668  const Export<typename CrsGraphType::local_ordinal_type,
1669  typename CrsGraphType::global_ordinal_type,
1670  typename CrsGraphType::node_type>& exporter,
1671  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1672  typename CrsGraphType::global_ordinal_type,
1673  typename CrsGraphType::node_type> >& domainMap,
1674  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1675  typename CrsGraphType::global_ordinal_type,
1676  typename CrsGraphType::node_type> >& rangeMap,
1677  const Teuchos::RCP<Teuchos::ParameterList>& params);
1678 
1679  // Friend declaration for nonmember function.
1680  template<class CrsGraphType>
1681  friend Teuchos::RCP<CrsGraphType>
1682  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
1683  const Export<typename CrsGraphType::local_ordinal_type,
1684  typename CrsGraphType::global_ordinal_type,
1685  typename CrsGraphType::node_type>& rowExporter,
1686  const Export<typename CrsGraphType::local_ordinal_type,
1687  typename CrsGraphType::global_ordinal_type,
1688  typename CrsGraphType::node_type>& domainExporter,
1689  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1690  typename CrsGraphType::global_ordinal_type,
1691  typename CrsGraphType::node_type> >& domainMap,
1692  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
1693  typename CrsGraphType::global_ordinal_type,
1694  typename CrsGraphType::node_type> >& rangeMap,
1695  const Teuchos::RCP<Teuchos::ParameterList>& params);
1696 
1697  public:
1713  void
1714  importAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1715  const import_type& importer,
1716  const Teuchos::RCP<const map_type>& domainMap,
1717  const Teuchos::RCP<const map_type>& rangeMap,
1718  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1719 
1735  void
1736  importAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1737  const import_type& rowImporter,
1738  const import_type& domainImporter,
1739  const Teuchos::RCP<const map_type>& domainMap,
1740  const Teuchos::RCP<const map_type>& rangeMap,
1741  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1742 
1743 
1759  void
1760  exportAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1761  const export_type& exporter,
1762  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1763  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1764  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1765 
1781  void
1782  exportAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1783  const export_type& rowExporter,
1784  const export_type& domainExporter,
1785  const Teuchos::RCP<const map_type>& domainMap,
1786  const Teuchos::RCP<const map_type>& rangeMap,
1787  const Teuchos::RCP<Teuchos::ParameterList>& params) const;
1788 
1789 
1790  private:
1811  void
1812  transferAndFillComplete (Teuchos::RCP<CrsGraph<local_ordinal_type, global_ordinal_type, Node> >& destGraph,
1813  const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, Node>& rowTransfer,
1814  const Teuchos::RCP<const ::Tpetra::Details::Transfer<local_ordinal_type, global_ordinal_type, Node> > & domainTransfer,
1815  const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1816  const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1817  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) const;
1818 
1819  protected:
1820  // these structs are conveniences, to cut down on the number of
1821  // arguments to some of the methods below.
1822  struct SLocalGlobalViews {
1823  Teuchos::ArrayView<const global_ordinal_type> ginds;
1824  Teuchos::ArrayView<const local_ordinal_type> linds;
1825  };
1826  struct SLocalGlobalNCViews {
1827  Teuchos::ArrayView<global_ordinal_type> ginds;
1828  Teuchos::ArrayView<local_ordinal_type> linds;
1829  };
1830 
1831  bool indicesAreAllocated () const;
1832 
1833  void
1834  allocateIndices(const ELocalGlobal lg, const bool verbose=false);
1835 
1837 
1838 
1848  void makeColMap (Teuchos::Array<int>& remotePIDs);
1849 
1870  std::pair<size_t, std::string>
1871  makeIndicesLocal(const bool verbose=false);
1872 
1881  void
1882  makeImportExport (Teuchos::Array<int>& remotePIDs,
1883  const bool useRemotePIDs);
1884 
1886 
1888 
1923  size_t
1924  insertIndices (RowInfo& rowInfo,
1925  const SLocalGlobalViews& newInds,
1926  const ELocalGlobal lg,
1927  const ELocalGlobal I);
1928 
1938  size_t
1940  const global_ordinal_type inputGblColInds[],
1941  const size_t numInputInds);
1942 
1952  size_t
1953  insertGlobalIndicesImpl (const RowInfo& rowInfo,
1954  const global_ordinal_type inputGblColInds[],
1955  const size_t numInputInds,
1956  std::function<void(const size_t, const size_t, const size_t)> fun =
1957  std::function<void(const size_t, const size_t, const size_t)>());
1958 
1959  void
1960  insertLocalIndicesImpl (const local_ordinal_type lclRow,
1961  const Teuchos::ArrayView<const local_ordinal_type>& gblColInds,
1962  std::function<void(const size_t, const size_t, const size_t)> fun =
1963  std::function<void(const size_t, const size_t, const size_t)>());
1964 
1980  size_t
1981  findGlobalIndices(const RowInfo& rowInfo,
1982  const Teuchos::ArrayView<const global_ordinal_type>& indices,
1983  std::function<void(const size_t, const size_t, const size_t)> fun) const;
1984 
1996  void
1998  const global_ordinal_type gblColInds[],
1999  const local_ordinal_type numGblColInds);
2000 
2012  void
2014  const global_ordinal_type gblColInds[],
2015  const local_ordinal_type numGblColInds);
2016 
2021  static const bool useAtomicUpdatesByDefault =
2022 #ifdef KOKKOS_ENABLE_SERIAL
2023  ! std::is_same<execution_space, Kokkos::Serial>::value;
2024 #else
2025  true;
2026 #endif // KOKKOS_ENABLE_SERIAL
2027 
2029 
2031 
2033  bool isMerged () const;
2034 
2040  void setLocallyModified ();
2041 
2042  private:
2047  void
2048  sortAndMergeAllIndices (const bool sorted, const bool merged);
2049 
2050  // mfh 08 May 2017: I only restore "protected" here for backwards
2051  // compatibility.
2052  protected:
2061  size_t sortAndMergeRowIndices (const RowInfo& rowInfo,
2062  const bool sorted,
2063  const bool merged);
2065 
2075  void
2076  setDomainRangeMaps (const Teuchos::RCP<const map_type>& domainMap,
2077  const Teuchos::RCP<const map_type>& rangeMap);
2078 
2079  void staticAssertions() const;
2080  void clearGlobalConstants();
2081 
2082  public:
2085 
2103  void computeGlobalConstants ();
2104 
2105  bool haveLocalOffRankOffsets() const { return haveLocalOffRankOffsets_;}
2106 
2107  protected:
2127  void computeLocalConstants ();
2128 
2131  RowInfo getRowInfo (const local_ordinal_type myRow) const;
2132 
2145  RowInfo getRowInfoFromGlobalRowIndex (const global_ordinal_type gblRow) const;
2146 
2147 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2151  // Replaced by getLocalIndsViewHost
2152  Teuchos::ArrayView<const local_ordinal_type>
2153  getLocalView (const RowInfo& rowinfo) const;
2154 #endif
2155 
2156  protected:
2157 
2158 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2162  // Replaced by getGlobalIndsViewHost
2163  Teuchos::ArrayView<const global_ordinal_type>
2164  getGlobalView (const RowInfo& rowinfo) const;
2165 #endif
2166 
2167  public:
2168 
2176 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
2177  // TPETRA_DEPRECATED
2178  local_graph_device_type getLocalGraph () const;
2179 #endif
2181  local_graph_host_type getLocalGraphHost () const;
2182 
2183  protected:
2184 
2185  void fillLocalGraph (const Teuchos::RCP<Teuchos::ParameterList>& params);
2186 
2188  void checkInternalState () const;
2189 
2193  void swap(CrsGraph<local_ordinal_type, global_ordinal_type, Node> & graph);
2194 
2195  // Friend the tester for CrsGraph::swap
2196  friend class Tpetra::crsGraph_Swap_Tester<local_ordinal_type, global_ordinal_type, Node>;
2197 
2198 
2200  Teuchos::RCP<const map_type> rowMap_;
2202  Teuchos::RCP<const map_type> colMap_;
2204  Teuchos::RCP<const map_type> rangeMap_;
2206  Teuchos::RCP<const map_type> domainMap_;
2207 
2214  Teuchos::RCP<const import_type> importer_;
2215 
2221  Teuchos::RCP<const export_type> exporter_;
2222 
2228  Teuchos::OrdinalTraits<size_t>::invalid();
2229 
2234  Teuchos::OrdinalTraits<global_size_t>::invalid();
2235 
2241  Teuchos::OrdinalTraits<global_size_t>::invalid();
2242 
2243  // Replacement for device view k_rowPtrs_
2244  // Device view rowPtrsUnpacked_dev_ takes place of k_rowPtrs_
2245  // Host view rowPtrsUnpacked_host_ takes place of copies and use of getEntryOnHost
2246  // Wish this could be a WrappedDualView, but deep_copies in DualView
2247  // don't work with const data views (e.g., StaticCrsGraph::row_map)
2248  // k_rowPtrs_ is offsets wrt the ALLOCATED indices array, not necessarily
2249  // the ACTUAL compressed indices array.
2250  // When !OptimizedStorage, k_rowPtrs_ may differ from ACTUAL compressed
2251  // indices array. (Karen is skeptical that !OptimizedStorage works)
2252  // When OptimizedStorage, rowPtrsUnpacked_ = k_rowPtrsPacked_
2253 
2254 //KDDKDD INROW using row_ptrs_device_view_type =
2255 //KDDKDD INROW Kokkos::View<const typename local_graph_device_type::size_type *,
2256 //KDDKDD INROW device_type> ;
2257 //KDDKDD INROW using row_ptrs_host_view_type =
2258 //KDDKDD INROW typename row_ptrs_device_view_type::HostMirror::const_type;
2259  row_ptrs_device_view_type rowPtrsUnpacked_dev_;
2260  row_ptrs_host_view_type rowPtrsUnpacked_host_;
2261 
2262  void setRowPtrsUnpacked(const row_ptrs_device_view_type &dview) {
2263  rowPtrsUnpacked_dev_ = dview;
2264  rowPtrsUnpacked_host_ =
2265  Kokkos::create_mirror_view_and_copy(
2266  typename row_ptrs_device_view_type::host_mirror_space(),
2267  dview);
2268  }
2269 
2270  // Row offsets into the actual graph local indices
2271  // Device view rowPtrsUnpacked_dev_ takes place of lclGraph_.row_map
2272 
2273  row_ptrs_device_view_type rowPtrsPacked_dev_;
2274  row_ptrs_host_view_type rowPtrsPacked_host_;
2275 
2276  void setRowPtrsPacked(const row_ptrs_device_view_type &dview) {
2277  rowPtrsPacked_dev_ = dview;
2278  rowPtrsPacked_host_ =
2279  Kokkos::create_mirror_view_and_copy(
2280  typename row_ptrs_device_view_type::host_mirror_space(),
2281  dview);
2282  }
2283 
2284 
2285 //KDDKDD Make private -- matrix shouldn't access directly
2298  local_inds_wdv_type lclIndsUnpacked_wdv;
2299 
2312  mutable local_inds_wdv_type lclIndsPacked_wdv;
2313 
2314 //KDDKDD Make private -- matrix shouldn't access directly
2322 
2323  global_inds_wdv_type gblInds_wdv;
2324 
2328  typename local_inds_dualv_type::t_host::const_type
2329  getLocalIndsViewHost (const RowInfo& rowinfo) const;
2330 
2334  typename local_inds_dualv_type::t_dev::const_type
2335  getLocalIndsViewDevice (const RowInfo& rowinfo) const;
2336 
2340  typename global_inds_dualv_type::t_host::const_type
2341  getGlobalIndsViewHost (const RowInfo& rowinfo) const;
2342 
2346  typename global_inds_dualv_type::t_dev::const_type
2347  getGlobalIndsViewDevice (const RowInfo& rowinfo) const;
2348 
2352  typename local_inds_dualv_type::t_host
2353  getLocalIndsViewHostNonConst (const RowInfo& rowinfo);
2354 
2355  // FOR NOW...
2356  // KEEP k_numRowEntries_ (though switch from HostMirror to Host)
2357  // KEEP k_numAllocPerRow_ (though perhaps switch from HostMirror to Host)
2358 
2384  typename Kokkos::View<const size_t*, device_type>::HostMirror
2386 
2397 
2399 
2400 
2402  typedef Kokkos::View<global_ordinal_type*, device_type> t_GlobalOrdinal_1D;
2403 
2425 
2433  typedef typename Kokkos::View<size_t*, Kokkos::LayoutLeft, device_type>::HostMirror num_row_entries_type;
2434 
2435  // typedef Kokkos::View<
2436  // size_t*,
2437  // Kokkos::LayoutLeft,
2438  // Kokkos::Device<
2439  // typename Kokkos::View<
2440  // size_t*,
2441  // Kokkos::LayoutLeft,
2442  // device_type>::HostMirror::execution_space,
2443  // Kokkos::HostSpace> > num_row_entries_type;
2444 
2452 
2458  mutable offset_device_view_type k_offRankOffsets_;
2459 
2461 
2472  Details::STORAGE_1D_UNPACKED;
2473 
2474  bool indicesAreAllocated_ = false;
2475  bool indicesAreLocal_ = false;
2476  bool indicesAreGlobal_ = false;
2477  bool fillComplete_ = false;
2478 
2480  bool indicesAreSorted_ = true;
2483  bool noRedundancies_ = true;
2485  bool haveLocalConstants_ = false;
2487  bool haveGlobalConstants_ = false;
2489  mutable bool haveLocalOffRankOffsets_ = false;
2490 
2491  typedef typename std::map<global_ordinal_type, std::vector<global_ordinal_type> > nonlocals_type;
2492 
2494  nonlocals_type nonlocals_;
2495 
2511 
2512  private:
2514  static bool getDebug();
2515 
2518  bool debug_ = getDebug();
2519 
2521  static bool getVerbose();
2522 
2526  bool verbose_ = getVerbose();
2527 
2528  private:
2530  mutable bool need_sync_host_uvm_access = false;
2531 
2533  void set_need_sync_host_uvm_access() {
2534  need_sync_host_uvm_access = true;
2535  }
2536 
2538  void execute_sync_host_uvm_access() const {
2539  if(need_sync_host_uvm_access) {
2540  Kokkos::fence();
2541  need_sync_host_uvm_access = false;
2542  }
2543  }
2544  }; // class CrsGraph
2545 
2553  template <class LocalOrdinal, class GlobalOrdinal, class Node>
2554  Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
2556  const Teuchos::RCP<
2558  size_t maxNumEntriesPerRow = 0,
2559  const Teuchos::RCP<Teuchos::ParameterList>& params =
2560  Teuchos::null)
2561  {
2562  using Teuchos::rcp;
2564  const ProfileType pftype = TPETRA_DEFAULT_PROFILE_TYPE;
2565  return rcp(new graph_type(map, maxNumEntriesPerRow,
2566  pftype, params));
2567  }
2568 
2618  template<class CrsGraphType>
2619  Teuchos::RCP<CrsGraphType>
2620  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2621  const Import<typename CrsGraphType::local_ordinal_type,
2622  typename CrsGraphType::global_ordinal_type,
2623  typename CrsGraphType::node_type>& importer,
2624  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2625  typename CrsGraphType::global_ordinal_type,
2626  typename CrsGraphType::node_type> >& domainMap = Teuchos::null,
2627  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2628  typename CrsGraphType::global_ordinal_type,
2629  typename CrsGraphType::node_type> >& rangeMap = Teuchos::null,
2630  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2631  {
2632  Teuchos::RCP<CrsGraphType> destGraph;
2633  sourceGraph->importAndFillComplete (destGraph,importer,domainMap, rangeMap, params);
2634  return destGraph;
2635  }
2636 
2687  template<class CrsGraphType>
2688  Teuchos::RCP<CrsGraphType>
2689  importAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2690  const Import<typename CrsGraphType::local_ordinal_type,
2691  typename CrsGraphType::global_ordinal_type,
2692  typename CrsGraphType::node_type>& rowImporter,
2693  const Import<typename CrsGraphType::local_ordinal_type,
2694  typename CrsGraphType::global_ordinal_type,
2695  typename CrsGraphType::node_type>& domainImporter,
2696  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2697  typename CrsGraphType::global_ordinal_type,
2698  typename CrsGraphType::node_type> >& domainMap,
2699  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2700  typename CrsGraphType::global_ordinal_type,
2701  typename CrsGraphType::node_type> >& rangeMap,
2702  const Teuchos::RCP<Teuchos::ParameterList>& params)
2703  {
2704  Teuchos::RCP<CrsGraphType> destGraph;
2705  sourceGraph->importAndFillComplete (destGraph,rowImporter,domainImporter, domainMap, rangeMap, params);
2706  return destGraph;
2707  }
2708 
2742  template<class CrsGraphType>
2743  Teuchos::RCP<CrsGraphType>
2744  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2745  const Export<typename CrsGraphType::local_ordinal_type,
2746  typename CrsGraphType::global_ordinal_type,
2747  typename CrsGraphType::node_type>& exporter,
2748  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2749  typename CrsGraphType::global_ordinal_type,
2750  typename CrsGraphType::node_type> >& domainMap = Teuchos::null,
2751  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2752  typename CrsGraphType::global_ordinal_type,
2753  typename CrsGraphType::node_type> >& rangeMap = Teuchos::null,
2754  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2755  {
2756  Teuchos::RCP<CrsGraphType> destGraph;
2757  sourceGraph->exportAndFillComplete (destGraph,exporter,domainMap, rangeMap, params);
2758  return destGraph;
2759  }
2760 
2794  template<class CrsGraphType>
2795  Teuchos::RCP<CrsGraphType>
2796  exportAndFillCompleteCrsGraph (const Teuchos::RCP<const CrsGraphType>& sourceGraph,
2797  const Export<typename CrsGraphType::local_ordinal_type,
2798  typename CrsGraphType::global_ordinal_type,
2799  typename CrsGraphType::node_type>& rowExporter,
2800  const Export<typename CrsGraphType::local_ordinal_type,
2801  typename CrsGraphType::global_ordinal_type,
2802  typename CrsGraphType::node_type>& domainExporter,
2803  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2804  typename CrsGraphType::global_ordinal_type,
2805  typename CrsGraphType::node_type> >& domainMap,
2806  const Teuchos::RCP<const Map<typename CrsGraphType::local_ordinal_type,
2807  typename CrsGraphType::global_ordinal_type,
2808  typename CrsGraphType::node_type> >& rangeMap,
2809  const Teuchos::RCP<Teuchos::ParameterList>& params)
2810  {
2811  Teuchos::RCP<CrsGraphType> destGraph;
2812  sourceGraph->exportAndFillComplete (destGraph,rowExporter,domainExporter,domainMap, rangeMap, params);
2813  return destGraph;
2814  }
2815 
2816 
2817 } // namespace Tpetra
2818 
2819 #endif // TPETRA_CRSGRAPH_DECL_HPP
Forward declaration of Tpetra::BlockCrsMatrix.
Forward declaration of Tpetra::CrsGraph.
Forward declaration of Tpetra::CrsMatrix.
Stand-alone utility functions and macros.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
bool isMerged() const
Whether duplicate column indices in each row have been merged.
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...
global_size_t globalMaxNumRowEntries_
Global maximum of the number of entries in each row.
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...
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...
size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const override
Get the number of entries in the given row (local index).
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 > &rowImporter, const Import< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > &domainImporter, const Teuchos::RCP< const Map< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > > &domainMap, const Teuchos::RCP< const Map< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Nonmember CrsGraph constructor that fuses Import and fillComplete().
Teuchos::RCP< const map_type > getColMap() const override
Returns the Map that describes the column distribution in this graph.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Default parameter list suitable for validation.
Details::EStorageStatus storageStatus_
Status of the graph's storage, when not in a fill-complete state.
::Tpetra::Import< LocalOrdinal, GlobalOrdinal, Node > import_type
The Import specialization used by this class.
global_ordinal_type packet_type
Type of each entry of the DistObject communication buffer.
GlobalOrdinal global_ordinal_type
The type of the graph's global indices.
void insertGlobalIndicesIntoNonownedRows(const global_ordinal_type gblRow, const global_ordinal_type gblColInds[], const local_ordinal_type numGblColInds)
Implementation of insertGlobalIndices for nonowned rows.
Teuchos::RCP< const map_type > rangeMap_
The Map describing the range of the (matrix corresponding to the) graph.
std::pair< size_t, std::string > makeIndicesLocal(const bool verbose=false)
Convert column indices from global to local.
global_size_t getGlobalNumEntries() const override
Returns the global number of entries in the graph.
bool isIdenticalTo(const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph) const
Create a cloned CrsGraph for a different Node type.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const override
Returns the communicator.
local_inds_wdv_type lclIndsUnpacked_wdv
Local ordinals of colum indices for all rows KDDKDD UVM Removal: Device view takes place of k_lclInds...
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
void globalAssemble()
Communicate nonlocal contributions to other processes.
RowInfo getRowInfoFromGlobalRowIndex(const global_ordinal_type gblRow) const
Get information about the locally owned row with global index gblRow.
void getLocalDiagOffsets(const Kokkos::View< size_t *, device_type, Kokkos::MemoryUnmanaged > &offsets) const
Get offsets of the diagonal entries in the graph.
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.
Kokkos::View< size_t *, Kokkos::LayoutLeft, device_type >::HostMirror num_row_entries_type
Row offsets for "1-D" storage.
CrsGraph(const CrsGraph< local_ordinal_type, global_ordinal_type, node_type > &)=default
Copy constructor (default).
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.
global_inds_wdv_type gblInds_wdv
Global ordinals of column indices for all rows KDDKDD UVM Removal: Device view takes place of k_gblIn...
size_t nodeMaxNumRowEntries_
Local maximum of the number of entries in each row.
size_t sortAndMergeRowIndices(const RowInfo &rowInfo, const bool sorted, const bool merged)
Sort and merge duplicate column indices in the given row.
Teuchos::RCP< const import_type > importer_
The Import from the domain Map to the column Map.
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().
num_row_entries_type k_numRowEntries_
The number of local entries in each locally owned row.
CrsGraph(CrsGraph< local_ordinal_type, global_ordinal_type, node_type > &&)=default
Move constructor (default).
size_t numAllocForAllRows_
The maximum number of entries to allow in each locally owned row.
bool hasColMap() const override
Whether the graph has a column Map.
LocalOrdinal local_ordinal_type
The type of the graph's local indices.
std::string description() const override
Return a one-line human-readable description of this object.
bool isStorageOptimized() const
Returns true if storage has been optimized.
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.
void removeLocalIndices(local_ordinal_type localRow)
Remove all graph indices from the specified local row.
void importAndFillComplete(Teuchos::RCP< CrsGraph< local_ordinal_type, global_ordinal_type, Node > > &destGraph, const import_type &importer, const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null) const
Import from this to the given destination graph, and make the result fill complete.
global_size_t getGlobalNumRows() const override
Returns the number of global rows in the graph.
Teuchos::RCP< const map_type > getDomainMap() const override
Returns the Map associated with the domain of this graph.
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.
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 ...
Teuchos::ArrayRCP< const local_ordinal_type > getNodePackedIndices() const
Get an Teuchos::ArrayRCP of the packed column-indices.
void computeLocalConstants()
Compute local constants, if they have not yet been computed.
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 setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params) override
Set the given list of parameters (must be nonnull).
static const bool useAtomicUpdatesByDefault
Whether transformLocalValues should use atomic updates by default.
void resumeFill(const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Resume fill operations.
size_t insertIndices(RowInfo &rowInfo, const SLocalGlobalViews &newInds, const ELocalGlobal lg, const ELocalGlobal I)
Insert indices into the given row.
typename Node::device_type device_type
This class' Kokkos device type.
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 insertGlobalIndicesFiltered(const local_ordinal_type lclRow, const global_ordinal_type gblColInds[], const local_ordinal_type numGblColInds)
Like insertGlobalIndices(), but with column Map filtering.
Kokkos::View< global_ordinal_type *, device_type > t_GlobalOrdinal_1D
Type of the k_gblInds1D_ array of global column indices.
RowInfo getRowInfo(const local_ordinal_type myRow) const
Get information about the locally owned row with local index myRow.
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...
typename local_graph_device_type::HostMirror local_graph_host_type
The type of the part of the sparse graph on each MPI process.
Teuchos::RCP< const map_type > colMap_
The Map describing the distribution of columns of the graph.
bool noRedundancies_
Whether the graph's indices are non-redundant (merged) in each row, on this process.
bool isSorted() const
Whether graph indices in all rows are known to be sorted.
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's data directly, using 1-D storage.
void insertLocalIndices(const local_ordinal_type localRow, const Teuchos::ArrayView< const local_ordinal_type > &indices)
Insert local indices into the graph.
bool supportsRowViews() const override
Whether this class implements getLocalRowView() and getGlobalRowView() (it does).
CrsGraph & operator=(const CrsGraph< local_ordinal_type, global_ordinal_type, node_type > &)=default
Assignment operator (default).
size_t getNumEntriesInGlobalRow(global_ordinal_type globalRow) const override
Returns the current number of entries on this node in the specified global row.
bool isFillComplete() const override
Whether fillComplete() has been called and the graph is in compute mode.
void setDomainRangeMaps(const Teuchos::RCP< const map_type > &domainMap, const Teuchos::RCP< const map_type > &rangeMap)
void swap(CrsGraph< local_ordinal_type, global_ordinal_type, Node > &graph)
Swaps the data from *this with the data and maps from graph.
void getGlobalRowView(const global_ordinal_type gblRow, global_inds_host_view_type &gblColInds) const override
Get a const view of the given global row's global column 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.
void makeColMap(Teuchos::Array< int > &remotePIDs)
Make and set the graph's column Map.
bool haveGlobalConstants_
Whether all processes have computed global constants.
size_t getGlobalMaxNumRowEntries() const override
Maximum number of entries in any row of the graph, over all processes in the graph's communicator.
void getNumEntriesPerLocalRowUpperBound(Teuchos::ArrayRCP< const size_t > &boundPerLocalRow, size_t &boundForAllLocalRows, bool &boundSameForAllLocalRows) const
Get an upper bound on the number of entries that can be stored in each row.
void checkInternalState() const
Throw an exception if the internal state is not consistent.
typename dist_object_type::buffer_device_type buffer_device_type
Kokkos::Device specialization for communication buffers.
Teuchos::RCP< const map_type > getRangeMap() const override
Returns the Map associated with the domain of this graph.
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.
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().
bool sortGhostsAssociatedWithEachProcessor_
Whether to require makeColMap() (and therefore fillComplete()) to order column Map GIDs associated wi...
size_t getNumAllocatedEntriesInGlobalRow(global_ordinal_type globalRow) const
Current number of allocated entries in the given row on the calling (MPI) process,...
Teuchos::RCP< const export_type > getExporter() const override
Returns the exporter associated with this graph.
typename device_type::execution_space execution_space
This class' Kokkos execution space.
void makeImportExport(Teuchos::Array< int > &remotePIDs, const bool useRemotePIDs)
Make the Import and Export objects, if needed.
global_ordinal_type getIndexBase() const override
Returns the index base for global indices for this graph.
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.
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...
bool isFillActive() const
Whether resumeFill() has been called and the graph is in edit mode.
Teuchos::RCP< const map_type > getRowMap() const override
Returns the Map that describes the row distribution in this graph.
global_size_t globalNumEntries_
Global number of entries in the graph.
size_t getNodeAllocationSize() const
The local number of indices allocated for the graph, over all rows on 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.
::Tpetra::Export< LocalOrdinal, GlobalOrdinal, Node > export_type
The Export specialization used by this class.
Teuchos::RCP< const import_type > getImporter() const override
Returns the importer associated with this graph.
local_inds_wdv_type lclIndsPacked_wdv
Local ordinals of colum indices for all rows KDDKDD UVM Removal: Device view takes place of lclGraph_...
Kokkos::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.
Teuchos::RCP< const map_type > domainMap_
The Map describing the domain of the (matrix corresponding to the) graph.
nonlocals_type nonlocals_
Nonlocal data given to insertGlobalIndices.
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
Pack this object's data for Import or Export.
Teuchos::ArrayRCP< const size_t > getNodeRowPtrs() const
Get a host view of the row offsets.
size_t getNodeMaxNumRowEntries() const override
Maximum number of entries in any row of the graph, on this process.
void getLocalOffRankOffsets(offset_device_view_type &offsets) const
Get offsets of the off-rank entries in the graph.
global_size_t getGlobalNumCols() const override
Returns the number of global columns in the graph.
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 indicesAreSorted_
Whether the graph's indices are sorted in each row, on this process.
Node node_type
This class' Kokkos Node type.
Teuchos::RCP< const export_type > exporter_
The Export from the row Map to the range Map.
size_t getNodeNumRows() const override
Returns the number of graph rows owned on the calling node.
void insertGlobalIndices(const global_ordinal_type globalRow, const Teuchos::ArrayView< const global_ordinal_type > &indices)
Insert global indices into the graph.
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...
void replaceDomainMap(const Teuchos::RCP< const map_type > &newDomainMap)
Replace the current domain Map with the given objects.
size_t getNodeNumEntries() const override
The local number of entries in the graph.
void computeGlobalConstants()
Compute global constants, if they have not yet been computed.
size_t getNumAllocatedEntriesInLocalRow(local_ordinal_type localRow) const
Current number of allocated entries in the given row on the calling (MPI) process,...
virtual ~CrsGraph()=default
Destructor (virtual for memory safety of derived classes).
ProfileType getProfileType() const
Returns true if the graph was allocated with static data structures.
offset_device_view_type k_offRankOffsets_
The offsets for off-rank entries.
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.
void setLocallyModified()
Report that we made a local modification to its structure.
void replaceRangeMap(const Teuchos::RCP< const map_type > &newRangeMap)
Replace the current Range Map with the given objects.
size_t getNodeNumCols() const override
Returns the number of columns connected to the locally owned rows of this graph.
Teuchos::RCP< const map_type > rowMap_
The Map describing the distribution of rows of the graph.
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 > &rowExporter, const Export< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > &domainExporter, const Teuchos::RCP< const Map< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > > &domainMap, const Teuchos::RCP< const Map< typename CrsGraphType::local_ordinal_type, typename CrsGraphType::global_ordinal_type, typename CrsGraphType::node_type > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > &params)
Nonmember CrsGraph constructor that fuses Export and fillComplete().
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const map_type > &newMap) override
Remove processes owning zero rows from the Maps and their communicator.
void getLocalRowView(const LocalOrdinal lclRow, local_inds_host_view_type &lclColInds) const override
Get a const view of the given local row's local column indices.
bool isGloballyIndexed() const override
Whether the graph's column indices are stored as global indices.
bool isLocallyIndexed() const override
Whether the graph's column indices are stored as local indices.
virtual bool checkSizes(const SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
local_graph_device_type getLocalGraphDevice() const
Get the local graph.
void replaceColMap(const Teuchos::RCP< const map_type > &newColMap)
Replace the graph's current column Map with the given Map.
bool haveLocalConstants_
Whether this process has computed local constants.
Kokkos::View< const size_t *, device_type >::HostMirror k_numAllocPerRow_
The maximum number of entries to allow in each locally owned row, per row.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries.
Keep track of how much more space a CrsGraph or CrsMatrix needs, when the graph or matrix is the targ...
Base class for distributed Tpetra objects that support data redistribution.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
Kokkos::Device specialization for communication buffers.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
A parallel distribution of indices over processes.
An abstract interface for graphs accessed by rows.
Abstract base class for objects that can be the source of an Import or Export operation.
Implementation details of Tpetra.
EStorageStatus
Status of the graph's or matrix's storage, when not in a fill-complete state.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
size_t global_size_t
Global size_t object.
CombineMode
Rule for combining data in an Import or Export.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.