Line data Source code
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::
45 : debug_logger()
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::
57 : error_logger()
58 : {
59 0 : return m_errStream;
60 : }
61 :
62 0 : inline int LogAssistant::
63 : get_output_process()
64 : {
65 0 : return m_outputProc;
66 : }
67 :
68 : inline LogAssistant&
69 0 : GetLogAssistant()
70 : {
71 3 : return LogAssistant::instance();
72 : }
73 :
74 : inline unsigned int
75 : GetNumberOfDigits (uint64_t i)
76 : {
77 0 : return i > 0 ? (unsigned int) log10 ((double) i) + 1 : 1;
78 : }
79 :
80 : inline std::string
81 0 : ConvertNumber (uint64_t size, unsigned int width, unsigned int numDisplayedDigits)
82 : {
83 0 : std::stringstream ss;
84 :
85 0 : if (GetNumberOfDigits(size) > width) {
86 0 : if (size >= UNIT_EXA) {
87 :
88 0 : ss << std::setprecision(numDisplayedDigits)
89 0 : << (((double)size) / UNIT_EXA)
90 0 : << " Ei";
91 :
92 0 : } else if (size >= UNIT_PETA) {
93 :
94 0 : ss << std::setprecision(numDisplayedDigits)
95 0 : << (((double)size) / UNIT_PETA)
96 0 : << " Pi";
97 :
98 0 : } else if (size >= UNIT_TERA) {
99 :
100 0 : ss << std::setprecision(numDisplayedDigits)
101 0 : << (((double)size) / UNIT_TERA)
102 0 : << " Ti";
103 :
104 0 : } else if (size >= UNIT_GIGA) {
105 :
106 0 : ss << std::setprecision(numDisplayedDigits)
107 0 : << (((double)size) / UNIT_GIGA)
108 0 : << " Gi";
109 :
110 0 : } else if (size >= UNIT_MEGA) {
111 :
112 0 : ss << std::setprecision(numDisplayedDigits)
113 0 : << (((double)size) / UNIT_MEGA)
114 0 : << " Mi";
115 :
116 0 : } else if (size >= UNIT_KILO) {
117 :
118 0 : ss << std::setprecision(numDisplayedDigits)
119 0 : << (((double)size) / UNIT_KILO)
120 0 : << " Ki";
121 :
122 : }
123 : } else {
124 :
125 : ss << size;
126 : }
127 :
128 0 : return(ss.str());
129 0 : }
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__ */
|