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.65 by schorsch, Mon Jun 30 14:59:13 2003 UTC vs.
Revision 2.66 by greg, Thu Jul 3 15:00:19 2003 UTC

# Line 96 | Line 96 | int    nowarn = 0;             /* no warnings */
96   int     explicate = 0;          /* explicate variables */
97   int     silent = 0;             /* do work silently */
98   int     touchonly = 0;          /* touch files only */
99 < int     noaction = 0;           /* don't do anything */
99 > int     nprocs = 1;             /* maximum executing processes */
100   int     sayview = 0;            /* print view out */
101   char    *rvdevice = NULL;       /* rview output device */
102   char    *viewselect = NULL;     /* specific view only */
103  
104   int     overture = 0;           /* overture calculation needed */
105  
106 + int     children_running = 0;   /* set negative in children */
107 +
108   char    *progname;              /* global argv[0] */
109   char    *rifname;               /* global rad input file name */
110  
# Line 125 | Line 127 | char   *argv[];
127                          silent++;
128                          break;
129                  case 'n':
130 <                        noaction++;
130 >                        nprocs = 0;
131                          break;
132 +                case 'N':
133 +                        nprocs = atoi(argv[++i]);
134 +                        if (nprocs < 0)
135 +                                nprocs = 0;
136 +                        break;
137                  case 't':
138                          touchonly++;
139                          break;
# Line 185 | Line 192 | char   *argv[];
192          quit(0);
193   userr:
194          fprintf(stderr,
195 < "Usage: %s [-w][-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
195 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
196                          progname);
197          quit(1);
198   }
# Line 299 | Line 306 | double org[3], *sizp;
306          register int    i;
307  
308          if (osiz <= FTINY)
309 <                if (noaction && fdate(oct1name) <
309 >                if (!nprocs && fdate(oct1name) <
310                                  (scenedate>illumdate?scenedate:illumdate)) {
311                                                          /* run getbbox */
312                          sprintf(buf, "getbbox -w -h %s",
# Line 1132 | Line 1139 | char   *opts, *po;
1139                  else
1140                          badvalue(REPORT);
1141          }
1142 <                                        /* do each view */
1136 <        vn = 0;
1142 >        vn = 0;                                 /* do each view */
1143          while ((vw = getview(vn++, vs)) != NULL) {
1144                  if (sayview)
1145                          printview(vw);
# Line 1160 | Line 1166 | char   *opts, *po;
1166                                  touch(picfile);
1167                          continue;
1168                  }
1169 +                if (next_process())             /* parallel running? */
1170 +                        continue;
1171 +                /* XXX Remember to call finish_process() */
1172                                                  /* build rpict command */
1173                  if (rfdt >= oct1date)           /* recover */
1174                          sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
# Line 1211 | Line 1220 | char   *opts, *po;
1220                          mvfile(rawfile, combuf);
1221                  } else
1222                          rmfile(rawfile);
1223 +                finish_process();               /* leave if child */
1224          }
1225 +        wait_process(1);                /* wait for children to finish */
1226   }
1227  
1228  
# Line 1220 | Line 1231 | char   *fn;
1231   {
1232          if (!silent)
1233                  printf("\ttouch %s\n", fn);
1234 <        if (noaction)
1234 >        if (!nprocs)
1235                  return(0);
1236   #ifdef notused
1237          if (access(fn, F_OK) == -1)             /* create it */
# Line 1236 | Line 1247 | char   *cs;
1247   {
1248          if (!silent)            /* echo it */
1249                  printf("\t%s\n", cs);
1250 <        if (noaction)
1250 >        if (!nprocs)
1251                  return(0);
1252          fflush(stdout);         /* flush output and pass to shell */
1253          return(system(cs));
# Line 1252 | Line 1263 | char   *fn;
1263   #else
1264                  printf("\trm -f %s\n", fn);
1265   #endif
1266 <        if (noaction)
1266 >        if (!nprocs)
1267                  return(0);
1268          return(unlink(fn));
1269   }
# Line 1267 | Line 1278 | char   *fold, *fnew;
1278   #else
1279                  printf("\tmv %s %s\n", fold, fnew);
1280   #endif
1281 <        if (noaction)
1281 >        if (!nprocs)
1282                  return(0);
1283          return(rename(fold, fnew));
1284   }
1285  
1286 +
1287 + #ifdef RHAS_FORK_EXEC
1288 + int
1289 + next_process()                  /* fork the next process (max. nprocs) */
1290 + {
1291 +        int     child_pid;
1292 +
1293 +        if (nprocs <= 1)
1294 +                return(0);              /* it's us or no one */
1295 +        if (children_running < 0) {
1296 +                fprintf(stderr, "%s: internal error 1 in spawn_process()\n",
1297 +                                progname);
1298 +                quit(1);
1299 +        }
1300 +        if (children_running >= nprocs)
1301 +                wait_process(0);        /* wait for someone to finish */
1302 +        fflush(stdout);
1303 +        child_pid = fork();             /* split process */
1304 +        if (child_pid == 0) {           /* we're the child */
1305 +                children_running = -1;
1306 +                return(0);
1307 +        }
1308 +        if (child_pid > 0) {            /* we're the parent */
1309 +                ++children_running;
1310 +                return(1);
1311 +        }
1312 +        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1313 +        return(0);
1314 + }
1315 +
1316 + wait_process(all)                       /* wait for process(es) to finish */
1317 + int     all;
1318 + {
1319 +        int     ourstatus = 0;
1320 +        int     pid, status;
1321 +
1322 +        if (all)
1323 +                all = children_running;
1324 +        else if (children_running > 0)
1325 +                all = 1;
1326 +        while (all-- > 0) {
1327 +                pid = wait(&status);
1328 +                if (pid < 0)
1329 +                        syserr(progname);
1330 +                status = status>>8 & 0xff;
1331 +                --children_running;
1332 +                if (status != 0) {      /* child's problem is our problem */
1333 +                        if (ourstatus == 0 & children_running > 0)
1334 +                                fprintf(stderr, "%s: waiting for remaining processes\n",
1335 +                                                progname);
1336 +                        ourstatus = status;
1337 +                        all = children_running;
1338 +                }
1339 +        }
1340 +        if (ourstatus != 0)
1341 +                quit(ourstatus);        /* bad status from child */
1342 + }
1343 + #else   /* ! RHAS_FORK_EXEC */
1344 + int
1345 + next_process()
1346 + {
1347 +        return(0);                      /* cannot start new process */
1348 + }
1349 + wait_process(all)
1350 + int     all;
1351 + {
1352 +        (void)all;                      /* no one to wait for */
1353 + }
1354 + #endif  /* ! RHAS_FORK_EXEC */
1355 +
1356 + finish_process()                        /* exit a child process */
1357 + {
1358 +        if (children_running >= 0)
1359 +                return;                 /* in parent -- noop */
1360 +        exit(0);
1361 + }
1362  
1363   #ifdef _WIN32
1364   setenv(vname, value)            /* set an environment variable */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines