--- ray/src/util/rad.c 2009/02/09 16:41:29 2.92 +++ ray/src/util/rad.c 2010/10/08 22:11:57 2.99 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rad.c,v 2.92 2009/02/09 16:41:29 greg Exp $"; +static const char RCSid[] = "$Id: rad.c,v 2.99 2010/10/08 22:11:57 greg Exp $"; #endif /* * Executive program for oconv, rpict and pfilt @@ -116,11 +116,14 @@ int sayview = 0; /* print view out */ char *rvdevice = NULL; /* rvu output device */ char *viewselect = NULL; /* specific view only */ +#define DEF_RPICT_PATH "rpict" /* default rpict path */ + /* command paths */ char c_oconv[256] = "oconv"; char c_mkillum[256] = "mkillum"; char c_rvu[256] = "rvu"; -char c_rpict[256] = "rpict"; +char c_rpict[256] = DEF_RPICT_PATH; +char c_rpiece[] = "rpiece"; char c_pfilt[256] = "pfilt"; int overture = 0; /* overture calculation needed */ @@ -162,7 +165,7 @@ static int touch(char *fn); static int runcom(char *cs); static int rmfile(char *fn); static int mvfile(char *fold, char *fnew); -static int next_process(void); +static int next_process(int reserve); static void wait_process(int all); static void finish_process(void); static void badvalue(int vc); @@ -218,9 +221,6 @@ main( if (i >= argc) goto userr; rifname = argv[i]; - /* check command-line options */ - if ((nprocs > 1) & (viewselect != NULL) & (rvdevice == NULL)) - nprocs = 1; /* assign Radiance root file name */ rootname(radname, rifname); /* load variable values */ @@ -751,7 +751,7 @@ lowqopts( /* low quality rendering options */ op = addarg(op, "-ds .4"); else op = addarg(op, "-ds 0"); - op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5"); + op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5"); if (vdef(AMBFILE)) { sprintf(op, " -af %s", vval(AMBFILE)); op += strlen(op); @@ -826,7 +826,7 @@ medqopts( /* medium quality rendering options */ op = addarg(op, "-ds .2 -dj .9"); else op = addarg(op, "-ds .3"); - op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1"); + op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss .7 -st .1"); if ( (overture = vint(INDIRECT)) ) { sprintf(op, " -ab %d", overture); op += strlen(op); @@ -904,7 +904,7 @@ hiqopts( /* high quality rendering options */ op = addarg(op, "-ds .1 -dj .9"); else op = addarg(op, "-ds .2"); - op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01"); + op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 1 -st .01"); sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); op += strlen(op); if (vdef(AMBFILE)) { @@ -1158,7 +1158,8 @@ getview( /* get view n, or NULL if none */ goto numview; } if (viewselect[0] == '-') { /* already specified */ - if (vn != NULL) *vn = '\0'; + if (vn != NULL) + strcpy(vn, "0"); return(viewselect); } if (vn != NULL) { @@ -1259,10 +1260,11 @@ rpict( /* run rpict and pfilt for each view */ char *po ) { - char combuf[PATH_MAX]; +#define do_rpiece (sfile[0]!='\0') + char combuf[4*PATH_MAX+512]; char rawfile[PATH_MAX], picfile[PATH_MAX]; char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; - char rppopt[128], *pfile = NULL; + char rppopt[128], sfile[64], *pfile = NULL; char pfopts[128]; char vs[32], *vw; int vn, mult; @@ -1309,18 +1311,29 @@ rpict( /* run rpict and pfilt for each view */ badvalue(REPORT); } /* set up parallel rendering */ - if ((nprocs > 1) & (!vdef(ZFILE))) { - strcpy(rppopt, "-S 1 -PP pfXXXXXX"); - pfile = rppopt+9; - if (mktemp(pfile) == NULL) + sfile[0] = '\0'; + if ((nprocs > 1) & !touchonly & !vdef(ZFILE) && + getview(0, vs) != NULL) { + if (!strcmp(c_rpict, DEF_RPICT_PATH) && + getview(1, NULL) == NULL) { + sprintf(sfile, "rpsync_%s.txt", vs); + strcpy(rppopt, "-PP pfXXXXXX"); + } else { + strcpy(rppopt, "-S 1 -PP pfXXXXXX"); + } + pfile = rppopt + strlen(rppopt) - 8; + if (mktemp(pfile) == NULL) { + if (do_rpiece) { + fprintf(stderr, "%s: cannot create\n", pfile); + quit(1); + } pfile = NULL; + } } vn = 0; /* do each view */ while ((vw = getview(vn++, vs)) != NULL) { if (sayview) myprintview(vw, stdout); - if (!vs[0]) - sprintf(vs, "%d", vn); sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs); if (vdef(ZFILE)) sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs); @@ -1342,17 +1355,43 @@ rpict( /* run rpict and pfilt for each view */ touch(picfile); continue; } - if (next_process()) { /* parallel running? */ + /* parallel running? */ + if (do_rpiece) { + if (rfdt < oct1date || !fdate(sfile)) { + int xdiv = 8+nprocs/3, ydiv = 8+nprocs/3; + rfdt = 0; /* start fresh */ + if (!silent) + printf("\techo %d %d > %s\n", + xdiv, ydiv, sfile); + if ((fp = fopen(sfile, "w")) == NULL) { + fprintf(stderr, "%s: cannot create\n", + sfile); + quit(1); + } + fprintf(fp, "%d %d\n", xdiv, ydiv); + fclose(fp); + } + } else if (next_process(0)) { if (pfile != NULL) - sleep(20); + sleep(10); continue; - } + } else if (!inchild()) + pfile = NULL; /* XXX Remember to call finish_process() */ /* build rpict command */ - if (rfdt >= oct1date) { /* recover */ - sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict, - rep, opts, po, zopt, rawfile, oct1name); - if (runcom(combuf)) /* run rpict */ + if (rfdt >= oct1date) { /* already in progress */ + if (do_rpiece) { + sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s", + c_rpiece, sfile, rppopt, rep, vw, + res, opts, po, rawfile, oct1name); + while (next_process(1)) { + sleep(10); + combuf[strlen(c_rpiece)+2] = 'F'; + } + } else + sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict, + rep, opts, po, zopt, rawfile, oct1name); + if (runcom(combuf)) /* run rpict/rpiece */ goto rperror; } else { if (overture) { /* run overture calculation */ @@ -1360,38 +1399,55 @@ rpict( /* run rpict and pfilt for each view */ "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", c_rpict, rep, vw, opts, oct1name, overfile); + if (do_rpiece) + while (next_process(1)) + sleep(5); if (runcom(combuf)) { fprintf(stderr, "%s: error in overture for view %s\n", progname, vs); quit(1); } + if (do_rpiece) { + finish_process(); + wait_process(1); + } #ifndef NULL_DEVICE rmfile(overfile); #endif } - sprintf(combuf, "%s%s %s %s%s%s%s %s > %s", - c_rpict, rep, vw, res, opts, po, - zopt, oct1name, rawfile); - if (pfile != NULL && inchild()) { - /* rpict persistent mode */ + if (do_rpiece) { + sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s", + c_rpiece, sfile, rppopt, rep, vw, + res, opts, po, rawfile, oct1name); + while (next_process(1)) + sleep(10); + } else { + sprintf(combuf, "%s%s %s %s%s%s%s %s > %s", + c_rpict, rep, vw, res, opts, po, + zopt, oct1name, rawfile); + } + if ((pfile != NULL) & !do_rpiece) { if (!silent) printf("\t%s\n", combuf); fflush(stdout); sprintf(combuf, "%s%s %s %s%s%s %s > %s", - c_rpict, rep, rppopt, res, opts, - po, oct1name, rawfile); + c_rpict, rep, rppopt, res, + opts, po, oct1name, rawfile); fp = popen(combuf, "w"); if (fp == NULL) goto rperror; myprintview(vw, fp); if (pclose(fp)) goto rperror; - } else { /* rpict normal mode */ - if (runcom(combuf)) - goto rperror; - } + } else if (runcom(combuf)) + goto rperror; } + if (do_rpiece) { /* need to finish raw, first */ + finish_process(); + wait_process(1); + /* XXX should check sync file to see if really done? */ + } if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { /* build pfilt command */ if (mult > 1) @@ -1415,10 +1471,13 @@ rpict( /* run rpict and pfilt for each view */ mvfile(rawfile, combuf); } else rmfile(rawfile); - finish_process(); /* exit if child */ + if (do_rpiece) /* done with sync file */ + rmfile(sfile); + else + finish_process(); /* exit if child */ } wait_process(1); /* wait for children to finish */ - if (pfile != NULL) { /* clean up rpict persistent mode */ + if (pfile != NULL) { /* clean up persistent rpict */ RT_PID pid; fp = fopen(pfile, "r"); if (fp != NULL) { @@ -1432,6 +1491,7 @@ rpict( /* run rpict and pfilt for each view */ rperror: fprintf(stderr, "%s: error rendering view %s\n", progname, vs); quit(1); +#undef do_rpiece } @@ -1444,11 +1504,6 @@ touch( /* update a file */ printf("\ttouch %s\n", fn); if (!nprocs) return(0); -#ifdef notused - if (access(fn, F_OK) == -1) /* create it */ - if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1) - return(-1); -#endif return(setfdate(fn, time((time_t *)NULL))); } @@ -1496,7 +1551,7 @@ mvfile( /* move a file */ #ifdef RHAS_FORK_EXEC static int -next_process(void) /* fork the next process (max. nprocs) */ +next_process(int reserve) /* fork the next process */ { RT_PID child_pid; @@ -1507,6 +1562,8 @@ next_process(void) /* fork the next process (max. np progname); quit(1); } + if (reserve > 0 && children_running >= nprocs-reserve) + return(0); /* caller holding back process(es) */ if (children_running >= nprocs) wait_process(0); /* wait for someone to finish */ fflush(NULL); /* flush output */ @@ -1554,7 +1611,7 @@ wait_process( /* wait for process(es) to finish */ } #else /* ! RHAS_FORK_EXEC */ static int -next_process(void) +next_process(int reserve) { return(0); /* cannot start new process */ }