Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_OverlappingRowMatrix_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_OVERLAPPINGROWMATRIX_DEF_HPP
44 #define IFPACK2_OVERLAPPINGROWMATRIX_DEF_HPP
45 
46 #include <sstream>
47 
48 #include <Ifpack2_Details_OverlappingRowGraph.hpp>
49 #include <Tpetra_CrsMatrix.hpp>
50 #include <Tpetra_Import.hpp>
51 #include "Tpetra_Map.hpp"
52 #include <Teuchos_CommHelpers.hpp>
53 
54 namespace Ifpack2 {
55 
56 template<class MatrixType>
59  const int overlapLevel) :
60  A_ (Teuchos::rcp_dynamic_cast<const crs_matrix_type> (A, true)),
61  OverlapLevel_ (overlapLevel)
62 {
63  using Teuchos::RCP;
64  using Teuchos::rcp;
65  using Teuchos::Array;
66  using Teuchos::outArg;
67  using Teuchos::REDUCE_SUM;
68  using Teuchos::reduceAll;
69  typedef Tpetra::global_size_t GST;
70  typedef Tpetra::CrsGraph<local_ordinal_type,
71  global_ordinal_type, node_type> crs_graph_type;
73  OverlapLevel_ <= 0, std::runtime_error,
74  "Ifpack2::OverlappingRowMatrix: OverlapLevel must be > 0.");
76  (A_.is_null (), std::runtime_error,
77  "Ifpack2::OverlappingRowMatrix: The input matrix must be a "
78  "Tpetra::CrsMatrix with the same scalar_type, local_ordinal_type, "
79  "global_ordinal_type, and device_type typedefs as MatrixType.");
81  A_->getComm()->getSize() == 1, std::runtime_error,
82  "Ifpack2::OverlappingRowMatrix: Matrix must be "
83  "distributed over more than one MPI process.");
84 
85  RCP<const crs_graph_type> A_crsGraph = A_->getCrsGraph ();
86  const size_t numMyRowsA = A_->getNodeNumRows ();
87  const global_ordinal_type global_invalid =
89 
90  // Temp arrays
91  Array<global_ordinal_type> ExtElements;
92  RCP<map_type> TmpMap;
93  RCP<crs_graph_type> TmpGraph;
94  RCP<import_type> TmpImporter;
95  RCP<const map_type> RowMap, ColMap;
96  ExtHaloStarts_.resize(OverlapLevel_+1);
97 
98  // The big import loop
99  for (int overlap = 0 ; overlap < OverlapLevel_ ; ++overlap) {
100  ExtHaloStarts_[overlap] = (size_t) ExtElements.size();
101 
102  // Get the current maps
103  if (overlap == 0) {
104  RowMap = A_->getRowMap ();
105  ColMap = A_->getColMap ();
106  }
107  else {
108  RowMap = TmpGraph->getRowMap ();
109  ColMap = TmpGraph->getColMap ();
110  }
111 
112  const size_t size = ColMap->getNodeNumElements () - RowMap->getNodeNumElements ();
113  Array<global_ordinal_type> mylist (size);
114  size_t count = 0;
115 
116  // define the set of rows that are in ColMap but not in RowMap
117  for (local_ordinal_type i = 0 ; (size_t) i < ColMap->getNodeNumElements() ; ++i) {
118  const global_ordinal_type GID = ColMap->getGlobalElement (i);
119  if (A_->getRowMap ()->getLocalElement (GID) == global_invalid) {
120  typedef typename Array<global_ordinal_type>::iterator iter_type;
121  const iter_type end = ExtElements.end ();
122  const iter_type pos = std::find (ExtElements.begin (), end, GID);
123  if (pos == end) {
124  ExtElements.push_back (GID);
125  mylist[count] = GID;
126  ++count;
127  }
128  }
129  }
130 
131  // mfh 24 Nov 2013: We don't need TmpMap, TmpGraph, or
132  // TmpImporter after this loop, so we don't have to construct them
133  // on the last round.
134  if (overlap + 1 < OverlapLevel_) {
135  // Allocate & import new matrices, maps, etc.
136  //
137  // FIXME (mfh 24 Nov 2013) Do we always want to use index base
138  // zero? It doesn't really matter, since the actual index base
139  // (in the current implementation of Map) will always be the
140  // globally least GID.
141  TmpMap = rcp (new map_type (global_invalid, mylist (0, count),
143  A_->getComm ()));
144  TmpGraph = rcp (new crs_graph_type (TmpMap, 0));
145  TmpImporter = rcp (new import_type (A_->getRowMap (), TmpMap));
146 
147  TmpGraph->doImport (*A_crsGraph, *TmpImporter, Tpetra::INSERT);
148  TmpGraph->fillComplete (A_->getDomainMap (), TmpMap);
149  }
150  } // end overlap loop
151  ExtHaloStarts_[OverlapLevel_] = (size_t) ExtElements.size();
152 
153 
154  // build the map containing all the nodes (original
155  // matrix + extended matrix)
156  Array<global_ordinal_type> mylist (numMyRowsA + ExtElements.size ());
157  for (local_ordinal_type i = 0; (size_t)i < numMyRowsA; ++i) {
158  mylist[i] = A_->getRowMap ()->getGlobalElement (i);
159  }
160  for (local_ordinal_type i = 0; i < ExtElements.size (); ++i) {
161  mylist[i + numMyRowsA] = ExtElements[i];
162  }
163 
164  RowMap_ = rcp (new map_type (global_invalid, mylist (),
166  A_->getComm ()));
167  Importer_ = rcp (new import_type (A_->getRowMap (), RowMap_));
168  ColMap_ = RowMap_;
169 
170  // now build the map corresponding to all the external nodes
171  // (with respect to A().RowMatrixRowMap().
172  ExtMap_ = rcp (new map_type (global_invalid, ExtElements (),
174  A_->getComm ()));
175  ExtImporter_ = rcp (new import_type (A_->getRowMap (), ExtMap_));
176 
177  {
178  RCP<crs_matrix_type> ExtMatrix_nc =
179  rcp (new crs_matrix_type (ExtMap_, ColMap_, 0));
180  ExtMatrix_nc->doImport (*A_, *ExtImporter_, Tpetra::INSERT);
181  ExtMatrix_nc->fillComplete (A_->getDomainMap (), RowMap_);
182  ExtMatrix_ = ExtMatrix_nc; // we only need the const version after here
183  }
184 
185  // fix indices for overlapping matrix
186  const size_t numMyRowsB = ExtMatrix_->getNodeNumRows ();
187 
188  GST NumMyNonzeros_tmp = A_->getNodeNumEntries () + ExtMatrix_->getNodeNumEntries ();
189  GST NumMyRows_tmp = numMyRowsA + numMyRowsB;
190  {
191  GST inArray[2], outArray[2];
192  inArray[0] = NumMyNonzeros_tmp;
193  inArray[1] = NumMyRows_tmp;
194  outArray[0] = 0;
195  outArray[1] = 0;
196  reduceAll<int, GST> (* (A_->getComm ()), REDUCE_SUM, 2, inArray, outArray);
197  NumGlobalNonzeros_ = outArray[0];
198  NumGlobalRows_ = outArray[1];
199  }
200  // reduceAll<int, GST> (* (A_->getComm ()), REDUCE_SUM, NumMyNonzeros_tmp,
201  // outArg (NumGlobalNonzeros_));
202  // reduceAll<int, GST> (* (A_->getComm ()), REDUCE_SUM, NumMyRows_tmp,
203  // outArg (NumGlobalRows_));
204 
205  MaxNumEntries_ = A_->getNodeMaxNumRowEntries ();
206  if (MaxNumEntries_ < ExtMatrix_->getNodeMaxNumRowEntries ()) {
207  MaxNumEntries_ = ExtMatrix_->getNodeMaxNumRowEntries ();
208  }
209 
210  // Create the graph (returned by getGraph()).
211  typedef Details::OverlappingRowGraph<row_graph_type> row_graph_impl_type;
212  RCP<row_graph_impl_type> graph =
213  rcp (new row_graph_impl_type (A_->getGraph (),
214  ExtMatrix_->getGraph (),
215  RowMap_,
216  ColMap_,
217  NumGlobalRows_,
218  NumGlobalRows_, // # global cols == # global rows
219  NumGlobalNonzeros_,
220  MaxNumEntries_,
221  Importer_,
222  ExtImporter_));
223  graph_ = Teuchos::rcp_const_cast<const row_graph_type>
224  (Teuchos::rcp_implicit_cast<row_graph_type> (graph));
225  // Resize temp arrays
226  Indices_.resize (MaxNumEntries_);
227  Values_.resize (MaxNumEntries_);
228 }
229 
230 
231 template<class MatrixType>
234 {
235  return A_->getComm ();
236 }
237 
238 
239 
240 
241 template<class MatrixType>
244 {
245  // FIXME (mfh 12 July 2013) Is this really the right Map to return?
246  return RowMap_;
247 }
248 
249 
250 template<class MatrixType>
253 {
254  // FIXME (mfh 12 July 2013) Is this really the right Map to return?
255  return ColMap_;
256 }
257 
258 
259 template<class MatrixType>
262 {
263  // The original matrix's domain map is irrelevant; we want the map associated
264  // with the overlap. This can then be used by LocalFilter, for example, while
265  // letting LocalFilter still filter based on domain and range maps (instead of
266  // column and row maps).
267  // FIXME Ideally, this would be the same map but restricted to a local
268  // communicator. If replaceCommWithSubset were free, that would be the way to
269  // go. That would require a new Map ctor. For now, we'll stick with ColMap_'s
270  // global communicator.
271  return ColMap_;
272 }
273 
274 
275 template<class MatrixType>
278 {
279  return RowMap_;
280 }
281 
282 
283 template<class MatrixType>
286 {
287  return graph_;
288 }
289 
290 
291 template<class MatrixType>
293 {
294  return NumGlobalRows_;
295 }
296 
297 
298 template<class MatrixType>
300 {
301  return NumGlobalRows_;
302 }
303 
304 
305 template<class MatrixType>
307 {
308  return A_->getNodeNumRows () + ExtMatrix_->getNodeNumRows ();
309 }
310 
311 
312 template<class MatrixType>
314 {
315  return this->getNodeNumRows ();
316 }
317 
318 
319 template<class MatrixType>
320 typename MatrixType::global_ordinal_type
322 {
323  return A_->getIndexBase();
324 }
325 
326 
327 template<class MatrixType>
329 {
330  return NumGlobalNonzeros_;
331 }
332 
333 
334 template<class MatrixType>
336 {
337  return A_->getNodeNumEntries () + ExtMatrix_->getNodeNumEntries ();
338 }
339 
340 
341 template<class MatrixType>
342 size_t
344 getNumEntriesInGlobalRow (global_ordinal_type globalRow) const
345 {
346  const local_ordinal_type localRow = RowMap_->getLocalElement (globalRow);
349  } else {
350  return getNumEntriesInLocalRow (localRow);
351  }
352 }
353 
354 
355 template<class MatrixType>
356 size_t
358 getNumEntriesInLocalRow (local_ordinal_type localRow) const
359 {
360  using Teuchos::as;
361  const size_t numMyRowsA = A_->getNodeNumRows ();
362  if (as<size_t> (localRow) < numMyRowsA) {
363  return A_->getNumEntriesInLocalRow (localRow);
364  } else {
365  return ExtMatrix_->getNumEntriesInLocalRow (as<local_ordinal_type> (localRow - numMyRowsA));
366  }
367 }
368 
369 
370 template<class MatrixType>
372 {
373  throw std::runtime_error("Ifpack2::OverlappingRowMatrix::getGlobalMaxNumRowEntries() not supported.");
374 }
375 
376 
377 template<class MatrixType>
379 {
380  return MaxNumEntries_;
381 }
382 
383 
384 template<class MatrixType>
386 {
387  return true;
388 }
389 
390 
391 template<class MatrixType>
393 {
394  return true;
395 }
396 
397 
398 template<class MatrixType>
400 {
401  return false;
402 }
403 
404 
405 template<class MatrixType>
407 {
408  return true;
409 }
410 
411 
412 template<class MatrixType>
413 void
415 getGlobalRowCopy (global_ordinal_type GlobalRow,
417  const Teuchos::ArrayView<scalar_type>& Values,
418  size_t& NumEntries) const
419 {
420  const local_ordinal_type LocalRow = RowMap_->getLocalElement (GlobalRow);
423  } else {
424  if (Teuchos::as<size_t> (LocalRow) < A_->getNodeNumRows ()) {
425  A_->getGlobalRowCopy (GlobalRow, Indices, Values, NumEntries);
426  } else {
427  ExtMatrix_->getGlobalRowCopy (GlobalRow, Indices, Values, NumEntries);
428  }
429  }
430 }
431 
432 
433 template<class MatrixType>
434 void
436 getLocalRowCopy (local_ordinal_type LocalRow,
438  const Teuchos::ArrayView<scalar_type> &Values,
439  size_t &NumEntries) const
440 {
441  using Teuchos::as;
442  const size_t numMyRowsA = A_->getNodeNumRows ();
443  if (as<size_t> (LocalRow) < numMyRowsA) {
444  A_->getLocalRowCopy (LocalRow, Indices, Values, NumEntries);
445  } else {
446  ExtMatrix_->getLocalRowCopy (LocalRow - as<local_ordinal_type> (numMyRowsA),
447  Indices, Values, NumEntries);
448  }
449 }
450 
451 
452 template<class MatrixType>
453 void
455 getGlobalRowView (global_ordinal_type GlobalRow,
458 {
459  const local_ordinal_type LocalRow = RowMap_->getLocalElement (GlobalRow);
461  indices = Teuchos::null;
462  values = Teuchos::null;
463  } else {
464  if (Teuchos::as<size_t> (LocalRow) < A_->getNodeNumRows ()) {
465  A_->getGlobalRowView (GlobalRow, indices, values);
466  } else {
467  ExtMatrix_->getGlobalRowView (GlobalRow, indices, values);
468  }
469  }
470 }
471 
472 
473 template<class MatrixType>
474 void
476 getLocalRowView (local_ordinal_type LocalRow,
479 {
480  using Teuchos::as;
481  const size_t numMyRowsA = A_->getNodeNumRows ();
482  if (as<size_t> (LocalRow) < numMyRowsA) {
483  A_->getLocalRowView (LocalRow, indices, values);
484  } else {
485  ExtMatrix_->getLocalRowView (LocalRow - as<local_ordinal_type> (numMyRowsA),
486  indices, values);
487  }
488 }
489 
490 
491 template<class MatrixType>
492 void
494 getLocalDiagCopy (Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& diag) const
495 {
496  using Teuchos::Array;
497 
498  //extract diagonal of original matrix
499  vector_type baseDiag(A_->getRowMap()); // diagonal of original matrix A_
500  A_->getLocalDiagCopy(baseDiag);
501  Array<scalar_type> baseDiagVals(baseDiag.getLocalLength());
502  baseDiag.get1dCopy(baseDiagVals());
503  //extra diagonal of ghost matrix
504  vector_type extDiag(ExtMatrix_->getRowMap());
505  ExtMatrix_->getLocalDiagCopy(extDiag);
506  Array<scalar_type> extDiagVals(extDiag.getLocalLength());
507  extDiag.get1dCopy(extDiagVals());
508 
509  Teuchos::ArrayRCP<scalar_type> allDiagVals = diag.getDataNonConst();
510  if (allDiagVals.size() != baseDiagVals.size() + extDiagVals.size()) {
511  std::ostringstream errStr;
512  errStr << "Ifpack2::OverlappingRowMatrix::getLocalDiagCopy : Mismatch in diagonal lengths, "
513  << allDiagVals.size() << " != " << baseDiagVals.size() << "+" << extDiagVals.size();
514  throw std::runtime_error(errStr.str());
515  }
516  for (Teuchos::Ordinal i=0; i<baseDiagVals.size(); ++i)
517  allDiagVals[i] = baseDiagVals[i];
518  Teuchos_Ordinal offset=baseDiagVals.size();
519  for (Teuchos::Ordinal i=0; i<extDiagVals.size(); ++i)
520  allDiagVals[i+offset] = extDiagVals[i];
521 }
522 
523 
524 template<class MatrixType>
525 void
527 leftScale (const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& /* x */)
528 {
529  throw std::runtime_error("Ifpack2::OverlappingRowMatrix does not support leftScale.");
530 }
531 
532 
533 template<class MatrixType>
534 void
536 rightScale (const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& /* x */)
537 {
538  throw std::runtime_error("Ifpack2::OverlappingRowMatrix does not support leftScale.");
539 }
540 
541 
542 template<class MatrixType>
543 typename OverlappingRowMatrix<MatrixType>::mag_type
545 {
546  throw std::runtime_error("Ifpack2::OverlappingRowMatrix does not support getFrobeniusNorm.");
547 }
548 
549 
550 template<class MatrixType>
551 void
553 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
554  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &Y,
555  Teuchos::ETransp mode,
556  scalar_type alpha,
557  scalar_type beta) const
558 {
559  using MV = Tpetra::MultiVector<scalar_type, local_ordinal_type,
560  global_ordinal_type, node_type>;
562  (X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
563  "Ifpack2::OverlappingRowMatrix::apply: X.getNumVectors() = "
564  << X.getNumVectors() << " != Y.getNumVectors() = " << Y.getNumVectors()
565  << ".");
566  // Check whether X aliases Y. In that case, we'll need to copy X.
567  auto X_d = X.getLocalViewDevice ();
568  auto Y_d = Y.getLocalViewDevice ();
569  bool aliases = true;
570  if (X_d.data () >= Y_d.data () + Y_d.span ()) {
571  aliases = false; // X starts after Y ends; no overlap
572  }
573  else if (Y_d.data () >= X_d.data () + X_d.span ()) {
574  aliases = false; // Y starts after X ends; no overlap
575  }
576  if (aliases) {
577  MV X_copy (X, Teuchos::Copy);
578  this->apply (X_copy, Y, mode, alpha, beta);
579  }
580 
581  const auto& rowMap0 = * (A_->getRowMap ());
582  const auto& colMap0 = * (A_->getColMap ());
583  MV X_0 (X, mode == Teuchos::NO_TRANS ? colMap0 : rowMap0, 0);
584  MV Y_0 (Y, mode == Teuchos::NO_TRANS ? rowMap0 : colMap0, 0);
585  A_->localApply (X_0, Y_0, mode, alpha, beta);
586 
587  const auto& rowMap1 = * (ExtMatrix_->getRowMap ());
588  const auto& colMap1 = * (ExtMatrix_->getColMap ());
589  MV X_1 (X, mode == Teuchos::NO_TRANS ? colMap1 : rowMap1, 0);
590  MV Y_1 (Y, mode == Teuchos::NO_TRANS ? rowMap1 : colMap1, A_->getNodeNumRows ());
591  ExtMatrix_->localApply (X_1, Y_1, mode, alpha, beta);
592 }
593 
594 
595 template<class MatrixType>
596 void
598 importMultiVector (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
599  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &OvX,
600  Tpetra::CombineMode CM)
601 {
602  OvX.doImport (X, *Importer_, CM);
603 }
604 
605 
606 template<class MatrixType>
607 void
608 OverlappingRowMatrix<MatrixType>::
609 exportMultiVector (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &OvX,
610  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> &X,
611  Tpetra::CombineMode CM)
612 {
613  X.doExport (OvX, *Importer_, CM);
614 }
615 
616 
617 template<class MatrixType>
619 {
620  return true;
621 }
622 
623 
624 template<class MatrixType>
626 {
627  return false;
628 }
629 
630 template<class MatrixType>
632 {
633  std::ostringstream oss;
634  if (isFillComplete()) {
635  oss << "{ isFillComplete: true"
636  << ", global rows: " << getGlobalNumRows()
637  << ", global columns: " << getGlobalNumCols()
638  << ", global entries: " << getGlobalNumEntries()
639  << " }";
640  }
641  else {
642  oss << "{ isFillComplete: false"
643  << ", global rows: " << getGlobalNumRows()
644  << " }";
645  }
646  return oss.str();
647 }
648 
649 template<class MatrixType>
650 void OverlappingRowMatrix<MatrixType>::describe(Teuchos::FancyOStream &out,
651  const Teuchos::EVerbosityLevel verbLevel) const
652 {
653  using std::endl;
654  using std::setw;
655  using Teuchos::as;
656  using Teuchos::VERB_DEFAULT;
657  using Teuchos::VERB_NONE;
658  using Teuchos::VERB_LOW;
659  using Teuchos::VERB_MEDIUM;
660  using Teuchos::VERB_HIGH;
661  using Teuchos::VERB_EXTREME;
662  using Teuchos::RCP;
663  using Teuchos::null;
664  using Teuchos::ArrayView;
665 
666  Teuchos::EVerbosityLevel vl = verbLevel;
667  if (vl == VERB_DEFAULT) {
668  vl = VERB_LOW;
669  }
670  RCP<const Teuchos::Comm<int> > comm = this->getComm();
671  const int myRank = comm->getRank();
672  const int numProcs = comm->getSize();
673  size_t width = 1;
674  for (size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
675  ++width;
676  }
677  width = std::max<size_t> (width, as<size_t> (11)) + 2;
678  Teuchos::OSTab tab(out);
679  // none: print nothing
680  // low: print O(1) info from node 0
681  // medium: print O(P) info, num entries per process
682  // high: print O(N) info, num entries per row
683  // extreme: print O(NNZ) info: print indices and values
684  //
685  // for medium and higher, print constituent objects at specified verbLevel
686  if (vl != VERB_NONE) {
687  if (myRank == 0) {
688  out << this->description() << std::endl;
689  }
690  // O(1) globals, minus what was already printed by description()
691  //if (isFillComplete() && myRank == 0) {
692  // out << "Global max number of entries in a row: " << getGlobalMaxNumRowEntries() << std::endl;
693  //}
694  // constituent objects
695  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
696  if (myRank == 0) {
697  out << endl << "Row map:" << endl;
698  }
699  getRowMap()->describe(out,vl);
700  //
701  if (getColMap() != null) {
702  if (getColMap() == getRowMap()) {
703  if (myRank == 0) {
704  out << endl << "Column map is row map.";
705  }
706  }
707  else {
708  if (myRank == 0) {
709  out << endl << "Column map:" << endl;
710  }
711  getColMap()->describe(out,vl);
712  }
713  }
714  if (getDomainMap() != null) {
715  if (getDomainMap() == getRowMap()) {
716  if (myRank == 0) {
717  out << endl << "Domain map is row map.";
718  }
719  }
720  else if (getDomainMap() == getColMap()) {
721  if (myRank == 0) {
722  out << endl << "Domain map is column map.";
723  }
724  }
725  else {
726  if (myRank == 0) {
727  out << endl << "Domain map:" << endl;
728  }
729  getDomainMap()->describe(out,vl);
730  }
731  }
732  if (getRangeMap() != null) {
733  if (getRangeMap() == getDomainMap()) {
734  if (myRank == 0) {
735  out << endl << "Range map is domain map." << endl;
736  }
737  }
738  else if (getRangeMap() == getRowMap()) {
739  if (myRank == 0) {
740  out << endl << "Range map is row map." << endl;
741  }
742  }
743  else {
744  if (myRank == 0) {
745  out << endl << "Range map: " << endl;
746  }
747  getRangeMap()->describe(out,vl);
748  }
749  }
750  if (myRank == 0) {
751  out << endl;
752  }
753  }
754  // O(P) data
755  if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
756  for (int curRank = 0; curRank < numProcs; ++curRank) {
757  if (myRank == curRank) {
758  out << "Process rank: " << curRank << std::endl;
759  out << " Number of entries: " << getNodeNumEntries() << std::endl;
760  out << " Max number of entries per row: " << getNodeMaxNumRowEntries() << std::endl;
761  }
762  comm->barrier();
763  comm->barrier();
764  comm->barrier();
765  }
766  }
767  // O(N) and O(NNZ) data
768  if (vl == VERB_HIGH || vl == VERB_EXTREME) {
769  for (int curRank = 0; curRank < numProcs; ++curRank) {
770  if (myRank == curRank) {
771  out << std::setw(width) << "Proc Rank"
772  << std::setw(width) << "Global Row"
773  << std::setw(width) << "Num Entries";
774  if (vl == VERB_EXTREME) {
775  out << std::setw(width) << "(Index,Value)";
776  }
777  out << endl;
778  for (size_t r = 0; r < getNodeNumRows (); ++r) {
779  const size_t nE = getNumEntriesInLocalRow(r);
780  typename MatrixType::global_ordinal_type gid = getRowMap()->getGlobalElement(r);
781  out << std::setw(width) << myRank
782  << std::setw(width) << gid
783  << std::setw(width) << nE;
784  if (vl == VERB_EXTREME) {
785  if (isGloballyIndexed()) {
786  ArrayView<const typename MatrixType::global_ordinal_type> rowinds;
787  ArrayView<const typename MatrixType::scalar_type> rowvals;
788  getGlobalRowView (gid, rowinds, rowvals);
789  for (size_t j = 0; j < nE; ++j) {
790  out << " (" << rowinds[j]
791  << ", " << rowvals[j]
792  << ") ";
793  }
794  }
795  else if (isLocallyIndexed()) {
796  ArrayView<const typename MatrixType::local_ordinal_type> rowinds;
797  ArrayView<const typename MatrixType::scalar_type> rowvals;
798  getLocalRowView (r, rowinds, rowvals);
799  for (size_t j=0; j < nE; ++j) {
800  out << " (" << getColMap()->getGlobalElement(rowinds[j])
801  << ", " << rowvals[j]
802  << ") ";
803  }
804  } // globally or locally indexed
805  } // vl == VERB_EXTREME
806  out << endl;
807  } // for each row r on this process
808 
809  } // if (myRank == curRank)
810  comm->barrier();
811  comm->barrier();
812  comm->barrier();
813  }
814 
815  out.setOutputToRootOnly(0);
816  out << "===========\nlocal matrix\n=================" << std::endl;
817  out.setOutputToRootOnly(-1);
818  A_->describe(out,Teuchos::VERB_EXTREME);
819  out.setOutputToRootOnly(0);
820  out << "===========\nend of local matrix\n=================" << std::endl;
821  comm->barrier();
822  out.setOutputToRootOnly(0);
823  out << "=================\nghost matrix\n=================" << std::endl;
824  out.setOutputToRootOnly(-1);
825  ExtMatrix_->describe(out,Teuchos::VERB_EXTREME);
826  out.setOutputToRootOnly(0);
827  out << "===========\nend of ghost matrix\n=================" << std::endl;
828  }
829  }
830 }
831 
832 template<class MatrixType>
834 OverlappingRowMatrix<MatrixType>::getUnderlyingMatrix() const
835 {
836  return A_;
837 }
838 
839 template<class MatrixType>
841 OverlappingRowMatrix<MatrixType>::getExtMatrix() const
842 {
843  return ExtMatrix_;
844 }
845 
846 template<class MatrixType>
847 Teuchos::ArrayView<const size_t> OverlappingRowMatrix<MatrixType>::getExtHaloStarts() const
848 {
849  return ExtHaloStarts_();
850 }
851 
852 
853 } // namespace Ifpack2
854 
855 #define IFPACK2_OVERLAPPINGROWMATRIX_INSTANT(S,LO,GO,N) \
856  template class Ifpack2::OverlappingRowMatrix< Tpetra::RowMatrix<S, LO, GO, N> >;
857 
858 #endif // IFPACK2_OVERLAPPINGROWMATRIX_DEF_HPP
virtual bool isGloballyIndexed() const
Whether this matrix is globally indexed.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:399
virtual mag_type getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:544
virtual size_t getNodeNumRows() const
The number of rows owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:306
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual bool isFillComplete() const
true if fillComplete() has been called, else false.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:406
size_type size() const
virtual void leftScale(const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &x)
Scales the RowMatrix on the left with the Vector x.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:527
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:233
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRowMap() const
The Map that describes the distribution of rows over processes.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:243
virtual global_size_t getGlobalNumRows() const
The global number of rows in this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:292
virtual global_size_t getGlobalNumCols() const
The global number of columns in this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:299
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual bool isLocallyIndexed() const
Whether this matrix is locally indexed.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:392
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRangeMap() const
The Map that describes the range of this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:277
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getDomainMap() const
The Map that describes the domain of this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:261
Sparse graph (Tpetra::RowGraph subclass) with ghost rows.
Definition: Ifpack2_Details_OverlappingRowGraph_decl.hpp:65
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
void resize(size_type new_size, const value_type &x=value_type())
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_OverlappingRowMatrix_def.hpp:344
virtual size_t getNodeNumEntries() const
The number of entries in this matrix owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:335
virtual global_size_t getGlobalNumEntries() const
The global number of entries in this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:328
virtual bool hasTransposeApply() const
Whether this operator&#39;s apply() method can apply the adjoint (transpose).
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:618
virtual global_ordinal_type getIndexBase() const
The index base for global indices for this matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:321
virtual bool hasColMap() const
Whether this matrix has a column Map.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:385
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_OverlappingRowMatrix_def.hpp:358
virtual void rightScale(const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &x)
Scales the RowMatrix on the right with the Vector x.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:536
virtual Teuchos::RCP< const Tpetra::RowGraph< local_ordinal_type, global_ordinal_type, node_type > > getGraph() const
This matrix&#39;s graph.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:285
virtual void getGlobalRowView(global_ordinal_type GlobalRow, Teuchos::ArrayView< const global_ordinal_type > &indices, Teuchos::ArrayView< const scalar_type > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:455
size_type size() const
TypeTo as(const TypeFrom &t)
virtual void getLocalDiagCopy(Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:494
Sparse matrix (Tpetra::RowMatrix subclass) with ghost rows.
Definition: Ifpack2_OverlappingRowMatrix_decl.hpp:58
OverlappingRowMatrix(const Teuchos::RCP< const row_matrix_type > &A, const int overlapLevel)
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:58
virtual size_t getNodeMaxNumRowEntries() const
The maximum number of entries in any row on the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:378
virtual void apply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const
Computes the operator-multivector application.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:553
virtual void getLocalRowCopy(local_ordinal_type LocalRow, const Teuchos::ArrayView< local_ordinal_type > &Indices, const Teuchos::ArrayView< scalar_type > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the graph. Put into storage allocated by callin...
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:436
virtual void getGlobalRowCopy(global_ordinal_type GlobalRow, const Teuchos::ArrayView< global_ordinal_type > &Indices, const Teuchos::ArrayView< scalar_type > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:415
virtual Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getColMap() const
The Map that describes the distribution of columns over processes.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:252
virtual void getLocalRowView(local_ordinal_type LocalRow, Teuchos::ArrayView< const local_ordinal_type > &indices, Teuchos::ArrayView< const scalar_type > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:476
virtual bool supportsRowViews() const
true if row views are supported, else false.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:625
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries in any row on any process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:371
virtual size_t getNodeNumCols() const
The number of columns owned by the calling process.
Definition: Ifpack2_OverlappingRowMatrix_def.hpp:313
bool is_null() const