--- ray/src/hd/rholo.c 1997/12/19 10:41:42 3.30 +++ ray/src/hd/rholo.c 1998/01/16 11:45:43 3.37 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -14,6 +14,9 @@ static char SCCSid[] = "$SunId$ SGI"; #include #include +#ifndef MAXQTIME +#define MAXQTIME 5 /* target maximum seconds in queue */ +#endif /* the following must be consistent with rholo.h */ int NVARS = NRHVARS; /* total number of variables */ @@ -48,6 +51,7 @@ long nraysdone = 0L; /* number of rays done */ long npacksdone = 0L; /* number of packets done */ PACKET *freepacks; /* available packets */ +int avgqlen; /* average queue length when full */ char *sigerr[NSIG]; /* signal error messages */ @@ -59,8 +63,7 @@ int argc; char *argv[]; { int i; - /* mark start time */ - starttime = time(NULL); + initurand(16384); /* initialize urand */ progname = argv[0]; /* get arguments */ for (i = 1; i < argc && argv[i][0] == '-'; i++) @@ -88,6 +91,8 @@ char *argv[]; goto userr; } /* get root file name */ + if (i >= argc) + goto userr; rootname(froot, hdkfile=argv[i++]); /* load variables? */ if (i < argc) @@ -104,7 +109,7 @@ char *argv[]; } /* check settings */ checkvalues(); - /* load RIF if any */ + /* load rad input file */ getradfile(); if (hdlist[0] == NULL) { /* create new holodeck */ @@ -170,7 +175,7 @@ int fd, mod; if (fstat(fd, &stbuf) < 0) error(SYSTEM, "cannot stat open holodeck file"); mod &= stbuf.st_mode; /* always more restrictive */ - if (mod == stbuf.st_mode) + if (mod == (stbuf.st_mode & 0777)) return(-1); /* already set */ /* else change it */ if (fchmod(fd, mod) < 0) { @@ -197,11 +202,6 @@ initrholo() /* get our holodeck running */ maxdisk = 0; else maxdisk = 1024.*1024.*vflt(DISKSPACE); - /* record end time */ - if (!vdef(TIME) || vflt(TIME) <= FTINY) - endtime = 0; - else - endtime = starttime + vflt(TIME)*3600. + .5; /* set up memory cache */ if (outdev == NULL) hdcachesize = 0; /* manual flushing */ @@ -213,6 +213,13 @@ initrholo() /* get our holodeck running */ if (*s && freopen(s, "a", stderr) == NULL) quit(2); } + /* mark the starting time */ + starttime = time(NULL); + /* compute end time */ + if (!vdef(TIME) || vflt(TIME) <= FTINY) + endtime = 0; + else + endtime = starttime + vflt(TIME)*3600. + .5; /* start rtrace */ if (ncprocs > 0) { i = start_rtrace(); @@ -226,6 +233,8 @@ initrholo() /* get our holodeck running */ freepacks = (PACKET *)bmalloc(i*sizeof(PACKET)); if (freepacks == NULL) goto memerr; + if (!(avgqlen = i/nprocs)) /* record mean queue length */ + avgqlen = 1; freepacks[--i].nr = 0; freepacks[i].next = NULL; if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { @@ -264,9 +273,9 @@ rholo() /* holodeck main loop */ { static int idle = 0; PACKET *pl = NULL, *plend; + int pksiz; register PACKET *p; time_t t; - long l; /* check display */ if (nprocs <= 0) idle = 1; @@ -283,9 +292,7 @@ rholo() /* holodeck main loop */ done_rtrace(); return(1); /* comes back */ } - /* check time */ - if (endtime > 0 || reporttime > 0) - t = time(NULL); + t = time(NULL); /* check time */ if (endtime > 0 && t >= endtime) { error(WARNING, "time limit exceeded"); done_rtrace(); @@ -293,10 +300,18 @@ rholo() /* holodeck main loop */ } if (reporttime > 0 && t >= reporttime) report(t); + /* figure out good packet size */ +#if MAXQTIME + pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L)); + if (pksiz < 1) + pksiz = 1; + else if (pksiz > RPACKSIZ) +#endif + pksiz = RPACKSIZ; idle = 0; /* get packets to process */ while (freepacks != NULL) { p = freepacks; freepacks = p->next; p->next = NULL; - if (!next_packet(p)) { + if (!next_packet(p, pksiz)) { p->next = freepacks; freepacks = p; idle = 1; break; @@ -317,7 +332,7 @@ register HDGRID *gp; extern char *atos(); register int i; int n; - double len[3], maxlen, d; + double len[3], d; char buf[64]; if (!vdef(SECTION)) { @@ -351,13 +366,15 @@ register HDGRID *gp; &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) badvalue(SECTION); - maxlen = 0.; for (i = 0; i < 3; i++) - if ((len[i] = VLEN(gp->xv[i])) > maxlen) - maxlen = len[i]; - if (!vdef(GRID)) - d = 0.125*maxlen; - else if ((d = vflt(GRID)) <= FTINY) + len[i] = VLEN(gp->xv[i]); + if (!vdef(GRID)) { + d = 2/5e5*( len[0]*len[0]*(len[1]*len[1] + + len[2]*len[2] + 4*len[1]*len[2]) + + len[1]*len[1]*len[2]*(len[2] + 4*len[0]) + + 4*len[0]*len[1]*len[2]*len[2] ); + d = sqrt(sqrt(d)); + } else if ((d = vflt(GRID)) <= FTINY) badvalue(GRID); for (i = 0; i < 3; i++) if (gp->grid[i] <= 0) @@ -481,15 +498,15 @@ PACKET *pl; if (outdev != NULL) /* display it */ disp_packet((PACKHEAD *)p); if (hdcachesize <= 0) /* manual flushing */ - n2flush += p->nr; + n2flush++; nraysdone += p->nr; npacksdone++; + p->nr = 0; } - p->nr = 0; /* push onto free list */ - p->next = freepacks; + p->next = freepacks; /* push onto free list */ freepacks = p; } - if (n2flush > 512*RPACKSIZ*nprocs) { + if (n2flush > 300/MAXQTIME*avgqlen*nprocs) { hdflush(NULL); /* flush holodeck buffers */ n2flush = 0; }