Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Zoltan2_MetricOutputManager.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
49
#ifndef _ZOLTAN2_METRICOUTPUT_MANAGER_CPP_
50
#define _ZOLTAN2_METRICOUTPUT_MANAGER_CPP_
51
52
#include <string>
53
#include <iostream>
54
#include <fstream>
55
56
namespace
Zoltan2
57
{
72
73
template
<
typename
T>
74
class
MetricOutputManager
75
{
76
public
:
77
89
90
MetricOutputManager
(
int
rank,
bool
doPrinting, std::ofstream &Os,
91
bool
metricsOn, std::string units=std::string(
""
),
int
width=10):
92
me_(rank),
93
os_(static_cast<std::ostream *>(&Os)), osFile_(&Os),
94
iPrint_(doPrinting), wePrint_(metricsOn),
95
units_(units), width_(width){}
96
97
106
107
MetricOutputManager
(
int
rank,
bool
doPrinting, std::ostream &Os,
108
bool
metricsOn, std::string units=std::string(
""
),
int
width=10):
109
me_(rank), os_(&Os), osFile_(NULL),
110
iPrint_(doPrinting), wePrint_(metricsOn),
111
units_(units), width_(width){}
112
115
~MetricOutputManager
() {}
116
119
inline
std::ostream *
getOStream
()
const
{
return
os_; }
120
123
inline
bool
getMetricsOn
()
const
{
return
wePrint_; }
124
129
inline
void
print
(
const
std::string &msg,
const
T val){
130
if
(iPrint_){
131
if
(os_){
132
os_->width(10); os_->fill(
'*'
);
133
*os_ << me_ <<
": "
<< val <<
" "
<< units_ <<
", "
<< msg << std::endl;
134
os_->width(0); os_->fill(
' '
);
135
}
136
else
{
137
osFile_->width(10); osFile_->fill(
'*'
);
138
*osFile_ << me_ <<
": "
<< val <<
" "
<< units_ <<
", "
<< msg << std::endl;
139
osFile_->width(0); osFile_->fill(
' '
);
140
}
141
}
142
}
143
150
inline
void
print
(
const
char
*msg, T val){
151
if
(iPrint_){
152
if
(os_){
153
os_->width(10); os_->fill(
'*'
);
154
*os_ << me_ <<
": "
<< val <<
" "
<< units_ <<
", "
<< msg << std::endl;
155
os_->width(0); os_->fill(
' '
);
156
}
157
else
{
158
osFile_->width(10); osFile_->fill(
'*'
);
159
*osFile_ << me_ <<
": "
<< val <<
" "
<< units_ <<
", "
<< msg << std::endl;
160
osFile_->width(0); osFile_->fill(
' '
);
161
}
162
}
163
}
164
165
private
:
166
167
int
me_;
168
std::ostream *os_;
169
std::ofstream *osFile_;
170
bool
iPrint_;
// I am printing metrics
171
bool
wePrint_;
// at least one process is printing metrics
172
std::string units_;
173
int
width_;
174
};
175
176
}
//namespace Zoltan2
177
178
#endif
MetricOutputManager::MetricOutputManager
MetricOutputManager(int rank, bool doPrinting, std::ofstream &Os, bool metricsOn, std::string units=std::string(""), int width=10)
Constructor for output to a file.
Definition
Zoltan2_MetricOutputManager.hpp:90
Zoltan2::MetricOutputManager::getMetricsOn
bool getMetricsOn() const
Return true if any process outputs metrics.
Definition
Zoltan2_MetricOutputManager.hpp:123
Zoltan2::MetricOutputManager::print
void print(const char *msg, T val)
A version of print that takes char to avoid the cost of converting char * to string.
Definition
Zoltan2_MetricOutputManager.hpp:150
Zoltan2::MetricOutputManager::MetricOutputManager
MetricOutputManager(int rank, bool doPrinting, std::ostream &Os, bool metricsOn, std::string units=std::string(""), int width=10)
Constructor for output to a stream.
Definition
Zoltan2_MetricOutputManager.hpp:107
Zoltan2::MetricOutputManager::~MetricOutputManager
~MetricOutputManager()
Destructor.
Definition
Zoltan2_MetricOutputManager.hpp:115
Zoltan2::MetricOutputManager::MetricOutputManager
MetricOutputManager(int rank, bool doPrinting, std::ofstream &Os, bool metricsOn, std::string units=std::string(""), int width=10)
Constructor for output to a file.
Definition
Zoltan2_MetricOutputManager.hpp:90
Zoltan2::MetricOutputManager::getOStream
std::ostream * getOStream() const
Return the output stream for messages.
Definition
Zoltan2_MetricOutputManager.hpp:119
Zoltan2::MetricOutputManager::print
void print(const std::string &msg, const T val)
Print a line of information.
Definition
Zoltan2_MetricOutputManager.hpp:129
Zoltan2
Created by mbenlioglu on Aug 31, 2020.
Definition
Zoltan2_AlgHybrid2GL.hpp:38
core
src
environment
Zoltan2_MetricOutputManager.hpp
Generated by
1.17.0