Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_RowGraph_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_ROWGRAPH_DEF_HPP
11 #define TPETRA_ROWGRAPH_DEF_HPP
12 
13 namespace Tpetra {
14  template<class LocalOrdinal, class GlobalOrdinal, class Node>
15  void
17  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
18  Teuchos::Array<GlobalOrdinal>& exports,
19  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
20  size_t& constantNumPackets) const
21  {
22  using Teuchos::Array;
23  typedef LocalOrdinal LO;
24  typedef GlobalOrdinal GO;
25  typedef Map<LO, GO, Node> map_type;
26  const char tfecfFuncName[] = "packAndPrepare";
27 
28  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
29  exportLIDs.size() != numPacketsPerLID.size(), std::runtime_error,
30  ": exportLIDs and numPacketsPerLID must have the same size.");
31 
32  const map_type& srcMap = * (this->getRowMap ());
33  constantNumPackets = 0;
34 
35  // Set numPacketsPerLID[i] to the number of entries owned by the
36  // calling process in (local) row exportLIDs[i] of the graph, that
37  // the caller wants us to send out. Compute the total number of
38  // packets (that is, entries) owned by this process in all the
39  // rows that the caller wants us to send out.
40  size_t totalNumPackets = 0;
41  nonconst_global_inds_host_view_type row;
42  for (LO i = 0; i < exportLIDs.size (); ++i) {
43  const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
44  size_t row_length = this->getNumEntriesInGlobalRow (GID);
45  numPacketsPerLID[i] = row_length;
46  totalNumPackets += row_length;
47  }
48 
49  exports.resize (totalNumPackets);
50 
51  // Loop again over the rows to export, and pack rows of indices
52  // into the output buffer.
53  size_t exportsOffset = 0;
54  for (LO i = 0; i < exportLIDs.size (); ++i) {
55  const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
56  size_t row_length = this->getNumEntriesInGlobalRow (GID);
57  Kokkos::resize(row,row_length);
58  size_t check_row_length = 0;
59  this->getGlobalRowCopy (GID, row, check_row_length);
60 
61  for (size_t j=0; j<row_length; ++j) {
62  exports[exportsOffset+j] = row[j];
63  }
64  exportsOffset += row.extent(0);
65  }
66  }
67 
68 } // namespace Tpetra
69 
70 //
71 // Explicit instantiation macro
72 //
73 // Must be expanded from within the Tpetra namespace!
74 //
75 
76 #define TPETRA_ROWGRAPH_INSTANT(LO,GO,NODE) \
77  template class RowGraph< LO , GO , NODE >;
78 
79 #endif // TPETRA_ROWGRAPH_DEF_HPP
virtual void pack(const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< GlobalOrdinal > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets) const
Pack this object&#39;s data for Import or Export.
global_ordinal_type getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.