ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
(Generate patch)

Comparing ray/src/util/rad.c (file contents):
Revision 2.93 by greg, Tue May 18 00:01:02 2010 UTC vs.
Revision 2.107 by greg, Fri Aug 26 22:39:56 2011 UTC

# Line 165 | Line 165 | static int touch(char  *fn);
165   static int runcom(char  *cs);
166   static int rmfile(char  *fn);
167   static int mvfile(char  *fold, char     *fnew);
168 < static int next_process(void);
168 > static int next_process(int     reserve);
169   static void wait_process(int    all);
170   static void finish_process(void);
171   static void badvalue(int        vc);
# Line 751 | Line 751 | lowqopts(                      /* low quality rendering options */
751                  op = addarg(op, "-ds .4");
752          else
753                  op = addarg(op, "-ds 0");
754 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
754 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5");
755          if (vdef(AMBFILE)) {
756                  sprintf(op, " -af %s", vval(AMBFILE));
757                  op += strlen(op);
# Line 772 | Line 772 | lowqopts(                      /* low quality rendering options */
772          d = ambval();
773          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
774          op += strlen(op);
775 <        op = addarg(op, "-lr 6 -lw .01");
775 >        op = addarg(op, "-lr 6 -lw .003");
776   }
777  
778  
# Line 826 | Line 826 | medqopts(                      /* medium quality rendering options */
826                  op = addarg(op, "-ds .2 -dj .9");
827          else
828                  op = addarg(op, "-ds .3");
829 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
829 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
830          if ( (overture = vint(INDIRECT)) ) {
831                  sprintf(op, " -ab %d", overture);
832                  op += strlen(op);
# Line 850 | Line 850 | medqopts(                      /* medium quality rendering options */
850          d = ambval();
851          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
852          op += strlen(op);
853 <        op = addarg(op, "-lr 8 -lw .002");
853 >        op = addarg(op, "-lr 8 -lw 1e-4");
854   }
855  
856  
# Line 904 | Line 904 | hiqopts(                               /* high quality rendering options */
904                  op = addarg(op, "-ds .1 -dj .9");
905          else
906                  op = addarg(op, "-ds .2");
907 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
907 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
908          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
909          op += strlen(op);
910          if (vdef(AMBFILE)) {
# Line 926 | Line 926 | hiqopts(                               /* high quality rendering options */
926          d = ambval();
927          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
928          op += strlen(op);
929 <        op = addarg(op, "-lr 12 -lw .0005");
929 >        op = addarg(op, "-lr 12 -lw 1e-5");
930   }
931  
932  
# Line 1254 | Line 1254 | rvu(                           /* run rvu with first view */
1254   }
1255  
1256  
1257 + static int
1258 + syncf_done(                     /* check if an rpiece sync file is complete */
1259 +        char *sfname
1260 + )
1261 + {
1262 +        FILE    *fp = fopen(sfname, "r");
1263 +        int     todo = 1;
1264 +        int     x, y;
1265 +
1266 +        if (fp == NULL)
1267 +                return(0);
1268 +        if (fscanf(fp, "%d %d", &x, &y) != 2)
1269 +                goto checked;
1270 +        todo = x*y;             /* total number of tiles */
1271 +        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1272 +                goto checked;
1273 +                                /* XXX assume no redundant tiles */
1274 +        while (fscanf(fp, "%d %d", &x, &y) == 2)
1275 +                if (!--todo)
1276 +                        break;
1277 + checked:
1278 +        fclose(fp);
1279 +        return(!todo);
1280 + }
1281 +
1282 +
1283   static void
1284   rpict(                          /* run rpict and pfilt for each view */
1285          char    *opts,
# Line 1261 | Line 1287 | rpict(                         /* run rpict and pfilt for each view */
1287   )
1288   {
1289   #define do_rpiece       (sfile[0]!='\0')
1290 <        char    combuf[4*PATH_MAX+512];
1290 >        char    combuf[5*PATH_MAX+512];
1291          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1292          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1293 <        char    rppopt[128], sfile[64], *pfile = NULL;
1293 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1294          char    pfopts[128];
1295          char    vs[32], *vw;
1296          int     vn, mult;
1297          FILE    *fp;
1298          time_t  rfdt, pfdt;
1299 +        int     xres, yres;
1300 +        double  aspect;
1301 +        int     n;
1302                                          /* get pfilt options */
1303          pfiltopts(pfopts);
1304                                          /* get resolution, reporting */
# Line 1284 | Line 1313 | rpict(                         /* run rpict and pfilt for each view */
1313                  mult = 3;
1314                  break;
1315          }
1316 <        {
1317 <                int     xres, yres;
1318 <                double  aspect;
1319 <                int     n;
1320 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1321 <                if (n == 3)
1322 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1323 <                                        mult*xres, mult*yres, aspect);
1324 <                else if (n) {
1325 <                        if (n == 1) yres = xres;
1297 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1298 <                } else
1299 <                        badvalue(RESOLUTION);
1300 <        }
1316 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1317 >        if (n == 3)
1318 >                sprintf(res, "-x %d -y %d -pa %.3f",
1319 >                                mult*xres, mult*yres, aspect);
1320 >        else if (n) {
1321 >                aspect = 1.;
1322 >                if (n == 1) yres = xres;
1323 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1324 >        } else
1325 >                badvalue(RESOLUTION);
1326          rep[0] = '\0';
1327          if (vdef(REPORT)) {
1328                  double  minutes;
1304                int     n;
1329                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1330                  if (n == 2)
1331                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1316 | Line 1340 | rpict(                         /* run rpict and pfilt for each view */
1340                                          getview(0, vs) != NULL) {
1341                  if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1342                                  getview(1, NULL) == NULL) {
1343 <                        sprintf(sfile, "rpiece_%s.txt", vs);
1343 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1344 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1345 >                                        vs);
1346                          strcpy(rppopt, "-PP pfXXXXXX");
1347                  } else {
1348                          strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1349                  }
1350                  pfile = rppopt + strlen(rppopt) - 8;
1351 <                if (mktemp(pfile) == NULL)
1351 >                if (mktemp(pfile) == NULL) {
1352                          if (do_rpiece) {
1353                                  fprintf(stderr, "%s: cannot create\n", pfile);
1354                                  quit(1);
1355 <                        } else
1356 <                                pfile = NULL;
1355 >                        }
1356 >                        pfile = NULL;
1357 >                }
1358          }
1359          vn = 0;                                 /* do each view */
1360          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1356 | Line 1383 | rpict(                         /* run rpict and pfilt for each view */
1383                  }
1384                                                  /* parallel running? */
1385                  if (do_rpiece) {
1386 <                        if (rfdt < oct1date || fdate(sfile) < oct1date) {
1387 <                                rfdt = 0;               /* start fresh */
1386 >                        if (rfdt < oct1date || !fdate(sfile)) {
1387 >                                int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1388 >                                if (rfdt >= oct1date) {
1389 >                                        fprintf(stderr,
1390 >                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1391 >                                        quit(1);
1392 >                                }
1393 >                                if (rfdt) {     /* start fresh */
1394 >                                        rmfile(rawfile);
1395 >                                        rfdt = 0;
1396 >                                }
1397 >                                if (!silent)
1398 >                                        printf("\techo %d %d > %s\n",
1399 >                                                        xdiv, ydiv, sfile);
1400                                  if ((fp = fopen(sfile, "w")) == NULL) {
1401                                          fprintf(stderr, "%s: cannot create\n",
1402                                                          sfile);
1403                                          quit(1);
1404                                  }
1405 <                                fprintf(fp, "%d %d\n", 8+nprocs/3, 8+nprocs/3);
1405 >                                fprintf(fp, "%d %d\n", xdiv, ydiv);
1406                                  fclose(fp);
1407                          }
1408 <                } else if (next_process()) {
1408 >                } else if (next_process(0)) {
1409                          if (pfile != NULL)
1410                                  sleep(10);
1411                          continue;
# Line 1379 | Line 1418 | rpict(                         /* run rpict and pfilt for each view */
1418                                  sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1419                                                  c_rpiece, sfile, rppopt, rep, vw,
1420                                                  res, opts, po, rawfile, oct1name);
1421 <                                while (children_running < nprocs-1 &&
1383 <                                                        next_process()) {
1421 >                                while (next_process(1)) {
1422                                          sleep(10);
1423                                          combuf[strlen(c_rpiece)+2] = 'F';
1424                                  }
# Line 1392 | Line 1430 | rpict(                         /* run rpict and pfilt for each view */
1430                  } else {
1431                          if (overture) {         /* run overture calculation */
1432                                  sprintf(combuf,
1433 <                                "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1433 >                                        "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1434                                                  c_rpict, rep, vw, opts,
1435                                                  oct1name, overfile);
1436 <                                if (runcom(combuf)) {
1437 <                                        fprintf(stderr,
1436 >                                if (!do_rpiece || !next_process(0)) {
1437 >                                        if (runcom(combuf)) {
1438 >                                                fprintf(stderr,
1439                                          "%s: error in overture for view %s\n",
1440 <                                                progname, vs);
1441 <                                        quit(1);
1442 <                                }
1440 >                                                        progname, vs);
1441 >                                                quit(1);
1442 >                                        }
1443   #ifndef NULL_DEVICE
1444 <                                rmfile(overfile);
1444 >                                        rmfile(overfile);
1445   #endif
1446 +                                } else if (do_rpiece)
1447 +                                        sleep(20);
1448                          }
1449                          if (do_rpiece) {
1450                                  sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1451                                                  c_rpiece, sfile, rppopt, rep, vw,
1452                                                  res, opts, po, rawfile, oct1name);
1453 <                                while (children_running < nprocs-1 &&
1413 <                                                        next_process())
1453 >                                while (next_process(1))
1454                                          sleep(10);
1455                          } else {
1456                                  sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
# Line 1436 | Line 1476 | rpict(                         /* run rpict and pfilt for each view */
1476                  if (do_rpiece) {                /* need to finish raw, first */
1477                          finish_process();
1478                          wait_process(1);
1479 <                        /* XXX should check sync file to see if really done? */
1479 >                        if (!syncf_done(sfile)) {
1480 >                                fprintf(stderr,
1481 >                        "%s: %s did not complete rendering of view %s\n",
1482 >                                                progname, c_rpiece, vs);
1483 >                                quit(1);
1484 >                        }
1485                  }
1486                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1487                                                  /* build pfilt command */
1488 <                        if (mult > 1)
1488 >                        if (do_rpiece)
1489 >                                sprintf(combuf,
1490 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1491 >                                        c_pfilt, pfopts, xres, yres, aspect,
1492 >                                        rawfile, picfile);
1493 >                        else if (mult > 1)
1494                                  sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1495                                          c_pfilt, pfopts, mult, mult,
1496                                          rawfile, picfile);
# Line 1467 | Line 1517 | rpict(                         /* run rpict and pfilt for each view */
1517                          finish_process();       /* exit if child */
1518          }
1519          wait_process(1);                /* wait for children to finish */
1520 <        if (pfile != NULL) {            /* clean up rpict persistent mode */
1520 >        if (pfile != NULL) {            /* clean up persistent rpict */
1521                  RT_PID  pid;
1522                  fp = fopen(pfile, "r");
1523                  if (fp != NULL) {
# Line 1494 | Line 1544 | touch(                 /* update a file */
1544                  printf("\ttouch %s\n", fn);
1545          if (!nprocs)
1546                  return(0);
1497 #ifdef notused
1498        if (access(fn, F_OK) == -1)             /* create it */
1499                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1500                        return(-1);
1501 #endif
1547          return(setfdate(fn, time((time_t *)NULL)));
1548   }
1549  
# Line 1546 | Line 1591 | mvfile(                /* move a file */
1591  
1592   #ifdef RHAS_FORK_EXEC
1593   static int
1594 < next_process(void)                      /* fork the next process (max. nprocs) */
1594 > next_process(int reserve)               /* fork the next process */
1595   {
1596          RT_PID  child_pid;
1597  
# Line 1557 | Line 1602 | next_process(void)                     /* fork the next process (max. np
1602                                  progname);
1603                  quit(1);
1604          }
1605 +        if (reserve > 0 && children_running >= nprocs-reserve)
1606 +                return(0);              /* caller holding back process(es) */
1607          if (children_running >= nprocs)
1608                  wait_process(0);        /* wait for someone to finish */
1609          fflush(NULL);                   /* flush output */
1610          child_pid = fork();             /* split process */
1611          if (child_pid == 0) {           /* we're the child */
1612                  children_running = -1;
1613 +                nprocs = 1;
1614                  return(0);
1615          }
1616          if (child_pid > 0) {            /* we're the parent */
# Line 1604 | Line 1652 | wait_process(                  /* wait for process(es) to finish */
1652   }
1653   #else   /* ! RHAS_FORK_EXEC */
1654   static int
1655 < next_process(void)
1655 > next_process(int reserve)
1656   {
1657          return(0);                      /* cannot start new process */
1658   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines