--- ray/src/rt/rcontrib.c 2012/06/09 07:16:47 2.1 +++ ray/src/rt/rcontrib.c 2012/06/13 00:16:42 2.5 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcontrib.c,v 2.1 2012/06/09 07:16:47 greg Exp $"; +static const char RCSid[] = "$Id: rcontrib.c,v 2.5 2012/06/13 00:16:42 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials @@ -11,6 +11,8 @@ static const char RCSid[] = "$Id: rcontrib.c,v 2.1 201 #include "otypes.h" #include "platform.h" +char *shm_boundary = NULL; /* boundary of shared memory */ + CUBE thescene; /* our scene */ OBJECT nsceneobjs; /* number of objects in our scene */ @@ -23,7 +25,7 @@ void (*trace)() = trace_contrib; int do_irrad = 0; /* compute irradiance? */ -int rand_samp = 0; /* pure Monte Carlo sampling? */ +int rand_samp = 1; /* pure Monte Carlo sampling? */ double dstrsrc = 0.0; /* square source distribution */ double shadthresh = .03; /* shadow threshold */ @@ -43,8 +45,8 @@ double specjitter = 1.; /* specular sampling jitter * int backvis = 1; /* back face visibility */ -int maxdepth = 8; /* maximum recursion depth */ -double minweight = 5e-4; /* minimum ray weight */ +int maxdepth = -10; /* maximum recursion depth */ +double minweight = 2e-3; /* minimum ray weight */ char *ambfile = NULL; /* ambient file name */ COLOR ambval = BLKCOLOR; /* ambient value */ @@ -61,29 +63,9 @@ int account; /* current accumulation count */ RNUMBER raysleft; /* number of rays left to trace */ long waitflush; /* how long until next flush */ -int lastray = 0; /* last ray number sent */ -int lastdone = 0; /* last ray output */ +RNUMBER lastray = 0; /* last ray number sent */ +RNUMBER lastdone = 0; /* last ray output */ -/* Close output stream and free record */ -static void -closestream(void *p) -{ - STREAMOUT *sop = (STREAMOUT *)p; - int status = 0; - if (sop->outpipe) - status = pclose(sop->ofp); - else if (sop->ofp != stdout) - status = fclose(sop->ofp); - if (status) - error(SYSTEM, "error closing output stream"); - free(p); -} - -LUTAB ofiletab = LU_SINIT(free,closestream); /* output file table */ - -#define OF_MODIFIER 01 -#define OF_BIN 02 - static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); } LUTAB modconttab = LU_SINIT(NULL,mcfree); /* modifier lookup table */ @@ -222,18 +204,14 @@ rcinit() if (nproc > MAXPROCESS) sprintf(errmsg, "too many processes requested -- reducing to %d", nproc = MAXPROCESS); - + if (nproc > 1) { + preload_objs(); /* preload auxiliary data */ + /* set shared memory boundary */ + shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY"); + } if ((nproc > 1) & (accumulate <= 0)) - zero_record(0); /* prime our queue to accumulate */ + put_zero_record(0); /* prime our queue to accumulate */ - if (recover) { /* recover previous output? */ - if (accumulate <= 0) { - reload_output(); - if ((nproc > 1) & (accumulate <= 0)) - queue_modifiers(); - } else - recover_output(); - } if (yres > 0) { /* set up flushing & ray counts */ if (xres > 0) raysleft = (RNUMBER)xres*yres; @@ -248,9 +226,20 @@ rcinit() for (i = 0; i < nsources; i++) source[i].sflags |= SFOLLOW; - if (nproc == 1 || in_rchild()) /* single process or child */ + if (nproc > 1 && in_rchild()) /* forked child? */ return; /* return to main processing loop */ + if (recover) { /* recover previous output? */ + if (accumulate <= 0) { + reload_output(); + if (nproc > 1) + queue_modifiers(); + } else + recover_output(); + } + if (nproc == 1) /* single process? */ + return; + parental_loop(); /* else run controller */ quit(0); /* parent musn't return! */ } @@ -356,15 +345,15 @@ rcontrib() static int ignore_warning_given = 0; FVECT orig, direc; double d; - /* initialize & fork */ + /* initialize (& fork more of us) */ rcinit(); /* load rays from stdin & process */ #ifdef getc_unlocked - flockfile(stdin); /* avoid lock/unlock overhead */ + flockfile(stdin); /* avoid mutex overhead */ #endif while (getvec(orig) == 0 && getvec(direc) == 0) { d = normalize(direc); - if ((d == 0.0) & (accumulate != 1)) { + if (nchild != -1 && (d == 0.0) & (accumulate != 1)) { if (!ignore_warning_given++) error(WARNING, "dummy ray(s) ignored during accumulation\n"); @@ -376,6 +365,7 @@ rcontrib() if (d == 0.0) { /* zero ==> flush */ if ((yres <= 0) | (xres <= 0)) waitflush = 1; /* flush right after */ + account = 1; } else { /* else compute */ eval_ray(orig, direc, lim_dist ? d : 0.0); } @@ -384,7 +374,7 @@ rcontrib() if (raysleft && !--raysleft) break; /* preemptive EOI */ } - if (accumulate <= 0 || account < accumulate) { + if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) { if (account < accumulate) { error(WARNING, "partial accumulation in final record"); accumulate -= account;