Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_OverlappingRowGraph_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4 //
5 // Copyright 2009 NTESS and the Ifpack2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
11 #define IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
12 
13 #include <Ifpack2_Details_OverlappingRowGraph_decl.hpp>
14 #include <Tpetra_Import.hpp>
15 #include <Tpetra_Export.hpp>
16 
17 namespace Ifpack2 {
18 namespace Details {
19 
20 template <class GraphType>
23  const Teuchos::RCP<const row_graph_type>& overlappingGraph,
24  const Teuchos::RCP<const map_type>& rowMap,
25  const Teuchos::RCP<const map_type>& colMap,
26  const Tpetra::global_size_t numGlobalRows,
27  const Tpetra::global_size_t numGlobalCols,
28  const Tpetra::global_size_t numGlobalNonzeros,
29  const size_t maxNumEntries,
30  const Teuchos::RCP<const import_type>& nonoverlappingImporter,
31  const Teuchos::RCP<const import_type>& overlappingImporter)
32  : nonoverlappingGraph_(nonoverlappingGraph)
33  , overlappingGraph_(overlappingGraph)
34  , rowMap_(rowMap)
35  , colMap_(colMap)
36  , numGlobalRows_(numGlobalRows)
37  , numGlobalCols_(numGlobalCols)
38  , numGlobalNonzeros_(numGlobalNonzeros)
39  , maxNumEntries_(maxNumEntries)
40  , nonoverlappingImporter_(nonoverlappingImporter)
41  , overlappingImporter_(overlappingImporter) {}
42 
43 template <class GraphType>
45 
46 template <class GraphType>
49  return nonoverlappingGraph_->getComm();
50 }
51 
52 template <class GraphType>
55  return rowMap_;
56 }
57 
58 template <class GraphType>
61  return colMap_;
62 }
63 
64 template <class GraphType>
67  return nonoverlappingGraph_->getDomainMap();
68 }
69 
70 template <class GraphType>
73  return nonoverlappingGraph_->getRangeMap();
74 }
75 
76 template <class GraphType>
79  return nonoverlappingImporter_;
80 }
81 
82 template <class GraphType>
85  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Not implemented");
86 }
87 
88 template <class GraphType>
90  return numGlobalRows_;
91 }
92 
93 template <class GraphType>
95  return numGlobalCols_;
96 }
97 
98 template <class GraphType>
100  return nonoverlappingGraph_->getLocalNumRows() +
101  overlappingGraph_->getLocalNumRows();
102 }
103 
104 template <class GraphType>
106  return this->getLocalNumRows();
107 }
108 
109 template <class GraphType>
110 typename GraphType::global_ordinal_type
112  return nonoverlappingGraph_->getIndexBase();
113 }
114 
115 template <class GraphType>
117  return numGlobalNonzeros_;
118 }
119 
120 template <class GraphType>
122  return nonoverlappingGraph_->getLocalNumEntries() +
123  overlappingGraph_->getLocalNumEntries();
124 }
125 
126 template <class GraphType>
127 size_t
129  getNumEntriesInGlobalRow(global_ordinal_type globalRow) const {
130  const local_ordinal_type localRow = rowMap_->getLocalElement(globalRow);
133  } else {
134  return getNumEntriesInLocalRow(localRow);
135  }
136 }
137 
138 template <class GraphType>
139 size_t
141  getNumEntriesInLocalRow(local_ordinal_type localRow) const {
142  using Teuchos::as;
143  const size_t numMyRowsA = nonoverlappingGraph_->getLocalNumRows();
144  if (as<size_t>(localRow) < numMyRowsA) {
145  return nonoverlappingGraph_->getNumEntriesInLocalRow(localRow);
146  } else {
147  return overlappingGraph_->getNumEntriesInLocalRow(as<local_ordinal_type>(localRow - numMyRowsA));
148  }
149 }
150 
151 template <class GraphType>
153  throw std::runtime_error("Ifpack2::OverlappingRowGraph::getGlobalMaxNumRowEntries() not supported.");
154 }
155 
156 template <class GraphType>
158  return maxNumEntries_;
159 }
160 
161 template <class GraphType>
163  return true;
164 }
165 
166 template <class GraphType>
168  return true;
169 }
170 
171 template <class GraphType>
173  return false;
174 }
175 
176 template <class GraphType>
178  return true;
179 }
180 
181 template <class GraphType>
183  getGlobalRowCopy(global_ordinal_type globalRow,
184  nonconst_global_inds_host_view_type& indices,
185  size_t& numIndices) const {
186  const local_ordinal_type localRow = rowMap_->getLocalElement(globalRow);
189  } else {
190  if (Teuchos::as<size_t>(localRow) < nonoverlappingGraph_->getLocalNumRows()) {
191  nonoverlappingGraph_->getGlobalRowCopy(globalRow, indices, numIndices);
192  } else {
193  overlappingGraph_->getGlobalRowCopy(globalRow, indices, numIndices);
194  }
195  }
196 }
197 
198 template <class GraphType>
200  getLocalRowCopy(local_ordinal_type localRow,
201  nonconst_local_inds_host_view_type& indices,
202  size_t& numIndices) const {
203  using Teuchos::as;
204  const size_t numMyRowsA = nonoverlappingGraph_->getLocalNumRows();
205  if (as<size_t>(localRow) < numMyRowsA) {
206  nonoverlappingGraph_->getLocalRowCopy(localRow, indices, numIndices);
207  } else {
208  const local_ordinal_type localRowOffset =
209  localRow - as<local_ordinal_type>(numMyRowsA);
210  overlappingGraph_->getLocalRowCopy(localRowOffset, indices, numIndices);
211  }
212 }
213 
214 template <class GraphType>
216  getGlobalRowView(global_ordinal_type GlobalRow,
217  global_inds_host_view_type& indices) const {
218  const local_ordinal_type LocalRow = rowMap_->getLocalElement(GlobalRow);
220  indices = global_inds_host_view_type();
221  } else {
222  if (Teuchos::as<size_t>(LocalRow) < nonoverlappingGraph_->getLocalNumRows()) {
223  nonoverlappingGraph_->getGlobalRowView(GlobalRow, indices);
224  } else {
225  overlappingGraph_->getGlobalRowView(GlobalRow, indices);
226  }
227  }
228 }
229 
230 template <class GraphType>
232  getLocalRowView(local_ordinal_type LocalRow,
233  local_inds_host_view_type& indices) const {
234  using Teuchos::as;
235  const size_t numMyRowsA = nonoverlappingGraph_->getLocalNumRows();
236  if (as<size_t>(LocalRow) < numMyRowsA) {
237  nonoverlappingGraph_->getLocalRowView(LocalRow, indices);
238  } else {
239  overlappingGraph_->getLocalRowView(LocalRow - as<local_ordinal_type>(numMyRowsA),
240  indices);
241  }
242 }
243 
244 } // namespace Details
245 } // namespace Ifpack2
246 
247 #define IFPACK2_DETAILS_OVERLAPPINGROWGRAPH_INSTANT(LO, GO, N) \
248  template class Ifpack2::Details::OverlappingRowGraph<Tpetra::CrsGraph<LO, GO, N> >; \
249  template class Ifpack2::Details::OverlappingRowGraph<Tpetra::RowGraph<LO, GO, N> >;
250 
251 #endif // IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
OverlappingRowGraph(const Teuchos::RCP< const row_graph_type > &nonoverlappingGraph, const Teuchos::RCP< const row_graph_type > &overlappingGraph, const Teuchos::RCP< const map_type > &rowMap, const Teuchos::RCP< const map_type > &colMap, const Tpetra::global_size_t numGlobalRows, const Tpetra::global_size_t numGlobalCols, const Tpetra::global_size_t numGlobalNonzeros, const size_t maxNumEntries, const Teuchos::RCP< const import_type > &nonoverlappingImporter, const Teuchos::RCP< const import_type > &overlappingImporter)
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:22
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries in any row on any process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:152
virtual Teuchos::RCP< const map_type > getRowMap() const
The Map that describes the distribution of rows over processes.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:54
virtual bool isGloballyIndexed() const
Whether this graph is globally indexed.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:172
virtual bool hasColMap() const
Whether this graph has a column Map.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:162
virtual Teuchos::RCP< const export_type > getExporter() const
Export object (from row Map to range Map).
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:84
virtual void getLocalRowView(const local_ordinal_type lclRow, local_inds_host_view_type &lclColInds) const
Get a constant, nonpersisting, locally indexed view of the given row of the graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:232
virtual void getLocalRowCopy(local_ordinal_type localRow, nonconst_local_inds_host_view_type &gblColInds, size_t &numIndices) const
Copy out a list of local column indices in the given local row that are owned by the calling process...
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:200
virtual global_ordinal_type getIndexBase() const
The index base for global indices for this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:111
virtual void getGlobalRowView(const global_ordinal_type gblRow, global_inds_host_view_type &gblColInds) const
Get a const, non-persisting view of the given global row&#39;s global column indices, as a Teuchos::Array...
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:216
virtual Teuchos::RCP< const map_type > getDomainMap() const
The Map that describes the domain of this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:66
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the graph is distributed.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:48
virtual size_t getLocalNumCols() const
The number of columns owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:105
virtual size_t getLocalNumEntries() const
The number of entries in this graph owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:121
virtual ~OverlappingRowGraph()
Destructor.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:44
virtual bool isLocallyIndexed() const
Whether this graph is locally indexed.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:167
virtual bool isFillComplete() const
true if fillComplete() has been called, else false.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:177
virtual global_size_t getGlobalNumCols() const
The global number of columns in this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:94
virtual size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const
The number of entries in the given local row that are owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:141
virtual size_t getLocalNumRows() const
The number of rows owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:99
virtual void getGlobalRowCopy(global_ordinal_type globalRow, nonconst_global_inds_host_view_type &gblColInds, size_t &numIndices) const
Copy out a list of column indices in the given global row that are owned by the calling process...
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:183
TypeTo as(const TypeFrom &t)
virtual Teuchos::RCP< const import_type > getImporter() const
Import object (from domain Map to column Map).
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:78
virtual size_t getLocalMaxNumRowEntries() const
The maximum number of entries in any row on the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:157
virtual Teuchos::RCP< const map_type > getColMap() const
The Map that describes the distribution of columns over processes.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:60
virtual global_size_t getGlobalNumRows() const
The global number of rows in this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:89
virtual Teuchos::RCP< const map_type > getRangeMap() const
The Map that describes the range of this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:72
virtual global_size_t getGlobalNumEntries() const
The global number of entries in this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:116
virtual size_t getNumEntriesInGlobalRow(global_ordinal_type globalRow) const
The number of entries in the given global row that are owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:129