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 |
|
|
26 |
|
char *hdkfile; /* holodeck file name */ |
27 |
|
char froot[256]; /* root file name */ |
28 |
|
|
26 |
– |
int nowarn = 0; /* turn warnings off? */ |
27 |
– |
|
29 |
|
int ncprocs = 0; /* desired number of compute processes */ |
30 |
|
|
31 |
|
char *outdev = NULL; /* output device name */ |
49 |
|
long npacksdone = 0L; /* number of packets done */ |
50 |
|
|
51 |
|
PACKET *freepacks; /* available packets */ |
52 |
+ |
int totqlen; /* maximum queue length when full */ |
53 |
|
|
54 |
|
char *sigerr[NSIG]; /* signal error messages */ |
55 |
|
|
56 |
+ |
extern int nowarn; /* turn warnings off? */ |
57 |
+ |
|
58 |
|
extern time_t time(); |
59 |
|
|
60 |
|
|
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(); |
225 |
> |
totqlen = i = start_rtrace(); |
226 |
|
if (i < 1) |
227 |
|
error(USER, "cannot start rtrace process(es)"); |
228 |
|
if (vdef(REPORT)) { /* make first report */ |
269 |
|
|
270 |
|
rholo() /* holodeck main loop */ |
271 |
|
{ |
272 |
< |
static int idle = 1; |
272 |
> |
static int idle = 0; |
273 |
|
PACKET *pl = NULL, *plend; |
274 |
+ |
int pksiz; |
275 |
|
register PACKET *p; |
276 |
|
time_t t; |
277 |
< |
long l; |
278 |
< |
|
271 |
< |
if (outdev != NULL) /* check display */ |
272 |
< |
if (!disp_check(idle)) |
273 |
< |
return(0); |
274 |
< |
/* display only? */ |
275 |
< |
if (nprocs <= 0) { |
277 |
> |
/* check display */ |
278 |
> |
if (nprocs <= 0) |
279 |
|
idle = 1; |
280 |
< |
return(outdev != NULL); |
281 |
< |
} |
280 |
> |
if (outdev != NULL) { |
281 |
> |
if (!disp_check(idle)) |
282 |
> |
return(0); /* quit request */ |
283 |
> |
if (nprocs <= 0) |
284 |
> |
return(1); |
285 |
> |
} else if (idle) |
286 |
> |
return(0); /* all done */ |
287 |
|
/* check file size */ |
288 |
|
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
289 |
|
error(WARNING, "file limit exceeded"); |
290 |
|
done_rtrace(); |
291 |
|
return(1); /* comes back */ |
292 |
|
} |
293 |
< |
/* check time */ |
286 |
< |
if (endtime > 0 || reporttime > 0) |
287 |
< |
t = time(NULL); |
293 |
> |
t = time(NULL); /* check time */ |
294 |
|
if (endtime > 0 && t >= endtime) { |
295 |
|
error(WARNING, "time limit exceeded"); |
296 |
|
done_rtrace(); |
298 |
|
} |
299 |
|
if (reporttime > 0 && t >= reporttime) |
300 |
|
report(t); |
301 |
+ |
/* figure out good packet size */ |
302 |
+ |
#if MAXQTIME |
303 |
+ |
pksiz = nraysdone*MAXQTIME/(totqlen*(t - starttime + 1L)); |
304 |
+ |
if (pksiz < 1) |
305 |
+ |
pksiz = 1; |
306 |
+ |
else if (pksiz > RPACKSIZ) |
307 |
+ |
#endif |
308 |
+ |
pksiz = RPACKSIZ; |
309 |
|
idle = 0; /* get packets to process */ |
310 |
|
while (freepacks != NULL) { |
311 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
312 |
< |
if (!next_packet(p)) { |
312 |
> |
if (!next_packet(p, pksiz)) { |
313 |
|
p->next = freepacks; freepacks = p; |
314 |
|
idle = 1; |
315 |
|
break; |
330 |
|
extern char *atos(); |
331 |
|
register int i; |
332 |
|
int n; |
333 |
< |
double len[3], maxlen, d; |
333 |
> |
double len[3], d; |
334 |
|
char buf[64]; |
335 |
|
|
336 |
|
if (!vdef(SECTION)) { |
364 |
|
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
365 |
|
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
366 |
|
badvalue(SECTION); |
353 |
– |
maxlen = 0.; |
367 |
|
for (i = 0; i < 3; i++) |
368 |
< |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
369 |
< |
maxlen = len[i]; |
370 |
< |
if (!vdef(GRID)) |
371 |
< |
d = 0.125*maxlen; |
372 |
< |
else if ((d = vflt(GRID)) <= FTINY) |
368 |
> |
len[i] = VLEN(gp->xv[i]); |
369 |
> |
if (!vdef(GRID)) { |
370 |
> |
d = 2/2e5*( len[0]*len[0]*(len[1]*len[1] + |
371 |
> |
len[2]*len[2] + 4*len[1]*len[2]) |
372 |
> |
+ len[1]*len[1]*len[2]*(len[2] + 4*len[0]) |
373 |
> |
+ 4*len[0]*len[1]*len[2]*len[2] ); |
374 |
> |
d = sqrt(sqrt(d)); |
375 |
> |
} else if ((d = vflt(GRID)) <= FTINY) |
376 |
|
badvalue(GRID); |
377 |
|
for (i = 0; i < 3; i++) |
378 |
|
if (gp->grid[i] <= 0) |
420 |
|
} |
421 |
|
|
422 |
|
|
423 |
+ |
int |
424 |
|
headline(s) /* process information header line */ |
425 |
|
char *s; |
426 |
|
{ |
434 |
|
HOLOFMT, hdkfile, FMTSTR, fmt); |
435 |
|
error(USER, errmsg); |
436 |
|
} |
437 |
< |
return; |
437 |
> |
return(0); |
438 |
|
} |
439 |
|
for (cp = s; *cp; cp++) /* take off any comments */ |
440 |
|
if (*cp == '#') { |
442 |
|
break; |
443 |
|
} |
444 |
|
setvariable(s, matchvar); /* don't flag errors */ |
445 |
+ |
return(0); |
446 |
|
} |
447 |
|
|
448 |
|
|
455 |
|
int4 nextloc; |
456 |
|
/* open holodeck file */ |
457 |
|
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
458 |
< |
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
459 |
< |
ncprocs>0 ? "appending" : "reading"); |
458 |
> |
sprintf(errmsg, "cannot %s \"%s\"", |
459 |
> |
ncprocs>0 ? "append" : "read", hdkfile); |
460 |
|
error(SYSTEM, errmsg); |
461 |
|
} |
462 |
|
/* load variables from header */ |
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) { |
510 |
< |
hdflush(NULL); /* flush holodeck buffers */ |
509 |
> |
#if MAXQTIME |
510 |
> |
if (n2flush > 300/MAXQTIME*totqlen) { |
511 |
> |
#else |
512 |
> |
if (n2flush > 50*totqlen) { |
513 |
> |
#endif |
514 |
> |
if (outdev == NULL) |
515 |
> |
hdflush(NULL); /* flush holodeck buffers */ |
516 |
> |
else |
517 |
> |
hdsync(NULL, 1); /* sync holodeck file */ |
518 |
|
n2flush = 0; |
519 |
|
} |
520 |
|
} |
559 |
|
fflush(stderr); |
560 |
|
midline = 0; |
561 |
|
} |
537 |
– |
} |
538 |
– |
|
539 |
– |
|
540 |
– |
wputs(s) /* put warning string to stderr */ |
541 |
– |
char *s; |
542 |
– |
{ |
543 |
– |
if (!nowarn) |
544 |
– |
eputs(s); |
562 |
|
} |
563 |
|
|
564 |
|
|