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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines