Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Details_OverlappingRowGraph_def.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
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 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
44 #define IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
45 
46 #include <Ifpack2_Details_OverlappingRowGraph_decl.hpp>
47 #include <Tpetra_Import.hpp>
48 #include <Tpetra_Export.hpp>
49 
50 
51 namespace Ifpack2 {
52 namespace Details {
53 
54 template<class GraphType>
56 OverlappingRowGraph (const Teuchos::RCP<const row_graph_type>& nonoverlappingGraph,
57  const Teuchos::RCP<const row_graph_type>& overlappingGraph,
58  const Teuchos::RCP<const map_type>& rowMap,
59  const Teuchos::RCP<const map_type>& colMap,
60  const Tpetra::global_size_t numGlobalRows,
61  const Tpetra::global_size_t numGlobalCols,
62  const Tpetra::global_size_t numGlobalNonzeros,
63  const size_t maxNumEntries,
64  const Teuchos::RCP<const import_type>& nonoverlappingImporter,
65  const Teuchos::RCP<const import_type>& overlappingImporter) :
66  nonoverlappingGraph_ (nonoverlappingGraph),
67  overlappingGraph_ (overlappingGraph),
68  rowMap_ (rowMap),
69  colMap_ (colMap),
70  numGlobalRows_ (numGlobalRows),
71  numGlobalCols_ (numGlobalCols),
72  numGlobalNonzeros_ (numGlobalNonzeros),
73  maxNumEntries_ (maxNumEntries),
74  nonoverlappingImporter_ (nonoverlappingImporter),
75  overlappingImporter_ (overlappingImporter)
76 {}
77 
78 
79 template<class GraphType>
81 
82 
83 template<class GraphType>
84 Teuchos::RCP<const Teuchos::Comm<int> >
86 {
87  return nonoverlappingGraph_->getComm ();
88 }
89 
90 
91 
92 
93 template<class GraphType>
94 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
96 {
97  return rowMap_;
98 }
99 
100 
101 template<class GraphType>
102 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
104 {
105  return colMap_;
106 }
107 
108 
109 template<class GraphType>
110 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
112 {
113  return nonoverlappingGraph_->getDomainMap ();
114 }
115 
116 
117 template<class GraphType>
118 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
120 {
121  return nonoverlappingGraph_->getRangeMap ();
122 }
123 
124 
125 template<class GraphType>
126 Teuchos::RCP<const Tpetra::Import<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
128 {
129  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Not implemented");
130 }
131 
132 
133 template<class GraphType>
134 Teuchos::RCP<const Tpetra::Export<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
136 {
137  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Not implemented");
138 }
139 
140 
141 template<class GraphType>
143 {
144  return numGlobalRows_;
145 }
146 
147 
148 template<class GraphType>
150 {
151  return numGlobalCols_;
152 }
153 
154 
155 template<class GraphType>
157 {
158  return nonoverlappingGraph_->getNodeNumRows () +
159  overlappingGraph_->getNodeNumRows ();
160 }
161 
162 
163 template<class GraphType>
165 {
166  return this->getNodeNumRows ();
167 }
168 
169 
170 template<class GraphType>
171 typename GraphType::global_ordinal_type
173 {
174  return nonoverlappingGraph_->getIndexBase ();
175 }
176 
177 
178 template<class GraphType>
180 {
181  return numGlobalNonzeros_;
182 }
183 
184 
185 template<class GraphType>
187 {
188  return nonoverlappingGraph_->getNodeNumEntries () +
189  overlappingGraph_->getNodeNumEntries ();
190 }
191 
192 
193 template<class GraphType>
194 size_t
196 getNumEntriesInGlobalRow (global_ordinal_type globalRow) const
197 {
198  const local_ordinal_type localRow = rowMap_->getLocalElement (globalRow);
199  if (localRow == Teuchos::OrdinalTraits<local_ordinal_type>::invalid ()) {
200  return Teuchos::OrdinalTraits<size_t>::invalid();
201  } else {
202  return getNumEntriesInLocalRow (localRow);
203  }
204 }
205 
206 
207 template<class GraphType>
208 size_t
210 getNumEntriesInLocalRow (local_ordinal_type localRow) const
211 {
212  using Teuchos::as;
213  const size_t numMyRowsA = nonoverlappingGraph_->getNodeNumRows ();
214  if (as<size_t> (localRow) < numMyRowsA) {
215  return nonoverlappingGraph_->getNumEntriesInLocalRow (localRow);
216  } else {
217  return overlappingGraph_->getNumEntriesInLocalRow (as<local_ordinal_type> (localRow - numMyRowsA));
218  }
219 }
220 
221 
222 template<class GraphType>
224 {
225  throw std::runtime_error("Ifpack2::OverlappingRowGraph::getGlobalMaxNumRowEntries() not supported.");
226 }
227 
228 
229 template<class GraphType>
231 {
232  return maxNumEntries_;
233 }
234 
235 
236 template<class GraphType>
238 {
239  return true;
240 }
241 
242 
243 template<class GraphType>
245 {
246  return true;
247 }
248 
249 
250 template<class GraphType>
252 {
253  return false;
254 }
255 
256 
257 template<class GraphType>
259 {
260  return true;
261 }
262 
263 template<class GraphType>
264 void
266  getGlobalRowCopy (global_ordinal_type globalRow,
267  nonconst_global_inds_host_view_type& indices,
268  size_t& numIndices) const
269 {
270  const local_ordinal_type localRow = rowMap_->getLocalElement (globalRow);
271  if (localRow == Teuchos::OrdinalTraits<local_ordinal_type>::invalid ()) {
272  numIndices = Teuchos::OrdinalTraits<size_t>::invalid ();
273  } else {
274  if (Teuchos::as<size_t> (localRow) < nonoverlappingGraph_->getNodeNumRows ()) {
275  nonoverlappingGraph_->getGlobalRowCopy (globalRow, indices, numIndices);
276  } else {
277  overlappingGraph_->getGlobalRowCopy (globalRow, indices, numIndices);
278  }
279  }
280 }
281 
282 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
283 template<class GraphType>
284 void
286 getGlobalRowCopy (global_ordinal_type globalRow,
287  const Teuchos::ArrayView<global_ordinal_type>& indices,
288  size_t& numIndices) const
289 {
290  const local_ordinal_type localRow = rowMap_->getLocalElement (globalRow);
291  if (localRow == Teuchos::OrdinalTraits<local_ordinal_type>::invalid ()) {
292  numIndices = Teuchos::OrdinalTraits<size_t>::invalid ();
293  } else {
294  if (Teuchos::as<size_t> (localRow) < nonoverlappingGraph_->getNodeNumRows ()) {
295  nonoverlappingGraph_->getGlobalRowCopy (globalRow, indices, numIndices);
296  } else {
297  overlappingGraph_->getGlobalRowCopy (globalRow, indices, numIndices);
298  }
299  }
300 }
301 #endif
302 
303 template<class GraphType>
304 void
306 getLocalRowCopy (local_ordinal_type localRow,
307  nonconst_local_inds_host_view_type& indices,
308  size_t& numIndices) const
309 {
310  using Teuchos::as;
311  const size_t numMyRowsA = nonoverlappingGraph_->getNodeNumRows ();
312  if (as<size_t> (localRow) < numMyRowsA) {
313  nonoverlappingGraph_->getLocalRowCopy (localRow, indices, numIndices);
314  } else {
315  const local_ordinal_type localRowOffset =
316  localRow - as<local_ordinal_type> (numMyRowsA);
317  overlappingGraph_->getLocalRowCopy (localRowOffset, indices, numIndices);
318  }
319 }
320 
321 
322 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
323 template<class GraphType>
324 void
326 getLocalRowCopy (local_ordinal_type localRow,
327  const Teuchos::ArrayView<local_ordinal_type>& indices,
328  size_t& numIndices) const
329 {
330  using Teuchos::as;
331  const size_t numMyRowsA = nonoverlappingGraph_->getNodeNumRows ();
332  if (as<size_t> (localRow) < numMyRowsA) {
333  nonoverlappingGraph_->getLocalRowCopy (localRow, indices, numIndices);
334  } else {
335  const local_ordinal_type localRowOffset =
336  localRow - as<local_ordinal_type> (numMyRowsA);
337  overlappingGraph_->getLocalRowCopy (localRowOffset, indices, numIndices);
338  }
339 }
340 #endif
341 
342 template<class GraphType>
343 void
345 getGlobalRowView (global_ordinal_type GlobalRow,
346  global_inds_host_view_type &indices) const {
347  const local_ordinal_type LocalRow = rowMap_->getLocalElement (GlobalRow);
348  if (LocalRow == Teuchos::OrdinalTraits<local_ordinal_type>::invalid()) {
349  indices = global_inds_host_view_type();
350  } else {
351  if (Teuchos::as<size_t> (LocalRow) < nonoverlappingGraph_->getNodeNumRows ()) {
352  nonoverlappingGraph_->getGlobalRowView (GlobalRow, indices);
353  } else {
354  overlappingGraph_->getGlobalRowView (GlobalRow, indices);
355  }
356  }
357 }
358 
359 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
360 template<class GraphType>
361 void
363 getGlobalRowView (global_ordinal_type GlobalRow,
364  Teuchos::ArrayView<const global_ordinal_type>& indices) const
365 {
366  const local_ordinal_type LocalRow = rowMap_->getLocalElement (GlobalRow);
367  if (LocalRow == Teuchos::OrdinalTraits<local_ordinal_type>::invalid()) {
368  indices = Teuchos::null;
369  } else {
370  if (Teuchos::as<size_t> (LocalRow) < nonoverlappingGraph_->getNodeNumRows ()) {
371  nonoverlappingGraph_->getGlobalRowView (GlobalRow, indices);
372  } else {
373  overlappingGraph_->getGlobalRowView (GlobalRow, indices);
374  }
375  }
376 }
377 #endif
378 
379 
380 template<class GraphType>
381 void
383  getLocalRowView (local_ordinal_type LocalRow,
384  local_inds_host_view_type & indices) const {
385  using Teuchos::as;
386  const size_t numMyRowsA = nonoverlappingGraph_->getNodeNumRows ();
387  if (as<size_t> (LocalRow) < numMyRowsA) {
388  nonoverlappingGraph_->getLocalRowView (LocalRow, indices);
389  } else {
390  overlappingGraph_->getLocalRowView (LocalRow - as<local_ordinal_type> (numMyRowsA),
391  indices);
392  }
393 
394 }
395 
396 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
397 template<class GraphType>
398 void
400 getLocalRowView (local_ordinal_type LocalRow,
401  Teuchos::ArrayView<const local_ordinal_type>& indices) const
402 {
403  using Teuchos::as;
404  const size_t numMyRowsA = nonoverlappingGraph_->getNodeNumRows ();
405  if (as<size_t> (LocalRow) < numMyRowsA) {
406  nonoverlappingGraph_->getLocalRowView (LocalRow, indices);
407  } else {
408  overlappingGraph_->getLocalRowView (LocalRow - as<local_ordinal_type> (numMyRowsA),
409  indices);
410  }
411 }
412 #endif
413 
414 
415 } // namespace Details
416 } // namespace Ifpack2
417 
418 #define IFPACK2_DETAILS_OVERLAPPINGROWGRAPH_INSTANT(LO,GO,N) \
419  template class Ifpack2::Details::OverlappingRowGraph<Tpetra::CrsGraph< LO, GO, N > >; \
420  template class Ifpack2::Details::OverlappingRowGraph<Tpetra::RowGraph< LO, GO, N > >;
421 
422 #endif // IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
virtual size_t getNodeNumCols() const
The number of columns owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:164
virtual bool isGloballyIndexed() const
Whether this graph is globally indexed.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:251
virtual size_t getNodeNumEntries() const
The number of entries in this graph owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:186
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:306
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:56
virtual bool isLocallyIndexed() const
Whether this graph is locally indexed.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:244
virtual size_t getNodeNumRows() const
The number of rows owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:156
virtual global_ordinal_type getIndexBase() const
The index base for global indices for this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:172
virtual Teuchos::RCP< const map_type > getRangeMap() const
The Map that describes the range of this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:119
virtual Teuchos::RCP< const import_type > getImporter() const
Import object (from domain Map to column Map).
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:127
virtual bool hasColMap() const
Whether this graph has a column Map.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:237
Ifpack2 implementation details.
virtual bool isFillComplete() const
true if fillComplete() has been called, else false.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:258
virtual Teuchos::RCP< const map_type > getRowMap() const
The Map that describes the distribution of rows over processes.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:95
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:210
virtual Teuchos::RCP< const map_type > getColMap() const
The Map that describes the distribution of columns over processes.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:103
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:266
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the graph is distributed.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:85
virtual global_size_t getGlobalNumEntries() const
The global number of entries in this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:179
virtual ~OverlappingRowGraph()
Destructor.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:80
virtual Teuchos::RCP< const export_type > getExporter() const
Export object (from row Map to range Map).
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:135
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:345
virtual global_size_t getGlobalNumCols() const
The global number of columns in this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:149
virtual Teuchos::RCP< const map_type > getDomainMap() const
The Map that describes the domain of this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:111
virtual global_size_t getGlobalNumRows() const
The global number of rows in this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:142
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:196
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:73
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries in any row on any process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:223
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:383
virtual size_t getNodeMaxNumRowEntries() const
The maximum number of entries in any row on the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:230