| 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 - "); |
| 93 |
|
sigerr[signo] = msg; |
| 94 |
|
} |
| 95 |
|
|
| 99 |
– |
const char * |
| 100 |
– |
formstr(int f) // return format identifier |
| 101 |
– |
{ |
| 102 |
– |
switch (f) { |
| 103 |
– |
case 'a': return("ascii"); |
| 104 |
– |
case 'f': return("float"); |
| 105 |
– |
case 'd': return("double"); |
| 106 |
– |
case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); |
| 107 |
– |
} |
| 108 |
– |
return("unknown"); |
| 109 |
– |
} |
| 110 |
– |
|
| 96 |
|
/* set input/output format */ |
| 97 |
|
static void |
| 98 |
|
setformat(const char *fmt) |
| 129 |
|
error(USER, errmsg); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
+ |
/* Set default options */ |
| 133 |
+ |
static void |
| 134 |
+ |
default_options(void) |
| 135 |
+ |
{ |
| 136 |
+ |
rand_samp = 1; |
| 137 |
+ |
dstrsrc = 0.9; |
| 138 |
+ |
directrelay = 3; |
| 139 |
+ |
vspretest = 512; |
| 140 |
+ |
srcsizerat = .2; |
| 141 |
+ |
specthresh = .02; |
| 142 |
+ |
specjitter = 1.; |
| 143 |
+ |
maxdepth = -10; |
| 144 |
+ |
minweight = 2e-3; |
| 145 |
+ |
ambres = 256; |
| 146 |
+ |
ambdiv = 350; |
| 147 |
+ |
ambounce = 1; |
| 148 |
+ |
} |
| 149 |
|
|
| 150 |
|
/* Set overriding options */ |
| 151 |
|
static void |
| 156 |
|
ambacc = 0; |
| 157 |
|
} |
| 158 |
|
|
| 157 |
– |
|
| 159 |
|
int |
| 160 |
|
main(int argc, char *argv[]) |
| 161 |
|
{ |
| 186 |
|
/* initialize calcomp routines early */ |
| 187 |
|
initfunc(); |
| 188 |
|
calcontext(RCCONTEXT); |
| 189 |
+ |
/* set rcontrib defaults */ |
| 190 |
+ |
default_options(); |
| 191 |
|
/* option city */ |
| 192 |
|
for (i = 1; i < argc; i++) { |
| 193 |
|
/* expand arguments */ |
| 240 |
|
if (rval) erract[WARNING].pf = wputs; |
| 241 |
|
else erract[WARNING].pf = NULL; |
| 242 |
|
break; |
| 240 |
– |
case 'e': /* .cal expression */ |
| 241 |
– |
check(2,"s"); |
| 242 |
– |
scompile(argv[++i], NULL, 0); |
| 243 |
– |
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 */ |
| 257 |
< |
if (!argv[i][2]) { |
| 258 |
< |
check(2,"s"); |
| 259 |
< |
loadfunc(argv[++i]); |
| 260 |
< |
break; |
| 261 |
< |
} |
| 255 |
> |
case 'f': /* force or format */ |
| 256 |
|
if (argv[i][2] == 'o') { |
| 257 |
|
check_bool(3,force_open); |
| 258 |
|
break; |
| 333 |
|
myRCmanager.LoadOctree(argv[argc-1]); |
| 334 |
|
// add to header |
| 335 |
|
myRCmanager.AddHeader(argc-1, argv); |
| 336 |
+ |
{ |
| 337 |
+ |
char buf[128] = "SOFTWARE= "; |
| 338 |
+ |
strcpy(buf+10, VersionID); |
| 339 |
+ |
myRCmanager.AddHeader(buf); |
| 340 |
+ |
} |
| 341 |
|
// prepare output files |
| 342 |
|
if (recover) |
| 343 |
|
myRCmanager.outOp = RCOrecover; |
| 348 |
|
// rval = # rows recovered |
| 349 |
|
rval = myRCmanager.PrepOutput(); |
| 350 |
|
// check if recovered everything |
| 351 |
< |
if (recover && rval >= myRCmanager.GetRowMax()) { |
| 351 |
> |
if (rval >= myRCmanager.GetRowMax()) { |
| 352 |
|
error(WARNING, "nothing left to compute"); |
| 353 |
|
quit(0); |
| 354 |
< |
} // add processes as requested |
| 356 |
< |
myRCmanager.SetThreadCount(nproc); |
| 357 |
< |
|
| 354 |
> |
} |
| 355 |
|
rxcontrib(rval); /* trace ray contributions (loop) */ |
| 356 |
|
|
| 357 |
|
quit(0); /* exit clean */ |
| 406 |
|
int n2go = myRCmanager.accum; |
| 407 |
|
|
| 408 |
|
switch (inpfmt) { |
| 409 |
< |
case 'a': // ASCII input |
| 409 |
> |
case 'a': // ASCII input |
| 410 |
|
if (!orig_dir) |
| 411 |
|
return skipWords(6*n2go); |
| 412 |
|
while (n2go-- > 0) { |
| 419 |
|
orig_dir += 2; |
| 420 |
|
} |
| 421 |
|
break; |
| 422 |
< |
case 'f': // float input |
| 422 |
> |
case 'f': // float input |
| 423 |
|
if (!orig_dir) |
| 424 |
|
return skipBytes(6*sizeof(float)*n2go); |
| 425 |
|
#ifdef SMLFLT |
| 426 |
|
if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) |
| 427 |
|
return false; |
| 428 |
+ |
orig_dir += 2*n2go; |
| 429 |
|
#else |
| 430 |
|
while (n2go-- > 0) { |
| 431 |
|
float fvecs[6]; |
| 437 |
|
} |
| 438 |
|
#endif |
| 439 |
|
break; |
| 440 |
< |
case 'd': // double input |
| 440 |
> |
case 'd': // double input |
| 441 |
|
if (!orig_dir) |
| 442 |
|
return skipBytes(6*sizeof(double)*n2go); |
| 443 |
|
#ifndef SMLFLT |
| 444 |
|
if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) |
| 445 |
|
return false; |
| 446 |
+ |
orig_dir += 2*n2go; |
| 447 |
|
#else |
| 448 |
|
while (n2go-- > 0) { |
| 449 |
|
double dvecs[6]; |
| 459 |
|
error(INTERNAL, "unsupported format in getRayBundle()"); |
| 460 |
|
return false; |
| 461 |
|
} |
| 462 |
< |
int warned = 0; // normalize directions |
| 464 |
< |
n2go = myRCmanager.accum; |
| 462 |
> |
n2go = myRCmanager.accum; // normalize directions |
| 463 |
|
while (n2go-- > 0) { |
| 464 |
|
orig_dir -= 2; |
| 465 |
< |
if (normalize(orig_dir[1]) == 0) |
| 468 |
< |
if (!warned++) |
| 469 |
< |
error(WARNING, "zero ray direction on input"); |
| 465 |
> |
normalize(orig_dir[1]); |
| 466 |
|
} |
| 467 |
|
return true; |
| 468 |
|
} |
| 490 |
|
} |
| 491 |
|
last_report = tstart = time(0); |
| 492 |
|
} |
| 493 |
< |
while (r < totRows) { // getting to work... |
| 493 |
> |
// start children as requested |
| 494 |
> |
myRCmanager.SetThreadCount(nproc); |
| 495 |
> |
|
| 496 |
> |
while (r < totRows) { // loop until done |
| 497 |
|
time_t tnow; |
| 498 |
|
if (!getRayBundle(odarr)) |
| 499 |
|
goto readerr; |
| 502 |
|
r++; |
| 503 |
|
if (report_intvl <= 0) |
| 504 |
|
continue; |
| 505 |
< |
if ((r < totRows) & ((tnow = time(0)) < last_report+report_intvl)) |
| 505 |
> |
if (r == totRows) // need to finish up? |
| 506 |
> |
myRCmanager.SetThreadCount(1); |
| 507 |
> |
tnow = time(0); |
| 508 |
> |
if ((r < totRows) & (tnow < last_report+report_intvl)) |
| 509 |
|
continue; |
| 510 |
|
sprintf(errmsg, "%.2f%% done after %.3f hours\n", |
| 511 |
< |
100.*r/totRows, (1./3600.)*(tnow - tstart)); |
| 511 |
> |
100.*myRCmanager.GetRowFinished()/totRows, |
| 512 |
> |
(1./3600.)*(tnow - tstart)); |
| 513 |
|
eputs(errmsg); |
| 514 |
|
last_report = tnow; |
| 515 |
|
} |
| 561 |
|
int code |
| 562 |
|
) |
| 563 |
|
{ |
| 564 |
< |
if (!code && myRCmanager.Ready()) // clean up on normal exit |
| 562 |
< |
code = myRCmanager.Cleanup(); |
| 564 |
> |
myRCmanager.FlushQueue(); // leave nothing in queue |
| 565 |
|
|
| 566 |
|
exit(code); |
| 567 |
|
} |