Zoltan2
PrintData.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 
46 #ifndef PRINTDATA_HPP
47 #define PRINTDATA_HPP
48 
49 #include "Zoltan2_config.h"
50 #include "Tpetra_CrsGraph.hpp"
51 #include "Teuchos_ArrayView.hpp"
52 
53 #include <iostream>
54 #include <string>
55 
56 using std::string;
57 using std::endl;
58 using std::ostream;
59 using Teuchos::ArrayView;
60 
61 template <typename lno_t, typename gno_t>
62  void printTpetraGraph(const Tpetra::CrsGraph<lno_t, gno_t> &graph,
63  ostream &os, size_t maxSize, string info)
64 {
65  size_t nrows = graph.getNodeNumRows();
66  if (nrows > maxSize)
67  return;
68 
69  const RCP<const typename Tpetra::Map<lno_t, gno_t> > &rowMap=
70  graph.getRowMap();
71  const RCP<const typename Tpetra::Map<lno_t, gno_t> > &colMap=
72  graph.getColMap();
73 
74  if (info.size() > 0)
75  os << info << endl;
76 
77  if (graph.isGloballyIndexed()){
78  ArrayView<const gno_t> indices;
79  for (size_t i=0; i < nrows; i++){
80  gno_t gid = rowMap->getGlobalElement(i);
81  graph.getGlobalRowView(gid, indices);
82  os << "Row " << gid << ": ";
83  for (typename ArrayView<const gno_t>::size_type j=0; j < indices.size(); j++){
84  os << indices[j] << " ";
85  }
86  os << endl;
87  }
88  }
89  else{
90  ArrayView<const lno_t> indices;
91  for (size_t i=0; i < nrows; i++){
92  gno_t gid = rowMap->getGlobalElement(i);
93  graph.getLocalRowView(i, indices);
94  os << "Row " << gid << ": ";
95  for (typename ArrayView<const lno_t>::size_type j=0; j < indices.size(); j++){
96  os << colMap->getGlobalElement(indices[j]) << " ";
97  }
98  os << endl;
99  }
100  }
101 }
102 
103 template <typename lno_t, typename gno_t>
104  void printTpetraGraph(const RCP<const Comm<int> > &comm,
105  const Tpetra::CrsGraph<lno_t, gno_t> &graph, ostream &os,
106  size_t maxSize, string info)
107 {
108  int rank = comm->getRank();
109  std::ostringstream oss;
110  oss << "rank " << rank;
111 
112  comm->barrier();
113  if (rank==0)
114  os << info << endl;
115  comm->barrier();
116 
117  for (int p=0; p < comm->getSize(); p++){
118  if (p == rank)
119  printTpetraGraph<lno_t, gno_t>(graph, os, maxSize, oss.str());
120  comm->barrier();
121  }
122 }
123 
124 #endif
void printTpetraGraph(const Tpetra::CrsGraph< lno_t, gno_t > &graph, ostream &os, size_t maxSize, string info)
Definition: PrintData.hpp:62