Skip to content

Commit 1de2fba

Browse files
kmittal2stgeke
authored andcommitted
Cache r-s-t data for local interpolation to avoid redundant communication (#34)
1 parent 00a074c commit 1de2fba

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

src/findpts_imp.h

+57-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#define obbox TOKEN_PASTE(obbox_,D)
32
#define local_hash_data TOKEN_PASTE(findpts_local_hash_data_,D)
43
#define hash_data TOKEN_PASTE(findpts_hash_data_,D)
@@ -23,6 +22,7 @@
2322
#define eval_src_pt TOKEN_PASTE(eval_src_pt_ ,D)
2423
#define eval_out_pt TOKEN_PASTE(eval_out_pt_ ,D)
2524
#define setup_aux TOKEN_PASTE(setup_aux_,D)
25+
#define setup_fev_aux TOKEN_PASTE(setup_fev_aux_,D)
2626
#define findpts_setup TOKEN_PASTE(PREFIXED_NAME(findpts_setup_),D)
2727
#define findpts_free TOKEN_PASTE(PREFIXED_NAME(findpts_free_ ),D)
2828
#define findpts TOKEN_PASTE(PREFIXED_NAME(findpts_ ),D)
@@ -200,6 +200,8 @@ struct findpts_data {
200200
struct crystal cr;
201201
struct findpts_local_data local;
202202
struct hash_data hash;
203+
struct array savpt;
204+
uint fevsetup;
203205
};
204206

205207
static void setup_aux(
@@ -214,6 +216,7 @@ static void setup_aux(
214216
npt_max, newt_tol);
215217
hash_build(&fd->hash,&fd->local.hd,fd->local.obb,nel,
216218
global_hash_size,&fd->cr);
219+
fd->fevsetup = 0;
217220
}
218221

219222
struct findpts_data *findpts_setup(
@@ -236,6 +239,7 @@ void findpts_free(struct findpts_data *fd)
236239
hash_free(&fd->hash);
237240
findpts_local_free(&fd->local);
238241
crystal_free(&fd->cr);
242+
if (fd->fevsetup==1) array_free(&fd->savpt);
239243
free(fd);
240244
}
241245

@@ -250,6 +254,7 @@ void findpts( uint *const code_base , const unsigned code_stride ,
250254
const double *const x_base[D], const unsigned x_stride[D],
251255
const uint npt, struct findpts_data *const fd)
252256
{
257+
if (fd->fevsetup==1) array_free(&fd->savpt); fd->fevsetup=0;
253258
const uint np = fd->cr.comm.np, id=fd->cr.comm.id;
254259
struct array hash_pt, src_pt, out_pt;
255260
/* look locally first */
@@ -377,16 +382,14 @@ void findpts( uint *const code_base , const unsigned code_stride ,
377382
struct eval_src_pt { double r[D]; uint index, proc, el; };
378383
struct eval_out_pt { double out; uint index, proc; };
379384

380-
void findpts_eval(
381-
double *const out_base, const unsigned out_stride,
385+
static void setup_fev_aux(
382386
const uint *const code_base, const unsigned code_stride,
383387
const uint *const proc_base, const unsigned proc_stride,
384388
const uint *const el_base, const unsigned el_stride,
385389
const double *const r_base, const unsigned r_stride,
386-
const uint npt,
387-
const double *const in, struct findpts_data *const fd)
390+
const uint npt, struct findpts_data *const fd)
388391
{
389-
struct array src, outpt;
392+
struct array src;
390393
/* copy user data, weed out unfound points, send out */
391394
{
392395
uint index;
@@ -411,22 +414,59 @@ void findpts_eval(
411414
src.n = pt - (struct eval_src_pt*)src.ptr;
412415
sarray_transfer(struct eval_src_pt,&src,proc,1,&fd->cr);
413416
}
414-
/* evaluate points, send back */
417+
/* setup space for source points*/
415418
{
416419
uint n=src.n;
420+
uint d;
417421
const struct eval_src_pt *spt;
418-
struct eval_out_pt *opt;
422+
struct eval_src_pt *opt;
419423
/* group points by element */
420424
sarray_sort(struct eval_src_pt,src.ptr,n, el,0, &fd->cr.data);
421-
array_init(struct eval_out_pt,&outpt,n), outpt.n=n;
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;
425-
findpts_local_eval(&opt->out ,sizeof(struct eval_out_pt),
426-
&spt->el ,sizeof(struct eval_src_pt),
427-
spt->r ,sizeof(struct eval_src_pt),
428-
src.n, in,&fd->local);
425+
array_init(struct eval_src_pt,&fd->savpt,n), fd->savpt.n=n;
426+
spt=src.ptr, opt=fd->savpt.ptr;
427+
for(;n;--n,++spt,++opt) {
428+
opt->index= spt->index;
429+
opt->proc = spt->proc;
430+
opt->el = spt->el ;
431+
for(d=0;d<D;++d) opt->r[d] = spt->r[d];
432+
}
429433
array_free(&src);
434+
}
435+
}
436+
437+
void findpts_eval(
438+
double *const out_base, const unsigned out_stride,
439+
const uint *const code_base, const unsigned code_stride,
440+
const uint *const proc_base, const unsigned proc_stride,
441+
const uint *const el_base, const unsigned el_stride,
442+
const double *const r_base, const unsigned r_stride,
443+
const uint npt,
444+
const double *const in, struct findpts_data *const fd)
445+
{
446+
if (fd->fevsetup==0) {
447+
setup_fev_aux(code_base,code_stride,
448+
proc_base,proc_stride,
449+
el_base, el_stride,
450+
r_base, r_stride,
451+
npt, fd);
452+
fd->fevsetup=1;
453+
}
454+
struct array outpt;
455+
/* evaluate points, send back */
456+
{
457+
uint n = fd->savpt.n;
458+
struct eval_src_pt *opt;
459+
struct eval_out_pt *opto;
460+
array_init(struct eval_out_pt,&outpt,n), outpt.n=n;
461+
opto=outpt.ptr;
462+
opt=fd->savpt.ptr;
463+
for(;n;--n,++opto,++opt) opto->index=opt->index,opto->proc=opt->proc;
464+
opto=outpt.ptr;
465+
opt=fd->savpt.ptr;
466+
findpts_local_eval(&opto->out ,sizeof(struct eval_out_pt),
467+
&opt->el ,sizeof(struct eval_src_pt),
468+
opt->r ,sizeof(struct eval_src_pt),
469+
fd->savpt.n, in,&fd->local);
430470
sarray_transfer(struct eval_out_pt,&outpt,proc,1,&fd->cr);
431471
}
432472
/* copy results to user data */
@@ -445,6 +485,7 @@ void findpts_eval(
445485
#undef findpts_free
446486
#undef findpts_setup
447487
#undef setup_aux
488+
#undef setup_fev_aux
448489
#undef eval_out_pt
449490
#undef eval_src_pt
450491
#undef out_pt

0 commit comments

Comments
 (0)