--- ray/src/rt/raypcalls.c 2008/02/20 05:21:29 2.19 +++ ray/src/rt/raypcalls.c 2009/12/12 05:20:10 2.22 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raypcalls.c,v 2.19 2008/02/20 05:21:29 greg Exp $"; +static const char RCSid[] = "$Id: raypcalls.c,v 2.22 2009/12/12 05:20:10 greg Exp $"; #endif /* * raypcalls.c - interface for parallel rendering using Radiance @@ -13,11 +13,11 @@ static const char RCSid[] = "$Id: raypcalls.c,v 2.19 2 * These calls are designed similarly to the ones in raycalls.c, * but allow for multiple rendering processes on the same host * machine. There is no sense in specifying more child processes - * than you have processors, but one child may help by allowing + * than you have processor cores, but one child may help by allowing * asynchronous ray computation in an interactive program, and * will protect the caller from fatal rendering errors. * - * You should first read and undrstand the header in raycalls.c, + * You should first read and understand the header in raycalls.c, * as some things are explained there that are not repated here. * * The first step is opening one or more rendering processes @@ -25,13 +25,15 @@ static const char RCSid[] = "$Id: raypcalls.c,v 2.19 2 * ray_pinit() loads the octree and data structures into the * caller's memory, and ray_popen() synchronizes the ambient * file, if any. Shared memory permits all sorts of queries - * that wouldn't be possible otherwise, without causing any real + * that wouldn't be possible otherwise without causing any real * memory overhead, since all the static data are shared - * between processes. Rays are then traced using a simple + * between processes. Rays are traced using a simple * queuing mechanism, explained below. * * The ray queue buffers RAYQLEN rays before sending to - * children, each of which may internally buffer RAYQLEN rays. + * children, each of which may internally buffer RAYQLEN rays + * during evaluation. Rays are not returned in the order + * they are sent when multiple processes are open. * * Rays are queued and returned by a single * ray_pqueue() call. A ray_pqueue() return @@ -73,7 +75,7 @@ static const char RCSid[] = "$Id: raypcalls.c,v 2.19 2 * until a value is available, returning 0 only if the * queue is completely empty. A negative return value * indicates that a rendering process died. If this - * happens, ray_close(0) is automatically called to close + * happens, ray_pclose(0) is automatically called to close * all child processes, and ray_pnprocs is set to zero. * * If you just want to fill the ray queue without checking for @@ -93,8 +95,8 @@ static const char RCSid[] = "$Id: raypcalls.c,v 2.19 2 * Any queued ray calculations will be awaited and discarded. * As with ray_done(), ray_pdone(0) hangs onto data files * and fonts that are likely to be used in subsequent renderings. - * Whether you want to bother cleaning up memory or not, you - * should at least call ray_pclose(0) to clean the child processes. + * Whether you need to clean up memory or not, you should + * at least call ray_pclose(0) to await the child processes. * * Warning: You cannot affect any of the rendering processes * by changing global parameter values onece ray_pinit() has @@ -124,7 +126,7 @@ static const char RCSid[] = "$Id: raypcalls.c,v 2.19 2 * returning a negative value from ray_pqueue() or * ray_presult(). If you get a negative value from either * of these calls, you can assume that the processes have - * been cleaned up with a call to ray_close(), though you + * been cleaned up with a call to ray_pclose(), though you * will have to call ray_pdone() yourself if you want to * free memory. Obviously, you cannot continue rendering * without risking further errors, but otherwise your @@ -160,13 +162,13 @@ static struct child_proc { int fd_send; /* write to child here */ int fd_recv; /* read from child here */ int npending; /* # rays in process */ - unsigned long rno[RAYQLEN]; /* working on these rays */ + RNUMBER rno[RAYQLEN]; /* working on these rays */ } r_proc[MAX_NPROCS]; /* our child processes */ static RAY r_queue[2*RAYQLEN]; /* ray i/o buffer */ static int r_send_next; /* next send ray placement */ static int r_recv_first; /* position of first unreported ray */ -static int r_recv_next; /* next receive ray placement */ +static int r_recv_next; /* next received ray placement */ #define sendq_full() (r_send_next >= RAYQLEN) @@ -174,7 +176,7 @@ static int ray_pflush(void); static void ray_pchild(int fd_in, int fd_out); -extern void +void ray_pinit( /* initialize ray-tracing processes */ char *otnm, int nproc @@ -185,12 +187,6 @@ ray_pinit( /* initialize ray-tracing processes */ ray_init(otnm); /* load the shared scene */ - preload_objs(); /* preload auxiliary data */ - - /* set shared memory boundary */ - shm_boundary = (char *)malloc(16); - strcpy(shm_boundary, "SHM_BOUNDARY"); - r_send_next = 0; /* set up queue */ r_recv_first = r_recv_next = RAYQLEN; @@ -233,7 +229,7 @@ ray_pflush(void) /* send queued rays to idle childre } -extern void +void ray_psend( /* add a ray to our send queue */ RAY *r ) @@ -248,7 +244,7 @@ ray_psend( /* add a ray to our send queue */ } -extern int +int ray_pqueue( /* queue a ray for computation */ RAY *r ) @@ -277,7 +273,7 @@ ray_pqueue( /* queue a ray for computation */ } -extern int +int ray_presult( /* check for a completed ray */ RAY *r, int poll @@ -314,7 +310,7 @@ getready: /* any children waiting for us? */ if (FD_ISSET(r_proc[pn].fd_recv, &readset) || FD_ISSET(r_proc[pn].fd_recv, &errset)) break; - /* call select if we must */ + /* call select() if we must */ if (pn < 0) { FD_ZERO(&readset); FD_ZERO(&errset); n = 0; for (pn = ray_pnprocs; pn--; ) { @@ -374,7 +370,7 @@ getready: /* any children waiting for us? */ } -extern void +void ray_pdone( /* reap children and free data */ int freall ) @@ -421,6 +417,7 @@ ray_pchild( /* process rays (never returns) */ r_queue[i].parent = NULL; r_queue[i].clipset = NULL; r_queue[i].slights = NULL; + r_queue[i].rlvl = 0; samplendx++; rayclear(&r_queue[i]); rayvalue(&r_queue[i]); @@ -437,7 +434,7 @@ ray_pchild( /* process rays (never returns) */ } -extern void +void ray_popen( /* open the specified # processes */ int nadd ) @@ -448,6 +445,12 @@ ray_popen( /* open the specified # processes */ if (nadd <= 0) return; ambsync(); /* load any new ambient values */ + if (shm_boundary == NULL) { /* first child process? */ + preload_objs(); /* preload auxiliary data */ + /* set shared memory boundary */ + shm_boundary = (char *)malloc(16); + strcpy(shm_boundary, "SHM_BOUNDARY"); + } fflush(NULL); /* clear pending output */ while (nadd--) { /* fork each new process */ int p0[2], p1[2]; @@ -481,7 +484,7 @@ ray_popen( /* open the specified # processes */ } -extern void +void ray_pclose( /* close one or more child processes */ int nsub )