2 #define obbox TOKEN_PASTE(obbox_,D)
3 #define local_hash_data TOKEN_PASTE(findpts_local_hash_data_,D)
4 #define hash_data TOKEN_PASTE(findpts_hash_data_,D)
5 #define hash_index TOKEN_PASTE(hash_index_ ,D)
6 #define hash_setfac TOKEN_PASTE(hash_setfac_ ,D)
7 #define hash_range TOKEN_PASTE(hash_range_ ,D)
8 #define hash_bb TOKEN_PASTE(hash_bb_ ,D)
9 #define set_local_mask TOKEN_PASTE(set_local_mask_ ,D)
10 #define fill_hash TOKEN_PASTE(fill_hash_ ,D)
11 #define table_from_hash TOKEN_PASTE(table_from_hash_ ,D)
12 #define hash_build TOKEN_PASTE(hash_build_ ,D)
13 #define hash_free TOKEN_PASTE(hash_free_ ,D)
15 #define findpts_local_data TOKEN_PASTE(findpts_local_data_,D)
16 #define findpts_local_setup TOKEN_PASTE(PREFIXED_NAME(findpts_local_setup_),D)
17 #define findpts_local_free TOKEN_PASTE(PREFIXED_NAME(findpts_local_free_ ),D)
18 #define findpts_local TOKEN_PASTE(PREFIXED_NAME(findpts_local_ ),D)
19 #define findpts_local_eval TOKEN_PASTE(PREFIXED_NAME(findpts_local_eval_ ),D)
20 #define findpts_data TOKEN_PASTE(findpts_data_,D)
21 #define src_pt TOKEN_PASTE(src_pt_ ,D)
22 #define out_pt TOKEN_PASTE(out_pt_ ,D)
23 #define eval_src_pt TOKEN_PASTE(eval_src_pt_ ,D)
24 #define eval_out_pt TOKEN_PASTE(eval_out_pt_ ,D)
25 #define setup_aux TOKEN_PASTE(setup_aux_,D)
26 #define findpts_setup TOKEN_PASTE(PREFIXED_NAME(findpts_setup_),D)
27 #define findpts_free TOKEN_PASTE(PREFIXED_NAME(findpts_free_ ),D)
28 #define findpts TOKEN_PASTE(PREFIXED_NAME(findpts_ ),D)
29 #define findpts_eval TOKEN_PASTE(PREFIXED_NAME(findpts_eval_ ),D)
58 const ulong i1 =
lceil ( (r.max - p->bnd[d].
min) * p->fac[d] );
59 ir.
min = i0<0 ? 0 : i0;
60 ir.
max = i1<p->hash_n ? i1 : p->hash_n;
68 double x[
D], buf[
D], ghs;
70 for(d=0;d<
D;++d) x[d]=lp->bnd[d].min;
72 for(d=0;d<
D;++d) p->
bnd[d].
min=x[d];
74 for(d=0;d<D;++d) x[d]=lp->bnd[d].max;
76 for(d=0;d<
D;++d) p->
bnd[d].
max=x[d];
83 printf(
"global bounding box (%g^%u):\n",(
double)p->
hash_n,D);
84 for(d=0;d<
D;++d) printf(
" [%.17g, %.17g]\n",p->
bnd[d].
min,p->
bnd[d].
max);
90 const ulong local_base[
D],
const uint local_n[D],
92 const struct obbox *
const obb,
const uint nel
96 for(el=0;el<nel;++el) {
99 #define FOR_LOOP() do { ulong i,j; WHEN_3D(ulong k;) \
100 WHEN_3D(for(k=ir[2].min;k<ir[2].max;++k)) \
101 for(j=ir[1].min;j<ir[1].max;++j) \
102 for(i=ir[0].min;i<ir[0].max;++i) \
103 set_bit(local_mask, (WHEN_3D((k-local_base[2]) *local_n[1]) \
104 +(j-local_base[1]))*local_n[0] \
114 const unsigned char *
const local_mask,
115 const ulong local_base[
D],
const uint local_n[D],
119 #define FOR_LOOP() do { uint bit=0,i,j; WHEN_3D(uint k;) \
120 WHEN_3D(for(k=0;k<local_n[2];++k)) \
121 for(j=0;j<local_n[1];++j) \
122 for(i=0;i<local_n[0];++i) { ulong hi; \
123 if(get_bit(local_mask,bit++)==0) continue; \
124 hi = (WHEN_3D( (local_base[2]+k) *hn ) \
125 +(local_base[1]+j))*hn \
126 +(local_base[0]+i); \
127 hp->proc = hi%np, hp->index = hi/np; \
136 struct array *
const hash,
141 uint ncell, *offset,
i, next_cell;
145 ncell = (hnd-1)/np+1;
151 const uint off = ncell+1+
i;
152 offset[off]=hp[
i].
proc;
153 while(next_cell<=cell ) offset[next_cell++]=off;
155 {
const uint off = ncell+1+
i;
156 while(next_cell<=ncell) offset[next_cell++]=off;
162 const struct obbox *
const obb,
const uint nel,
163 const uint hash_size,
166 ulong local_base[
D];
uint local_n[
D], local_ntot=1;
167 unsigned char *local_mask;
173 local_base[d]=rng.
min;
174 local_n[d]=rng.
max-rng.
min;
175 local_ntot*=local_n[d];
178 printf(
"local_range %u: %lu to %lu\n",
179 d,(
unsigned long)rng.
min,(
unsigned long)rng.
max);
183 local_mask =
tcalloc(
unsigned char, (local_ntot+CHAR_BIT-1)/CHAR_BIT);
185 nc=
count_bits(local_mask,(local_ntot+CHAR_BIT-1)/CHAR_BIT);
187 printf(
"findpts_hash(%u): local cells : %u / %u\n",cr->
comm.
id,nc,local_ntot);
207 const double *
const elx[
D],
208 const unsigned n[D],
const uint nel,
209 const unsigned m[D],
const double bbox_tol,
210 const uint local_hash_size,
const uint global_hash_size,
211 const unsigned npt_max,
const double newt_tol)
216 global_hash_size,&fd->
cr);
221 const double *
const elx[
D],
222 const unsigned n[D],
const uint nel,
223 const unsigned m[D],
const double bbox_tol,
224 const uint local_hash_size,
const uint global_hash_size,
225 const unsigned npt_max,
const double newt_tol)
230 local_hash_size,global_hash_size,npt_max,newt_tol);
245 void findpts(
uint *
const code_base ,
const unsigned code_stride ,
246 uint *
const proc_base ,
const unsigned proc_stride ,
247 uint *
const el_base ,
const unsigned el_stride ,
248 double *
const r_base ,
const unsigned r_stride ,
249 double *
const dist2_base ,
const unsigned dist2_stride ,
250 const double *
const x_base[
D],
const unsigned x_stride[D],
254 struct array hash_pt, src_pt, out_pt;
259 dist2_base,dist2_stride,
265 uint *code=code_base, *proc=proc_base;
268 unsigned d;
for(d=0;d<
D;++d) xp[d]=x_base[d];
270 for(index=0;index<npt;++
index) {
271 double x[
D];
for(d=0;d<
D;++d) x[d]=*xp[d];
276 for(d=0;d<
D;++d) pt->
x[d]=x[d];
282 xp[d] = (
const double*)((
const char*)xp[d]+ x_stride[d]);
283 code = (
uint*)( (
char*)code +code_stride );
284 proc = (
uint*)( (
char*)proc +proc_stride );
286 hash_pt.
n = pt - (
struct src_pt*)hash_pt.
ptr;
293 const struct src_pt *p = hash_pt.
ptr, *
const pe = p+hash_pt.
n;
297 const uint i = hash_offset[hi], ie = hash_offset[hi+1];
302 for(p=hash_pt.
ptr;p!=pe;++p) {
304 uint i = hash_offset[hi];
const uint ie = hash_offset[hi+1];
306 const uint pp = hash_offset[
i];
307 if(pp==p->
proc)
continue;
313 src_pt.
n = proc_p-
proc;
315 printf(
"(proc %u) hashed; routing %u/%u\n",
id,(
unsigned)src_pt.
n,count);
323 const struct src_pt *spt;
326 spt=src_pt.
ptr, opt=out_pt.
ptr;
327 for(;
n;--
n,++spt,++opt) opt->
index=spt->index,opt->
proc=spt->proc;
328 spt=src_pt.
ptr, opt=out_pt.
ptr;
330 const double *spt_x_base[
D];
unsigned spt_x_stride[
D];
331 unsigned d;
for(d=0;d<
D;++d) spt_x_base[d] = spt[0].
x+d,
332 spt_x_stride[d] =
sizeof(
struct src_pt);
334 &opt[0].
el ,
sizeof(
struct out_pt),
335 opt[0].
r ,
sizeof(
struct out_pt),
336 &opt[0].
dist2,
sizeof(
struct out_pt),
337 spt_x_base ,spt_x_stride,
346 printf(
"(proc %u) sending back %u found points\n",
id,(
unsigned)out_pt.
n);
352 #define AT(T,var,i) (T*)((char*)var##_base+(i)*var##_stride)
355 for(opt=out_pt.
ptr;n;--n,++opt) {
358 double *
dist2 =
AT(
double,dist2,index);
362 || opt->
dist2<*dist2) {
363 double *
r =
AT(
double,r,index);
365 unsigned d;
for(d=0;d<
D;++d) r[d]=opt->
r[d];
381 double *
const out_base,
const unsigned out_stride,
382 const uint *
const code_base,
const unsigned code_stride,
383 const uint *
const proc_base,
const unsigned proc_stride,
384 const uint *
const el_base,
const unsigned el_stride,
385 const double *
const r_base,
const unsigned r_stride,
389 struct array src, outpt;
393 const uint *code=code_base, *proc=proc_base, *el=el_base;
394 const double *r=r_base;
397 for(index=0;index<npt;++
index) {
400 for(d=0;d<
D;++d) pt->
r[d]=r[d];
406 r = (
const double*)((
const char*)r + r_stride);
407 code = (
const uint*)((
const char*)code+code_stride);
408 proc = (
const uint*)((
const char*)proc+proc_stride);
409 el = (
const uint*)((
const char*)el + el_stride);
422 spt=src.
ptr, opt=outpt.
ptr;
423 for(;
n;--
n,++spt,++opt) opt->
index=spt->index,opt->
proc=spt->proc;
424 spt=src.
ptr, opt=outpt.
ptr;
434 #define AT(T,var,i) (T*)((char*)var##_base+(i)*var##_stride)
453 #undef findpts_local_eval
455 #undef findpts_local_free
456 #undef findpts_local_setup
457 #undef findpts_local_data
461 #undef table_from_hash
463 #undef set_local_mask
469 #undef local_hash_data
static uint count_bits(unsigned char *p, uint n)
#define tmalloc(type, count)
static slong lfloor(double x)
#define findpts_local_free
#define findpts_local_setup
#define sarray_transfer_ext(T, A, proc, proc_stride, cr)
void comm_allreduce(const struct comm *com, gs_dom dom, gs_op op, void *v, uint vn, void *buf)
#define tcalloc(type, count)
#define findpts_local_eval
struct findpts_local_data local
#define array_init(T, a, max)
static double elx[NR *NS]
#define sarray_sort(T, A, n, field, is_long, buf)
static ulong hash_index_aux(double low, double fac, ulong n, double x)
#define sarray_transfer(T, A, proc_field, set_src, cr)
static slong lceil(double x)