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