1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
61 |
|
register PACKHEAD *clist; |
62 |
|
int nents; |
63 |
|
{ |
64 |
+ |
int oldnr; |
65 |
|
register int i, n; |
66 |
< |
|
66 |
> |
/* look for common members */ |
67 |
> |
for (n = 0; n < nents; n++) { |
68 |
> |
for (i = 0; i < complen; i++) |
69 |
> |
if (clist[n].bi == complist[i].bi && |
70 |
> |
clist[n].hd == complist[i].hd) { |
71 |
> |
oldnr = complist[i].nr; |
72 |
> |
clist[n].nc = complist[i].nc; |
73 |
> |
switch (op) { |
74 |
> |
case BS_ADD: /* add to count */ |
75 |
> |
complist[i].nr += clist[n].nr; |
76 |
> |
clist[n].nr = 0; |
77 |
> |
break; |
78 |
> |
case BS_ADJ: /* reset count */ |
79 |
> |
complist[i].nr = clist[n].nr; |
80 |
> |
clist[n].nr = 0; |
81 |
> |
break; |
82 |
> |
case BS_DEL: /* delete count */ |
83 |
> |
if (clist[n].nr == 0 || |
84 |
> |
clist[n].nr >= complist[i].nr) |
85 |
> |
complist[i].nr = 0; |
86 |
> |
else |
87 |
> |
complist[i].nr -= clist[n].nr; |
88 |
> |
break; |
89 |
> |
} |
90 |
> |
if (complist[i].nr != oldnr) |
91 |
> |
lastin = -1; /* flag sort */ |
92 |
> |
break; |
93 |
> |
} |
94 |
> |
if (i >= complen) |
95 |
> |
clist[n].nc = bnrays(hdlist[clist[n].hd], clist[n].bi); |
96 |
> |
} |
97 |
> |
/* complete list operations */ |
98 |
|
switch (op) { |
99 |
|
case BS_NEW: /* new computation set */ |
100 |
< |
if (complen) |
100 |
> |
listpos = 0; lastin = -1; |
101 |
> |
if (complen) /* free old list */ |
102 |
|
free((char *)complist); |
103 |
< |
if (nents <= 0) { |
104 |
< |
complist = NULL; |
72 |
< |
listpos = complen = 0; |
73 |
< |
lastin = -1; |
103 |
> |
complist = NULL; |
104 |
> |
if (!(complen = nents)) |
105 |
|
return; |
75 |
– |
} |
106 |
|
complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD)); |
107 |
|
if (complist == NULL) |
108 |
|
goto memerr; |
109 |
|
bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); |
80 |
– |
complen = nents; /* finish initialization below */ |
110 |
|
break; |
111 |
|
case BS_ADD: /* add to computation set */ |
112 |
|
case BS_ADJ: /* adjust set quantities */ |
113 |
|
if (nents <= 0) |
114 |
|
return; |
115 |
< |
/* merge any common members */ |
87 |
< |
for (n = 0; n < nents; n++) { |
88 |
< |
for (i = 0; i < complen; i++) |
89 |
< |
if (clist[n].bi == complist[i].bi && |
90 |
< |
clist[n].hd == complist[i].hd) { |
91 |
< |
int oldnr = complist[i].nr; |
92 |
< |
if (op == BS_ADD) |
93 |
< |
complist[i].nr += clist[n].nr; |
94 |
< |
else /* op == BS_ADJ */ |
95 |
< |
complist[i].nr = clist[n].nr; |
96 |
< |
clist[n].nr = 0; |
97 |
< |
clist[n].nc = complist[i].nc; |
98 |
< |
if (complist[i].nr != oldnr) |
99 |
< |
lastin = -1; /* flag sort */ |
100 |
< |
break; |
101 |
< |
} |
102 |
< |
if (i >= complen) |
103 |
< |
clist[n].nc = bnrays(hdlist[clist[n].hd], |
104 |
< |
clist[n].bi); |
105 |
< |
} |
106 |
< |
/* sort updated list */ |
107 |
< |
sortcomplist(); |
108 |
< |
/* sort new entries */ |
115 |
> |
sortcomplist(); /* sort updated list & new entries */ |
116 |
|
qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); |
117 |
|
/* what can't we satisfy? */ |
118 |
|
for (n = 0; n < nents && clist[n].nr > clist[n].nc; n++) |
136 |
|
lastin = complen-1; /* list is now sorted */ |
137 |
|
break; |
138 |
|
case BS_DEL: /* delete from computation set */ |
139 |
< |
if (nents <= 0) |
133 |
< |
return; |
134 |
< |
/* find each member */ |
135 |
< |
for (i = 0; i < complen; i++) |
136 |
< |
for (n = 0; n < nents; n++) |
137 |
< |
if (clist[n].bi == complist[i].bi && |
138 |
< |
clist[n].hd == complist[i].hd) { |
139 |
< |
if (clist[n].nr == 0 || |
140 |
< |
clist[n].nr >= complist[i].nr) |
141 |
< |
complist[i].nr = 0; |
142 |
< |
else |
143 |
< |
complist[i].nr -= clist[n].nr; |
144 |
< |
lastin = -1; /* flag full sort */ |
145 |
< |
break; |
146 |
< |
} |
147 |
< |
return; /* no display */ |
139 |
> |
return; /* already done */ |
140 |
|
default: |
141 |
|
error(CONSISTENCY, "bundle_set called with unknown operation"); |
142 |
|
} |
151 |
|
hdloadbeams(hb, nents, dispbeam); |
152 |
|
free((char *)hb); |
153 |
|
} |
162 |
– |
if (op == BS_NEW) { |
163 |
– |
done_packets(flush_queue()); /* empty queue, so we can... */ |
164 |
– |
for (i = 0; i < complen; i++) /* ...get number computed */ |
165 |
– |
complist[i].nc = bnrays(hdlist[complist[i].hd], |
166 |
– |
complist[i].bi); |
167 |
– |
listpos = 0; |
168 |
– |
lastin = -1; /* flag for initial sort */ |
169 |
– |
} |
154 |
|
return; |
155 |
|
memerr: |
156 |
|
error(SYSTEM, "out of memory in bundle_set"); |
196 |
|
double frac; |
197 |
|
int i; |
198 |
|
register int j, k; |
199 |
< |
/* free old list */ |
200 |
< |
if (complen > 0) |
199 |
> |
/* free old list and empty queue */ |
200 |
> |
if (complen > 0) { |
201 |
|
free((char *)complist); |
202 |
+ |
done_packets(flush_queue()); |
203 |
+ |
} |
204 |
|
/* allocate beam list */ |
205 |
|
complen = 0; |
206 |
|
for (j = 0; hdlist[j] != NULL; j++) |
211 |
|
/* compute beam weights */ |
212 |
|
k = 0; |
213 |
|
for (j = 0; hdlist[j] != NULL; j++) { |
214 |
< |
frac = 512. * hdlist[j]->wg[0] * |
215 |
< |
hdlist[j]->wg[1] * hdlist[j]->wg[2]; |
216 |
< |
if (frac < 0.) frac = -frac; |
214 |
> |
frac = 512. * VLEN(hdlist[j]->wg[0]) * |
215 |
> |
VLEN(hdlist[j]->wg[1]) * |
216 |
> |
VLEN(hdlist[j]->wg[2]); |
217 |
|
for (i = nbeams(hdlist[j]); i > 0; i--) { |
218 |
|
complist[k].hd = j; |
219 |
|
complist[k].bi = i; |
220 |
|
complist[k].nr = frac*beamvolume(hdlist[j], i) + 0.5; |
221 |
+ |
complist[k].nc = bnrays(hdlist[j], i); |
222 |
|
wtotal += complist[k++].nr; |
223 |
|
} |
224 |
|
} |
229 |
|
frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL)); |
230 |
|
while (k--) |
231 |
|
complist[k].nr = frac * complist[k].nr; |
232 |
< |
listpos = 0; lastin = -1; /* flag initial sort */ |
232 |
> |
listpos = 0; lastin = -1; /* perform initial sort */ |
233 |
> |
sortcomplist(); |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
mergeclists(cdest, cl1, n1, cl2, n2) /* merge two sorted lists */ |
238 |
< |
PACKHEAD *cdest; |
239 |
< |
PACKHEAD *cl1, *cl2; |
238 |
> |
register PACKHEAD *cdest; |
239 |
> |
register PACKHEAD *cl1, *cl2; |
240 |
|
int n1, n2; |
241 |
|
{ |
242 |
< |
int cmp; |
242 |
> |
register int cmp; |
243 |
|
|
244 |
|
while (n1 | n2) { |
245 |
|
if (!n1) cmp = 1; |
304 |
|
* list and start again from the beginning. Since |
305 |
|
* a merge sort is used, the sorting costs are minimal. |
306 |
|
*/ |
307 |
< |
next_packet(p) /* prepare packet for computation */ |
307 |
> |
next_packet(p, n) /* prepare packet for computation */ |
308 |
|
register PACKET *p; |
309 |
+ |
int n; |
310 |
|
{ |
311 |
|
register int i; |
312 |
|
|
320 |
|
p->nr = complist[listpos].nr - p->nc; |
321 |
|
if (p->nr <= 0) |
322 |
|
return(0); |
323 |
< |
if (p->nr > RPACKSIZ) |
324 |
< |
p->nr = RPACKSIZ; |
323 |
> |
#ifdef DEBUG |
324 |
> |
if (n < 1 | n > RPACKSIZ) |
325 |
> |
error(CONSISTENCY, "next_packet called with bad n value"); |
326 |
> |
#endif |
327 |
> |
if (p->nr > n) |
328 |
> |
p->nr = n; |
329 |
|
complist[listpos].nc += p->nr; /* find where this one would go */ |
330 |
|
while (lastin > listpos && |
331 |
|
beamcmp(complist+lastin, complist+listpos) > 0) |