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