1 |
/* |
2 |
================================================================== |
3 |
Photon map diagnostic output and progress reports |
4 |
|
5 |
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
6 |
(c) Fraunhofer Institute for Solar Energy Systems, |
7 |
(c) Lucerne University of Applied Sciences and Arts, |
8 |
supported by the Swiss National Science Foundation (SNSF, #147053) |
9 |
================================================================== |
10 |
|
11 |
$Id: pmapdiag.c,v 2.3 2015/04/22 20:28:16 rschregle Exp $ |
12 |
*/ |
13 |
|
14 |
|
15 |
|
16 |
#include "pmapdiag.h" |
17 |
#include "pmapdata.h" |
18 |
#include "standard.h" |
19 |
|
20 |
|
21 |
|
22 |
time_t repStartTime, repLastTime = 0; /* Time at start & last report */ |
23 |
unsigned long repProgress, /* Report progress counter */ |
24 |
repComplete; /* Report completion count */ |
25 |
|
26 |
|
27 |
|
28 |
static char* biasCompStats (const PhotonMap *pmap, PhotonMapType type, |
29 |
char *stats) |
30 |
/* Dump bias compensation statistics */ |
31 |
{ |
32 |
unsigned avgBwidth; |
33 |
float avgErr; |
34 |
|
35 |
/* Check if photon map is valid and bias compensated */ |
36 |
if (pmap && pmap -> maxGather > pmap -> minGather) { |
37 |
avgBwidth = pmap -> numDensity |
38 |
? pmap -> totalGathered / pmap -> numDensity : 0, |
39 |
avgErr = pmap -> numDensity |
40 |
? sqrt(pmap -> rmsError / pmap -> numDensity) : 0; |
41 |
|
42 |
sprintf(stats, "%d/%d/%d %s (%.1f/%.1f/%.1f%% error), ", |
43 |
pmap -> minGathered, pmap -> maxGathered, avgBwidth, |
44 |
pmapName [type], |
45 |
100 * pmap -> minError, 100 * pmap -> maxError, 100 * avgErr); |
46 |
|
47 |
return stats; |
48 |
} |
49 |
|
50 |
return NULL; |
51 |
} |
52 |
|
53 |
|
54 |
|
55 |
void pmapBiasCompReport (char *stats) |
56 |
/* Append full bias compensation statistics to stats; interface to rpict's |
57 |
* report() */ |
58 |
{ |
59 |
char tmp [512]; |
60 |
unsigned t; |
61 |
|
62 |
stats [0] = '\0'; |
63 |
|
64 |
for (t = 0; t < NUM_PMAP_TYPES; t++) |
65 |
if (biasCompStats(photonMaps [t], t, tmp)) |
66 |
strcat(stats, tmp); |
67 |
} |
68 |
|
69 |
|
70 |
|
71 |
#ifndef NON_POSIX |
72 |
void pmapPreCompReport() |
73 |
/* Report global photon precomputation progress */ |
74 |
{ |
75 |
extern char *myhostname(); |
76 |
float u, s; |
77 |
char tmp [512]; |
78 |
|
79 |
#ifdef BSD |
80 |
struct rusage rubuf; |
81 |
#else |
82 |
struct tms tbuf; |
83 |
float period; |
84 |
#endif |
85 |
|
86 |
repLastTime = time(NULL); |
87 |
|
88 |
#ifdef BSD |
89 |
getrusage(RUSAGE_SELF, &rubuf); |
90 |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec / 1e6; |
91 |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec / 1e6; |
92 |
getrusage(RUSAGE_CHILDREN, &rubuf); |
93 |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec / 1e6; |
94 |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec / 1e6; |
95 |
#else |
96 |
times(&tbuf); |
97 |
|
98 |
#ifdef _SC_CLK_TCK |
99 |
period = 1.0 / sysconf(_SC_CLK_TCK); |
100 |
#else |
101 |
period = 1.0 / 60; |
102 |
#endif |
103 |
|
104 |
u = (tbuf.tms_utime + tbuf.tms_cutime) * period; |
105 |
s = (tbuf.tms_stime + tbuf.tms_cstime) * period; |
106 |
#endif |
107 |
|
108 |
sprintf(errmsg, "%lu precomputed, ", repProgress); |
109 |
|
110 |
/* Append bias compensation stats */ |
111 |
biasCompStats(preCompPmap, PMAP_TYPE_PRECOMP, tmp); |
112 |
strcat(errmsg, tmp); |
113 |
|
114 |
sprintf(tmp, "%4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
115 |
100.0 * repProgress / repComplete, u / 3600, s / 3600, |
116 |
(repLastTime - repStartTime) / 3600.0, myhostname()); |
117 |
strcat(errmsg, tmp); |
118 |
|
119 |
eputs(errmsg); |
120 |
fflush(stderr); |
121 |
|
122 |
#ifdef SIGCONT |
123 |
signal(SIGCONT, pmapPreCompReport); |
124 |
#endif |
125 |
} |
126 |
|
127 |
|
128 |
|
129 |
void pmapDistribReport() |
130 |
/* Report photon distribution progress */ |
131 |
{ |
132 |
extern char *myhostname(); |
133 |
float u, s; |
134 |
unsigned t; |
135 |
char tmp [512]; |
136 |
|
137 |
#ifdef BSD |
138 |
struct rusage rubuf; |
139 |
#else |
140 |
struct tms tbuf; |
141 |
float period; |
142 |
#endif |
143 |
|
144 |
repLastTime = time(NULL); |
145 |
|
146 |
#ifdef BSD |
147 |
getrusage(RUSAGE_SELF, &rubuf); |
148 |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec / 1e6; |
149 |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec / 1e6; |
150 |
getrusage(RUSAGE_CHILDREN, &rubuf); |
151 |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec / 1e6; |
152 |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec / 1e6; |
153 |
#else |
154 |
times(&tbuf); |
155 |
|
156 |
#ifdef _SC_CLK_TCK |
157 |
period = 1.0 / sysconf(_SC_CLK_TCK); |
158 |
#else |
159 |
period = 1.0 / 60; |
160 |
#endif |
161 |
|
162 |
u = (tbuf.tms_utime + tbuf.tms_cutime) * period; |
163 |
s = (tbuf.tms_stime + tbuf.tms_cstime) * period; |
164 |
#endif |
165 |
|
166 |
sprintf(errmsg, "%lu emitted, ", repProgress); |
167 |
|
168 |
for (t = 0; t < NUM_PMAP_TYPES; t++) |
169 |
if (photonMaps [t]) { |
170 |
sprintf(tmp, "%lu %s, ", |
171 |
photonMaps [t] -> heapEnd, pmapName [t]); |
172 |
strcat(errmsg, tmp); |
173 |
} |
174 |
|
175 |
sprintf(tmp, "%4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
176 |
100.0 * repProgress / repComplete, u / 3600, s / 3600, |
177 |
(repLastTime - repStartTime) / 3600.0, myhostname()); |
178 |
|
179 |
strcat(errmsg, tmp); |
180 |
eputs(errmsg); |
181 |
fflush(stderr); |
182 |
|
183 |
#ifndef SIGCONT |
184 |
signal(SIGCONT, pmapDistribReport); |
185 |
#endif |
186 |
} |
187 |
|
188 |
#else /* POSIX */ |
189 |
|
190 |
void pmapPreCompReport() |
191 |
/* Report global photon precomputation progress */ |
192 |
{ |
193 |
char tmp [512]; |
194 |
|
195 |
repLastTime = time(NULL); |
196 |
sprintf(errmsg, "%lu precomputed, ", repProgress); |
197 |
|
198 |
/* Append bias compensation stats */ |
199 |
biasCompStats(preCompPmap, PMAP_TYPE_PRECOMP, tmp); |
200 |
strcat(errmsg, tmp); |
201 |
|
202 |
sprintf(tmp, "%4.2f%% after %5.4f hours\n", |
203 |
100.0 * repProgress / repComplete, |
204 |
(repLastTime - repStartTime) / 3600.0); |
205 |
strcat(errmsg, tmp); |
206 |
|
207 |
eputs(errmsg); |
208 |
fflush(stderr); |
209 |
} |
210 |
|
211 |
|
212 |
|
213 |
void pmapDistribReport() |
214 |
/* Report photon distribution progress */ |
215 |
{ |
216 |
char tmp [512]; |
217 |
unsigned t; |
218 |
|
219 |
repLastTime = time(NULL); |
220 |
sprintf(errmsg, "%lu emitted, ", repProgress); |
221 |
|
222 |
for (t = 0; t < NUM_PMAP_TYPES; t++) |
223 |
if (photonMaps [t]) { |
224 |
sprintf(tmp, "%lu %s, ", |
225 |
photonMaps [t] -> heapEnd, pmapName [t]); |
226 |
strcat(errmsg, tmp); |
227 |
} |
228 |
|
229 |
sprintf(tmp, "%4.2f%% after %5.4f hours\n", |
230 |
100.0 * repProgress / repComplete, |
231 |
(repLastTime - repStartTime) / 3600.0); |
232 |
strcat(errmsg, tmp); |
233 |
|
234 |
eputs(errmsg); |
235 |
fflush(stderr); |
236 |
} |
237 |
#endif |
238 |
|
239 |
|
240 |
|