1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: pmapdiag.c,v 2.7 2016/05/17 17:39:47 rschregle Exp $"; |
3 |
#endif |
4 |
|
5 |
/* |
6 |
================================================================== |
7 |
Photon map diagnostic output and progress reports |
8 |
|
9 |
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
10 |
(c) Fraunhofer Institute for Solar Energy Systems, |
11 |
(c) Lucerne University of Applied Sciences and Arts, |
12 |
supported by the Swiss National Science Foundation (SNSF, #147053) |
13 |
================================================================== |
14 |
|
15 |
$Id: pmapdiag.c,v 2.7 2016/05/17 17:39:47 rschregle Exp $ |
16 |
*/ |
17 |
|
18 |
|
19 |
|
20 |
#include "pmap.h" |
21 |
#include "pmapdiag.h" |
22 |
#include "pmapdata.h" |
23 |
#include "standard.h" |
24 |
|
25 |
|
26 |
|
27 |
time_t repStartTime, repLastTime = 0; /* Time at start & last report */ |
28 |
unsigned long repProgress, /* Report progress counter */ |
29 |
repComplete, /* Report completion count */ |
30 |
repEmitted; /* Num emitted photons */ |
31 |
|
32 |
|
33 |
static char* biasCompStats (const PhotonMap *pmap, PhotonMapType type, |
34 |
char *stats) |
35 |
/* Dump bias compensation statistics */ |
36 |
{ |
37 |
unsigned avgBwidth; |
38 |
float avgErr; |
39 |
|
40 |
stats [0] = '\0'; |
41 |
|
42 |
/* Check if photon map is valid and bias compensated */ |
43 |
if (pmap && pmap -> maxGather > pmap -> minGather) { |
44 |
avgBwidth = pmap -> numDensity |
45 |
? pmap -> totalGathered / pmap -> numDensity : 0, |
46 |
avgErr = pmap -> numDensity |
47 |
? sqrt(pmap -> rmsError / pmap -> numDensity) : 0; |
48 |
|
49 |
sprintf(stats, "%d/%d/%d %s photon bwidth (%.1f/%.1f/%.1f%% error), ", |
50 |
pmap -> minGathered, pmap -> maxGathered, avgBwidth, |
51 |
pmapName [type], |
52 |
100 * pmap -> minError, 100 * pmap -> maxError, 100 * avgErr); |
53 |
|
54 |
return stats; |
55 |
} |
56 |
|
57 |
return NULL; |
58 |
} |
59 |
|
60 |
|
61 |
|
62 |
void pmapBiasCompReport (char *stats) |
63 |
/* Append full bias compensation statistics to stats; interface to rpict's |
64 |
* report() */ |
65 |
{ |
66 |
char tmp [512]; |
67 |
unsigned t; |
68 |
|
69 |
stats [0] = '\0'; |
70 |
|
71 |
for (t = 0; t < NUM_PMAP_TYPES; t++) |
72 |
if (biasCompStats(photonMaps [t], t, tmp)) |
73 |
strcat(stats, tmp); |
74 |
} |
75 |
|
76 |
|
77 |
|
78 |
#ifdef PMAP_OOC |
79 |
static char* oocCacheStats (const PhotonMap *pmap, PhotonMapType type, |
80 |
char *stats) |
81 |
/* Dump OOC I/O cache statistics */ |
82 |
{ |
83 |
const OOC_Cache *cache; |
84 |
stats [0] = '\0'; |
85 |
|
86 |
|
87 |
/* Check for photon map is valid and caching enabled */ |
88 |
if (pmap && (cache = pmap -> store.cache) && cache -> numReads) { |
89 |
sprintf(stats, "%ld %s photons cached in %d/%d pages " |
90 |
"(%.1f%% hit, %.1f%% rept, %.1f coll), ", |
91 |
(unsigned long)cache -> pageCnt * cache -> recPerPage, |
92 |
pmapName [type], cache -> pageCnt, cache -> numPages, |
93 |
100.0 * cache -> numHits / cache -> numReads, |
94 |
100.0 * cache -> numRept / cache -> numReads, |
95 |
(float)cache -> numColl / cache -> numReads); |
96 |
|
97 |
return stats; |
98 |
} |
99 |
|
100 |
return NULL; |
101 |
} |
102 |
|
103 |
|
104 |
|
105 |
void pmapOOCCacheReport (char *stats) |
106 |
/* Append full OOC I/O cache statistics to stats; interface to rpict's |
107 |
* report() */ |
108 |
{ |
109 |
char tmp [512]; |
110 |
unsigned t; |
111 |
|
112 |
stats [0] = '\0'; |
113 |
|
114 |
for (t = 0; t < NUM_PMAP_TYPES; t++) |
115 |
if (oocCacheStats(photonMaps [t], t, tmp)) |
116 |
strcat(stats, tmp); |
117 |
} |
118 |
#endif |
119 |
|
120 |
|
121 |
|
122 |
#ifndef NON_POSIX |
123 |
void pmapPreCompReport() |
124 |
/* Report global photon precomputation progress */ |
125 |
{ |
126 |
extern char *myhostname(); |
127 |
float u, s, rtime, eta, progress; |
128 |
char tmp [512]; |
129 |
|
130 |
#ifdef BSD |
131 |
struct rusage rubuf; |
132 |
#else |
133 |
struct tms tbuf; |
134 |
float period; |
135 |
#endif |
136 |
|
137 |
repLastTime = time(NULL); |
138 |
|
139 |
#ifdef BSD |
140 |
getrusage(RUSAGE_SELF, &rubuf); |
141 |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec / 1e6; |
142 |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec / 1e6; |
143 |
getrusage(RUSAGE_CHILDREN, &rubuf); |
144 |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec / 1e6; |
145 |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec / 1e6; |
146 |
#else |
147 |
times(&tbuf); |
148 |
|
149 |
#ifdef _SC_CLK_TCK |
150 |
period = 1.0 / sysconf(_SC_CLK_TCK); |
151 |
#else |
152 |
period = 1.0 / 60; |
153 |
#endif |
154 |
|
155 |
u = (tbuf.tms_utime + tbuf.tms_cutime) * period; |
156 |
s = (tbuf.tms_stime + tbuf.tms_cstime) * period; |
157 |
#endif |
158 |
|
159 |
sprintf(errmsg, "%lu precomputed, ", repProgress); |
160 |
|
161 |
/* Append bias compensation stats */ |
162 |
biasCompStats(preCompPmap, PMAP_TYPE_PRECOMP, tmp); |
163 |
strcat(errmsg, tmp); |
164 |
|
165 |
rtime = (repLastTime - repStartTime) / 3600.0; |
166 |
progress = (float)repProgress / repComplete; |
167 |
eta = max(0, rtime * (progress > FTINY ? 1 / progress - 1 : 0)); |
168 |
|
169 |
sprintf( |
170 |
tmp, "%4.2f%% after %.3fu %.3fs %.3fr hours on %s, ETA=%.3fh\n", |
171 |
100 * progress, u / 3600, s / 3600, rtime, myhostname(), eta |
172 |
); |
173 |
strcat(errmsg, tmp); |
174 |
|
175 |
eputs(errmsg); |
176 |
fflush(stderr); |
177 |
|
178 |
#ifdef SIGCONT |
179 |
signal(SIGCONT, pmapPreCompReport); |
180 |
#endif |
181 |
} |
182 |
|
183 |
|
184 |
|
185 |
void pmapDistribReport() |
186 |
/* Report photon distribution progress */ |
187 |
{ |
188 |
extern char *myhostname(); |
189 |
float u, s, rtime, eta, progress; |
190 |
unsigned t; |
191 |
char tmp [512]; |
192 |
|
193 |
#ifdef BSD |
194 |
struct rusage rubuf; |
195 |
#else |
196 |
struct tms tbuf; |
197 |
float period; |
198 |
#endif |
199 |
|
200 |
repLastTime = time(NULL); |
201 |
|
202 |
#ifdef BSD |
203 |
getrusage(RUSAGE_SELF, &rubuf); |
204 |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec / 1e6; |
205 |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec / 1e6; |
206 |
getrusage(RUSAGE_CHILDREN, &rubuf); |
207 |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec / 1e6; |
208 |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec / 1e6; |
209 |
#else |
210 |
times(&tbuf); |
211 |
|
212 |
#ifdef _SC_CLK_TCK |
213 |
period = 1.0 / sysconf(_SC_CLK_TCK); |
214 |
#else |
215 |
period = 1.0 / 60; |
216 |
#endif |
217 |
|
218 |
u = (tbuf.tms_utime + tbuf.tms_cutime) * period; |
219 |
s = (tbuf.tms_stime + tbuf.tms_cstime) * period; |
220 |
#endif |
221 |
|
222 |
sprintf(errmsg, "%lu emitted, ", repEmitted); |
223 |
|
224 |
for (t = 0; t < NUM_PMAP_TYPES; t++) |
225 |
if (photonMaps [t]) { |
226 |
sprintf(tmp, "%lu %s, ", photonMaps [t] -> numPhotons, |
227 |
pmapName [t]); |
228 |
strcat(errmsg, tmp); |
229 |
} |
230 |
|
231 |
rtime = (repLastTime - repStartTime) / 3600.0; |
232 |
progress = (float)repProgress / repComplete; |
233 |
eta = max(0, rtime * (progress > FTINY ? 1 / progress - 1 : 0)); |
234 |
|
235 |
sprintf( |
236 |
tmp, "%4.2f%% after %.3fu %.3fs %.3fr hours on %s, ETA=%.3fh\n", |
237 |
100 * progress, u / 3600, s / 3600, rtime, myhostname(), eta |
238 |
); |
239 |
|
240 |
strcat(errmsg, tmp); |
241 |
eputs(errmsg); |
242 |
fflush(stderr); |
243 |
|
244 |
#ifndef SIGCONT |
245 |
signal(SIGCONT, pmapDistribReport); |
246 |
#endif |
247 |
} |
248 |
|
249 |
#else /* POSIX */ |
250 |
|
251 |
void pmapPreCompReport() |
252 |
/* Report global photon precomputation progress */ |
253 |
{ |
254 |
char tmp [512]; |
255 |
float rtime, progress, eta; |
256 |
|
257 |
repLastTime = time(NULL); |
258 |
sprintf(errmsg, "%lu precomputed, ", repProgress); |
259 |
|
260 |
/* Append bias compensation stats */ |
261 |
biasCompStats(preCompPmap, PMAP_TYPE_PRECOMP, tmp); |
262 |
strcat(errmsg, tmp); |
263 |
|
264 |
rtime = (repLastTime - repStartTime) / 3600.0; |
265 |
progress = (float)repProgress / repComplete; |
266 |
eta = max(0, rtime * (progress > FTINY ? 1 / progress - 1 : 0)); |
267 |
|
268 |
sprintf( |
269 |
tmp, "%4.2f%% after %5.4f hours, ETA=%.3fh\n", |
270 |
100 * progress, rtime, eta |
271 |
); |
272 |
strcat(errmsg, tmp); |
273 |
|
274 |
eputs(errmsg); |
275 |
fflush(stderr); |
276 |
} |
277 |
|
278 |
|
279 |
|
280 |
void pmapDistribReport() |
281 |
/* Report photon distribution progress */ |
282 |
{ |
283 |
char tmp [512]; |
284 |
unsigned t; |
285 |
float rtime, progress, eta; |
286 |
|
287 |
repLastTime = time(NULL); |
288 |
sprintf(errmsg, "%lu emitted, ", repEmitted); |
289 |
|
290 |
for (t = 0; t < NUM_PMAP_TYPES; t++) |
291 |
if (photonMaps [t]) { |
292 |
sprintf(tmp, "%lu %s, ", photonMaps [t] -> numPhotons, |
293 |
pmapName [t]); |
294 |
strcat(errmsg, tmp); |
295 |
} |
296 |
|
297 |
rtime = (repLastTime - repStartTime) / 3600.0; |
298 |
progress = (float)repProgress / repComplete; |
299 |
eta = max(0, rtime * (progress > FTINY ? 1 / progress - 1 : 0)); |
300 |
|
301 |
sprintf( |
302 |
tmp, "%4.2f%% after %5.4f hours, ETA=%.3fh\n", |
303 |
100 * progress, rtime, eta |
304 |
); |
305 |
strcat(errmsg, tmp); |
306 |
|
307 |
eputs(errmsg); |
308 |
fflush(stderr); |
309 |
} |
310 |
#endif |
311 |
|
312 |
|
313 |
|