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.46 by gwlarson, Thu Jan 7 22:05:34 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 14 | Line 14 | static char SCCSid[] = "$SunId$ SGI";
14   #include <sys/types.h>
15   #include <sys/stat.h>
16  
17 + #ifndef RTFLUSH
18 + #define RTFLUSH         0               /* flush one at a time in batch */
19 + #endif
20 + #ifndef FRAGWARN
21 + #define FRAGWARN        20              /* fragmentation for warning (%) */
22 + #endif
23 + #ifndef MAXQTIME
24 + #define MAXQTIME        5               /* target maximum seconds in queue */
25 + #endif
26                          /* the following must be consistent with rholo.h */
27   int     NVARS = NRHVARS;                /* total number of variables */
28  
# Line 23 | Line 32 | char   *progname;              /* our program name */
32   char    *hdkfile;               /* holodeck file name */
33   char    froot[256];             /* root file name */
34  
26 int     nowarn = 0;             /* turn warnings off? */
27
35   int     ncprocs = 0;            /* desired number of compute processes */
36  
37   char    *outdev = NULL;         /* output device name */
# Line 48 | Line 55 | long   nraysdone = 0L;         /* number of rays done */
55   long    npacksdone = 0L;        /* number of packets done */
56  
57   PACKET  *freepacks;             /* available packets */
58 + int     totqlen;                /* maximum queue length when full */
59  
60   char  *sigerr[NSIG];            /* signal error messages */
61  
62 + extern int      nowarn;         /* turn warnings off? */
63 +
64   extern time_t   time();
65  
66  
# Line 59 | Line 69 | int    argc;
69   char    *argv[];
70   {
71          int     i;
72 <                                                /* mark start time */
63 <        starttime = time(NULL);
72 >
73          initurand(16384);                       /* initialize urand */
74          progname = argv[0];                     /* get arguments */
75          for (i = 1; i < argc && argv[i][0] == '-'; i++)
# Line 88 | Line 97 | char   *argv[];
97                          goto userr;
98                  }
99                                                  /* get root file name */
100 +        if (i >= argc)
101 +                goto userr;
102          rootname(froot, hdkfile=argv[i++]);
103                                                  /* load variables? */
104          if (i < argc)
# Line 104 | Line 115 | char   *argv[];
115                  }
116                                                  /* check settings */
117          checkvalues();
118 <                                                /* load RIF if any */
118 >                                                /* load rad input file */
119          getradfile();
120  
121          if (hdlist[0] == NULL) {                /* create new holodeck */
# Line 142 | Line 153 | int  signo;
153          if (gotsig++)                   /* two signals and we're gone! */
154                  _exit(signo);
155  
156 <        alarm(60);                      /* allow 60 seconds to clean up */
156 >        alarm(180);                     /* allow 3 minutes to clean up */
157          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
158          eputs("signal - ");
159          eputs(sigerr[signo]);
# Line 170 | Line 181 | int    fd, mod;
181          if (fstat(fd, &stbuf) < 0)
182                  error(SYSTEM, "cannot stat open holodeck file");
183          mod &= stbuf.st_mode;           /* always more restrictive */
184 <        if (mod == stbuf.st_mode)
184 >        if (mod == (stbuf.st_mode & 0777))
185                  return(-1);             /* already set */
186                                          /* else change it */
187          if (fchmod(fd, mod) < 0) {
# Line 197 | Line 208 | initrholo()                    /* get our holodeck running */
208                  maxdisk = 0;
209          else
210                  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;
211                                                  /* set up memory cache */
212          if (outdev == NULL)
213                  hdcachesize = 0;        /* manual flushing */
# Line 213 | Line 219 | initrholo()                    /* get our holodeck running */
219                  if (*s && freopen(s, "a", stderr) == NULL)
220                          quit(2);
221          }
222 +                                                /* mark the starting time */
223 +        starttime = time(NULL);
224 +                                                /* compute end time */
225 +        if (!vdef(TIME) || vflt(TIME) <= FTINY)
226 +                endtime = 0;
227 +        else
228 +                endtime = starttime + vflt(TIME)*3600. + .5;
229                                                  /* start rtrace */
230          if (ncprocs > 0) {
231 <                i = start_rtrace();
231 >                totqlen = i = start_rtrace();
232                  if (i < 1)
233                          error(USER, "cannot start rtrace process(es)");
234                  if (vdef(REPORT)) {             /* make first report */
# Line 262 | Line 275 | memerr:
275  
276   rholo()                         /* holodeck main loop */
277   {
278 +        static long     nextfragwarn = 100*(1L<<20);
279          static int      idle = 0;
280          PACKET  *pl = NULL, *plend;
281 +        long    fsiz;
282 +        int     pksiz;
283          register PACKET *p;
284          time_t  t;
269        long    l;
285                                          /* check display */
286          if (nprocs <= 0)
287                  idle = 1;
# Line 277 | Line 292 | rholo()                                /* holodeck main loop */
292                          return(1);
293          } else if (idle)
294                  return(0);              /* all done */
295 <                                        /* check file size */
296 <        if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
295 >        fsiz = hdfilen(hdlist[0]->fd);  /* check file size */
296 >        if (maxdisk > 0 && fsiz >= maxdisk) {
297                  error(WARNING, "file limit exceeded");
298                  done_rtrace();
299                  return(1);      /* comes back */
300          }
301 <                                        /* check time */
302 <        if (endtime > 0 || reporttime > 0)
303 <                t = time(NULL);
301 > #if FRAGWARN
302 >        if (fsiz >= nextfragwarn &&
303 >                (fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) {
304 >                sprintf(errmsg, "holodeck file fragmentation is %.0f%%",
305 >                                100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz);
306 >                error(WARNING, errmsg);
307 >                nextfragwarn = fsiz + (fsiz>>2);        /* decent interval */
308 >        }
309 > #endif
310 >        t = time(NULL);                 /* check time */
311          if (endtime > 0 && t >= endtime) {
312                  error(WARNING, "time limit exceeded");
313                  done_rtrace();
# Line 293 | Line 315 | rholo()                                /* holodeck main loop */
315          }
316          if (reporttime > 0 && t >= reporttime)
317                  report(t);
318 +                                        /* figure out good packet size */
319 + #if MAXQTIME
320 +        pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
321 +        if (pksiz < 1)
322 +                pksiz = 1;
323 +        else if (pksiz > RPACKSIZ)
324 + #endif
325 +                pksiz = RPACKSIZ;
326          idle = 0;                       /* get packets to process */
327          while (freepacks != NULL) {
328                  p = freepacks; freepacks = p->next; p->next = NULL;
329 <                if (!next_packet(p)) {
329 >                if (!next_packet(p, pksiz)) {
330                          p->next = freepacks; freepacks = p;
331                          idle = 1;
332                          break;
# Line 317 | Line 347 | register HDGRID        *gp;
347          extern char     *atos();
348          register int    i;
349          int     n;
350 <        double  len[3], maxlen, d;
350 >        double  len[3], d;
351          char    buf[64];
352  
353          if (!vdef(SECTION)) {
# Line 351 | Line 381 | register HDGRID        *gp;
381                                  &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
382                                  &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
383                          badvalue(SECTION);
354                maxlen = 0.;
384                  for (i = 0; i < 3; i++)
385 <                        if ((len[i] = VLEN(gp->xv[i])) > maxlen)
386 <                                maxlen = len[i];
387 <                if (!vdef(GRID))
388 <                        d = 0.125*maxlen;
389 <                else if ((d = vflt(GRID)) <= FTINY)
385 >                        len[i] = VLEN(gp->xv[i]);
386 >                if (!vdef(GRID)) {
387 >                        d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] +
388 >                                        len[2]*len[2] + 4*len[1]*len[2])
389 >                                + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
390 >                                + 4*len[0]*len[1]*len[2]*len[2] );
391 >                        d = sqrt(sqrt(d));
392 >                } else if ((d = vflt(GRID)) <= FTINY)
393                          badvalue(GRID);
394                  for (i = 0; i < 3; i++)
395                          if (gp->grid[i] <= 0)
# Line 405 | Line 437 | HDGRID *gp;
437   }
438  
439  
440 + int
441   headline(s)                     /* process information header line */
442   char    *s;
443   {
# Line 418 | Line 451 | char   *s;
451                                          HOLOFMT, hdkfile, FMTSTR, fmt);
452                          error(USER, errmsg);
453                  }
454 <                return;
454 >                return(0);
455          }
456          for (cp = s; *cp; cp++)         /* take off any comments */
457                  if (*cp == '#') {
# Line 426 | Line 459 | char   *s;
459                          break;
460                  }
461          setvariable(s, matchvar);       /* don't flag errors */
462 +        return(0);
463   }
464  
465  
# Line 438 | Line 472 | loadholo()                     /* start loading a holodeck from fname */
472          int4    nextloc;
473                                          /* open holodeck file */
474          if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
475 <                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
476 <                                ncprocs>0 ? "appending" : "reading");
475 >                sprintf(errmsg, "cannot %s \"%s\"",
476 >                                ncprocs>0 ? "append" : "read", hdkfile);
477                  error(SYSTEM, errmsg);
478          }
479                                          /* load variables from header */
# Line 480 | Line 514 | PACKET *pl;
514                                  p->nr*sizeof(RAYVAL));
515                          if (outdev != NULL)     /* display it */
516                                  disp_packet((PACKHEAD *)p);
517 <                        if (hdcachesize <= 0)   /* manual flushing */
518 <                                n2flush += p->nr;
517 >                        if (hdcachesize <= 0) {
518 > #if RTFLUSH
519 >                                if (outdev == NULL)
520 >                                        hdfreebeam(hdlist[p->hd], p->bi);
521 > #endif
522 >                                n2flush++;
523 >                        }
524                          nraysdone += p->nr;
525                          npacksdone++;
526 +                        p->nr = 0;
527                  }
528 <                p->nr = 0;                      /* push onto free list */
489 <                p->next = freepacks;
528 >                p->next = freepacks;            /* push onto free list */
529                  freepacks = p;
530          }
531 <        if (n2flush > 1024*RPACKSIZ*nprocs) {
532 <                hdflush(NULL);                  /* flush holodeck buffers */
531 > #if MAXQTIME
532 >        if (n2flush > 300/MAXQTIME*totqlen) {
533 > #else
534 >        if (n2flush > 50*totqlen) {
535 > #endif
536 > #if RTFLUSH
537 >                hdsync(NULL, outdev!=NULL);     /* sync beams & directories */
538 > #else
539 >                if (outdev != NULL)
540 >                        hdsync(NULL, 1);
541 >                else
542 >                        hdflush(NULL);
543 > #endif
544                  n2flush = 0;
545          }
546   }
# Line 535 | Line 585 | register char  *s;
585                  fflush(stderr);
586                  midline = 0;
587          }
538 }
539
540
541 wputs(s)                        /* put warning string to stderr */
542 char    *s;
543 {
544        if (!nowarn)
545                eputs(s);
588   }
589  
590  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines