ug4
log_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Authors: Andreas Vogel, Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__COMMON__LOG_IMPL__
34 #define __H__UG__COMMON__LOG_IMPL__
35 
36 #include <iostream>
37 #include <string> // added for 'string'
38 #include <sstream> // added for 'stringstream'
39 #include <iomanip> // added for 'setprecision()'
40 #include <cmath>
41 
42 namespace ug{
43 
44 inline std::ostream& LogAssistant::
46 {
47  return std::cout;
48 }
49 
50 inline std::ostream& LogAssistant::
51 logger()
52 {
53  return std::cout;
54 }
55 
56 inline std::ostream& LogAssistant::
58 {
59  return m_errStream;
60 }
61 
62 inline int LogAssistant::
64 {
65  return m_outputProc;
66 }
67 
68 inline LogAssistant&
70 {
71  return LogAssistant::instance();
72 }
73 
74 inline unsigned int
75 GetNumberOfDigits (uint64_t i)
76 {
77  return i > 0 ? (unsigned int) log10 ((double) i) + 1 : 1;
78 }
79 
80 inline std::string
81 ConvertNumber (uint64_t size, unsigned int width, unsigned int numDisplayedDigits)
82 {
83  std::stringstream ss;
84 
85  if (GetNumberOfDigits(size) > width) {
86  if (size >= UNIT_EXA) {
87 
88  ss << std::setprecision(numDisplayedDigits)
89  << (((double)size) / UNIT_EXA)
90  << " Ei";
91 
92  } else if (size >= UNIT_PETA) {
93 
94  ss << std::setprecision(numDisplayedDigits)
95  << (((double)size) / UNIT_PETA)
96  << " Pi";
97 
98  } else if (size >= UNIT_TERA) {
99 
100  ss << std::setprecision(numDisplayedDigits)
101  << (((double)size) / UNIT_TERA)
102  << " Ti";
103 
104  } else if (size >= UNIT_GIGA) {
105 
106  ss << std::setprecision(numDisplayedDigits)
107  << (((double)size) / UNIT_GIGA)
108  << " Gi";
109 
110  } else if (size >= UNIT_MEGA) {
111 
112  ss << std::setprecision(numDisplayedDigits)
113  << (((double)size) / UNIT_MEGA)
114  << " Mi";
115 
116  } else if (size >= UNIT_KILO) {
117 
118  ss << std::setprecision(numDisplayedDigits)
119  << (((double)size) / UNIT_KILO)
120  << " Ki";
121 
122  }
123  } else {
124 
125  ss << size;
126  }
127 
128  return(ss.str());
129 }
130 
131 inline std::string
132 ConvertNumberSI (uint64_t size, unsigned int width, unsigned int numDisplayedDigits)
133 {
134  std::stringstream ss;
135 
136  if (GetNumberOfDigits(size) > width) {
137  if (size >= UNIT_EXA_SI) {
138 
139  ss << std::setprecision(numDisplayedDigits)
140  << (((double)size) / UNIT_EXA_SI)
141  << " E";
142 
143  } else if (size >= UNIT_PETA_SI) {
144 
145  ss << std::setprecision(numDisplayedDigits)
146  << (((double)size) / UNIT_PETA_SI)
147  << " P";
148 
149  } else if (size >= UNIT_TERA_SI) {
150 
151  ss << std::setprecision(numDisplayedDigits)
152  << (((double)size) / UNIT_TERA_SI)
153  << " T";
154 
155  } else if (size >= UNIT_GIGA_SI) {
156 
157  ss << std::setprecision(numDisplayedDigits)
158  << (((double)size) / UNIT_GIGA_SI)
159  << " G";
160 
161  } else if (size >= UNIT_MEGA_SI) {
162 
163  ss << std::setprecision(numDisplayedDigits)
164  << (((double)size) / UNIT_MEGA_SI)
165  << " M";
166 
167  } else if (size >= UNIT_KILO_SI) {
168 
169  ss << std::setprecision(numDisplayedDigits)
170  << (((double)size) / UNIT_KILO_SI)
171  << " K";
172 
173  }
174  } else {
175 
176  ss << size;
177  }
178 
179  return(ss.str());
180 }
181 
182 } // end namespace ug
183 
184 #endif /* __H__UG__COMMON__LOG_IMPL__ */
Definition: log.h:97
int get_output_process()
returns the rank of the current output-process or -1 if all procs perform output.
Definition: log_impl.h:63
std::ostream & error_logger()
returns the error output stream
Definition: log_impl.h:57
std::ostream & logger()
returns the normal output stream
Definition: log_impl.h:51
static LogAssistant & instance()
returns a reference to the single instance of LogAssistant
Definition: log.cpp:112
std::stringstream m_errStream
Definition: log.h:219
int m_outputProc
Definition: log.h:224
std::ostream & debug_logger()
returns the debug output stream
Definition: log_impl.h:45
const uint64 UNIT_PETA_SI
Definition: log.h:74
const uint64 UNIT_KILO_SI
Definition: log.h:70
LogAssistant & GetLogAssistant()
Definition: log_impl.h:69
const uint64 UNIT_PETA
Definition: log.h:66
const uint64 UNIT_GIGA_SI
Definition: log.h:72
std::string ConvertNumberSI(uint64_t size, unsigned int width, unsigned int numDisplayedDigits)
returns number 'size' in a more human readable format (using SI prefixes)
Definition: log_impl.h:132
const uint64 UNIT_TERA
Definition: log.h:65
const uint64 UNIT_GIGA
Definition: log.h:64
const uint64 UNIT_EXA_SI
Definition: log.h:75
const uint64 UNIT_MEGA
Definition: log.h:63
const uint64 UNIT_KILO
Definition: log.h:62
const uint64 UNIT_EXA
Definition: log.h:67
const uint64 UNIT_TERA_SI
Definition: log.h:73
const uint64 UNIT_MEGA_SI
Definition: log.h:71
std::string ConvertNumber(uint64_t size, unsigned int width, unsigned int numDisplayedDigits)
returns number 'size' in a more human readable format (using IEC binary prefixes)
Definition: log_impl.h:81
the ug namespace
unsigned int GetNumberOfDigits(uint64_t i)
Definition: log_impl.h:75