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.42 by gwlarson, Tue Oct 27 08:49:50 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1998 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 MAXQTIME
18 + #define MAXQTIME        5               /* target maximum seconds in queue */
19 + #endif
20                          /* the following must be consistent with rholo.h */
21   int     NVARS = NRHVARS;                /* total number of variables */
22  
# Line 23 | Line 26 | char   *progname;              /* our program name */
26   char    *hdkfile;               /* holodeck file name */
27   char    froot[256];             /* root file name */
28  
26 int     nowarn = 0;             /* turn warnings off? */
27
29   int     ncprocs = 0;            /* desired number of compute processes */
30  
31   char    *outdev = NULL;         /* output device name */
# Line 48 | Line 49 | long   nraysdone = 0L;         /* number of rays done */
49   long    npacksdone = 0L;        /* number of packets done */
50  
51   PACKET  *freepacks;             /* available packets */
52 + int     totqlen;                /* maximum queue length when full */
53  
54   char  *sigerr[NSIG];            /* signal error messages */
55  
56 + extern int      nowarn;         /* turn warnings off? */
57 +
58   extern time_t   time();
59  
60  
# Line 59 | Line 63 | int    argc;
63   char    *argv[];
64   {
65          int     i;
66 <                                                /* mark start time */
63 <        starttime = time(NULL);
66 >
67          initurand(16384);                       /* initialize urand */
68          progname = argv[0];                     /* get arguments */
69          for (i = 1; i < argc && argv[i][0] == '-'; i++)
# Line 88 | Line 91 | char   *argv[];
91                          goto userr;
92                  }
93                                                  /* get root file name */
94 +        if (i >= argc)
95 +                goto userr;
96          rootname(froot, hdkfile=argv[i++]);
97                                                  /* load variables? */
98          if (i < argc)
# Line 104 | Line 109 | char   *argv[];
109                  }
110                                                  /* check settings */
111          checkvalues();
112 <                                                /* load RIF if any */
112 >                                                /* load rad input file */
113          getradfile();
114  
115          if (hdlist[0] == NULL) {                /* create new holodeck */
# Line 170 | Line 175 | int    fd, mod;
175          if (fstat(fd, &stbuf) < 0)
176                  error(SYSTEM, "cannot stat open holodeck file");
177          mod &= stbuf.st_mode;           /* always more restrictive */
178 <        if (mod == stbuf.st_mode)
178 >        if (mod == (stbuf.st_mode & 0777))
179                  return(-1);             /* already set */
180                                          /* else change it */
181          if (fchmod(fd, mod) < 0) {
# Line 197 | Line 202 | initrholo()                    /* get our holodeck running */
202                  maxdisk = 0;
203          else
204                  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;
205                                                  /* set up memory cache */
206          if (outdev == NULL)
207                  hdcachesize = 0;        /* manual flushing */
# Line 213 | Line 213 | initrholo()                    /* get our holodeck running */
213                  if (*s && freopen(s, "a", stderr) == NULL)
214                          quit(2);
215          }
216 +                                                /* mark the starting time */
217 +        starttime = time(NULL);
218 +                                                /* compute end time */
219 +        if (!vdef(TIME) || vflt(TIME) <= FTINY)
220 +                endtime = 0;
221 +        else
222 +                endtime = starttime + vflt(TIME)*3600. + .5;
223                                                  /* start rtrace */
224          if (ncprocs > 0) {
225 <                i = start_rtrace();
225 >                totqlen = i = start_rtrace();
226                  if (i < 1)
227                          error(USER, "cannot start rtrace process(es)");
228                  if (vdef(REPORT)) {             /* make first report */
# Line 264 | Line 271 | rholo()                                /* holodeck main loop */
271   {
272          static int      idle = 0;
273          PACKET  *pl = NULL, *plend;
274 +        int     pksiz;
275          register PACKET *p;
276          time_t  t;
269        long    l;
277                                          /* check display */
278          if (nprocs <= 0)
279                  idle = 1;
# Line 283 | Line 290 | rholo()                                /* holodeck main loop */
290                  done_rtrace();
291                  return(1);      /* comes back */
292          }
293 <                                        /* check time */
287 <        if (endtime > 0 || reporttime > 0)
288 <                t = time(NULL);
293 >        t = time(NULL);                 /* check time */
294          if (endtime > 0 && t >= endtime) {
295                  error(WARNING, "time limit exceeded");
296                  done_rtrace();
# Line 293 | Line 298 | rholo()                                /* holodeck main loop */
298          }
299          if (reporttime > 0 && t >= reporttime)
300                  report(t);
301 +                                        /* figure out good packet size */
302 + #if MAXQTIME
303 +        pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L));
304 +        if (pksiz < 1)
305 +                pksiz = 1;
306 +        else if (pksiz > RPACKSIZ)
307 + #endif
308 +                pksiz = RPACKSIZ;
309          idle = 0;                       /* get packets to process */
310          while (freepacks != NULL) {
311                  p = freepacks; freepacks = p->next; p->next = NULL;
312 <                if (!next_packet(p)) {
312 >                if (!next_packet(p, pksiz)) {
313                          p->next = freepacks; freepacks = p;
314                          idle = 1;
315                          break;
# Line 317 | Line 330 | register HDGRID        *gp;
330          extern char     *atos();
331          register int    i;
332          int     n;
333 <        double  len[3], maxlen, d;
333 >        double  len[3], d;
334          char    buf[64];
335  
336          if (!vdef(SECTION)) {
# Line 351 | Line 364 | register HDGRID        *gp;
364                                  &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
365                                  &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
366                          badvalue(SECTION);
354                maxlen = 0.;
367                  for (i = 0; i < 3; i++)
368 <                        if ((len[i] = VLEN(gp->xv[i])) > maxlen)
369 <                                maxlen = len[i];
370 <                if (!vdef(GRID))
371 <                        d = 0.125*maxlen;
372 <                else if ((d = vflt(GRID)) <= FTINY)
368 >                        len[i] = VLEN(gp->xv[i]);
369 >                if (!vdef(GRID)) {
370 >                        d = 2/5e5*( len[0]*len[0]*(len[1]*len[1] +
371 >                                        len[2]*len[2] + 4*len[1]*len[2])
372 >                                + len[1]*len[1]*len[2]*(len[2] + 4*len[0])
373 >                                + 4*len[0]*len[1]*len[2]*len[2] );
374 >                        d = sqrt(sqrt(d));
375 >                } else if ((d = vflt(GRID)) <= FTINY)
376                          badvalue(GRID);
377                  for (i = 0; i < 3; i++)
378                          if (gp->grid[i] <= 0)
# Line 405 | Line 420 | HDGRID *gp;
420   }
421  
422  
423 + int
424   headline(s)                     /* process information header line */
425   char    *s;
426   {
# Line 418 | Line 434 | char   *s;
434                                          HOLOFMT, hdkfile, FMTSTR, fmt);
435                          error(USER, errmsg);
436                  }
437 <                return;
437 >                return(0);
438          }
439          for (cp = s; *cp; cp++)         /* take off any comments */
440                  if (*cp == '#') {
# Line 426 | Line 442 | char   *s;
442                          break;
443                  }
444          setvariable(s, matchvar);       /* don't flag errors */
445 +        return(0);
446   }
447  
448  
# Line 438 | Line 455 | loadholo()                     /* start loading a holodeck from fname */
455          int4    nextloc;
456                                          /* open holodeck file */
457          if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
458 <                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
459 <                                ncprocs>0 ? "appending" : "reading");
458 >                sprintf(errmsg, "cannot %s \"%s\"",
459 >                                ncprocs>0 ? "append" : "read", hdkfile);
460                  error(SYSTEM, errmsg);
461          }
462                                          /* load variables from header */
# Line 481 | Line 498 | PACKET *pl;
498                          if (outdev != NULL)     /* display it */
499                                  disp_packet((PACKHEAD *)p);
500                          if (hdcachesize <= 0)   /* manual flushing */
501 <                                n2flush += p->nr;
501 >                                n2flush++;
502                          nraysdone += p->nr;
503                          npacksdone++;
504 +                        p->nr = 0;
505                  }
506 <                p->nr = 0;                      /* push onto free list */
489 <                p->next = freepacks;
506 >                p->next = freepacks;            /* push onto free list */
507                  freepacks = p;
508          }
509 <        if (n2flush > 1024*RPACKSIZ*nprocs) {
510 <                hdflush(NULL);                  /* flush holodeck buffers */
509 > #if MAXQTIME
510 >        if (n2flush > 300/MAXQTIME*totqlen) {
511 > #else
512 >        if (n2flush > 50*totqlen) {
513 > #endif
514 >                if (outdev == NULL)
515 >                        hdflush(NULL);          /* flush holodeck buffers */
516 >                else
517 >                        hdsync(NULL, 1);        /* sync holodeck file */
518                  n2flush = 0;
519          }
520   }
# Line 535 | Line 559 | register char  *s;
559                  fflush(stderr);
560                  midline = 0;
561          }
538 }
539
540
541 wputs(s)                        /* put warning string to stderr */
542 char    *s;
543 {
544        if (!nowarn)
545                eputs(s);
562   }
563  
564  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines