Back to index

radiance  4R0+20100331
raypwin.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char RCSid[] = "$Id: raypwin.c,v 2.6 2009/12/15 19:13:45 greg Exp $";
00003 #endif
00004 /*
00005  *  raypwin.c - interface for parallel rendering using Radiance (Windows ver)
00006  *
00007  *  External symbols declared in ray.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 /*
00013  * See raypcalls.c for an explanation of these routines.
00014  */
00015 
00016 /***** XXX CURRENTLY, THIS IS JUST A COLLECTION OF IMPOTENT STUBS XXX *****/
00017 
00018 #include  "ray.h"
00019 
00020 int           ray_pnprocs = 0;     /* number of child processes */
00021 int           ray_pnidle = 0;             /* number of idle children */
00022 
00023 static RAY    queued_ray;
00024 
00025 void
00026 ray_pinit(           /* initialize ray-tracing processes */
00027        char   *otnm,
00028        int    nproc
00029 )
00030 {
00031        ray_pdone(0);
00032        ray_init(otnm);
00033        ray_popen(nproc);
00034 }
00035 
00036 
00037 int
00038 ray_psend(                  /* add a ray to our send queue */
00039        RAY    *r
00040 )
00041 {
00042        if (r == NULL)
00043               return(0);
00044        if (ray_pnidle <= 0)
00045               return(0);
00046        queued_ray = *r;
00047        ray_pnidle = 0;
00048        return(1);
00049 }
00050 
00051 
00052 int
00053 ray_pqueue(                 /* queue a ray for computation */
00054        RAY    *r
00055 )
00056 {
00057        if (r == NULL)
00058               return(0);
00059        if (ray_pnidle <= 0) {
00060               RAY    new_ray = *r;
00061               *r = queued_ray;
00062               queued_ray = new_ray;
00063        }
00064        samplendx++;
00065        rayvalue(r);
00066        return(1);
00067 }
00068 
00069 
00070 int
00071 ray_presult(         /* check for a completed ray */
00072        RAY    *r,
00073        int    poll
00074 )
00075 {
00076        if (r == NULL)
00077               return(0);
00078        if (ray_pnidle <= 0) {
00079               *r = queued_ray;
00080               samplendx++;
00081               rayvalue(r);
00082               ray_pnidle = 1;
00083               return(1);
00084        }
00085        return(0);
00086 }
00087 
00088 
00089 void
00090 ray_pdone(           /* reap children and free data */
00091        int    freall
00092 )
00093 {
00094        ray_done(freall);
00095        ray_pnprocs = ray_pnidle = 0;
00096 }
00097 
00098 
00099 void
00100 ray_popen(                  /* open the specified # processes */
00101        int    nadd
00102 )
00103 {
00104        if (ray_pnprocs + nadd > 1) {
00105               error(WARNING, "only single process supported");
00106               nadd = 1 - ray_pnprocs;
00107        }
00108        ray_pnprocs += nadd;
00109        ray_pnidle += nadd;
00110 }
00111 
00112 
00113 void
00114 ray_pclose(          /* close one or more child processes */
00115        int    nsub
00116 )
00117 {
00118        if (nsub > ray_pnprocs)
00119               nsub = ray_pnprocs;
00120        ray_pnprocs -= nsub;
00121        if ((ray_pnidle -= nsub) < 0)
00122               ray_pnidle = 0;
00123 }
00124 
00125 
00126 void
00127 quit(ec)                    /* make sure exit is called */
00128 int    ec;
00129 {
00130        exit(ec);
00131 }