ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/pmapdiag.c
Revision: 2.5
Committed: Tue Aug 18 18:45:55 2015 UTC (8 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +4 -1 lines
Log Message:
Added missing RCSid forgotten during initial check-in

File Contents

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