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