--- ray/src/hd/rholo.c 1998/01/04 18:36:43 3.34 +++ ray/src/hd/rholo.c 1998/05/14 13:05:27 3.39 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -51,7 +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 */ +int totqlen; /* maximum queue length when full */ char *sigerr[NSIG]; /* signal error messages */ @@ -109,9 +109,8 @@ char *argv[]; } /* check settings */ checkvalues(); - /* load RIF if rtrace */ - if (ncprocs) - getradfile(); + /* load rad input file */ + getradfile(); if (hdlist[0] == NULL) { /* create new holodeck */ HDGRID hdg[HDMAX]; @@ -176,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) { @@ -223,7 +222,7 @@ initrholo() /* get our holodeck running */ endtime = starttime + vflt(TIME)*3600. + .5; /* start rtrace */ if (ncprocs > 0) { - i = start_rtrace(); + totqlen = i = start_rtrace(); if (i < 1) error(USER, "cannot start rtrace process(es)"); if (vdef(REPORT)) { /* make first report */ @@ -234,8 +233,6 @@ 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)) { @@ -303,7 +300,7 @@ rholo() /* holodeck main loop */ report(t); /* figure out good packet size */ #if MAXQTIME - pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L)); + pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); if (pksiz < 1) pksiz = 1; else if (pksiz > RPACKSIZ) @@ -333,7 +330,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)) { @@ -367,13 +364,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) @@ -454,8 +453,8 @@ loadholo() /* start loading a holodeck from fname */ int4 nextloc; /* open holodeck file */ if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { - sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, - ncprocs>0 ? "appending" : "reading"); + sprintf(errmsg, "cannot %s \"%s\"", + ncprocs>0 ? "append" : "read", hdkfile); error(SYSTEM, errmsg); } /* load variables from header */ @@ -505,7 +504,7 @@ PACKET *pl; p->next = freepacks; /* push onto free list */ freepacks = p; } - if (n2flush > 300/MAXQTIME*avgqlen*nprocs) { + if (n2flush > 300/MAXQTIME*totqlen) { hdflush(NULL); /* flush holodeck buffers */ n2flush = 0; }