--- ray/src/util/rad.c 2009/02/09 16:41:29 2.92 +++ ray/src/util/rad.c 2011/02/25 06:51:51 2.105 @@ -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.105 2011/02/25 06:51:51 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); @@ -772,7 +772,7 @@ lowqopts( /* low quality rendering options */ d = ambval(); sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); - op = addarg(op, "-lr 6 -lw .01"); + op = addarg(op, "-lr 6 -lw .003"); } @@ -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 1 -st .1"); if ( (overture = vint(INDIRECT)) ) { sprintf(op, " -ab %d", overture); op += strlen(op); @@ -850,7 +850,7 @@ medqopts( /* medium quality rendering options */ d = ambval(); sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); - op = addarg(op, "-lr 8 -lw .002"); + op = addarg(op, "-lr 8 -lw 1e-4"); } @@ -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 16 -st .01"); sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); op += strlen(op); if (vdef(AMBFILE)) { @@ -926,7 +926,7 @@ hiqopts( /* high quality rendering options */ d = ambval(); sprintf(op, " -av %.2g %.2g %.2g", d, d, d); op += strlen(op); - op = addarg(op, "-lr 12 -lw .0005"); + op = addarg(op, "-lr 12 -lw 1e-5"); } @@ -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,15 +1260,19 @@ rpict( /* run rpict and pfilt for each view */ char *po ) { - char combuf[PATH_MAX]; +#define do_rpiece (sfile[0]!='\0') + char combuf[5*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[32], sfile[PATH_MAX], *pfile = NULL; char pfopts[128]; char vs[32], *vw; int vn, mult; FILE *fp; time_t rfdt, pfdt; + int xres, yres; + double aspect; + int n; /* get pfilt options */ pfiltopts(pfopts); /* get resolution, reporting */ @@ -1282,24 +1287,19 @@ rpict( /* run rpict and pfilt for each view */ mult = 3; break; } - { - int xres, yres; - double aspect; - int n; - n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); - if (n == 3) - sprintf(res, "-x %d -y %d -pa %.3f", - mult*xres, mult*yres, aspect); - else if (n) { - if (n == 1) yres = xres; - sprintf(res, "-x %d -y %d", mult*xres, mult*yres); - } else - badvalue(RESOLUTION); - } + n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); + if (n == 3) + sprintf(res, "-x %d -y %d -pa %.3f", + mult*xres, mult*yres, aspect); + else if (n) { + aspect = 1.; + if (n == 1) yres = xres; + sprintf(res, "-x %d -y %d", mult*xres, mult*yres); + } else + badvalue(RESOLUTION); rep[0] = '\0'; if (vdef(REPORT)) { double minutes; - int n; n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile); if (n == 2) sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); @@ -1309,18 +1309,31 @@ 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, "%s_%s_rpsync.txt", + vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), + 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,59 +1355,111 @@ 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; + if (rfdt >= oct1date) { + fprintf(stderr, + "%s: partial output not created with rpiece\n", rawfile); + quit(1); + } + if (rfdt) { /* start fresh */ + rmfile(rawfile); + rfdt = 0; + } + 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 */ sprintf(combuf, - "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", + "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", c_rpict, rep, vw, opts, oct1name, overfile); - if (runcom(combuf)) { - fprintf(stderr, + if (!do_rpiece || !next_process(0)) { + if (runcom(combuf)) { + fprintf(stderr, "%s: error in overture for view %s\n", - progname, vs); - quit(1); - } + progname, vs); + quit(1); + } #ifndef NULL_DEVICE - rmfile(overfile); + rmfile(overfile); #endif + } else if (do_rpiece) + sleep(20); } - 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) + if (do_rpiece) + sprintf(combuf, + "%s%s -x %d -y %d -p %.3f %s > %s", + c_pfilt, pfopts, xres, yres, aspect, + rawfile, picfile); + else if (mult > 1) sprintf(combuf, "%s%s -x /%d -y /%d %s > %s", c_pfilt, pfopts, mult, mult, rawfile, picfile); @@ -1415,10 +1480,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 +1500,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 +1513,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 +1560,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,12 +1571,15 @@ 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 */ child_pid = fork(); /* split process */ if (child_pid == 0) { /* we're the child */ children_running = -1; + nprocs = 1; return(0); } if (child_pid > 0) { /* we're the parent */ @@ -1554,7 +1621,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 */ }