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

Comparing ray/src/cv/bsdfmesh.c (file contents):
Revision 2.4 by greg, Thu Nov 8 23:11:41 2012 UTC vs.
Revision 2.5 by greg, Thu Nov 8 23:32:30 2012 UTC

# Line 197 | Line 197 | min_cost(double amt2move, const double *avail, const P
197          int             j;
198  
199          if (amt2move <= FTINY)                  /* pre-emptive check */
200 <                return(0.);
200 >                return(.0);
201                                                  /* move cheapest first */
202          for (j = 0; j < pm->ncols && amt2move > FTINY; j++) {
203                  int     d = psortrow(pm,s)[j];
# Line 215 | Line 215 | migration_step(MIGRATION *mig, double *src_rem, double
215   {
216          const double    maxamt = 1./(double)pm->ncols;
217          const double    minamt = maxamt*5e-6;
218 <        static double   *src_cost = NULL;
219 <        static int      n_alloc = 0;
218 >        double          *src_cost;
219          struct {
220                  int     s, d;   /* source and destination */
221                  double  price;  /* price estimate per amount moved */
222                  double  amt;    /* amount we can move */
223          } cur, best;
224          int             i;
225 <
226 <        if (pm->nrows > n_alloc) {              /* allocate cost array */
227 <                if (n_alloc)
228 <                        free(src_cost);
229 <                src_cost = (double *)malloc(sizeof(double)*pm->nrows);
230 <                if (src_cost == NULL) {
232 <                        fprintf(stderr, "%s: Out of memory in migration_step()\n",
233 <                                        progname);
234 <                        exit(1);
235 <                }
236 <                n_alloc = pm->nrows;
225 >                                                /* allocate cost array */
226 >        src_cost = (double *)malloc(sizeof(double)*pm->nrows);
227 >        if (src_cost == NULL) {
228 >                fprintf(stderr, "%s: Out of memory in migration_step()\n",
229 >                                progname);
230 >                exit(1);
231          }
232          for (i = pm->nrows; i--; )              /* starting costs for diff. */
233                  src_cost[i] = min_cost(src_rem[i], dst_rem, pm, i);
# Line 242 | Line 236 | migration_step(MIGRATION *mig, double *src_rem, double
236          best.s = best.d = -1; best.price = FHUGE; best.amt = 0;
237          for (cur.s = pm->nrows; cur.s--; ) {
238              double      cost_others = 0;
239 +
240              if (src_rem[cur.s] <= minamt)
241                      continue;
242                                                  /* examine cheapest dest. */
243              for (i = 0; i < pm->ncols; i++)
244 <                if (dst_rem[cur.d = psortrow(pm,cur.s)[i]] > minamt)
244 >                if (dst_rem[ cur.d = psortrow(pm,cur.s)[i] ] > minamt)
245                          break;
246              if (i >= pm->ncols)
247 <                    return(.0);
247 >                break;
248              if ((cur.price = pricerow(pm,cur.s)[cur.d]) >= best.price)
249 <                    continue;                   /* no point checking further */
249 >                continue;                       /* no point checking further */
250              cur.amt = (src_rem[cur.s] < dst_rem[cur.d]) ?
251                                  src_rem[cur.s] : dst_rem[cur.d];
252              if (cur.amt > maxamt) cur.amt = maxamt;
# Line 265 | Line 260 | migration_step(MIGRATION *mig, double *src_rem, double
260              if (cur.price < best.price)         /* are we better than best? */
261                      best = cur;
262          }
263 <        if ((best.s < 0) | (best.d < 0))
263 >        free(src_cost);                         /* finish up */
264 >
265 >        if ((best.s < 0) | (best.d < 0))        /* nothing left to move? */
266                  return(.0);
267 <                                                /* make the actual move */
267 >                                                /* else make the actual move */
268          mtx_coef(mig,best.s,best.d) += best.amt;
269          src_rem[best.s] -= best.amt;
270          dst_rem[best.d] -= best.amt;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines