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.39 by gwlarson, Thu May 14 13:05:27 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 48 | Line 51 | long   nraysdone = 0L;         /* number of rays done */
51   long    npacksdone = 0L;        /* number of packets done */
52  
53   PACKET  *freepacks;             /* available packets */
54 + int     totqlen;                /* maximum queue length when full */
55  
56   char  *sigerr[NSIG];            /* signal error messages */
57  
# 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 438 | Line 453 | loadholo()                     /* start loading a holodeck from fname */
453          int4    nextloc;
454                                          /* open holodeck file */
455          if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
456 <                sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
457 <                                ncprocs>0 ? "appending" : "reading");
456 >                sprintf(errmsg, "cannot %s \"%s\"",
457 >                                ncprocs>0 ? "append" : "read", hdkfile);
458                  error(SYSTEM, errmsg);
459          }
460                                          /* load variables from header */
# Line 481 | Line 496 | PACKET *pl;
496                          if (outdev != NULL)     /* display it */
497                                  disp_packet((PACKHEAD *)p);
498                          if (hdcachesize <= 0)   /* manual flushing */
499 <                                n2flush += p->nr;
499 >                                n2flush++;
500                          nraysdone += p->nr;
501                          npacksdone++;
502 +                        p->nr = 0;
503                  }
504 <                p->nr = 0;                      /* push onto free list */
489 <                p->next = freepacks;
504 >                p->next = freepacks;            /* push onto free list */
505                  freepacks = p;
506          }
507 <        if (n2flush > 1024*RPACKSIZ*nprocs) {
507 >        if (n2flush > 300/MAXQTIME*totqlen) {
508                  hdflush(NULL);                  /* flush holodeck buffers */
509                  n2flush = 0;
510          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines