Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PrintData.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef PRINTDATA_HPP
11 #define PRINTDATA_HPP
12 
13 #include "Zoltan2_config.h"
14 #include "Tpetra_CrsGraph.hpp"
15 #include "Teuchos_ArrayView.hpp"
16 
17 #include <iostream>
18 #include <string>
19 
20 using std::string;
21 using Teuchos::ArrayView;
22 
23 template <typename lno_t, typename gno_t>
24  void printTpetraGraph(const Tpetra::CrsGraph<lno_t, gno_t> &graph,
25  std::ostream &os, size_t maxSize, string info)
26 {
27  size_t nrows = graph.getLocalNumRows();
28  if (nrows > maxSize)
29  return;
30 
31  const RCP<const typename Tpetra::Map<lno_t, gno_t> > &rowMap=
32  graph.getRowMap();
33  const RCP<const typename Tpetra::Map<lno_t, gno_t> > &colMap=
34  graph.getColMap();
35 
36  if (info.size() > 0)
37  os << info << std::endl;
38 
39  if (graph.isGloballyIndexed()){
40  ArrayView<const gno_t> indices;
41  for (size_t i=0; i < nrows; i++){
42  gno_t gid = rowMap->getGlobalElement(i);
43  graph.getGlobalRowView(gid, indices);
44  os << "Row " << gid << ": ";
45  for (typename ArrayView<const gno_t>::size_type j=0; j < indices.size(); j++){
46  os << indices[j] << " ";
47  }
48  os << std::endl;
49  }
50  }
51  else{
52  ArrayView<const lno_t> indices;
53  for (size_t i=0; i < nrows; i++){
54  gno_t gid = rowMap->getGlobalElement(i);
55  graph.getLocalRowView(i, indices);
56  os << "Row " << gid << ": ";
57  for (typename ArrayView<const lno_t>::size_type j=0; j < indices.size(); j++){
58  os << colMap->getGlobalElement(indices[j]) << " ";
59  }
60  os << std::endl;
61  }
62  }
63 }
64 
65 template <typename lno_t, typename gno_t>
66  void printTpetraGraph(const RCP<const Comm<int> > &comm,
67  const Tpetra::CrsGraph<lno_t, gno_t> &graph, std::ostream &os,
68  size_t maxSize, string info)
69 {
70  int rank = comm->getRank();
71  std::ostringstream oss;
72  oss << "rank " << rank;
73 
74  comm->barrier();
75  if (rank==0)
76  os << info << std::endl;
77  comm->barrier();
78 
79  for (int p=0; p < comm->getSize(); p++){
80  if (p == rank)
81  printTpetraGraph<lno_t, gno_t>(graph, os, maxSize, oss.str());
82  comm->barrier();
83  }
84 }
85 
86 #endif
map_t::global_ordinal_type gno_t
Definition: mapRemotes.cpp:27
void printTpetraGraph(const Tpetra::CrsGraph< lno_t, gno_t > &graph, std::ostream &os, size_t maxSize, string info)
Definition: PrintData.hpp:24