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

Comparing ray/src/rt/rtmain.c (file contents):
Revision 2.5 by schorsch, Thu Jun 26 00:58:10 2003 UTC vs.
Revision 2.18 by greg, Sat Dec 12 19:01:00 2009 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7  
8   #include "copyright.h"
9  
10 #include  <sys/types.h>
10   #include  <signal.h>
11  
12   #include  "platform.h"
13 + #include  "rtprocess.h" /* getpid() */
14 + #include  "resolu.h"
15   #include  "ray.h"
16   #include  "source.h"
17   #include  "ambient.h"
18   #include  "random.h"
19   #include  "paths.h"
20  
21 + extern char     *progname;              /* global argv[0] */
22 +
23 + extern char     *shm_boundary;          /* boundary of shared memory */
24 +
25                                          /* persistent processes define */
26   #ifdef  F_SETLKW
27   #define  PERSIST        1               /* normal persist */
# Line 24 | Line 29 | static const char      RCSid[] = "$Id$";
29   #define  PCHILD         3               /* child of normal persist */
30   #endif
31  
32 < char  *progname;                        /* argv[0] */
32 > char  *sigerr[NSIG];                    /* signal error messages */
33 > char  *errfile = NULL;                  /* error output file */
34  
35 < char  *octname;                         /* octree name */
35 > int  nproc = 1;                         /* number of processes */
36  
37 < char  *sigerr[NSIG];                    /* signal error messages */
37 > extern char  *formstr();                /* string from format */
38 > int  inform = 'a';                      /* input format */
39 > int  outform = 'a';                     /* output format */
40 > char  *outvals = "v";                   /* output specification */
41  
42 < char  *shm_boundary = NULL;             /* boundary of shared memory */
42 > int  hresolu = 0;                       /* horizontal (scan) size */
43 > int  vresolu = 0;                       /* vertical resolution */
44  
45 < char  *errfile = NULL;                  /* error output file */
45 > int  imm_irrad = 0;                     /* compute immediate irradiance? */
46 > int  lim_dist = 0;                      /* limit distance? */
47  
48 < extern char  *formstr();                /* string from format */
49 < extern int  inform;                     /* input format */
50 < extern int  outform;                    /* output format */
40 < extern char  *outvals;                  /* output values */
48 > #ifndef MAXMODLIST
49 > #define MAXMODLIST      1024            /* maximum modifiers we'll track */
50 > #endif
51  
52 < extern int  hresolu;                    /* horizontal resolution */
53 < extern int  vresolu;                    /* vertical resolution */
52 > extern void  (*addobjnotify[])();       /* object notification calls */
53 > extern void  tranotify(OBJECT obj);
54  
55 < extern int  imm_irrad;                  /* compute immediate irradiance? */
56 < extern int  lim_dist;                   /* limit distance? */
55 > char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
56 > int  traincl = -1;                      /* include == 1, exclude == 0 */
57  
58 < extern char  *tralist[];                /* list of modifers to trace (or no) */
49 < extern int  traincl;                    /* include == 1, exclude == 0 */
58 > static int  loadflags = ~IO_FILES;      /* what to load from octree */
59  
60 < void    onsig();
61 < void    sigdie();
62 < void    printdefaults();
60 > static void onsig(int  signo);
61 > static void sigdie(int  signo, char  *msg);
62 > static void printdefaults(void);
63  
64  
65   int
66 < main(argc, argv)
58 < int  argc;
59 < char  *argv[];
66 > main(int  argc, char  *argv[])
67   {
68   #define  check(ol,al)           if (argv[i][ol] || \
69                                  badarg(argc-i-1,argv+i+1,al)) \
# Line 68 | Line 75 | char  *argv[];
75                                  case 'n': case 'N': case 'f': case 'F': \
76                                  case '-': case '0': var = 0; break; \
77                                  default: goto badopt; }
71        int  loadflags = ~IO_FILES;
78          int  persist = 0;
79 +        char  *octnm = NULL;
80          char  **tralp;
81          int  duped1;
82          int  rval;
83          int  i;
84                                          /* global program name */
85          progname = argv[0] = fixargv0(argv[0]);
86 +                                        /* add trace notify function */
87 +        for (i = 0; addobjnotify[i] != NULL; i++)
88 +                ;
89 +        addobjnotify[i] = tranotify;
90 +                                        /* set our defaults */
91 +        maxdepth = -10;
92 +        minweight = 2e-3;
93                                          /* option city */
94          for (i = 1; i < argc; i++) {
95                                                  /* expand arguments */
# Line 102 | Line 116 | char  *argv[];
116                          continue;
117                  }
118                  switch (argv[i][1]) {
119 +                case 'n':                               /* number of cores */
120 +                        check(2,"i");
121 +                        nproc = atoi(argv[++i]);
122 +                        if (nproc <= 0)
123 +                                error(USER, "bad number of processes");
124 +                        break;
125                  case 'x':                               /* x resolution */
126                          check(2,"i");
127                          hresolu = atoi(argv[++i]);
# Line 228 | Line 248 | char  *argv[];
248                          goto badopt;
249                  }
250          }
251 +        if (nproc > 1) {
252 +                if (persist)
253 +                        error(USER, "multiprocessing incompatible with persist file");
254 +                if (imm_irrad)
255 +                        error(USER, "multiprocessing incompatible with immediate irradiance");
256 +                if (hresolu > 0 && hresolu < nproc)
257 +                        error(WARNING, "number of cores should not exceed horizontal resolution");
258 +                if (trace != NULL)
259 +                        error(WARNING, "multiprocessing does not work properly with trace mode");
260 +        }
261                                          /* initialize object types */
262          initotypes();
263                                          /* initialize urand */
264 <        initurand(2048);
264 >        if (rand_samp) {
265 >                srandom((long)time(0));
266 >                initurand(0);
267 >        } else {
268 >                srandom(0L);
269 >                initurand(2048);
270 >        }
271                                          /* set up signal handling */
272          sigdie(SIGINT, "Interrupt");
273   #ifdef SIGHUP
# Line 263 | Line 299 | char  *argv[];
299   #endif
300                                          /* get octree */
301          if (i == argc)
302 <                octname = NULL;
302 >                octnm = NULL;
303          else if (i == argc-1)
304 <                octname = argv[i];
304 >                octnm = argv[i];
305          else
306                  goto badopt;
307 <        if (octname == NULL)
307 >        if (octnm == NULL)
308                  error(USER, "missing octree argument");
309                                          /* set up output */
310   #ifdef  PERSIST
# Line 277 | Line 313 | char  *argv[];
313                  openheader();
314          }
315   #endif
280 #ifdef  _WIN32
316          if (outform != 'a')
317                  SET_FILE_BINARY(stdout);
318 <        if (octname == NULL)
284 <                SET_FILE_BINARY(stdin);
285 < #endif
286 <        readoct(octname, loadflags, &thescene, NULL);
318 >        readoct(octnm, loadflags, &thescene, NULL);
319          nsceneobjs = nobjects;
320  
321          if (loadflags & IO_INFO) {      /* print header */
# Line 311 | Line 343 | char  *argv[];
343                          while ((rval=fork()) == 0) {    /* keep on forkin' */
344                                  pflock(1);
345                                  pfhold();
346 +                                ambsync();              /* load new values */
347                          }
348                          if (rval < 0)
349                                  error(SYSTEM, "cannot fork child for persist function");
350 <                        pfdetach();             /* parent exits */
350 >                        pfdetach();             /* parent will run then exit */
351                  }
352          }
353   runagain:
354          if (persist)
355                  dupheader();                    /* send header to stdout */
356   #endif
357 +        if (nproc > 1)                  /* start multiprocessing */
358 +                ray_popen(nproc);
359                                          /* trace rays */
360          rtrace(NULL);
361                                          /* flush ambient file */
# Line 337 | Line 372 | runagain:
372                  }
373          }
374          if (persist == PCHILD) {        /* wait for a signal then go again */
340                close(duped1);                  /* release output handle */
375                  pfhold();
376                  raynum = nrays = 0;             /* reinitialize */
377                  goto runagain;
# Line 348 | Line 382 | runagain:
382   badopt:
383          sprintf(errmsg, "command line error at '%s'", argv[i]);
384          error(USER, errmsg);
385 +        return 1; /* pro forma return */
386  
387   #undef  check
388   #undef  bool
# Line 355 | Line 390 | badopt:
390  
391  
392   void
393 < wputs(s)                                /* warning output function */
394 < char    *s;
393 > wputs(                          /* warning output function */
394 >        char    *s
395 > )
396   {
397          int  lasterrno = errno;
398          eputs(s);
# Line 365 | Line 401 | char   *s;
401  
402  
403   void
404 < eputs(s)                                /* put string to stderr */
405 < register char  *s;
404 > eputs(                          /* put string to stderr */
405 >        register char  *s
406 > )
407   {
408          static int  midline = 0;
409  
# Line 384 | Line 421 | register char  *s;
421   }
422  
423  
424 < void
425 < onsig(signo)                            /* fatal signal */
426 < int  signo;
424 > static void
425 > onsig(                          /* fatal signal */
426 >        int  signo
427 > )
428   {
429          static int  gotsig = 0;
430  
# Line 404 | Line 442 | int  signo;
442   }
443  
444  
445 < void
446 < sigdie(signo, msg)                      /* set fatal signal */
447 < int  signo;
448 < char  *msg;
445 > static void
446 > sigdie(                 /* set fatal signal */
447 >        int  signo,
448 >        char  *msg
449 > )
450   {
451          if (signal(signo, onsig) == SIG_IGN)
452                  signal(signo, SIG_IGN);
# Line 415 | Line 454 | char  *msg;
454   }
455  
456  
457 < void
458 < printdefaults()                 /* print default values to stdout */
457 > static void
458 > printdefaults(void)                     /* print default values to stdout */
459   {
460          register char  *cp;
461  
462          if (imm_irrad)
463                  printf("-I+\t\t\t\t# immediate irradiance on\n");
464 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
465 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
464 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
465 >        printf("-x %-9d\t\t\t# x resolution (flush interval)\n", hresolu);
466 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
467          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
468                          "-ld-\t\t\t\t# limit distance off\n");
469 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
470 +                        loadflags & IO_INFO ? "output" : "no");
471          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
472                          inform, outform, formstr(inform), formstr(outform));
473 <        printf("-o%s\t\t\t\t# output", outvals);
473 >        printf("-o%-9s\t\t\t# output", outvals);
474          for (cp = outvals; *cp; cp++)
475                  switch (*cp) {
476 <                case 't': printf(" trace"); break;
476 >                case 't': case 'T': printf(" trace"); break;
477                  case 'o': printf(" origin"); break;
478                  case 'd': printf(" direction"); break;
479                  case 'v': printf(" value"); break;
480 +                case 'V': printf(" contribution"); break;
481                  case 'l': printf(" length"); break;
482                  case 'L': printf(" first_length"); break;
483                  case 'p': printf(" point"); break;
# Line 442 | Line 485 | printdefaults()                        /* print default values to stdout */
485                  case 'N': printf(" unperturbed_normal"); break;
486                  case 's': printf(" surface"); break;
487                  case 'w': printf(" weight"); break;
488 +                case 'W': printf(" coefficient"); break;
489                  case 'm': printf(" modifier"); break;
490 +                case 'M': printf(" material"); break;
491 +                case '-': printf(" stroke"); break;
492                  }
493          putchar('\n');
494          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines