ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo.c
(Generate patch)

Comparing ray/src/hd/rholo.c (file contents):
Revision 3.31 by gregl, Fri Dec 19 10:47:27 1997 UTC vs.
Revision 3.50 by gwlarson, Tue Mar 9 08:51:39 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1999 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ SGI";
11   #include "rholo.h"
12   #include "random.h"
13   #include <signal.h>
14 #include <sys/types.h>
14   #include <sys/stat.h>
15  
16 + #ifndef FRAGWARN
17 + #define FRAGWARN        20              /* fragmentation for warning (%) */
18 + #endif
19 + #ifndef MAXQTIME
20 + #define MAXQTIME        5               /* target maximum seconds in queue */
21 + #endif
22 +                                        /* manual cache flushing frequency */
23 + #ifndef RTFLUSH
24 + #if MAXQTIME
25 + #define RTFLUSH         (300/MAXQTIME*totqlen)  /* <= 5 minutes */
26 + #else
27 + #define RTFLUSH         (50*totqlen)            /* just guess */
28 + #endif
29 + #endif
30                          /* the following must be consistent with rholo.h */
31   int     NVARS = NRHVARS;                /* total number of variables */
32  
# Line 23 | Line 36 | char   *progname;              /* our program name */
36   char    *hdkfile;               /* holodeck file name */
37   char    froot[256];             /* root file name */
38  
26 int     nowarn = 0;             /* turn warnings off? */
27
39   int     ncprocs = 0;            /* desired number of compute processes */
40  
41   char    *outdev = NULL;         /* output device name */
# Line 48 | Line 59 | long   nraysdone = 0L;         /* number of rays done */
59   long    npacksdone = 0L;        /* number of packets done */
60  
61   PACKET  *freepacks;             /* available packets */
62 + int     totqlen;                /* maximum queue length (number of packets) */
63  
64   char  *sigerr[NSIG];            /* signal error messages */
65  
66 + extern int      nowarn;         /* turn warnings off? */
67 +
68   extern time_t   time();
69  
70  
# Line 59 | Line 73 | int    argc;
73   char    *argv[];
74   {
75          int     i;
76 <                                                /* mark start time */
63 <        starttime = time(NULL);
76 >
77          initurand(16384);                       /* initialize urand */
78          progname = argv[0];                     /* get arguments */
79          for (i = 1; i < argc && argv[i][0] == '-'; i++)
# Line 88 | Line 101 | char   *argv[];
101                          goto userr;
102                  }
103                                                  /* get root file name */
104 +        if (i >= argc)
105 +                goto userr;
106          rootname(froot, hdkfile=argv[i++]);
107                                                  /* load variables? */
108          if (i < argc)
# Line 104 | Line 119 | char   *argv[];
119                  }
120                                                  /* check settings */
121          checkvalues();
122 <                                                /* load RIF if any */
122 >                                                /* load rad input file */
123          getradfile();
124  
125          if (hdlist[0] == NULL) {                /* create new holodeck */
# Line 139 | Line 154 | int  signo;
154   {
155          static int  gotsig = 0;
156  
157 <        if (gotsig++)                   /* two signals and we're gone! */
157 >        if (gotsig > 1)                 /* we're going as fast as we can! */
158 >                return;
159 >        if (gotsig++) {                 /* two signals and we split */
160 >                hdsync(NULL, 0);        /* don't leave w/o saying goodbye */
161                  _exit(signo);
162 <
163 <        alarm(60);                      /* allow 60 seconds to clean up */
146 <        signal(SIGALRM, SIG_DFL);       /* make certain we do die */
162 >        }
163 >        alarm(300);                     /* allow 5 minutes to clean up */
164          eputs("signal - ");
165          eputs(sigerr[signo]);
166          eputs("\n");
# Line 170 | Line 187 | int    fd, mod;
187          if (fstat(fd, &stbuf) < 0)
188                  error(SYSTEM, "cannot stat open holodeck file");
189          mod &= stbuf.st_mode;           /* always more restrictive */
190 <        if (mod == stbuf.st_mode)
190 >        if (mod == (stbuf.st_mode & 0777))
191                  return(-1);             /* already set */
192                                          /* else change it */
193          if (fchmod(fd, mod) < 0) {
# Line 197 | Line 214 | initrholo()                    /* get our holodeck running */
214                  maxdisk = 0;
215          else
216                  maxdisk = 1024.*1024.*vflt(DISKSPACE);
200                                                /* record end time */
201        if (!vdef(TIME) || vflt(TIME) <= FTINY)
202                endtime = 0;
203        else
204                endtime = starttime + vflt(TIME)*3600. + .5;
217                                                  /* set up memory cache */
218          if (outdev == NULL)
219 <                hdcachesize = 0;        /* manual flushing */
219 >                hdcachesize = 0;                /* manual flushing */
220          else if (vdef(CACHE))
221                  hdcachesize = 1024.*1024.*vflt(CACHE);
222                                                  /* open report file */
# Line 213 | Line 225 | initrholo()                    /* get our holodeck running */
225                  if (*s && freopen(s, "a", stderr) == NULL)
226                          quit(2);
227          }
228 +                                                /* mark the starting time */
229 +        starttime = time(NULL);
230 +                                                /* compute end time */
231 +        if (!vdef(TIME) || vflt(TIME) <= FTINY)
232 +                endtime = 0;
233 +        else
234 +                endtime = starttime + vflt(TIME)*3600. + .5;
235                                                  /* start rtrace */
236          if (ncprocs > 0) {
237 <                i = start_rtrace();
237 >                totqlen = i = start_rtrace();
238                  if (i < 1)
239                          error(USER, "cannot start rtrace process(es)");
240                  if (vdef(REPORT)) {             /* make first report */
# Line 252 | Line 271 | initrholo()                    /* get our holodeck running */
271          sigdie(SIGXCPU, "CPU limit exceeded");
272          sigdie(SIGXFSZ, "File size exceeded");
273   #endif
274 <                                                /* protect holodeck file */
274 >                                        /* protect holodeck file */
275          orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444);
276          return;
277   memerr:
# Line 262 | Line 281 | memerr:
281  
282   rholo()                         /* holodeck main loop */
283   {
284 +        static long     nextfragwarn = 100*(1L<<20);
285          static int      idle = 0;
286          PACKET  *pl = NULL, *plend;
287 +        long    fsiz;
288 +        int     pksiz;
289          register PACKET *p;
290          time_t  t;
269        long    l;
291                                          /* check display */
292          if (nprocs <= 0)
293                  idle = 1;
# Line 277 | Line 298 | rholo()                                /* holodeck main loop */
298                          return(1);
299          } else if (idle)
300                  return(0);              /* all done */
301 <                                        /* check file size */
302 <        if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
301 >        fsiz = hdfilen(hdlist[0]->fd);  /* check file size */
302 >        if (maxdisk > 0 && fsiz >= maxdisk) {
303                  error(WARNING, "file limit exceeded");
304                  done_rtrace();
305                  return(1);      /* comes back */
306          }
307 <                                        /* check time */
308 <        if (endtime > 0 || reporttime > 0)
309 <                t = time(NULL);
307 > #if FRAGWARN
308 >        if (fsiz >= nextfragwarn &&
309 >                (fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) {
310 >                sprintf(errmsg, "holodeck file fragmentation is %.0f%%",
311 >                                100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz);
312 >                error(WARNING, errmsg);
313 >                nextfragwarn = fsiz + (fsiz>>2);        /* decent interval */
314 >        }
315 > #endif
316 >        t = time(NULL);                 /* check time */
317          if (endtime > 0 && t >= endtime) {
318                  error(WARNING, "time limit exceeded");
319                  done_rtrace();
# Line 293 | Line 321 | rholo()                                /* holodeck main loop */
321          }
322          if (reporttime > 0 && t >= reporttime)
323                  report(t);
324 +                                        /* figure out good packet size */
325 +        pksiz = RPACKSIZ;
326 + #if MAXQTIME
327 +        if (!chunkycmp) {
328 +                pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
329 +                if (pksiz < 1) pksiz = 1;
330 +                else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ;
331 +        }
332 + #endif
333          idle = 0;                       /* get packets to process */
334          while (freepacks != NULL) {
335                  p = freepacks; freepacks = p->next; p->next = NULL;
336 <                if (!next_packet(p)) {
336 >                if (!next_packet(p, pksiz)) {
337                          p->next = freepacks; freepacks = p;
338                          idle = 1;
339                          break;
# Line 317 | Line 354 | register HDGRID        *gp;
354          extern char     *atos();
355          register int    i;
356          int     n;
357 <        double  len[3], maxlen, d;
357 >        double  len[3], d;
358          char    buf[64];
359  
360          if (!vdef(SECTION)) {
# Line 351 | Line 388 | register HDGRID        *gp;
388                                  &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
389                                  &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
390                          badvalue(SECTION);
354                maxlen = 0.;
391                  for (i = 0; i < 3; i++)
392 <                        if ((len[i] = VLEN(gp->xv[i])) > maxlen)
393 <                                maxlen = len[i];
394 <                if (!vdef(GRID))
395 <                        d = 0.125*maxlen;
396 <                else if ((d = vflt(GRID)) <= FTINY)
392 >                        len[i] = VLEN(gp->xv[i]);
393 >                if (!vdef(GRID)) {
394 >                        d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] +
395 >                                        len[2]*len[2] + 4*len[1]*len[2])
396 >                                + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
397 >                                + 4*len[0]*len[1]*len[2]*len[2] );
398 >                        d = sqrt(sqrt(d));
399 >                } else if ((d = vflt(GRID)) <= FTINY)
400                          badvalue(GRID);
401                  for (i = 0; i < 3; i++)
402                          if (gp->grid[i] <= 0)
# Line 405 | Line 444 | HDGRID *gp;
444   }
445  
446  
447 + int
448   headline(s)                     /* process information header line */
449   char    *s;
450   {
# Line 418 | Line 458 | char   *s;
458                                          HOLOFMT, hdkfile, FMTSTR, fmt);
459                          error(USER, errmsg);
460                  }
461 <                return;
461 >                return(0);
462          }
463          for (cp = s; *cp; cp++)         /* take off any comments */
464                  if (*cp == '#') {
# Line 426 | Line 466 | char   *s;
466                          break;
467                  }
468          setvariable(s, matchvar);       /* don't flag errors */
469 +        return(0);
470   }
471  
472  
# Line 438 | Line 479 | loadholo()                     /* start loading a holodeck from fname */
479          int4    nextloc;
480                                          /* open holodeck file */
481          if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
482 <                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
483 <                                ncprocs>0 ? "appending" : "reading");
482 >                sprintf(errmsg, "cannot %s \"%s\"",
483 >                                ncprocs>0 ? "append" : "read", hdkfile);
484                  error(SYSTEM, errmsg);
485          }
486                                          /* load variables from header */
# Line 480 | Line 521 | PACKET *pl;
521                                  p->nr*sizeof(RAYVAL));
522                          if (outdev != NULL)     /* display it */
523                                  disp_packet((PACKHEAD *)p);
524 <                        if (hdcachesize <= 0)   /* manual flushing */
525 <                                n2flush += p->nr;
524 >                        if (hdcachesize <= 0)
525 >                                n2flush++;
526                          nraysdone += p->nr;
527                          npacksdone++;
528 +                        p->nr = 0;
529                  }
530 <                p->nr = 0;                      /* push onto free list */
489 <                p->next = freepacks;
530 >                p->next = freepacks;            /* push onto free list */
531                  freepacks = p;
532          }
533 <        if (n2flush > 1024*RPACKSIZ*nprocs) {
534 <                hdflush(NULL);                  /* flush holodeck buffers */
533 >        if (n2flush >= RTFLUSH) {
534 >                if (outdev != NULL)
535 >                        hdsync(NULL, 1);
536 >                else
537 >                        hdflush(NULL);
538                  n2flush = 0;
539          }
540   }
# Line 535 | Line 579 | register char  *s;
579                  fflush(stderr);
580                  midline = 0;
581          }
538 }
539
540
541 wputs(s)                        /* put warning string to stderr */
542 char    *s;
543 {
544        if (!nowarn)
545                eputs(s);
582   }
583  
584  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines