Zoltan2
Loading...
Searching...
No Matches
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
20namespace Zoltan2
21{
37template <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
129private:
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
MetricOutputManager handles output of profiling messages.
bool getMetricsOn() const
Return true if any process outputs metrics.
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.
MetricOutputManager(int rank, bool doPrinting, std::ofstream &Os, bool metricsOn, std::string units=std::string(""), int width=10)
Constructor for output to a file.
std::ostream * getOStream() const
Return the output stream for messages.
void print(const std::string &msg, const T val)
Print a line of information.
Created by mbenlioglu on Aug 31, 2020.