56 |
|
* proportion to the number of CPUs you have available on your |
57 |
|
* system. If the ray queue is full before the call, ray_pqueue() |
58 |
|
* will block until a result is ready so it can queue this one. |
59 |
< |
* The global int ray_idle indicates the number of currently idle |
59 |
> |
* The global int ray_pnidle indicates the number of currently idle |
60 |
|
* children. If you want to check for completed rays without blocking, |
61 |
|
* or get the results from rays that have been queued without |
62 |
|
* queuing any new ones, the ray_presult() call is for you: |
71 |
|
* queue is completely empty. A negative return value |
72 |
|
* indicates that a rendering process died. If this |
73 |
|
* happens, ray_close(0) is automatically called to close |
74 |
< |
* all child processes, and ray_nprocs is set to zero. |
74 |
> |
* all child processes, and ray_pnprocs is set to zero. |
75 |
|
* |
76 |
|
* If you just want to fill the ray queue without checking for |
77 |
< |
* results, check ray_idle and call ray_psend(): |
77 |
> |
* results, check ray_pnidle and call ray_psend(): |
78 |
|
* |
79 |
< |
* while (ray_idle) { |
79 |
> |
* while (ray_pnidle) { |
80 |
|
* ( set up ray ) |
81 |
|
* ray_psend(&myRay); |
82 |
|
* } |
142 |
|
|
143 |
|
extern char *shm_boundary; /* boundary of shared memory */ |
144 |
|
|
145 |
< |
int ray_nprocs = 0; /* number of child processes */ |
146 |
< |
int ray_idle = 0; /* number of idle children */ |
145 |
> |
int ray_pnprocs = 0; /* number of child processes */ |
146 |
> |
int ray_pnidle = 0; /* number of idle children */ |
147 |
|
|
148 |
|
static struct child_proc { |
149 |
|
int pid; /* child process id */ |
189 |
|
{ |
190 |
|
int nc, n, nw, i, sfirst; |
191 |
|
|
192 |
< |
if ((ray_idle <= 0 | r_send_next <= 0)) |
192 |
> |
if ((ray_pnidle <= 0 | r_send_next <= 0)) |
193 |
|
return(0); /* nothing we can send */ |
194 |
|
|
195 |
|
sfirst = 0; /* divvy up labor */ |
196 |
< |
nc = ray_idle; |
197 |
< |
for (i = ray_nprocs; nc && i--; ) { |
196 |
> |
nc = ray_pnidle; |
197 |
> |
for (i = ray_pnprocs; nc && i--; ) { |
198 |
|
if (r_proc[i].npending > 0) |
199 |
|
continue; /* child looks busy */ |
200 |
|
n = (r_send_next - sfirst)/nc--; |
210 |
|
while (n--) /* record ray IDs */ |
211 |
|
r_proc[i].rno[n] = r_queue[sfirst+n].rno; |
212 |
|
sfirst += r_proc[i].npending; |
213 |
< |
ray_idle--; /* now she's busy */ |
213 |
> |
ray_pnidle--; /* now she's busy */ |
214 |
|
} |
215 |
|
if (sfirst != r_send_next) |
216 |
|
error(CONSISTENCY, "code screwup in ray_pflush"); |
283 |
|
r_recv_first++; |
284 |
|
return(1); |
285 |
|
} |
286 |
< |
n = ray_nprocs - ray_idle; /* pending before flush? */ |
286 |
> |
n = ray_pnprocs - ray_pnidle; /* pending before flush? */ |
287 |
|
|
288 |
|
if (ray_pflush() < 0) /* send new rays to process */ |
289 |
|
return(-1); |
291 |
|
r_recv_first = r_recv_next = RAYQLEN; |
292 |
|
|
293 |
|
if (!poll) /* count newly sent unless polling */ |
294 |
< |
n = ray_nprocs - ray_idle; |
294 |
> |
n = ray_pnprocs - ray_pnidle; |
295 |
|
if (n <= 0) /* return if nothing to await */ |
296 |
|
return(0); |
297 |
|
getready: /* any children waiting for us? */ |
298 |
< |
for (pn = ray_nprocs; pn--; ) |
298 |
> |
for (pn = ray_pnprocs; pn--; ) |
299 |
|
if (FD_ISSET(r_proc[pn].fd_recv, &readset) || |
300 |
|
FD_ISSET(r_proc[pn].fd_recv, &errset)) |
301 |
|
break; |
302 |
|
/* call select if we must */ |
303 |
|
if (pn < 0) { |
304 |
|
FD_ZERO(&readset); FD_ZERO(&errset); n = 0; |
305 |
< |
for (pn = ray_nprocs; pn--; ) { |
305 |
> |
for (pn = ray_pnprocs; pn--; ) { |
306 |
|
if (r_proc[pn].npending > 0) |
307 |
|
FD_SET(r_proc[pn].fd_recv, &readset); |
308 |
|
FD_SET(r_proc[pn].fd_recv, &errset); |
338 |
|
if (n <= 0) |
339 |
|
FD_CLR(r_proc[pn].fd_recv, &errset); |
340 |
|
r_proc[pn].npending = 0; |
341 |
< |
ray_idle++; |
341 |
> |
ray_pnidle++; |
342 |
|
/* check for rendering errors */ |
343 |
|
if (!ok) { |
344 |
|
ray_pclose(0); /* process died -- clean up */ |
426 |
|
int nadd; |
427 |
|
{ |
428 |
|
/* check if our table has room */ |
429 |
< |
if (ray_nprocs + nadd > MAX_NPROCS) |
430 |
< |
nadd = MAX_NPROCS - ray_nprocs; |
429 |
> |
if (ray_pnprocs + nadd > MAX_NPROCS) |
430 |
> |
nadd = MAX_NPROCS - ray_pnprocs; |
431 |
|
if (nadd <= 0) |
432 |
|
return; |
433 |
|
fflush(stderr); /* clear pending output */ |
436 |
|
int p0[2], p1[2]; |
437 |
|
if (pipe(p0) < 0 || pipe(p1) < 0) |
438 |
|
error(SYSTEM, "cannot create pipe"); |
439 |
< |
if ((r_proc[ray_nprocs].pid = fork()) == 0) { |
439 |
> |
if ((r_proc[ray_pnprocs].pid = fork()) == 0) { |
440 |
|
int pn; /* close others' descriptors */ |
441 |
< |
for (pn = ray_nprocs; pn--; ) { |
441 |
> |
for (pn = ray_pnprocs; pn--; ) { |
442 |
|
close(r_proc[pn].fd_send); |
443 |
|
close(r_proc[pn].fd_recv); |
444 |
|
} |
446 |
|
/* following call never returns */ |
447 |
|
ray_pchild(p1[0], p0[1]); |
448 |
|
} |
449 |
< |
if (r_proc[ray_nprocs].pid < 0) |
449 |
> |
if (r_proc[ray_pnprocs].pid < 0) |
450 |
|
error(SYSTEM, "cannot fork child process"); |
451 |
|
close(p1[0]); close(p0[1]); |
452 |
< |
r_proc[ray_nprocs].fd_send = p1[1]; |
453 |
< |
r_proc[ray_nprocs].fd_recv = p0[0]; |
454 |
< |
r_proc[ray_nprocs].npending = 0; |
455 |
< |
ray_nprocs++; |
456 |
< |
ray_idle++; |
452 |
> |
r_proc[ray_pnprocs].fd_send = p1[1]; |
453 |
> |
r_proc[ray_pnprocs].fd_recv = p0[0]; |
454 |
> |
r_proc[ray_pnprocs].npending = 0; |
455 |
> |
ray_pnprocs++; |
456 |
> |
ray_pnidle++; |
457 |
|
} |
458 |
|
} |
459 |
|
|
469 |
|
return; |
470 |
|
inclose++; |
471 |
|
/* check argument */ |
472 |
< |
if ((nsub <= 0 | nsub > ray_nprocs)) |
473 |
< |
nsub = ray_nprocs; |
472 |
> |
if ((nsub <= 0 | nsub > ray_pnprocs)) |
473 |
> |
nsub = ray_pnprocs; |
474 |
|
/* clear our ray queue */ |
475 |
|
while (ray_presult(&res,0) > 0) |
476 |
|
; |
477 |
|
/* clean up children */ |
478 |
|
while (nsub--) { |
479 |
|
int status; |
480 |
< |
ray_nprocs--; |
481 |
< |
close(r_proc[ray_nprocs].fd_recv); |
482 |
< |
close(r_proc[ray_nprocs].fd_send); |
483 |
< |
while (wait(&status) != r_proc[ray_nprocs].pid) |
480 |
> |
ray_pnprocs--; |
481 |
> |
close(r_proc[ray_pnprocs].fd_recv); |
482 |
> |
close(r_proc[ray_pnprocs].fd_send); |
483 |
> |
while (wait(&status) != r_proc[ray_pnprocs].pid) |
484 |
|
; |
485 |
|
if (status) { |
486 |
|
sprintf(errmsg, |
487 |
|
"rendering process %d exited with code %d", |
488 |
< |
r_proc[ray_nprocs].pid, status>>8); |
488 |
> |
r_proc[ray_pnprocs].pid, status>>8); |
489 |
|
error(WARNING, errmsg); |
490 |
|
} |
491 |
< |
ray_idle--; |
491 |
> |
ray_pnidle--; |
492 |
|
} |
493 |
|
inclose--; |
494 |
|
} |