10 |
|
|
11 |
|
#include "rholo.h" |
12 |
|
#include "random.h" |
13 |
– |
#include "paths.h" |
13 |
|
#include <signal.h> |
14 |
|
#include <sys/types.h> |
15 |
|
#include <sys/stat.h> |
21 |
|
|
22 |
|
char *progname; /* our program name */ |
23 |
|
char *hdkfile; /* holodeck file name */ |
24 |
< |
char froot[MAXPATH]; /* root file name */ |
24 |
> |
char froot[256]; /* root file name */ |
25 |
|
|
26 |
|
int nowarn = 0; /* turn warnings off? */ |
27 |
|
|
29 |
|
|
30 |
|
char *outdev = NULL; /* output device name */ |
31 |
|
|
32 |
+ |
int readinp = 0; /* read commands from stdin */ |
33 |
+ |
|
34 |
+ |
int force = 0; /* allow overwrite of holodeck */ |
35 |
+ |
|
36 |
|
time_t starttime; /* time we got started */ |
37 |
|
time_t endtime; /* time we should end by */ |
38 |
|
time_t reporttime; /* time for next report */ |
60 |
|
{ |
61 |
|
HDGRID hdg; |
62 |
|
int i; |
60 |
– |
int force = 0; |
63 |
|
/* mark start time */ |
64 |
|
starttime = time(NULL); |
65 |
< |
initurand(10240); /* initialize urand */ |
65 |
> |
initurand(16384); /* initialize urand */ |
66 |
|
progname = argv[0]; /* get arguments */ |
67 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
68 |
|
switch (argv[i][1]) { |
72 |
|
case 'f': /* force overwrite */ |
73 |
|
force++; |
74 |
|
break; |
75 |
+ |
case 'i': /* read input from stdin */ |
76 |
+ |
readinp++; |
77 |
+ |
break; |
78 |
|
case 'n': /* compute processes */ |
79 |
|
if (i >= argc-2) |
80 |
|
goto userr; |
88 |
|
default: |
89 |
|
goto userr; |
90 |
|
} |
86 |
– |
/* do we have a job? */ |
87 |
– |
if (outdev == NULL && ncprocs <= 0) |
88 |
– |
goto userr; |
91 |
|
/* get root file name */ |
92 |
|
rootname(froot, hdkfile=argv[i++]); |
93 |
|
/* load... */ |
103 |
|
/* check settings */ |
104 |
|
checkvalues(); |
105 |
|
/* load RIF if any */ |
106 |
< |
if (vdef(RIF)) |
105 |
< |
getradfile(vval(RIF)); |
106 |
> |
getradfile(); |
107 |
|
/* set defaults */ |
108 |
|
setdefaults(&hdg); |
109 |
|
/* holodeck exists? */ |
117 |
|
/* check settings */ |
118 |
|
checkvalues(); |
119 |
|
/* load RIF if any */ |
120 |
< |
if (vdef(RIF)) |
120 |
< |
getradfile(vval(RIF)); |
120 |
> |
getradfile(); |
121 |
|
/* set defaults */ |
122 |
|
setdefaults(NULL); |
123 |
|
} |
130 |
|
quit(0); |
131 |
|
userr: |
132 |
|
fprintf(stderr, |
133 |
< |
"Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n", |
133 |
> |
"Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif [VAR=val ..]]\n", |
134 |
|
progname); |
135 |
|
quit(1); |
136 |
|
} |
187 |
|
{ |
188 |
|
extern int global_packet(); |
189 |
|
register int i; |
190 |
+ |
/* close holodeck on exec() */ |
191 |
+ |
fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC); |
192 |
|
|
193 |
|
if (outdev != NULL) /* open output device */ |
194 |
|
disp_open(outdev); |
203 |
|
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
204 |
|
endtime = 0; |
205 |
|
else |
206 |
< |
endtime = starttime + vflt(TIME)*3600.; |
206 |
> |
endtime = starttime + vflt(TIME)*3600. + .5; |
207 |
|
/* set up memory cache */ |
208 |
|
if (outdev == NULL) |
209 |
|
hdcachesize = 0; /* manual flushing */ |
219 |
|
if (ncprocs > 0) { |
220 |
|
i = start_rtrace(); |
221 |
|
if (i < 1) |
222 |
< |
error(USER, "cannot start rtrace process"); |
222 |
> |
error(USER, "cannot start rtrace process(es)"); |
223 |
|
if (vdef(REPORT)) { /* make first report */ |
224 |
|
printargs(rtargc, rtargv, stderr); |
225 |
|
report(0); |
230 |
|
goto memerr; |
231 |
|
freepacks[--i].nr = 0; |
232 |
|
freepacks[i].next = NULL; |
233 |
< |
if (!vbool(OBSTRUCTIONS)) { |
233 |
> |
if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { |
234 |
|
freepacks[i].offset = (float *)bmalloc( |
235 |
|
RPACKSIZ*sizeof(float)*(i+1) ); |
236 |
|
if (freepacks[i].offset == NULL) |
274 |
|
if (!disp_check(idle)) |
275 |
|
return(0); |
276 |
|
/* display only? */ |
277 |
< |
if (ncprocs <= 0) |
278 |
< |
return(1); |
277 |
> |
if (nprocs <= 0) |
278 |
> |
return(outdev != NULL); |
279 |
|
/* check file size */ |
280 |
|
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
281 |
|
error(WARNING, "file limit exceeded"); |
282 |
< |
return(0); |
282 |
> |
done_rtrace(); |
283 |
> |
idle = 1; |
284 |
> |
return(1); /* comes back */ |
285 |
|
} |
286 |
|
/* check time */ |
287 |
|
if (endtime > 0 || reporttime > 0) |
288 |
|
t = time(NULL); |
289 |
|
if (endtime > 0 && t >= endtime) { |
290 |
|
error(WARNING, "time limit exceeded"); |
291 |
< |
return(0); |
291 |
> |
done_rtrace(); |
292 |
> |
idle = 1; |
293 |
> |
return(1); /* comes back */ |
294 |
|
} |
295 |
|
if (reporttime > 0 && t >= reporttime) |
296 |
|
report(t); |
299 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
300 |
|
if (!next_packet(p)) { |
301 |
|
p->next = freepacks; freepacks = p; |
302 |
+ |
idle = 1; |
303 |
|
break; |
304 |
|
} |
305 |
|
if (pl == NULL) pl = p; |
306 |
|
else plend->next = p; |
307 |
|
plend = p; |
308 |
|
} |
309 |
< |
idle = pl == NULL && freepacks != NULL; |
303 |
< |
/* are we out of stuff to do? */ |
304 |
< |
if (idle && outdev == NULL) |
305 |
< |
return(0); |
306 |
< |
/* else process packets */ |
309 |
> |
/* process packets */ |
310 |
|
done_packets(do_packets(pl)); |
311 |
|
return(1); /* and continue */ |
312 |
|
} |
313 |
|
|
314 |
|
|
312 |
– |
report(t) /* report progress so far */ |
313 |
– |
time_t t; |
314 |
– |
{ |
315 |
– |
if (t == 0) |
316 |
– |
t = time(NULL); |
317 |
– |
fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n", |
318 |
– |
progname, npacksdone, nraysdone, (t-starttime)/3600.); |
319 |
– |
fflush(stderr); |
320 |
– |
if (vdef(REPORT)) |
321 |
– |
reporttime = t + (time_t)(vflt(REPORT)*60.+.5); |
322 |
– |
} |
323 |
– |
|
324 |
– |
|
315 |
|
setdefaults(gp) /* set default values */ |
316 |
|
register HDGRID *gp; |
317 |
|
{ |
334 |
|
sprintf(vval(OCTREE), "%s.oct", froot); |
335 |
|
vdef(OCTREE)++; |
336 |
|
} |
347 |
– |
if (!vdef(OBSTRUCTIONS)) { |
348 |
– |
vval(OBSTRUCTIONS) = "T"; |
349 |
– |
vdef(OBSTRUCTIONS)++; |
350 |
– |
} |
337 |
|
if (!vdef(VDIST)) { |
338 |
|
vval(VDIST) = "F"; |
339 |
|
vdef(VDIST)++; |
479 |
|
p->next = freepacks; |
480 |
|
freepacks = p; |
481 |
|
} |
482 |
< |
if (n2flush > 512*RPACKSIZ*ncprocs) { |
482 |
> |
if (n2flush > 512*RPACKSIZ*nprocs) { |
483 |
|
hdflush(NULL); /* flush holodeck buffers */ |
484 |
|
n2flush = 0; |
485 |
|
} |
486 |
|
} |
487 |
|
|
488 |
|
|
503 |
– |
getradfile(rfargs) /* run rad and get needed variables */ |
504 |
– |
char *rfargs; |
505 |
– |
{ |
506 |
– |
static short mvar[] = {OCTREE,-1}; |
507 |
– |
static char tf1[] = TEMPLATE; |
508 |
– |
char tf2[64]; |
509 |
– |
char combuf[256]; |
510 |
– |
char *pippt; |
511 |
– |
register int i; |
512 |
– |
register char *cp; |
513 |
– |
/* create rad command */ |
514 |
– |
mktemp(tf1); |
515 |
– |
sprintf(tf2, "%s.rif", tf1); |
516 |
– |
sprintf(combuf, |
517 |
– |
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
518 |
– |
rfargs, tf1); |
519 |
– |
cp = combuf; |
520 |
– |
while (*cp){ |
521 |
– |
if (*cp == '|') pippt = cp; |
522 |
– |
cp++; |
523 |
– |
} /* match unset variables */ |
524 |
– |
for (i = 0; mvar[i] >= 0; i++) |
525 |
– |
if (!vdef(mvar[i])) { |
526 |
– |
*cp++ = '|'; |
527 |
– |
strcpy(cp, vnam(mvar[i])); |
528 |
– |
while (*cp) cp++; |
529 |
– |
pippt = NULL; |
530 |
– |
} |
531 |
– |
if (pippt != NULL) |
532 |
– |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
533 |
– |
else |
534 |
– |
sprintf(cp, ")[ \t]*=' > %s", tf2); |
535 |
– |
if (system(combuf)) { |
536 |
– |
error(SYSTEM, "cannot execute rad command"); |
537 |
– |
unlink(tf2); /* clean up */ |
538 |
– |
unlink(tf1); |
539 |
– |
quit(1); |
540 |
– |
} |
541 |
– |
if (pippt == NULL) { |
542 |
– |
loadvars(tf2); /* load variables */ |
543 |
– |
unlink(tf2); |
544 |
– |
} |
545 |
– |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
546 |
– |
unlink(tf1); /* clean up */ |
547 |
– |
} |
548 |
– |
|
549 |
– |
|
489 |
|
rootname(rn, fn) /* remove tail from end of fn */ |
490 |
|
register char *rn, *fn; |
491 |
|
{ |
492 |
|
char *tp, *dp; |
493 |
|
|
494 |
|
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
495 |
< |
if (ISDIRSEP(*rn)) |
495 |
> |
if (*rn == '/') |
496 |
|
dp = rn; |
497 |
|
else if (*rn == '.') |
498 |
|
tp = rn; |
541 |
|
{ |
542 |
|
int status = 0; |
543 |
|
|
544 |
< |
if (hdlist[0] != NULL) { /* flush holodeck */ |
545 |
< |
if (ncprocs > 0) { |
546 |
< |
done_packets(flush_queue()); |
547 |
< |
status = end_rtrace(); /* close rtrace */ |
548 |
< |
hdflush(NULL); |
549 |
< |
if (vdef(REPORT)) { |
550 |
< |
long fsiz, fuse; |
551 |
< |
report(0); |
613 |
< |
fsiz = hdfilen(hdlist[0]->fd); |
614 |
< |
fuse = hdfiluse(hdlist[0]->fd, 1); |
615 |
< |
fprintf(stderr, |
544 |
> |
if (hdlist[0] != NULL) { /* close holodeck */ |
545 |
> |
if (nprocs > 0) |
546 |
> |
status = done_rtrace(); /* calls hdsync() */ |
547 |
> |
if (ncprocs > 0 && vdef(REPORT)) { |
548 |
> |
long fsiz, fuse; |
549 |
> |
fsiz = hdfilen(hdlist[0]->fd); |
550 |
> |
fuse = hdfiluse(hdlist[0]->fd, 1); |
551 |
> |
fprintf(stderr, |
552 |
|
"%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", |
553 |
< |
hdkfile, fsiz/(1024.*1024.), |
554 |
< |
100.*(fsiz-fuse)/fsiz); |
555 |
< |
} |
620 |
< |
} else |
621 |
< |
hdflush(NULL); |
553 |
> |
hdkfile, fsiz/(1024.*1024.), |
554 |
> |
100.*(fsiz-fuse)/fsiz); |
555 |
> |
} |
556 |
|
} |
557 |
|
if (orig_mode >= 0) /* reset holodeck access mode */ |
558 |
|
fchmod(hdlist[0]->fd, orig_mode); |