Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_MetricOutputManager.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 
13 #ifndef _ZOLTAN2_METRICOUTPUT_MANAGER_CPP_
14 #define _ZOLTAN2_METRICOUTPUT_MANAGER_CPP_
15 
16 #include <string>
17 #include <iostream>
18 #include <fstream>
19 
20 namespace Zoltan2
21 {
37 template <typename T>
39 {
40  public:
41 
54  MetricOutputManager (int rank, bool doPrinting, std::ofstream &Os,
55  bool metricsOn, std::string units=std::string(""), int width=10):
56  me_(rank),
57  os_(static_cast<std::ostream *>(&Os)), osFile_(&Os),
58  iPrint_(doPrinting), wePrint_(metricsOn),
59  units_(units), width_(width){}
60 
61 
71  MetricOutputManager (int rank, bool doPrinting, std::ostream &Os,
72  bool metricsOn, std::string units=std::string(""), int width=10):
73  me_(rank), os_(&Os), osFile_(NULL),
74  iPrint_(doPrinting), wePrint_(metricsOn),
75  units_(units), width_(width){}
76 
80 
83  inline std::ostream *getOStream() const { return os_; }
84 
87  inline bool getMetricsOn() const { return wePrint_; }
88 
93  inline void print(const std::string &msg, const T val){
94  if (iPrint_){
95  if (os_){
96  os_->width(10); os_->fill('*');
97  *os_ << me_ << ": " << val << " " << units_ << ", " << msg << std::endl;
98  os_->width(0); os_->fill(' ');
99  }
100  else{
101  osFile_->width(10); osFile_->fill('*');
102  *osFile_ << me_ << ": " << val << " " << units_ << ", " << msg << std::endl;
103  osFile_->width(0); osFile_->fill(' ');
104  }
105  }
106  }
107 
114  inline void print(const char *msg, T val){
115  if (iPrint_){
116  if (os_){
117  os_->width(10); os_->fill('*');
118  *os_ << me_ << ": " << val << " " << units_ << ", " << msg << std::endl;
119  os_->width(0); os_->fill(' ');
120  }
121  else{
122  osFile_->width(10); osFile_->fill('*');
123  *osFile_ << me_ << ": " << val << " " << units_ << ", " << msg << std::endl;
124  osFile_->width(0); osFile_->fill(' ');
125  }
126  }
127  }
128 
129 private:
130 
131  int me_;
132  std::ostream *os_;
133  std::ofstream *osFile_;
134  bool iPrint_; // I am printing metrics
135  bool wePrint_; // at least one process is printing metrics
136  std::string units_;
137  int width_;
138 };
139 
140 } //namespace Zoltan2
141 
142 #endif
void print(const std::string &msg, const T val)
Print a line of information.
MetricOutputManager handles output of profiling messages.
void print(const char *msg, T val)
A version of print that takes char to avoid the cost of converting char * to string.
MetricOutputManager(int rank, bool doPrinting, std::ostream &Os, bool metricsOn, std::string units=std::string(""), int width=10)
Constructor for output to a stream.
std::ostream * getOStream() const
Return the output stream for messages.
bool getMetricsOn() const
Return true if any process outputs metrics.
MetricOutputManager(int rank, bool doPrinting, std::ofstream &Os, bool metricsOn, std::string units=std::string(""), int width=10)
Constructor for output to a file.