| 24 |
|
extern const char BIGEND[]; |
| 25 |
|
extern const char FMTSTR[]; |
| 26 |
|
|
| 27 |
– |
int contrib = 0; // computing contributions? |
| 28 |
– |
|
| 29 |
– |
int xres = 0; // horizontal (scan) size |
| 30 |
– |
int yres = 0; // vertical resolution |
| 31 |
– |
|
| 27 |
|
// new/exclusive, overwrite if exists, or recover data |
| 28 |
|
int RSDOflags[] = {RDSwrite|RDSexcl|RDSextend, RDSwrite|RDSextend, |
| 29 |
|
RDSread|RDSwrite}; |
| 35 |
|
struct RcontribMod { |
| 36 |
|
RcontribOutput * opl; // pointer to first output channel |
| 37 |
|
char * params; // parameters string |
| 38 |
< |
EPNODE * binv; // bin expression |
| 38 |
> |
EPNODE * binv; // bin expression (NULL if 1 bin) |
| 39 |
|
int nbins; // bin count this modifier |
| 40 |
|
int coffset; // column offset in bytes |
| 41 |
|
DCOLORV cbin[1]; // bin accumulator (extends struct) |
| 52 |
|
uint32 ac; // accumulation count |
| 53 |
|
}; |
| 54 |
|
|
| 55 |
< |
// Our default data share function |
| 61 |
< |
RdataShare * |
| 62 |
< |
defDataShare(const char *name, RCOutputOp op, size_t siz) |
| 63 |
< |
{ |
| 64 |
< |
return new RdataShareMap(name, RSDOflags[op], siz); |
| 65 |
< |
} |
| 55 |
> |
static const char ROW_DONE[] = "ROW FINISHED\n"; |
| 56 |
|
|
| 57 |
< |
// Allocate rcontrib accumulator |
| 58 |
< |
RcontribMod * |
| 57 |
> |
// allocate rcontrib accumulator |
| 58 |
> |
static RcontribMod * |
| 59 |
|
NewRcMod(const char *prms, const char *binexpr, int ncbins) |
| 60 |
|
{ |
| 61 |
< |
if (ncbins <= 0) return NULL; |
| 61 |
> |
if (binexpr && !*binexpr) binexpr = NULL; |
| 62 |
|
if (!prms) prms = ""; |
| 63 |
< |
if (!binexpr | (ncbins == 1)) |
| 64 |
< |
binexpr = "0"; |
| 65 |
< |
|
| 63 |
> |
if ((ncbins > 1) & !binexpr) { |
| 64 |
> |
error(USER, "missing bin expression"); |
| 65 |
> |
return NULL; |
| 66 |
> |
} |
| 67 |
> |
if (ncbins < 1) ncbins = 1; |
| 68 |
> |
|
| 69 |
|
RcontribMod * mp = (RcontribMod *)ecalloc(1, sizeof(RcontribMod) + |
| 70 |
|
sizeof(DCOLORV)*(NCSAMP*ncbins-1) + |
| 71 |
|
strlen(prms)+1); |
| 72 |
|
|
| 73 |
+ |
if (binexpr) { // get/check bin expression |
| 74 |
+ |
mp->binv = eparse(const_cast<char *>(binexpr)); |
| 75 |
+ |
if (mp->binv->type == NUM) { // constant expression (0)? |
| 76 |
+ |
if ((int)evalue(mp->binv) != 0) { |
| 77 |
+ |
sprintf(errmsg, "illegal non-zero constant for bin (%s)", |
| 78 |
+ |
binexpr); |
| 79 |
+ |
error(USER, errmsg); |
| 80 |
+ |
} |
| 81 |
+ |
if (ncbins > 1) { |
| 82 |
+ |
sprintf(errmsg, "bad bin count (%d should be 1)", ncbins); |
| 83 |
+ |
error(USER, errmsg); |
| 84 |
+ |
} |
| 85 |
+ |
epfree(mp->binv, true); |
| 86 |
+ |
mp->binv = NULL; |
| 87 |
+ |
prms = ""; |
| 88 |
+ |
ncbins = 1; |
| 89 |
+ |
} |
| 90 |
+ |
} |
| 91 |
|
mp->params = strcpy((char *)(mp->cbin + ncbins*NCSAMP), prms); |
| 81 |
– |
mp->binv = eparse(const_cast<char *>(binexpr)); |
| 92 |
|
mp->nbins = ncbins; |
| 93 |
|
return mp; |
| 94 |
|
} |
| 95 |
|
|
| 96 |
< |
// Free an RcontribMod |
| 96 |
> |
// Free an RcontribMod (public for RcontribSimulManager constructor) |
| 97 |
|
void |
| 98 |
|
FreeRcMod(void *p) |
| 99 |
|
{ |
| 100 |
|
if (!p) return; |
| 101 |
< |
epfree((*(RcontribMod *)p).binv, true); |
| 101 |
> |
EPNODE * bep = (*(RcontribMod *)p).binv; |
| 102 |
> |
if (bep) epfree(bep, true); |
| 103 |
|
efree(p); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
+ |
// Get format identifier |
| 107 |
+ |
const char * |
| 108 |
+ |
formstr(int f) |
| 109 |
+ |
{ |
| 110 |
+ |
switch (f) { |
| 111 |
+ |
case 'a': return("ascii"); |
| 112 |
+ |
case 'f': return("float"); |
| 113 |
+ |
case 'd': return("double"); |
| 114 |
+ |
case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); |
| 115 |
+ |
} |
| 116 |
+ |
return("unknown"); |
| 117 |
+ |
} |
| 118 |
+ |
|
| 119 |
+ |
// Standard file data share function |
| 120 |
+ |
RdataShare * |
| 121 |
+ |
fileDataShare(const char *name, RCOutputOp op, size_t siz) |
| 122 |
+ |
{ |
| 123 |
+ |
if (op == RCOrecover && access(name, R_OK|W_OK) < 0) { |
| 124 |
+ |
sprintf(errmsg, "cannot recover from '%s'", name); |
| 125 |
+ |
error(SYSTEM, errmsg); |
| 126 |
+ |
return NULL; |
| 127 |
+ |
} |
| 128 |
+ |
return new RdataShareFile(name, RSDOflags[op], siz); |
| 129 |
+ |
} |
| 130 |
+ |
|
| 131 |
+ |
// Memory-mapped data share function |
| 132 |
+ |
RdataShare * |
| 133 |
+ |
mapDataShare(const char *name, RCOutputOp op, size_t siz) |
| 134 |
+ |
{ |
| 135 |
+ |
if (op == RCOrecover && access(name, R_OK|W_OK) < 0) { |
| 136 |
+ |
sprintf(errmsg, "cannot recover from '%s'", name); |
| 137 |
+ |
error(SYSTEM, errmsg); |
| 138 |
+ |
return NULL; |
| 139 |
+ |
} |
| 140 |
+ |
return new RdataShareMap(name, RSDOflags[op], siz); |
| 141 |
+ |
} |
| 142 |
+ |
|
| 143 |
|
// Set output format ('f', 'd', or 'c') |
| 144 |
|
bool |
| 145 |
|
RcontribSimulManager::SetDataFormat(int ty) |
| 183 |
|
if (!mp) |
| 184 |
|
return 0; // not in our modifier list |
| 185 |
|
|
| 186 |
< |
worldfunc(RCCONTEXT, r); // compute bin # |
| 187 |
< |
set_eparams(mp->params); |
| 188 |
< |
double bval = evalue(mp->binv); |
| 189 |
< |
if (bval <= -.5) |
| 190 |
< |
return 0; // silently ignore negative bin index |
| 191 |
< |
DCOLORV * dvp = (*mp)[int(bval + .5)]; |
| 186 |
> |
int bi = 0; // get bin index |
| 187 |
> |
if (mp->binv) { |
| 188 |
> |
worldfunc(RCCONTEXT, r); |
| 189 |
> |
set_eparams(mp->params); |
| 190 |
> |
double bval = evalue(mp->binv); |
| 191 |
> |
if (bval <= -.5) |
| 192 |
> |
return 0; // silently ignore negative bin index |
| 193 |
> |
bi = int(bval + .5); |
| 194 |
> |
} |
| 195 |
> |
DCOLORV * dvp = (*mp)[bi]; |
| 196 |
|
if (!dvp) { |
| 197 |
< |
sprintf(errmsg, "bad bin number for '%s' (%.1f ignored)", mname, bval); |
| 197 |
> |
sprintf(errmsg, "bad bin number for '%s' (%d ignored)", mname, bi); |
| 198 |
|
error(WARNING, errmsg); |
| 199 |
|
return 0; |
| 200 |
|
} |
| 201 |
|
SCOLOR contr; |
| 202 |
|
raycontrib(contr, r, PRIMARY); // compute coefficient |
| 203 |
< |
if (contrib) |
| 203 |
> |
if (rcp->HasFlag(RCcontrib)) |
| 204 |
|
smultscolor(contr, r->rcol); // -> value contribution |
| 205 |
+ |
|
| 206 |
|
for (int i = 0; i < NCSAMP; i++) |
| 207 |
|
*dvp++ += contr[i]; // accumulate color/spectrum |
| 208 |
|
return 1; |
| 231 |
|
RcontribSimulManager::AddModifier(const char *modn, const char *outspec, |
| 232 |
|
const char *prms, const char *binval, int bincnt) |
| 233 |
|
{ |
| 234 |
< |
if (!modn | !outspec | (bincnt <= 0) || !*modn | !*outspec) { |
| 234 |
> |
if (!modn | !outspec || !*modn | !*outspec) { |
| 235 |
|
error(WARNING, "ignoring bad call to AddModifier()"); |
| 236 |
|
return false; |
| 237 |
|
} |
| 238 |
+ |
if (*outspec == '!') { |
| 239 |
+ |
error(USER, "command output not supported by RcontribSimulManager"); |
| 240 |
+ |
return false; |
| 241 |
+ |
} |
| 242 |
|
if (!nChan) { // initial call? |
| 243 |
+ |
if ((xres < 0) | (yres <= 0)) { |
| 244 |
+ |
error(USER, "xres, yres must be set before first modifier"); |
| 245 |
+ |
return false; |
| 246 |
+ |
} |
| 247 |
|
if (!SetDataFormat(dtyp)) |
| 248 |
|
return false; |
| 249 |
|
nChan = NCSAMP; |
| 250 |
|
} else if (nChan != NCSAMP) { |
| 251 |
< |
error(INTERNAL, "number of spectral channels must be fixed"); |
| 251 |
> |
error(USER, "# spectral channels must be fixed in AddModifier()"); |
| 252 |
|
return false; |
| 253 |
|
} |
| 254 |
|
if (Ready()) { |
| 271 |
|
const int binndx = hasFormat(outspec, "diouxX"); |
| 272 |
|
int bin0 = 0; |
| 273 |
|
char fnbuf[512]; |
| 274 |
< |
if (!modndx | (modndx > binndx)) |
| 274 |
> |
if (!modndx || (binndx > 0) & (modndx > binndx)) |
| 275 |
|
sprintf(fnbuf, outspec, bin0, modn); |
| 276 |
|
else |
| 277 |
|
sprintf(fnbuf, outspec, modn, bin0); |
| 300 |
|
mp->opl = op; // first (maybe only) output channel |
| 301 |
|
if (modndx) // remember modifier if part of name |
| 302 |
|
op->omod = lp->key; |
| 303 |
< |
if (binndx > 0) { // append output image/bin list |
| 303 |
> |
if (binndx) { // append output image/bin list |
| 304 |
|
op->rowBytes += dsiz; |
| 305 |
|
op->obin = bin0; |
| 306 |
|
for (bincnt = 1; bincnt < mp->nbins; bincnt++) { |
| 307 |
< |
if (!modndx | (modndx > binndx)) |
| 307 |
> |
if (!modndx || (binndx > 0) & (modndx > binndx)) |
| 308 |
|
sprintf(fnbuf, outspec, bin0+bincnt, modn); |
| 309 |
|
else |
| 310 |
|
sprintf(fnbuf, outspec, modn, bin0+bincnt); |
| 323 |
|
op->rowBytes += dsiz; |
| 324 |
|
} |
| 325 |
|
} else // else send all results to this channel |
| 326 |
< |
op->rowBytes += bincnt*dsiz; |
| 326 |
> |
op->rowBytes += mp->nbins*dsiz; |
| 327 |
|
return true; |
| 328 |
|
} |
| 329 |
|
|
| 344 |
|
} |
| 345 |
|
char mod[MAXSTR]; |
| 346 |
|
while (fgetword(mod, sizeof(mod), fp)) |
| 347 |
< |
if (!AddModifier(mod, outspec, prms, binval, bincnt)) |
| 347 |
> |
if (!AddModifier(mod, outspec, prms, binval, bincnt)) { |
| 348 |
> |
fclose(fp); |
| 349 |
|
return false; |
| 350 |
+ |
} |
| 351 |
|
fclose(fp); |
| 352 |
|
return true; |
| 353 |
|
} |
| 354 |
|
|
| 355 |
+ |
// call-back to check if modifier has been loaded |
| 356 |
+ |
static int |
| 357 |
+ |
checkModExists(const LUENT *lp, void *p) |
| 358 |
+ |
{ |
| 359 |
+ |
OBJECT mod = modifier(lp->key); |
| 360 |
+ |
|
| 361 |
+ |
if ((mod != OVOID) & (mod < nsceneobjs)) |
| 362 |
+ |
return 1; |
| 363 |
+ |
|
| 364 |
+ |
sprintf(errmsg, "tracked modifier '%s' not found in main scene", lp->key); |
| 365 |
+ |
error(WARNING, errmsg); |
| 366 |
+ |
return 0; |
| 367 |
+ |
} |
| 368 |
+ |
|
| 369 |
|
// Prepare output channels and return # completed rows |
| 370 |
|
int |
| 371 |
|
RcontribSimulManager::PrepOutput() |
| 372 |
|
{ |
| 373 |
|
if (!outList || !RtraceSimulManager::Ready()) { |
| 374 |
< |
error(INTERNAL, "PrepOutput() called before octree & modifiers assigned"); |
| 374 |
> |
error(INTERNAL, "PrepOutput() called before octree & modifiers set"); |
| 375 |
|
return -1; |
| 376 |
|
} |
| 377 |
+ |
if (!cdsF) { |
| 378 |
+ |
error(INTERNAL, "missing RdataShare constructor call (cdsF)"); |
| 379 |
+ |
return -1; |
| 380 |
+ |
} |
| 381 |
+ |
if (lu_doall(&modLUT, checkModExists, NULL) < 0) |
| 382 |
+ |
return -1; |
| 383 |
+ |
|
| 384 |
+ |
outList->nRows = yres * (xres + !xres); // all outputs have same #rows |
| 385 |
|
int remWarnings = 20; |
| 386 |
|
for (RcontribOutput *op = outList; op; op = op->next) { |
| 387 |
|
if (op->rData) { |
| 388 |
|
error(INTERNAL, "output channel already open in PrepOutput()"); |
| 389 |
|
return -1; |
| 390 |
|
} |
| 391 |
< |
op->nRows = yres * (xres + !xres); |
| 391 |
> |
op->nRows = outList->nRows; |
| 392 |
|
op->rData = (*cdsF)(op->ofname, outOp, |
| 393 |
|
GetHeadLen()+1024 + op->nRows*op->rowBytes); |
| 394 |
|
freeqstr(op->ofname); op->ofname = NULL; |
| 397 |
|
if (rd < 0) |
| 398 |
|
return -1; |
| 399 |
|
if (rd >= op->nRows) { |
| 400 |
< |
if (remWarnings >= 0) { |
| 401 |
< |
sprintf(errmsg, "recovered output '%s' already done", |
| 400 |
> |
if (remWarnings > 0) { |
| 401 |
> |
sprintf(errmsg, "recovered output '%s' is complete", |
| 402 |
|
op->GetName()); |
| 403 |
< |
error(WARNING, remWarnings ? errmsg : "etc..."); |
| 319 |
< |
remWarnings--; |
| 403 |
> |
error(WARNING, --remWarnings ? errmsg : "etc..."); |
| 404 |
|
} |
| 405 |
|
rd = op->nRows; |
| 406 |
|
} |
| 414 |
|
} |
| 415 |
|
rowsDone.NewBitMap(outList->nRows); // create row completion map |
| 416 |
|
rowsDone.ClearBits(0, rInPos, true); |
| 417 |
< |
return rInPos; |
| 417 |
> |
return nrDone = rInPos; |
| 418 |
|
} |
| 419 |
|
|
| 420 |
|
// Create header in open write-only channel |
| 442 |
|
strcpy(hdr+begData, ROWZEROSTR); |
| 443 |
|
rowCountPos = begData+LNROWSTR; |
| 444 |
|
begData += sizeof(ROWZEROSTR)-1; |
| 445 |
< |
if (!xres | (rowBytes > esiz)) { |
| 445 |
> |
if (!rcp->xres | (rowBytes > esiz)) { |
| 446 |
|
sprintf(hdr+begData, "NCOLS=%d\n", int(rowBytes/esiz)); |
| 447 |
|
begData += strlen(hdr+begData); |
| 448 |
|
} |
| 449 |
|
sprintf(hdr+begData, "%s%d\n", NCOMPSTR, NCSAMP); |
| 450 |
|
begData += strlen(hdr+begData); |
| 451 |
|
if (NCSAMP > 3) { |
| 452 |
< |
sprintf(hdr+begData, "%s %f %f %f %f\n", WLSPLTSTR, |
| 452 |
> |
sprintf(hdr+begData, "%s %g %g %g %g\n", WLSPLTSTR, |
| 453 |
|
WLPART[0], WLPART[1], WLPART[2], WLPART[3]); |
| 454 |
|
begData += strlen(hdr+begData); |
| 455 |
|
} |
| 480 |
|
hdr[begData++] = ' '; |
| 481 |
|
hdr[begData++] = '\n'; // EOL for data format |
| 482 |
|
hdr[begData++] = '\n'; // end of nominal header |
| 483 |
< |
if ((xres > 0) & (rowBytes == esiz)) { // tack on resolution string? |
| 484 |
< |
sprintf(hdr+begData, PIXSTDFMT, yres, xres); |
| 483 |
> |
if ((rcp->xres > 0) & (rowBytes == esiz)) { // tack on resolution string? |
| 484 |
> |
sprintf(hdr+begData, PIXSTDFMT, rcp->yres, rcp->xres); |
| 485 |
|
begData += strlen(hdr+begData); |
| 486 |
|
} |
| 487 |
|
return rData->ReleaseMemory(hdr, RDSwrite); |
| 527 |
|
return -1; |
| 528 |
|
} |
| 529 |
|
// check format |
| 530 |
< |
if (!(cp = findArgs(hdr, FMTSTR, begData)) || strcmp(cp, formstr(etyp))) { |
| 530 |
> |
if (!(cp = findArgs(hdr, FMTSTR, begData)) || |
| 531 |
> |
strncmp(cp, formstr(etyp), strlen(formstr(etyp)))) { |
| 532 |
|
sprintf(errmsg, "expected %s%s in '%s'", FMTSTR, formstr(etyp), GetName()); |
| 533 |
|
error(USER, errmsg); |
| 534 |
|
return -1; |
| 535 |
|
} |
| 536 |
|
// check #columns |
| 537 |
< |
if (((cp = findArgs(hdr, "NCOLS=", begData)) && atoi(cp)*esiz != rowBytes) || |
| 538 |
< |
!xres | (rowBytes > esiz)) { |
| 539 |
< |
sprintf(errmsg, "expected NCOLS=%d in '%s'", |
| 455 |
< |
int(rowBytes/esiz), GetName()); |
| 537 |
> |
if ((cp = findArgs(hdr, "NCOLS=", begData)) ? (atoi(cp)*esiz != rowBytes) |
| 538 |
> |
: (!rcp->xres | (rowBytes > esiz))) { |
| 539 |
> |
sprintf(errmsg, "expected NCOLS=%d in '%s'", int(rowBytes/esiz), GetName()); |
| 540 |
|
error(USER, errmsg); |
| 541 |
|
return -1; |
| 542 |
|
} |
| 549 |
|
rowCountPos = cp - hdr; |
| 550 |
|
int rlast = atoi(cp); |
| 551 |
|
begData++; // advance past closing EOL |
| 552 |
< |
if ((xres > 0) & (rowBytes == esiz)) { // check/skip resolution string? |
| 552 |
> |
if ((rcp->xres > 0) & (rowBytes == esiz)) { // check/skip resolution string? |
| 553 |
|
char rbuf[64]; |
| 554 |
< |
sprintf(rbuf, PIXSTDFMT, yres, xres); |
| 554 |
> |
sprintf(rbuf, PIXSTDFMT, rcp->yres, rcp->xres); |
| 555 |
|
int rlen = strlen(rbuf); |
| 556 |
|
if (strncmp(rbuf, hdr+begData, rlen)) { |
| 557 |
|
sprintf(errmsg, "bad resolution string in '%s'", GetName()); |
| 578 |
|
return false; |
| 579 |
|
|
| 580 |
|
rowsDone.ClearBits(r, rInPos-r, false); |
| 581 |
< |
rInPos = r; |
| 581 |
> |
nrDone = rInPos = r; |
| 582 |
|
return true; |
| 583 |
|
} |
| 584 |
|
|
| 625 |
|
} |
| 626 |
|
} break; |
| 627 |
|
default: |
| 628 |
< |
error(CONSISTENCY, "unsupported output type in sendModContrib()"); |
| 628 |
> |
error(CONSISTENCY, "unsupported output type in putModContrib()"); |
| 629 |
|
return -1; |
| 630 |
|
} |
| 631 |
|
// clear for next tally |
| 644 |
|
return 0; |
| 645 |
|
} |
| 646 |
|
if (nkids > 0) { // in parent process? |
| 647 |
< |
int k = GetChild(); // updates output rows |
| 648 |
< |
if (k < 0) return -1; // can't really happen |
| 647 |
> |
int k = GetChild(false); // updates output rows |
| 648 |
> |
if (k < 0) return -1; // someone died? |
| 649 |
|
RowAssignment rass; |
| 650 |
|
rass.row = kidRow[k] = rInPos++; |
| 651 |
|
rass.ac = accum; |
| 690 |
|
return -1; |
| 691 |
|
// take inventory |
| 692 |
|
int pn, n = 0; |
| 693 |
< |
fd_set writeset, errset; |
| 694 |
< |
FD_ZERO(&writeset); FD_ZERO(&errset); |
| 693 |
> |
fd_set readset, errset; |
| 694 |
> |
FD_ZERO(&readset); FD_ZERO(&errset); |
| 695 |
|
for (pn = nkids; pn--; ) { |
| 696 |
|
if (kidRow[pn] < 0) { // child already ready? |
| 697 |
|
if (forceWait) continue; |
| 698 |
|
return pn; // good enough |
| 699 |
|
} |
| 700 |
< |
FD_SET(kid[pn].w, &writeset); // will check on this one |
| 701 |
< |
FD_SET(kid[pn].w, &errset); |
| 702 |
< |
if (kid[pn].w >= n) |
| 703 |
< |
n = kid[pn].w + 1; |
| 700 |
> |
FD_SET(kid[pn].r, &readset); // will check on this one |
| 701 |
> |
FD_SET(kid[pn].r, &errset); |
| 702 |
> |
if (kid[pn].r >= n) |
| 703 |
> |
n = kid[pn].r + 1; |
| 704 |
|
} |
| 705 |
|
if (!n) // every child is idle? |
| 706 |
|
return -1; |
| 707 |
|
// wait on "busy" child(ren) |
| 708 |
< |
while ((n = select(n, NULL, &writeset, &errset, NULL)) <= 0) |
| 708 |
> |
while ((n = select(n, &readset, NULL, &errset, NULL)) <= 0) |
| 709 |
|
if (errno != EINTR) { |
| 710 |
|
error(SYSTEM, "select call failed in GetChild()"); |
| 711 |
|
return -1; |
| 712 |
|
} |
| 713 |
+ |
char buf[sizeof(ROW_DONE)] = "X"; |
| 714 |
|
pn = -1; // get flags set by select |
| 715 |
|
for (n = nkids; n--; ) |
| 716 |
|
if (kidRow[n] >= 0 && |
| 717 |
< |
FD_ISSET(kid[n].w, &writeset) | |
| 718 |
< |
FD_ISSET(kid[n].w, &errset)) { |
| 717 |
> |
FD_ISSET(kid[n].r, &readset) | |
| 718 |
> |
FD_ISSET(kid[n].r, &errset)) { |
| 719 |
> |
// check for error |
| 720 |
> |
if (FD_ISSET(kid[n].r, &errset) || |
| 721 |
> |
read(kid[n].r, buf, sizeof(ROW_DONE)) <= 0 || |
| 722 |
> |
memcmp(buf, ROW_DONE, sizeof(ROW_DONE))) |
| 723 |
> |
return -1; |
| 724 |
|
// update output row counts |
| 725 |
|
UpdateRowsDone(kidRow[n]); |
| 726 |
< |
kidRow[n] = -1; // flag it available |
| 726 |
> |
kidRow[n] = -1; // flag child available |
| 727 |
|
pn = n; |
| 728 |
|
} |
| 729 |
|
return pn; |
| 737 |
|
error(WARNING, "redundant call to UpdateRowsDone()"); |
| 738 |
|
return false; |
| 739 |
|
} |
| 740 |
< |
int nDone = GetRowFinished(); |
| 741 |
< |
if (nDone <= r) |
| 740 |
> |
GetRowFinished(); |
| 741 |
> |
if (nrDone <= r) |
| 742 |
|
return true; // nothing to update, yet |
| 743 |
|
for (RcontribOutput *op = outList; op; op = op->next) |
| 744 |
< |
if (!op->SetRowsDone(nDone)) |
| 744 |
> |
if (!op->SetRowsDone(nrDone)) |
| 745 |
|
return false; |
| 746 |
|
return true; // up-to-date |
| 747 |
|
} |
| 761 |
|
error(CONSISTENCY, "bad accumulator count in child"); |
| 762 |
|
exit(1); |
| 763 |
|
} |
| 764 |
< |
if (rass.ac > accum) |
| 765 |
< |
vecList = (FVECT *)erealloc(vecList, |
| 766 |
< |
sizeof(FVECT)*2*rass.ac); |
| 764 |
> |
if (rass.ac > accum) { |
| 765 |
> |
efree(vecList); |
| 766 |
> |
vecList = (FVECT *)emalloc(sizeof(FVECT)*2*rass.ac); |
| 767 |
> |
} |
| 768 |
|
accum = rass.ac; |
| 769 |
|
rInPos = rass.row; |
| 770 |
|
|
| 774 |
|
|
| 775 |
|
if (ComputeRecord(vecList) <= 0) |
| 776 |
|
exit(1); |
| 777 |
+ |
// signal this row is done |
| 778 |
+ |
if (write(1, ROW_DONE, sizeof(ROW_DONE)) != sizeof(ROW_DONE)) |
| 779 |
+ |
exit(1); |
| 780 |
|
} |
| 781 |
|
if (nr) { |
| 782 |
|
error(SYSTEM, "read error in child process"); |
| 802 |
|
fflush(stdout); // shouldn't use, anyway |
| 803 |
|
while (nkids < n2go) { |
| 804 |
|
kid[nkids] = sp_inactive; |
| 711 |
– |
kid[nkids].w = dup(1); |
| 712 |
– |
kid[nkids].flags |= PF_FILT_OUT; |
| 805 |
|
int rv = open_process(&kid[nkids], NULL); |
| 806 |
|
if (!rv) { // in child process? |
| 807 |
< |
while (nkids-- > 0) |
| 807 |
> |
while (nkids-- > 0) { |
| 808 |
> |
close(kid[nkids].r); |
| 809 |
|
close(kid[nkids].w); |
| 810 |
+ |
} |
| 811 |
|
free(kid); free(kidRow); |
| 812 |
|
kid = NULL; kidRow = NULL; |
| 719 |
– |
rowsDone.NewBitMap(0); |
| 813 |
|
RunChild(); // should never return |
| 814 |
|
_exit(1); |
| 815 |
|
} |
| 858 |
|
return 0; |
| 859 |
|
} |
| 860 |
|
if (nt < 0) |
| 861 |
< |
return nkids; |
| 861 |
> |
return NThreads(); |
| 862 |
|
if (!nt) nt = GetNCores(); |
| 863 |
|
int status = 0; |
| 864 |
|
if (nt == 1) |
| 871 |
|
sprintf(errmsg, "non-zero (%d) status from child", status); |
| 872 |
|
error(WARNING, errmsg); |
| 873 |
|
} |
| 874 |
< |
return nkids; |
| 874 |
> |
return NThreads(); |
| 875 |
|
} |