| 1 | 
< | 
/* Copyright (c) 1997 Silicon Graphics, Inc. */ | 
| 1 | 
> | 
/* Copyright (c) 1998 Silicon Graphics, Inc. */ | 
| 2 | 
  | 
 | 
| 3 | 
  | 
#ifndef lint | 
| 4 | 
  | 
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 | 
  | 
 | 
| 51 | 
  | 
long    npacksdone = 0L;        /* number of packets done */ | 
| 52 | 
  | 
 | 
| 53 | 
  | 
PACKET  *freepacks;             /* available packets */ | 
| 54 | 
+ | 
int     avgqlen;                /* average queue length when full */ | 
| 55 | 
  | 
 | 
| 56 | 
  | 
char  *sigerr[NSIG];            /* signal error messages */ | 
| 57 | 
  | 
 | 
| 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++) | 
| 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) | 
| 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 */ | 
| 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) { | 
| 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 */ | 
| 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(); | 
| 233 | 
  | 
                freepacks = (PACKET *)bmalloc(i*sizeof(PACKET)); | 
| 234 | 
  | 
                if (freepacks == NULL) | 
| 235 | 
  | 
                        goto memerr; | 
| 236 | 
+ | 
                if (!(avgqlen = i/nprocs))      /* record mean queue length */ | 
| 237 | 
+ | 
                        avgqlen = 1; | 
| 238 | 
  | 
                freepacks[--i].nr = 0; | 
| 239 | 
  | 
                freepacks[i].next = NULL; | 
| 240 | 
  | 
                if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { | 
| 271 | 
  | 
 | 
| 272 | 
  | 
rholo()                         /* holodeck main loop */ | 
| 273 | 
  | 
{ | 
| 274 | 
< | 
        static int      idle = 1; | 
| 274 | 
> | 
        static int      idle = 0; | 
| 275 | 
  | 
        PACKET  *pl = NULL, *plend; | 
| 276 | 
+ | 
        int     pksiz; | 
| 277 | 
  | 
        register PACKET *p; | 
| 278 | 
  | 
        time_t  t; | 
| 279 | 
< | 
        long    l; | 
| 280 | 
< | 
 | 
| 271 | 
< | 
        if (outdev != NULL)             /* check display */ | 
| 272 | 
< | 
                if (!disp_check(idle)) | 
| 273 | 
< | 
                        return(0); | 
| 274 | 
< | 
                                        /* display only? */ | 
| 275 | 
< | 
        if (nprocs <= 0) { | 
| 279 | 
> | 
                                        /* check display */ | 
| 280 | 
> | 
        if (nprocs <= 0) | 
| 281 | 
  | 
                idle = 1; | 
| 282 | 
< | 
                return(outdev != NULL); | 
| 283 | 
< | 
        } | 
| 282 | 
> | 
        if (outdev != NULL) { | 
| 283 | 
> | 
                if (!disp_check(idle)) | 
| 284 | 
> | 
                        return(0);      /* quit request */ | 
| 285 | 
> | 
                if (nprocs <= 0) | 
| 286 | 
> | 
                        return(1); | 
| 287 | 
> | 
        } else if (idle) | 
| 288 | 
> | 
                return(0);              /* all done */ | 
| 289 | 
  | 
                                        /* check file size */ | 
| 290 | 
  | 
        if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { | 
| 291 | 
  | 
                error(WARNING, "file limit exceeded"); | 
| 292 | 
  | 
                done_rtrace(); | 
| 293 | 
  | 
                return(1);      /* comes back */ | 
| 294 | 
  | 
        } | 
| 295 | 
< | 
                                        /* check time */ | 
| 286 | 
< | 
        if (endtime > 0 || reporttime > 0) | 
| 287 | 
< | 
                t = time(NULL); | 
| 295 | 
> | 
        t = time(NULL);                 /* check time */ | 
| 296 | 
  | 
        if (endtime > 0 && t >= endtime) { | 
| 297 | 
  | 
                error(WARNING, "time limit exceeded"); | 
| 298 | 
  | 
                done_rtrace(); | 
| 300 | 
  | 
        } | 
| 301 | 
  | 
        if (reporttime > 0 && t >= reporttime) | 
| 302 | 
  | 
                report(t); | 
| 303 | 
+ | 
                                        /* figure out good packet size */ | 
| 304 | 
+ | 
#if MAXQTIME | 
| 305 | 
+ | 
        pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L)); | 
| 306 | 
+ | 
        if (pksiz < 1) | 
| 307 | 
+ | 
                pksiz = 1; | 
| 308 | 
+ | 
        else if (pksiz > RPACKSIZ) | 
| 309 | 
+ | 
#endif | 
| 310 | 
+ | 
                pksiz = RPACKSIZ; | 
| 311 | 
  | 
        idle = 0;                       /* get packets to process */ | 
| 312 | 
  | 
        while (freepacks != NULL) { | 
| 313 | 
  | 
                p = freepacks; freepacks = p->next; p->next = NULL; | 
| 314 | 
< | 
                if (!next_packet(p)) { | 
| 314 | 
> | 
                if (!next_packet(p, pksiz)) { | 
| 315 | 
  | 
                        p->next = freepacks; freepacks = p; | 
| 316 | 
  | 
                        idle = 1; | 
| 317 | 
  | 
                        break; | 
| 332 | 
  | 
        extern char     *atos(); | 
| 333 | 
  | 
        register int    i; | 
| 334 | 
  | 
        int     n; | 
| 335 | 
< | 
        double  len[3], maxlen, d; | 
| 335 | 
> | 
        double  len[3], d; | 
| 336 | 
  | 
        char    buf[64]; | 
| 337 | 
  | 
 | 
| 338 | 
  | 
        if (!vdef(SECTION)) { | 
| 366 | 
  | 
                                &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], | 
| 367 | 
  | 
                                &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) | 
| 368 | 
  | 
                        badvalue(SECTION); | 
| 353 | 
– | 
                maxlen = 0.; | 
| 369 | 
  | 
                for (i = 0; i < 3; i++) | 
| 370 | 
< | 
                        if ((len[i] = VLEN(gp->xv[i])) > maxlen) | 
| 371 | 
< | 
                                maxlen = len[i]; | 
| 372 | 
< | 
                if (!vdef(GRID)) | 
| 373 | 
< | 
                        d = 0.125*maxlen; | 
| 374 | 
< | 
                else if ((d = vflt(GRID)) <= FTINY) | 
| 370 | 
> | 
                        len[i] = VLEN(gp->xv[i]); | 
| 371 | 
> | 
                if (!vdef(GRID)) { | 
| 372 | 
> | 
                        d = 2/5e5*( len[0]*len[0]*(len[1]*len[1] + | 
| 373 | 
> | 
                                        len[2]*len[2] + 4*len[1]*len[2]) | 
| 374 | 
> | 
                                + len[1]*len[1]*len[2]*(len[2] + 4*len[0]) | 
| 375 | 
> | 
                                + 4*len[0]*len[1]*len[2]*len[2] ); | 
| 376 | 
> | 
                        d = sqrt(sqrt(d)); | 
| 377 | 
> | 
                } else if ((d = vflt(GRID)) <= FTINY) | 
| 378 | 
  | 
                        badvalue(GRID); | 
| 379 | 
  | 
                for (i = 0; i < 3; i++) | 
| 380 | 
  | 
                        if (gp->grid[i] <= 0) | 
| 498 | 
  | 
                        if (outdev != NULL)     /* display it */ | 
| 499 | 
  | 
                                disp_packet((PACKHEAD *)p); | 
| 500 | 
  | 
                        if (hdcachesize <= 0)   /* manual flushing */ | 
| 501 | 
< | 
                                n2flush += p->nr; | 
| 501 | 
> | 
                                n2flush++; | 
| 502 | 
  | 
                        nraysdone += p->nr; | 
| 503 | 
  | 
                        npacksdone++; | 
| 504 | 
+ | 
                        p->nr = 0; | 
| 505 | 
  | 
                } | 
| 506 | 
< | 
                p->nr = 0;                      /* push onto free list */ | 
| 488 | 
< | 
                p->next = freepacks; | 
| 506 | 
> | 
                p->next = freepacks;            /* push onto free list */ | 
| 507 | 
  | 
                freepacks = p; | 
| 508 | 
  | 
        } | 
| 509 | 
< | 
        if (n2flush > 512*RPACKSIZ*nprocs) { | 
| 509 | 
> | 
        if (n2flush > 300/MAXQTIME*avgqlen*nprocs) { | 
| 510 | 
  | 
                hdflush(NULL);                  /* flush holodeck buffers */ | 
| 511 | 
  | 
                n2flush = 0; | 
| 512 | 
  | 
        } |