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.44 by gwlarson, Wed Dec 30 08:02:37 1998 UTC vs.
Revision 3.53 by greg, Tue May 13 17:58:33 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Radiance holodeck generation controller
6   */
# Line 11 | Line 8 | static char SCCSid[] = "$SunId$ SGI";
8   #include "rholo.h"
9   #include "random.h"
10   #include <signal.h>
14 #include <sys/types.h>
11   #include <sys/stat.h>
12  
13   #ifndef FRAGWARN
# Line 20 | Line 16 | static char SCCSid[] = "$SunId$ SGI";
16   #ifndef MAXQTIME
17   #define MAXQTIME        5               /* target maximum seconds in queue */
18   #endif
19 +                                        /* manual cache flushing frequency */
20 + #ifndef RTFLUSH
21 + #if MAXQTIME
22 + #define RTFLUSH         (300/MAXQTIME*totqlen)  /* <= 5 minutes */
23 + #else
24 + #define RTFLUSH         (50*totqlen)            /* just guess */
25 + #endif
26 + #endif
27                          /* the following must be consistent with rholo.h */
28   int     NVARS = NRHVARS;                /* total number of variables */
29  
# Line 35 | Line 39 | char   *outdev = NULL;         /* output device name */
39  
40   int     readinp = 0;            /* read commands from stdin */
41  
42 < int     force = 0;              /* allow overwrite of holodeck */
42 > int     force = 0;              /* allow overwrite of holodeck (-1 == read-only) */
43  
44   time_t  starttime;              /* time we got started */
45   time_t  endtime;                /* time we should end by */
# Line 52 | Line 56 | long   nraysdone = 0L;         /* number of rays done */
56   long    npacksdone = 0L;        /* number of packets done */
57  
58   PACKET  *freepacks;             /* available packets */
59 < int     totqlen;                /* maximum queue length when full */
59 > int     totqlen;                /* maximum queue length (number of packets) */
60  
61   char  *sigerr[NSIG];            /* signal error messages */
62  
# Line 75 | Line 79 | char   *argv[];
79                          nowarn++;
80                          break;
81                  case 'f':                       /* force overwrite */
82 <                        force++;
82 >                        force = 1;
83                          break;
84 +                case 'r':                       /* read-only mode */
85 +                        force = -1;
86 +                        break;
87                  case 'i':                       /* read input from stdin */
88                          readinp++;
89                          break;
# Line 119 | Line 126 | char   *argv[];
126                  HDGRID  hdg[HDMAX];
127                                                          /* set defaults */
128                  setdefaults(hdg);
129 +                                                        /* check read-only */
130 +                if (force < 0)
131 +                        error(USER, "cannot create read-only holodeck");
132                                                          /* holodeck exists? */
133                  if (!force && access(hdkfile, R_OK|W_OK) == 0)
134                          error(USER,
# Line 136 | Line 146 | char   *argv[];
146          quit(0);
147   userr:
148          fprintf(stderr,
149 < "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
149 > "Usage: %s [-n nprocs][-o disp][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n",
150                          progname);
151          quit(1);
152   }
# Line 147 | Line 157 | int  signo;
157   {
158          static int  gotsig = 0;
159  
160 <        if (gotsig++)                   /* two signals and we're gone! */
160 >        if (gotsig > 1)                 /* we're going as fast as we can! */
161 >                return;
162 >        if (gotsig++) {                 /* two signals and we split */
163 >                hdsync(NULL, 0);        /* don't leave w/o saying goodbye */
164                  _exit(signo);
165 <
166 <        alarm(60);                      /* allow 60 seconds to clean up */
154 <        signal(SIGALRM, SIG_DFL);       /* make certain we do die */
165 >        }
166 >        alarm(300);                     /* allow 5 minutes to clean up */
167          eputs("signal - ");
168          eputs(sigerr[signo]);
169          eputs("\n");
# Line 202 | Line 214 | initrholo()                    /* get our holodeck running */
214                  init_global();
215                                                  /* record disk space limit */
216          if (!vdef(DISKSPACE))
217 <                maxdisk = 0;
217 >                maxdisk = (1L<<(sizeof(long)*8-2)) - 1024;
218          else
219                  maxdisk = 1024.*1024.*vflt(DISKSPACE);
220                                                  /* set up memory cache */
221          if (outdev == NULL)
222 <                hdcachesize = 0;        /* manual flushing */
222 >                hdcachesize = 0;                /* manual flushing */
223          else if (vdef(CACHE))
224                  hdcachesize = 1024.*1024.*vflt(CACHE);
225                                                  /* open report file */
# Line 262 | Line 274 | initrholo()                    /* get our holodeck running */
274          sigdie(SIGXCPU, "CPU limit exceeded");
275          sigdie(SIGXFSZ, "File size exceeded");
276   #endif
277 <                                                /* protect holodeck file */
278 <        orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444);
277 >                                        /* protect holodeck file */
278 >        orig_mode = resfmode(hdlist[0]->fd, ncprocs>0&force>=0 ? 0 : 0444);
279          return;
280   memerr:
281          error(SYSTEM, "out of memory in initrholo");
# Line 313 | Line 325 | rholo()                                /* holodeck main loop */
325          if (reporttime > 0 && t >= reporttime)
326                  report(t);
327                                          /* figure out good packet size */
328 +        pksiz = RPACKSIZ;
329   #if MAXQTIME
330 <        pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
331 <        if (pksiz < 1)
332 <                pksiz = 1;
333 <        else if (pksiz > RPACKSIZ)
330 >        if (!chunkycmp) {
331 >                pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
332 >                if (pksiz < 1) pksiz = 1;
333 >                else if (pksiz > RPACKSIZ) pksiz = RPACKSIZ;
334 >        }
335   #endif
322                pksiz = RPACKSIZ;
336          idle = 0;                       /* get packets to process */
337          while (freepacks != NULL) {
338                  p = freepacks; freepacks = p->next; p->next = NULL;
# Line 417 | Line 430 | HDGRID *gp;
430          putw(HOLOMAGIC, fp);            /* put magic number */
431          fd = dup(fileno(fp));
432          fclose(fp);                     /* flush and close stdio stream */
433 <        lastloc = lseek(fd, 0L, 2);
433 >        lastloc = lseek(fd, (off_t)0L, 2);
434          for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */
435                  nextloc = 0L;
436                  write(fd, (char *)&nextloc, sizeof(nextloc));
# Line 425 | Line 438 | HDGRID *gp;
438                  if (!n)
439                          break;
440                  nextloc = hdfilen(fd);          /* write section pointer */
441 <                if (lseek(fd, (long)lastloc, 0) < 0)
441 >                if (lseek(fd, (off_t)lastloc, 0) < 0)
442                          error(SYSTEM,
443                                  "cannot seek on holodeck file in creatholo");
444                  write(fd, (char *)&nextloc, sizeof(nextloc));
445 <                lseek(fd, (long)(lastloc=nextloc), 0);
445 >                lseek(fd, (off_t)(lastloc=nextloc), 0);
446          }
447   }
448  
# Line 467 | Line 480 | loadholo()                     /* start loading a holodeck from fname */
480          int     fd;
481          int     n;
482          int4    nextloc;
483 <                                        /* open holodeck file */
484 <        if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
485 <                sprintf(errmsg, "cannot %s \"%s\"",
486 <                                ncprocs>0 ? "append" : "read", hdkfile);
487 <                error(SYSTEM, errmsg);
483 >        
484 >        if (ncprocs > 0 & force >= 0)
485 >                fp = fopen(hdkfile, "r+");
486 >        else
487 >                fp = NULL;
488 >        if (fp == NULL) {
489 >                if ((fp = fopen(hdkfile, "r")) == NULL) {
490 >                        sprintf(errmsg, "cannot open \"%s\"", hdkfile);
491 >                        error(SYSTEM, errmsg);
492 >                }
493 >                if (ncprocs > 0) {
494 >                        sprintf(errmsg,
495 >                        "\"%s\" opened read-only; new rays will be discarded",
496 >                                        hdkfile);
497 >                        error(WARNING, errmsg);
498 >                        force = -1;
499 >                }
500          }
501                                          /* load variables from header */
502          getheader(fp, headline, NULL);
# Line 485 | Line 510 | loadholo()                     /* start loading a holodeck from fname */
510          fd = dup(fileno(fp));
511          fclose(fp);                             /* done with stdio */
512          for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
513 <                lseek(fd, (long)nextloc, 0);
513 >                lseek(fd, (off_t)nextloc, 0);
514                  read(fd, (char *)&nextloc, sizeof(nextloc));
515                  hdinit(fd, NULL);
516          }
# Line 506 | Line 531 | PACKET *pl;
531          while (pl != NULL) {
532                  p = pl; pl = p->next; p->next = NULL;
533                  if (p->nr > 0) {                /* add to holodeck */
534 <                        bcopy((char *)p->ra,
535 <                                (char *)hdnewrays(hdlist[p->hd],p->bi,p->nr),
534 >                        bcopy((void *)p->ra,
535 >                                (void *)hdnewrays(hdlist[p->hd],p->bi,p->nr),
536                                  p->nr*sizeof(RAYVAL));
537                          if (outdev != NULL)     /* display it */
538                                  disp_packet((PACKHEAD *)p);
539 <                        if (hdcachesize <= 0)   /* manual flushing */
539 >                        if (hdcachesize <= 0)
540                                  n2flush++;
541                          nraysdone += p->nr;
542                          npacksdone++;
# Line 520 | Line 545 | PACKET *pl;
545                  p->next = freepacks;            /* push onto free list */
546                  freepacks = p;
547          }
548 < #if MAXQTIME
549 <        if (n2flush > 300/MAXQTIME*totqlen) {
550 < #else
526 <        if (n2flush > 50*totqlen) {
527 < #endif
528 <                if (outdev == NULL)
529 <                        hdflush(NULL);          /* flush holodeck buffers */
548 >        if (n2flush >= RTFLUSH) {
549 >                if (outdev != NULL)
550 >                        hdsync(NULL, 1);
551                  else
552 <                        hdsync(NULL, 1);        /* sync holodeck file */
552 >                        hdflush(NULL);
553                  n2flush = 0;
554          }
555   }
# Line 557 | Line 578 | int    vc;
578   }
579  
580  
581 + void
582   eputs(s)                        /* put error message to stderr */
583   register char  *s;
584   {
# Line 576 | Line 598 | register char  *s;
598   }
599  
600  
601 + void
602   quit(ec)                        /* exit program gracefully */
603   int     ec;
604   {
# Line 584 | Line 607 | int    ec;
607          if (hdlist[0] != NULL) {        /* close holodeck */
608                  if (nprocs > 0)
609                          status = done_rtrace();         /* calls hdsync() */
610 <                if (ncprocs > 0 && vdef(REPORT)) {
610 >                if (ncprocs > 0 & force >= 0 && vdef(REPORT)) {
611                          long    fsiz, fuse;
612                          fsiz = hdfilen(hdlist[0]->fd);
613                          fuse = hdfiluse(hdlist[0]->fd, 1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines