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

Comparing ray/src/hd/rholo3.c (file contents):
Revision 3.4 by gregl, Tue Nov 4 11:52:21 1997 UTC vs.
Revision 3.12 by gregl, Mon Dec 1 16:35:02 1997 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ SGI";
10  
11   #include "rholo.h"
12  
13
13   #define abs(x)          ((x) > 0 ? (x) : -(x))
14   #define sgn(x)          ((x) > 0 ? 1 : (x) < 0 ? -1 : 0)
15  
17
16   static PACKHEAD *complist=NULL; /* list of beams to compute */
17   static int      complen=0;      /* length of complist */
18   static int      listpos=0;      /* current list position for next_packet */
# Line 25 | Line 23 | int
23   beamcmp(b0, b1)                 /* comparison for descending compute order */
24   register PACKHEAD       *b0, *b1;
25   {
26 <        return( b1->nr*(bnrays(hdlist[b0->hd],b0->bi)+1) -
29 <                b0->nr*(bnrays(hdlist[b1->hd],b1->bi)+1) );
26 >        return( b1->nr*(b0->nc+1) - b0->nr*(b1->nc+1) );
27   }
28  
29  
# Line 53 | Line 50 | int    nents;
50                  if (complist == NULL)
51                          goto memerr;
52                  bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD));
53 <                complen = nents;
57 <                listpos = 0;
58 <                lastin = -1;            /* flag for initial sort */
53 >                complen = nents;        /* finish initialization below */
54                  break;
55          case BS_ADD:                    /* add to computation set */
56 +        case BS_ADJ:                    /* adjust set quantities */
57                  if (nents <= 0)
58                          return;
59                                          /* merge any common members */
60 <                for (i = 0; i < complen; i++)
61 <                        for (n = 0; n < nents; n++)
60 >                for (n = 0; n < nents; n++) {
61 >                        for (i = 0; i < complen; i++)
62                                  if (clist[n].bi == complist[i].bi &&
63                                                  clist[n].hd == complist[i].hd) {
64 <                                        complist[i].nr += clist[n].nr;
64 >                                        int     oldnr = complist[i].nr;
65 >                                        if (op == BS_ADD)
66 >                                                complist[i].nr += clist[n].nr;
67 >                                        else /* op == BS_ADJ */
68 >                                                complist[i].nr = clist[n].nr;
69                                          clist[n].nr = 0;
70 <                                        lastin = -1;    /* flag full sort */
70 >                                        clist[n].nc = complist[i].nc;
71 >                                        if (complist[i].nr != oldnr)
72 >                                                lastin = -1;    /* flag sort */
73                                          break;
74                                  }
75 +                        if (i >= complen)
76 +                                clist[n].nc = bnrays(hdlist[clist[n].hd],
77 +                                                clist[n].bi);
78 +                }
79                                          /* sort updated list */
80                  sortcomplist();
81                                          /* sort new entries */
82                  qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp);
83                                          /* what can't we satisfy? */
84 <                for (n = 0; n < nents && clist[n].nr >
79 <                                bnrays(hdlist[clist[n].hd],clist[n].bi); n++)
84 >                for (n = 0; n < nents && clist[n].nr > clist[n].nc; n++)
85                          ;
86 +                if (op == BS_ADJ)
87 +                        nents = n;
88                  if (n) {                /* allocate space for merged list */
89                          PACKHEAD        *newlist;
90                          newlist = (PACKHEAD *)malloc(
# Line 110 | Line 117 | int    nents;
117                                          lastin = -1;    /* flag full sort */
118                                          break;
119                                  }
113                if (lastin < 0)         /* sort updated list */
114                        sortcomplist();
120                  return;                 /* no display */
121          default:
122                  error(CONSISTENCY, "bundle_set called with unknown operation");
123          }
124 <        n = 0;                          /* allocate packet holder */
125 <        for (i = 0; i < nents; i++)
126 <                if (clist[i].nr > n)
127 <                        n = clist[i].nr;
123 <        p = (PACKHEAD *)malloc(sizeof(PACKHEAD) + n*sizeof(RAYVAL));
124 >        if (outdev == NULL)
125 >                return;
126 >        n = 32*RPACKSIZ;                /* allocate packet holder */
127 >        p = (PACKHEAD *)malloc(packsiz(n));
128          if (p == NULL)
129                  goto memerr;
130                                          /* display what we have */
131          for (i = 0; i < nents; i++)
132                  if ((b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) {
133 <                        bcopy((char *)hdbray(b), (char *)(p+1),
134 <                                        (p->nr=b->nrm)*sizeof(RAYVAL));
135 <                        disp_packet((PACKET *)p);
133 >                        if (b->nrm > n) {
134 >                                n = b->nrm;
135 >                                p = (PACKHEAD *)realloc((char *)p, packsiz(n));
136 >                                if (p == NULL)
137 >                                        goto memerr;
138 >                        }
139 >                        bcopy((char *)hdbray(b), (char *)packra(p),
140 >                                        b->nrm*sizeof(RAYVAL));
141 >                        p->hd = clist[i].hd;
142 >                        p->bi = clist[i].bi;
143 >                        p->nr = p->nc = b->nrm;
144 >                        disp_packet(p);
145                  }
146          free((char *)p);                /* clean up */
147 +        if (op == BS_NEW) {
148 +                done_packets(flush_queue());    /* empty queue, so we can... */
149 +                for (i = 0; i < complen; i++)   /* ...get number computed */
150 +                        complist[i].nc = bnrays(hdlist[complist[i].hd],
151 +                                                complist[i].bi);
152 +                listpos = 0;
153 +                lastin = -1;            /* flag for initial sort */
154 +        }
155          return;
156   memerr:
157          error(SYSTEM, "out of memory in bundle_set");
# Line 230 | Line 251 | init_global()                  /* initialize global ray computation *
251                          wtotal += complist[k++].nr;
252                  }
253                                          /* adjust weights */
254 <        if (vdef(DISKSPACE)) {
254 >        if (vdef(DISKSPACE))
255                  frac = 1024.*1024.*vflt(DISKSPACE) / (wtotal*sizeof(RAYVAL));
256 <                if (frac < 0.95 | frac > 1.05)
257 <                        while (k--)
258 <                                complist[k].nr = frac * complist[k].nr;
259 <        }
256 >        else
257 >                frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL));
258 >        while (k--)
259 >                complist[k].nr = frac * complist[k].nr;
260          listpos = 0; lastin = -1;       /* flag initial sort */
261   }
262  
# Line 268 | Line 289 | sortcomplist()                 /* fix our list order */
289          PACKHEAD        *list2;
290          register int    i;
291  
271                                /* empty queue */
272        done_packets(flush_queue());
292          if (complen <= 0)       /* check to see if there is even a list */
293                  return;
294 <        if (lastin < 0)         /* flag to sort entire list */
294 >        if (lastin < 0 || listpos*4 >= complen*3)
295                  qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp);
296          else if (listpos) {     /* else sort and merge sublist */
297                  list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD));
# Line 284 | Line 303 | sortcomplist()                 /* fix our list order */
303                                  complist+listpos, complen-listpos);
304                  free((char *)list2);
305          }
287                                        /* check for all finished */
288        if (complist[0].nr <= bnrays(hdlist[complist[0].hd],complist[0].bi)) {
289                free((char *)complist);
290                complist = NULL;
291                complen = 0;
292        }
306                                          /* drop satisfied requests */
307 <        for (i = complen; i-- && complist[i].nr <=
295 <                        bnrays(hdlist[complist[i].hd],complist[i].bi); )
307 >        for (i = complen; i-- && complist[i].nr <= complist[i].nc; )
308                  ;
309          if (i < 0) {
310                  free((char *)complist);
# Line 316 | Line 328 | sortcomplist()                 /* fix our list order */
328   * a given bundle to move way down in the computation order.  We keep
329   * track of where the computed bundle with the highest priority would end
330   * up, and if we get further in our compute list than this, we resort the
331 < * list and start again from the beginning.  We have to flush the queue
332 < * each time we sort, to ensure that we are not disturbing the order.
321 < *      If our major assumption is violated, and we have a very steep
322 < * descent in our weights, then we will end up resorting much more often
323 < * than necessary, resulting in frequent flushing of the queue.  Since
324 < * a merge sort is used, the sorting costs will be minimal.
331 > * list and start again from the beginning.  Since
332 > * a merge sort is used, the sorting costs are minimal.
333   */
334   next_packet(p)                  /* prepare packet for computation */
335   register PACKET *p;
336   {
329        int     ncomp;
337          register int    i;
338  
332        if (complen <= 0)
333                return(0);
339          if (listpos > lastin)           /* time to sort the list */
340                  sortcomplist();
341 +        if (complen <= 0)
342 +                return(0);
343          p->hd = complist[listpos].hd;
344          p->bi = complist[listpos].bi;
345 <        ncomp = bnrays(hdlist[p->hd],p->bi);
346 <        p->nr = complist[listpos].nr - ncomp;
345 >        p->nc = complist[listpos].nc;
346 >        p->nr = complist[listpos].nr - p->nc;
347          if (p->nr <= 0)
348                  return(0);
349          if (p->nr > RPACKSIZ)
350                  p->nr = RPACKSIZ;
351 <        ncomp += p->nr;                 /* find where this one would go */
352 <        while (lastin > listpos && complist[listpos].nr *
353 <                (bnrays(hdlist[complist[lastin].hd],complist[lastin].bi)+1)
347 <                        > complist[lastin].nr * (ncomp+1))
351 >        complist[listpos].nc += p->nr;  /* find where this one would go */
352 >        while (lastin > listpos &&
353 >                        beamcmp(complist+lastin, complist+listpos) > 0)
354                  lastin--;
355          listpos++;
356          return(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines