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.37 by gregl, Fri Jan 16 11:45:43 1998 UTC vs.
Revision 3.51 by gwlarson, Thu Aug 5 19:20:10 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1998 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1999 Regents of the University of California */
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 26 | Line 36 | char   *progname;              /* our program name */
36   char    *hdkfile;               /* holodeck file name */
37   char    froot[256];             /* root file name */
38  
29 int     nowarn = 0;             /* turn warnings off? */
30
39   int     ncprocs = 0;            /* desired number of compute processes */
40  
41   char    *outdev = NULL;         /* output device name */
42  
43   int     readinp = 0;            /* read commands from stdin */
44  
45 < int     force = 0;              /* allow overwrite of holodeck */
45 > int     force = 0;              /* allow overwrite of holodeck (-1 == read-only) */
46  
47   time_t  starttime;              /* time we got started */
48   time_t  endtime;                /* time we should end by */
# Line 51 | 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     avgqlen;                /* average queue length when full */
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 72 | Line 82 | char   *argv[];
82                          nowarn++;
83                          break;
84                  case 'f':                       /* force overwrite */
85 <                        force++;
85 >                        force = 1;
86                          break;
87 +                case 'r':                       /* read-only mode */
88 +                        force = -1;
89 +                        break;
90                  case 'i':                       /* read input from stdin */
91                          readinp++;
92                          break;
# Line 116 | Line 129 | char   *argv[];
129                  HDGRID  hdg[HDMAX];
130                                                          /* set defaults */
131                  setdefaults(hdg);
132 +                                                        /* check read-only */
133 +                if (force < 0)
134 +                        error(USER, "cannot create read-only holodeck");
135                                                          /* holodeck exists? */
136                  if (!force && access(hdkfile, R_OK|W_OK) == 0)
137                          error(USER,
# Line 133 | Line 149 | char   *argv[];
149          quit(0);
150   userr:
151          fprintf(stderr,
152 < "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
152 > "Usage: %s [-n nprocs][-o disp][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
153                          progname);
154          quit(1);
155   }
# Line 144 | Line 160 | int  signo;
160   {
161          static int  gotsig = 0;
162  
163 <        if (gotsig++)                   /* two signals and we're gone! */
163 >        if (gotsig > 1)                 /* we're going as fast as we can! */
164 >                return;
165 >        if (gotsig++) {                 /* two signals and we split */
166 >                hdsync(NULL, 0);        /* don't leave w/o saying goodbye */
167                  _exit(signo);
168 <
169 <        alarm(60);                      /* allow 60 seconds to clean up */
151 <        signal(SIGALRM, SIG_DFL);       /* make certain we do die */
168 >        }
169 >        alarm(300);                     /* allow 5 minutes to clean up */
170          eputs("signal - ");
171          eputs(sigerr[signo]);
172          eputs("\n");
# Line 204 | Line 222 | initrholo()                    /* get our holodeck running */
222                  maxdisk = 1024.*1024.*vflt(DISKSPACE);
223                                                  /* set up memory cache */
224          if (outdev == NULL)
225 <                hdcachesize = 0;        /* manual flushing */
225 >                hdcachesize = 0;                /* manual flushing */
226          else if (vdef(CACHE))
227                  hdcachesize = 1024.*1024.*vflt(CACHE);
228                                                  /* open report file */
# Line 222 | Line 240 | initrholo()                    /* get our holodeck running */
240                  endtime = starttime + vflt(TIME)*3600. + .5;
241                                                  /* start rtrace */
242          if (ncprocs > 0) {
243 <                i = start_rtrace();
243 >                totqlen = i = start_rtrace();
244                  if (i < 1)
245                          error(USER, "cannot start rtrace process(es)");
246                  if (vdef(REPORT)) {             /* make first report */
# Line 233 | Line 251 | initrholo()                    /* get our holodeck running */
251                  freepacks = (PACKET *)bmalloc(i*sizeof(PACKET));
252                  if (freepacks == NULL)
253                          goto memerr;
236                if (!(avgqlen = i/nprocs))      /* record mean queue length */
237                        avgqlen = 1;
254                  freepacks[--i].nr = 0;
255                  freepacks[i].next = NULL;
256                  if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) {
# Line 261 | Line 277 | initrholo()                    /* get our holodeck running */
277          sigdie(SIGXCPU, "CPU limit exceeded");
278          sigdie(SIGXFSZ, "File size exceeded");
279   #endif
280 <                                                /* protect holodeck file */
280 >                                        /* protect holodeck file */
281          orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444);
282          return;
283   memerr:
# Line 271 | Line 287 | memerr:
287  
288   rholo()                         /* holodeck main loop */
289   {
290 +        static long     nextfragwarn = 100*(1L<<20);
291          static int      idle = 0;
292          PACKET  *pl = NULL, *plend;
293 +        long    fsiz;
294          int     pksiz;
295          register PACKET *p;
296          time_t  t;
# Line 286 | Line 304 | rholo()                                /* holodeck main loop */
304                          return(1);
305          } else if (idle)
306                  return(0);              /* all done */
307 <                                        /* check file size */
308 <        if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
307 >        fsiz = hdfilen(hdlist[0]->fd);  /* check file size */
308 >        if (maxdisk > 0 && fsiz >= maxdisk) {
309                  error(WARNING, "file limit exceeded");
310                  done_rtrace();
311                  return(1);      /* comes back */
312          }
313 + #if FRAGWARN
314 +        if (fsiz >= nextfragwarn &&
315 +                (fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) {
316 +                sprintf(errmsg, "holodeck file fragmentation is %.0f%%",
317 +                                100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz);
318 +                error(WARNING, errmsg);
319 +                nextfragwarn = fsiz + (fsiz>>2);        /* decent interval */
320 +        }
321 + #endif
322          t = time(NULL);                 /* check time */
323          if (endtime > 0 && t >= endtime) {
324                  error(WARNING, "time limit exceeded");
# Line 301 | Line 328 | rholo()                                /* holodeck main loop */
328          if (reporttime > 0 && t >= reporttime)
329                  report(t);
330                                          /* figure out good packet size */
331 +        pksiz = RPACKSIZ;
332   #if MAXQTIME
333 <        pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L));
334 <        if (pksiz < 1)
335 <                pksiz = 1;
336 <        else if (pksiz > RPACKSIZ)
333 >        if (!chunkycmp) {
334 >                pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
335 >                if (pksiz < 1) pksiz = 1;
336 >                else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ;
337 >        }
338   #endif
310                pksiz = RPACKSIZ;
339          idle = 0;                       /* get packets to process */
340          while (freepacks != NULL) {
341                  p = freepacks; freepacks = p->next; p->next = NULL;
# Line 369 | Line 397 | register HDGRID        *gp;
397                  for (i = 0; i < 3; i++)
398                          len[i] = VLEN(gp->xv[i]);
399                  if (!vdef(GRID)) {
400 <                        d = 2/5e5*( len[0]*len[0]*(len[1]*len[1] +
400 >                        d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] +
401                                          len[2]*len[2] + 4*len[1]*len[2])
402                                  + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
403                                  + 4*len[0]*len[1]*len[2]*len[2] );
# Line 422 | Line 450 | HDGRID *gp;
450   }
451  
452  
453 + int
454   headline(s)                     /* process information header line */
455   char    *s;
456   {
# Line 435 | Line 464 | char   *s;
464                                          HOLOFMT, hdkfile, FMTSTR, fmt);
465                          error(USER, errmsg);
466                  }
467 <                return;
467 >                return(0);
468          }
469          for (cp = s; *cp; cp++)         /* take off any comments */
470                  if (*cp == '#') {
# Line 443 | Line 472 | char   *s;
472                          break;
473                  }
474          setvariable(s, matchvar);       /* don't flag errors */
475 +        return(0);
476   }
477  
478  
# Line 453 | Line 483 | loadholo()                     /* start loading a holodeck from fname */
483          int     fd;
484          int     n;
485          int4    nextloc;
486 <                                        /* open holodeck file */
487 <        if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
488 <                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
489 <                                ncprocs>0 ? "appending" : "reading");
490 <                error(SYSTEM, errmsg);
486 >        
487 >        if (ncprocs > 0 & force >= 0)
488 >                fp = fopen(hdkfile, "r+");
489 >        else
490 >                fp = NULL;
491 >        if (fp == NULL) {
492 >                if ((fp = fopen(hdkfile, "r")) == NULL) {
493 >                        sprintf(errmsg, "cannot open \"%s\"", hdkfile);
494 >                        error(SYSTEM, errmsg);
495 >                }
496 >                if (ncprocs > 0) {
497 >                        sprintf(errmsg,
498 >                        "\"%s\" opened read-only; new rays will be discarded",
499 >                                        hdkfile);
500 >                        error(WARNING, errmsg);
501 >                        force = -1;
502 >                }
503          }
504                                          /* load variables from header */
505          getheader(fp, headline, NULL);
# Line 497 | Line 539 | PACKET *pl;
539                                  p->nr*sizeof(RAYVAL));
540                          if (outdev != NULL)     /* display it */
541                                  disp_packet((PACKHEAD *)p);
542 <                        if (hdcachesize <= 0)   /* manual flushing */
542 >                        if (hdcachesize <= 0)
543                                  n2flush++;
544                          nraysdone += p->nr;
545                          npacksdone++;
# Line 506 | Line 548 | PACKET *pl;
548                  p->next = freepacks;            /* push onto free list */
549                  freepacks = p;
550          }
551 <        if (n2flush > 300/MAXQTIME*avgqlen*nprocs) {
552 <                hdflush(NULL);                  /* flush holodeck buffers */
551 >        if (n2flush >= RTFLUSH) {
552 >                if (outdev != NULL)
553 >                        hdsync(NULL, 1);
554 >                else
555 >                        hdflush(NULL);
556                  n2flush = 0;
557          }
558   }
# Line 555 | Line 600 | register char  *s;
600   }
601  
602  
558 wputs(s)                        /* put warning string to stderr */
559 char    *s;
560 {
561        if (!nowarn)
562                eputs(s);
563 }
564
565
603   quit(ec)                        /* exit program gracefully */
604   int     ec;
605   {
# Line 571 | Line 608 | int    ec;
608          if (hdlist[0] != NULL) {        /* close holodeck */
609                  if (nprocs > 0)
610                          status = done_rtrace();         /* calls hdsync() */
611 <                if (ncprocs > 0 && vdef(REPORT)) {
611 >                if (ncprocs > 0 & force >= 0 && vdef(REPORT)) {
612                          long    fsiz, fuse;
613                          fsiz = hdfilen(hdlist[0]->fd);
614                          fuse = hdfiluse(hdlist[0]->fd, 1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines