7 |
|
* External symbols declared in ray.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
/* ==================================================================== |
11 |
< |
* The Radiance Software License, Version 1.0 |
12 |
< |
* |
13 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
14 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
15 |
< |
* |
16 |
< |
* Redistribution and use in source and binary forms, with or without |
17 |
< |
* modification, are permitted provided that the following conditions |
18 |
< |
* are met: |
19 |
< |
* |
20 |
< |
* 1. Redistributions of source code must retain the above copyright |
21 |
< |
* notice, this list of conditions and the following disclaimer. |
22 |
< |
* |
23 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
24 |
< |
* notice, this list of conditions and the following disclaimer in |
25 |
< |
* the documentation and/or other materials provided with the |
26 |
< |
* distribution. |
27 |
< |
* |
28 |
< |
* 3. The end-user documentation included with the redistribution, |
29 |
< |
* if any, must include the following acknowledgment: |
30 |
< |
* "This product includes Radiance software |
31 |
< |
* (http://radsite.lbl.gov/) |
32 |
< |
* developed by the Lawrence Berkeley National Laboratory |
33 |
< |
* (http://www.lbl.gov/)." |
34 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
35 |
< |
* if and wherever such third-party acknowledgments normally appear. |
36 |
< |
* |
37 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
38 |
< |
* and "The Regents of the University of California" must |
39 |
< |
* not be used to endorse or promote products derived from this |
40 |
< |
* software without prior written permission. For written |
41 |
< |
* permission, please contact [email protected]. |
42 |
< |
* |
43 |
< |
* 5. Products derived from this software may not be called "Radiance", |
44 |
< |
* nor may "Radiance" appear in their name, without prior written |
45 |
< |
* permission of Lawrence Berkeley National Laboratory. |
46 |
< |
* |
47 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
48 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
49 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
50 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
51 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
52 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
53 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
54 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
55 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
56 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
57 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 |
< |
* SUCH DAMAGE. |
59 |
< |
* ==================================================================== |
60 |
< |
* |
61 |
< |
* This software consists of voluntary contributions made by many |
62 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
63 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
64 |
< |
* <http://www.lbl.gov/>. |
65 |
< |
*/ |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
|
/* |
13 |
|
* These calls are designed similarly to the ones in raycalls.c, |
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"); |
229 |
|
if (sendq_full() && ray_pflush() <= 0) |
230 |
|
error(INTERNAL, "ray_pflush failed in ray_psend"); |
231 |
|
|
232 |
< |
copystruct(&r_queue[r_send_next], r); |
232 |
> |
r_queue[r_send_next] = *r; |
233 |
|
r_send_next++; |
234 |
|
} |
235 |
|
|
244 |
|
if (sendq_full()) { |
245 |
|
RAY mySend; |
246 |
|
int rval; |
247 |
< |
copystruct(&mySend, r); |
247 |
> |
mySend = *r; |
248 |
|
/* wait for a result */ |
249 |
|
rval = ray_presult(r, 0); |
250 |
|
/* put new ray in queue */ |
251 |
< |
copystruct(&r_queue[r_send_next], &mySend); |
251 |
> |
r_queue[r_send_next] = mySend; |
252 |
|
r_send_next++; |
253 |
|
return(rval); /* done */ |
254 |
|
} |
255 |
|
/* add ray to send queue */ |
256 |
< |
copystruct(&r_queue[r_send_next], r); |
256 |
> |
r_queue[r_send_next] = *r; |
257 |
|
r_send_next++; |
258 |
|
/* check for returned ray... */ |
259 |
|
if (r_recv_first >= r_recv_next) |
260 |
|
return(0); |
261 |
|
/* ...one is sitting in queue */ |
262 |
< |
copystruct(r, &r_queue[r_recv_first]); |
262 |
> |
*r = r_queue[r_recv_first]; |
263 |
|
r_recv_first++; |
264 |
|
return(1); |
265 |
|
} |
279 |
|
return(0); |
280 |
|
/* check queued results first */ |
281 |
|
if (r_recv_first < r_recv_next) { |
282 |
< |
copystruct(r, &r_queue[r_recv_first]); |
282 |
> |
*r = r_queue[r_recv_first]; |
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 */ |
354 |
|
rp->slights = NULL; |
355 |
|
} |
356 |
|
/* return first ray received */ |
357 |
< |
copystruct(r, &r_queue[r_recv_first]); |
357 |
> |
*r = r_queue[r_recv_first]; |
358 |
|
r_recv_first++; |
359 |
|
return(1); |
360 |
|
} |
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 |
|
} |