--- ray/src/hd/rholo.c 1997/12/16 15:45:55 3.29 +++ ray/src/hd/rholo.c 1998/12/30 08:02:37 3.44 @@ -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,12 @@ static char SCCSid[] = "$SunId$ SGI"; #include #include +#ifndef FRAGWARN +#define FRAGWARN 20 /* fragmentation for warning (%) */ +#endif +#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 */ @@ -23,8 +29,6 @@ char *progname; /* our program name */ char *hdkfile; /* holodeck file name */ char froot[256]; /* root file name */ -int nowarn = 0; /* turn warnings off? */ - int ncprocs = 0; /* desired number of compute processes */ char *outdev = NULL; /* output device name */ @@ -48,9 +52,12 @@ long nraysdone = 0L; /* number of rays done */ long npacksdone = 0L; /* number of packets done */ PACKET *freepacks; /* available packets */ +int totqlen; /* maximum queue length when full */ char *sigerr[NSIG]; /* signal error messages */ +extern int nowarn; /* turn warnings off? */ + extern time_t time(); @@ -59,8 +66,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 +94,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 +112,7 @@ char *argv[]; } /* check settings */ checkvalues(); - /* load RIF if any */ + /* load rad input file */ getradfile(); if (hdlist[0] == NULL) { /* create new holodeck */ @@ -170,7 +178,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 +205,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,9 +216,16 @@ 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(); + totqlen = i = start_rtrace(); if (i < 1) error(USER, "cannot start rtrace process(es)"); if (vdef(REPORT)) { /* make first report */ @@ -262,29 +272,39 @@ memerr: rholo() /* holodeck main loop */ { - static int idle = 1; + static long nextfragwarn = 100*(1L<<20); + static int idle = 0; PACKET *pl = NULL, *plend; + long fsiz; + int pksiz; register PACKET *p; time_t t; - long l; - - if (outdev != NULL) /* check display */ - if (!disp_check(idle)) - return(0); - /* display only? */ - if (nprocs <= 0) { + /* check display */ + if (nprocs <= 0) idle = 1; - return(outdev != NULL); - } - /* check file size */ - if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { + if (outdev != NULL) { + if (!disp_check(idle)) + return(0); /* quit request */ + if (nprocs <= 0) + return(1); + } else if (idle) + return(0); /* all done */ + fsiz = hdfilen(hdlist[0]->fd); /* check file size */ + if (maxdisk > 0 && fsiz >= maxdisk) { error(WARNING, "file limit exceeded"); done_rtrace(); return(1); /* comes back */ } - /* check time */ - if (endtime > 0 || reporttime > 0) - t = time(NULL); +#if FRAGWARN + if (fsiz >= nextfragwarn && + (fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) { + sprintf(errmsg, "holodeck file fragmentation is %.0f%%", + 100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz); + error(WARNING, errmsg); + nextfragwarn = fsiz + (fsiz>>2); /* decent interval */ + } +#endif + t = time(NULL); /* check time */ if (endtime > 0 && t >= endtime) { error(WARNING, "time limit exceeded"); done_rtrace(); @@ -292,10 +312,18 @@ rholo() /* holodeck main loop */ } if (reporttime > 0 && t >= reporttime) report(t); + /* figure out good packet size */ +#if MAXQTIME + pksiz = nraysdone*MAXQTIME/(totqlen*(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; @@ -316,7 +344,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)) { @@ -350,13 +378,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/2e5*( 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) @@ -404,6 +434,7 @@ HDGRID *gp; } +int headline(s) /* process information header line */ char *s; { @@ -417,7 +448,7 @@ char *s; HOLOFMT, hdkfile, FMTSTR, fmt); error(USER, errmsg); } - return; + return(0); } for (cp = s; *cp; cp++) /* take off any comments */ if (*cp == '#') { @@ -425,6 +456,7 @@ char *s; break; } setvariable(s, matchvar); /* don't flag errors */ + return(0); } @@ -437,8 +469,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 */ @@ -480,16 +512,23 @@ 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) { - hdflush(NULL); /* flush holodeck buffers */ +#if MAXQTIME + if (n2flush > 300/MAXQTIME*totqlen) { +#else + if (n2flush > 50*totqlen) { +#endif + if (outdev == NULL) + hdflush(NULL); /* flush holodeck buffers */ + else + hdsync(NULL, 1); /* sync holodeck file */ n2flush = 0; } } @@ -534,14 +573,6 @@ register char *s; fflush(stderr); midline = 0; } -} - - -wputs(s) /* put warning string to stderr */ -char *s; -{ - if (!nowarn) - eputs(s); }