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 |
|
|
$Id: pmapdiag.c,v 1.2 2014/09/24 09:42:18 taschreg Exp taschreg $ |
11 |
|
|
*/ |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
#include "pmapdiag.h" |
16 |
|
|
#include "pmapdata.h" |
17 |
|
|
#include "standard.h" |
18 |
|
|
#include <signal.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 |
|
|
#ifndef BSD |
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 BSD |
184 |
|
|
signal(SIGCONT, pmapDistribReport); |
185 |
|
|
#endif |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
#else /* POSIX */ |
189 |
|
|
|
190 |
|
|
void pmapPreCompReport() |
191 |
|
|
/* Report global photon precomputation progress */ |
192 |
|
|
{ |
193 |
|
|
repLastTime = time(NULL); |
194 |
|
|
sprintf(errmsg, "%lu precomputed, ", repProgress); |
195 |
|
|
|
196 |
|
|
/* Append bias compensation stats */ |
197 |
|
|
biasCompStats(preCompPmap, PMAP_TYPE_PRECOMP, tmp); |
198 |
|
|
strcat(errmsg, tmp); |
199 |
|
|
|
200 |
|
|
sprintf(tmp, "%4.2f%% after %5.4f hours\n", |
201 |
|
|
100.0 * repProgress / repComplete, |
202 |
|
|
(repLastTime - repStartTime) / 3600.0); |
203 |
|
|
strcat(errmsg, tmp); |
204 |
|
|
|
205 |
|
|
eputs(errmsg); |
206 |
|
|
fflush(stderr); |
207 |
|
|
} |
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
void pmapDistribReport() |
212 |
|
|
/* Report photon distribution progress */ |
213 |
|
|
{ |
214 |
|
|
char tmp [512]; |
215 |
|
|
unsigned t; |
216 |
|
|
|
217 |
|
|
repLastTime = time(NULL); |
218 |
|
|
sprintf(errmsg, "%lu emitted, ", repProgress); |
219 |
|
|
|
220 |
|
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
221 |
|
|
if (photonMaps [t]) { |
222 |
|
|
sprintf(tmp, "%lu %s, ", |
223 |
|
|
photonMaps [t] -> heapEnd, pmapName [t]); |
224 |
|
|
strcat(errmsg, tmp); |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
sprintf(tmp, "%4.2f%% after %5.4f hours\n", |
228 |
|
|
100.0 * repProgress / repComplete, |
229 |
|
|
(repLastTime - repStartTime) / 3600.0); |
230 |
|
|
strcat(errmsg, tmp); |
231 |
|
|
|
232 |
|
|
eputs(errmsg); |
233 |
|
|
fflush(stderr); |
234 |
|
|
} |
235 |
|
|
#endif |
236 |
|
|
|
237 |
|
|
|
238 |
|
|
|