| 23 |
|
|
| 24 |
|
int report_intvl = 0; /* reporting interval (seconds) */ |
| 25 |
|
|
| 26 |
– |
extern char * progname; // global argv[0] |
| 27 |
– |
|
| 26 |
|
RcontribSimulManager myRCmanager; // global rcontrib simulation manager |
| 27 |
|
|
| 28 |
|
#define RCONTRIB_FEATURES "Multiprocessing\n" \ |
| 45 |
|
if (myRCmanager.HasFlag(RTimmIrrad)) |
| 46 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
| 47 |
|
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
| 48 |
< |
if (myRCmanager.xres > 0) |
| 51 |
< |
printf("-x %-9d\t\t\t# x resolution\n", myRCmanager.xres); |
| 48 |
> |
printf("-x %-9d\t\t\t# x resolution\n", myRCmanager.xres); |
| 49 |
|
printf("-y %-9d\t\t\t# y resolution\n", myRCmanager.yres); |
| 50 |
|
printf(myRCmanager.HasFlag(RTlimDist) ? |
| 51 |
|
"-ld+\t\t\t\t# limit distance on\n" : |
| 53 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
| 54 |
|
inpfmt, outfmt, formstr(inpfmt), formstr(outfmt)); |
| 55 |
|
if (report_intvl > 0) |
| 56 |
< |
printf("-t %-9d\t\t\t# time between reports\n", report_intvl); |
| 56 |
> |
printf("-t %-9d\t\t\t# time between reports\n", report_intvl); |
| 57 |
|
printf(erract[WARNING].pf != NULL ? |
| 58 |
|
"-w+\t\t\t\t# warning messages on\n" : |
| 59 |
|
"-w-\t\t\t\t# warning messages off\n"); |
| 72 |
|
_exit(signo); |
| 73 |
|
|
| 74 |
|
#ifdef SIGALRM |
| 75 |
< |
alarm(180); /* allow 3 minutes to clean up */ |
| 75 |
> |
alarm(600); /* allow 10 minutes to clean up */ |
| 76 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
| 77 |
|
#endif |
| 78 |
|
eputs("signal - "); |
| 125 |
|
if (!fmt[2]) |
| 126 |
|
return; |
| 127 |
|
fmterr: |
| 128 |
< |
sprintf(errmsg, "Unsupported i/o format: -f%s", fmt); |
| 128 |
> |
sprintf(errmsg, "unsupported i/o format: -f%s", fmt); |
| 129 |
|
error(USER, errmsg); |
| 130 |
|
} |
| 131 |
|
|
| 240 |
|
if (rval) erract[WARNING].pf = wputs; |
| 241 |
|
else erract[WARNING].pf = NULL; |
| 242 |
|
break; |
| 246 |
– |
case 'e': /* .cal expression */ |
| 247 |
– |
check(2,"s"); |
| 248 |
– |
scompile(argv[++i], NULL, 0); |
| 249 |
– |
break; |
| 243 |
|
case 'l': /* limit distance */ |
| 244 |
|
if (argv[i][2] != 'd') |
| 245 |
|
goto badopt; |
| 252 |
|
check_bool(2,rval); |
| 253 |
|
myRCmanager.SetFlag(RTimmIrrad, rval); |
| 254 |
|
break; |
| 255 |
< |
case 'f': /* .cal file or force or format */ |
| 263 |
< |
if (!argv[i][2]) { |
| 264 |
< |
check(2,"s"); |
| 265 |
< |
loadfunc(argv[++i]); |
| 266 |
< |
break; |
| 267 |
< |
} |
| 255 |
> |
case 'f': /* force or format */ |
| 256 |
|
if (argv[i][2] == 'o') { |
| 257 |
|
check_bool(3,force_open); |
| 258 |
|
break; |
| 286 |
|
break; |
| 287 |
|
case 'm': /* modifier name */ |
| 288 |
|
check(2,"s"); |
| 289 |
< |
myRCmanager.AddModifier(argv[++i], curout, prms, binval, bincnt); |
| 289 |
> |
if (!myRCmanager.AddModifier(argv[++i], curout, prms, binval, bincnt)) { |
| 290 |
> |
sprintf(errmsg, "bad settings for modifier '%s'", argv[i]); |
| 291 |
> |
error(USER, errmsg); |
| 292 |
> |
} |
| 293 |
|
break; |
| 294 |
|
case 'M': /* file of modifier names */ |
| 295 |
|
check(2,"s"); |
| 296 |
< |
myRCmanager.AddModFile(argv[++i], curout, prms, binval, bincnt); |
| 296 |
> |
if (!myRCmanager.AddModFile(argv[++i], curout, prms, binval, bincnt)) { |
| 297 |
> |
sprintf(errmsg, "bad settings for modifier file '%s'", argv[i]); |
| 298 |
> |
error(USER, errmsg); |
| 299 |
> |
} |
| 300 |
|
break; |
| 301 |
|
case 't': /* reporting interval */ |
| 302 |
|
check(2,"i"); |
| 339 |
|
myRCmanager.LoadOctree(argv[argc-1]); |
| 340 |
|
// add to header |
| 341 |
|
myRCmanager.AddHeader(argc-1, argv); |
| 342 |
+ |
{ |
| 343 |
+ |
char buf[128] = "SOFTWARE= "; |
| 344 |
+ |
strcpy(buf+10, VersionID); |
| 345 |
+ |
myRCmanager.AddHeader(buf); |
| 346 |
+ |
} |
| 347 |
|
// prepare output files |
| 348 |
|
if (recover) |
| 349 |
|
myRCmanager.outOp = RCOrecover; |
| 353 |
|
myRCmanager.outOp = RCOnew; |
| 354 |
|
// rval = # rows recovered |
| 355 |
|
rval = myRCmanager.PrepOutput(); |
| 356 |
< |
// check if recovered everything |
| 357 |
< |
if (rval >= myRCmanager.GetRowMax()) { |
| 356 |
> |
|
| 357 |
> |
if (rval < 0) // PrepOutput() failure? |
| 358 |
> |
error(USER, "issue loading or creating output(s)"); |
| 359 |
> |
// in case we recovered everything |
| 360 |
> |
if (rval >= myRCmanager.GetRowMax()) |
| 361 |
|
error(WARNING, "nothing left to compute"); |
| 362 |
< |
quit(0); |
| 363 |
< |
} // add processes as requested |
| 362 |
< |
myRCmanager.SetThreadCount(nproc); |
| 362 |
> |
else |
| 363 |
> |
rxcontrib(rval); // trace ray contributions (loop) |
| 364 |
|
|
| 365 |
< |
rxcontrib(rval); /* trace ray contributions (loop) */ |
| 365 |
> |
quit(0); // exit clean |
| 366 |
|
|
| 366 |
– |
quit(0); /* exit clean */ |
| 367 |
– |
|
| 367 |
|
badopt: |
| 368 |
|
fprintf(stderr, |
| 369 |
|
"Usage: %s [-V][-c count][-r][-e expr][-f source][-o ospec][-p p1=V1,p2=V2][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n", |
| 414 |
|
int n2go = myRCmanager.accum; |
| 415 |
|
|
| 416 |
|
switch (inpfmt) { |
| 417 |
< |
case 'a': // ASCII input |
| 417 |
> |
case 'a': // ASCII input |
| 418 |
|
if (!orig_dir) |
| 419 |
|
return skipWords(6*n2go); |
| 420 |
|
while (n2go-- > 0) { |
| 427 |
|
orig_dir += 2; |
| 428 |
|
} |
| 429 |
|
break; |
| 430 |
< |
case 'f': // float input |
| 430 |
> |
case 'f': // float input |
| 431 |
|
if (!orig_dir) |
| 432 |
|
return skipBytes(6*sizeof(float)*n2go); |
| 433 |
|
#ifdef SMLFLT |
| 434 |
|
if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) |
| 435 |
|
return false; |
| 436 |
+ |
orig_dir += 2*n2go; |
| 437 |
|
#else |
| 438 |
|
while (n2go-- > 0) { |
| 439 |
|
float fvecs[6]; |
| 445 |
|
} |
| 446 |
|
#endif |
| 447 |
|
break; |
| 448 |
< |
case 'd': // double input |
| 448 |
> |
case 'd': // double input |
| 449 |
|
if (!orig_dir) |
| 450 |
|
return skipBytes(6*sizeof(double)*n2go); |
| 451 |
|
#ifndef SMLFLT |
| 452 |
|
if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) |
| 453 |
|
return false; |
| 454 |
+ |
orig_dir += 2*n2go; |
| 455 |
|
#else |
| 456 |
|
while (n2go-- > 0) { |
| 457 |
|
double dvecs[6]; |
| 467 |
|
error(INTERNAL, "unsupported format in getRayBundle()"); |
| 468 |
|
return false; |
| 469 |
|
} |
| 470 |
< |
int warned = 0; // normalize directions |
| 470 |
< |
n2go = myRCmanager.accum; |
| 470 |
> |
n2go = myRCmanager.accum; // normalize directions |
| 471 |
|
while (n2go-- > 0) { |
| 472 |
|
orig_dir -= 2; |
| 473 |
< |
if (normalize(orig_dir[1]) == 0) |
| 474 |
< |
if (!warned++) |
| 475 |
< |
error(WARNING, "zero ray direction on input"); |
| 473 |
> |
normalize(orig_dir[1]); |
| 474 |
|
} |
| 475 |
|
return true; |
| 476 |
|
} |
| 498 |
|
} |
| 499 |
|
last_report = tstart = time(0); |
| 500 |
|
} |
| 501 |
+ |
// start children as requested |
| 502 |
+ |
myRCmanager.SetThreadCount(nproc); |
| 503 |
+ |
|
| 504 |
|
while (r < totRows) { // loop until done |
| 505 |
|
time_t tnow; |
| 506 |
|
if (!getRayBundle(odarr)) |
| 510 |
|
r++; |
| 511 |
|
if (report_intvl <= 0) |
| 512 |
|
continue; |
| 513 |
< |
tnow = time(0); // time to report progress? |
| 514 |
< |
if (r == totRows) |
| 515 |
< |
myRCmanager.FlushQueue(); |
| 516 |
< |
else if (tnow < last_report+report_intvl) |
| 513 |
> |
if (r == totRows) // need to finish up? |
| 514 |
> |
myRCmanager.SetThreadCount(1); |
| 515 |
> |
tnow = time(0); |
| 516 |
> |
if ((r < totRows) & (tnow < last_report+report_intvl)) |
| 517 |
|
continue; |
| 518 |
|
sprintf(errmsg, "%.2f%% done after %.3f hours\n", |
| 519 |
|
100.*myRCmanager.GetRowFinished()/totRows, |
| 569 |
|
int code |
| 570 |
|
) |
| 571 |
|
{ |
| 572 |
< |
if (!code && myRCmanager.Ready()) // clean up on normal exit |
| 572 |
< |
code = myRCmanager.Cleanup(); |
| 572 |
> |
myRCmanager.FlushQueue(); // leave nothing in queue |
| 573 |
|
|
| 574 |
|
exit(code); |
| 575 |
|
} |