--- ray/src/hd/rholo.c 1998/01/10 16:37:10 3.36 +++ ray/src/hd/rholo.c 1999/01/07 22:05:34 3.46 @@ -1,4 +1,4 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ +/* Copyright (c) 1999 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -14,6 +14,12 @@ static char SCCSid[] = "$SunId$ SGI"; #include #include +#ifndef RTFLUSH +#define RTFLUSH 0 /* flush one at a time in batch */ +#endif +#ifndef FRAGWARN +#define FRAGWARN 20 /* fragmentation for warning (%) */ +#endif #ifndef MAXQTIME #define MAXQTIME 5 /* target maximum seconds in queue */ #endif @@ -26,8 +32,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 */ @@ -51,10 +55,12 @@ 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 */ +extern int nowarn; /* turn warnings off? */ + extern time_t time(); @@ -147,7 +153,7 @@ int signo; if (gotsig++) /* two signals and we're gone! */ _exit(signo); - alarm(60); /* allow 60 seconds to clean up */ + alarm(180); /* allow 3 minutes to clean up */ signal(SIGALRM, SIG_DFL); /* make certain we do die */ eputs("signal - "); eputs(sigerr[signo]); @@ -222,7 +228,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 */ @@ -233,8 +239,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)) { @@ -271,8 +275,10 @@ memerr: rholo() /* holodeck main loop */ { + static long nextfragwarn = 100*(1L<<20); static int idle = 0; PACKET *pl = NULL, *plend; + long fsiz; int pksiz; register PACKET *p; time_t t; @@ -286,12 +292,21 @@ rholo() /* holodeck main loop */ return(1); } else if (idle) return(0); /* all done */ - /* check file size */ - if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { + fsiz = hdfilen(hdlist[0]->fd); /* check file size */ + if (maxdisk > 0 && fsiz >= maxdisk) { error(WARNING, "file limit exceeded"); done_rtrace(); return(1); /* comes back */ } +#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"); @@ -302,7 +317,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) @@ -332,7 +347,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)) { @@ -366,13 +381,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) @@ -420,6 +437,7 @@ HDGRID *gp; } +int headline(s) /* process information header line */ char *s; { @@ -433,7 +451,7 @@ char *s; HOLOFMT, hdkfile, FMTSTR, fmt); error(USER, errmsg); } - return; + return(0); } for (cp = s; *cp; cp++) /* take off any comments */ if (*cp == '#') { @@ -441,6 +459,7 @@ char *s; break; } setvariable(s, matchvar); /* don't flag errors */ + return(0); } @@ -453,8 +472,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 */ @@ -495,8 +514,13 @@ PACKET *pl; p->nr*sizeof(RAYVAL)); if (outdev != NULL) /* display it */ disp_packet((PACKHEAD *)p); - if (hdcachesize <= 0) /* manual flushing */ + if (hdcachesize <= 0) { +#if RTFLUSH + if (outdev == NULL) + hdfreebeam(hdlist[p->hd], p->bi); +#endif n2flush++; + } nraysdone += p->nr; npacksdone++; p->nr = 0; @@ -504,8 +528,19 @@ PACKET *pl; p->next = freepacks; /* push onto free list */ freepacks = p; } - if (n2flush > 300/MAXQTIME*avgqlen*nprocs) { - hdflush(NULL); /* flush holodeck buffers */ +#if MAXQTIME + if (n2flush > 300/MAXQTIME*totqlen) { +#else + if (n2flush > 50*totqlen) { +#endif +#if RTFLUSH + hdsync(NULL, outdev!=NULL); /* sync beams & directories */ +#else + if (outdev != NULL) + hdsync(NULL, 1); + else + hdflush(NULL); +#endif n2flush = 0; } } @@ -550,14 +585,6 @@ register char *s; fflush(stderr); midline = 0; } -} - - -wputs(s) /* put warning string to stderr */ -char *s; -{ - if (!nowarn) - eputs(s); }