Skip to content

Commit 39d1baa

Browse files
committed
Revert "[findpt] No more setup inside findpt_eval (#43)"
This reverts commit 26e56f4.
1 parent 26e56f4 commit 39d1baa

File tree

1 file changed

+60
-67
lines changed

1 file changed

+60
-67
lines changed

src/findpts_imp.h

+60-67
Original file line numberDiff line numberDiff line change
@@ -266,62 +266,6 @@ void findptsms_free(struct findpts_data *fd)
266266
free(fd);
267267
}
268268

269-
270-
struct eval_src_pt { double r[D]; uint index, proc, el; };
271-
struct eval_out_pt { double out; uint index, proc; };
272-
273-
static void setup_fev_aux(
274-
const uint *const code_base, const unsigned code_stride,
275-
const uint *const proc_base, const unsigned proc_stride,
276-
const uint *const el_base, const unsigned el_stride,
277-
const double *const r_base, const unsigned r_stride,
278-
const uint npt, struct findpts_data *const fd)
279-
{
280-
struct array src;
281-
/* copy user data, weed out unfound points, send out */
282-
{
283-
uint index;
284-
const uint *code=code_base, *proc=proc_base, *el=el_base;
285-
const double *r=r_base;
286-
struct eval_src_pt *pt;
287-
array_init(struct eval_src_pt, &src, npt), pt=src.ptr;
288-
for(index=0;index<npt;++index) {
289-
if(*code!=CODE_NOT_FOUND) {
290-
unsigned d;
291-
for(d=0;d<D;++d) pt->r[d]=r[d];
292-
pt->index=index;
293-
pt->proc=*proc;
294-
pt->el=*el;
295-
++pt;
296-
}
297-
r = (const double*)((const char*)r + r_stride);
298-
code = (const uint*)((const char*)code+code_stride);
299-
proc = (const uint*)((const char*)proc+proc_stride);
300-
el = (const uint*)((const char*)el + el_stride);
301-
}
302-
src.n = pt - (struct eval_src_pt*)src.ptr;
303-
sarray_transfer(struct eval_src_pt,&src,proc,1,&fd->cr);
304-
}
305-
/* setup space for source points*/
306-
{
307-
uint n=src.n;
308-
uint d;
309-
const struct eval_src_pt *spt;
310-
struct eval_src_pt *opt;
311-
/* group points by element */
312-
sarray_sort(struct eval_src_pt,src.ptr,n, el,0, &fd->cr.data);
313-
array_init(struct eval_src_pt,&fd->savpt,n), fd->savpt.n=n;
314-
spt=src.ptr, opt=fd->savpt.ptr;
315-
for(;n;--n,++spt,++opt) {
316-
opt->index= spt->index;
317-
opt->proc = spt->proc;
318-
opt->el = spt->el ;
319-
for(d=0;d<D;++d) opt->r[d] = spt->r[d];
320-
}
321-
array_free(&src);
322-
}
323-
}
324-
325269
struct src_pt { double x[D]; uint index, proc, session_id; };
326270
struct out_pt { double r[D], dist2, disti; uint index, code, el, proc, elsid; };
327271

@@ -577,14 +521,60 @@ void findptsms( uint *const code_base, const unsigned code
577521
}
578522
free(distv);
579523
free(elsidv);
580-
581-
if (fd->fevsetup==0) {
582-
setup_fev_aux(code_base,code_stride,
583-
proc_base,proc_stride,
584-
el_base, el_stride,
585-
r_base, r_stride,
586-
npt, fd);
587-
fd->fevsetup=1;
524+
}
525+
526+
struct eval_src_pt { double r[D]; uint index, proc, el; };
527+
struct eval_out_pt { double out; uint index, proc; };
528+
529+
static void setup_fev_aux(
530+
const uint *const code_base, const unsigned code_stride,
531+
const uint *const proc_base, const unsigned proc_stride,
532+
const uint *const el_base, const unsigned el_stride,
533+
const double *const r_base, const unsigned r_stride,
534+
const uint npt, struct findpts_data *const fd)
535+
{
536+
struct array src;
537+
/* copy user data, weed out unfound points, send out */
538+
{
539+
uint index;
540+
const uint *code=code_base, *proc=proc_base, *el=el_base;
541+
const double *r=r_base;
542+
struct eval_src_pt *pt;
543+
array_init(struct eval_src_pt, &src, npt), pt=src.ptr;
544+
for(index=0;index<npt;++index) {
545+
if(*code!=CODE_NOT_FOUND) {
546+
unsigned d;
547+
for(d=0;d<D;++d) pt->r[d]=r[d];
548+
pt->index=index;
549+
pt->proc=*proc;
550+
pt->el=*el;
551+
++pt;
552+
}
553+
r = (const double*)((const char*)r + r_stride);
554+
code = (const uint*)((const char*)code+code_stride);
555+
proc = (const uint*)((const char*)proc+proc_stride);
556+
el = (const uint*)((const char*)el + el_stride);
557+
}
558+
src.n = pt - (struct eval_src_pt*)src.ptr;
559+
sarray_transfer(struct eval_src_pt,&src,proc,1,&fd->cr);
560+
}
561+
/* setup space for source points*/
562+
{
563+
uint n=src.n;
564+
uint d;
565+
const struct eval_src_pt *spt;
566+
struct eval_src_pt *opt;
567+
/* group points by element */
568+
sarray_sort(struct eval_src_pt,src.ptr,n, el,0, &fd->cr.data);
569+
array_init(struct eval_src_pt,&fd->savpt,n), fd->savpt.n=n;
570+
spt=src.ptr, opt=fd->savpt.ptr;
571+
for(;n;--n,++spt,++opt) {
572+
opt->index= spt->index;
573+
opt->proc = spt->proc;
574+
opt->el = spt->el ;
575+
for(d=0;d<D;++d) opt->r[d] = spt->r[d];
576+
}
577+
array_free(&src);
588578
}
589579
}
590580

@@ -598,10 +588,13 @@ void findptsms_eval(
598588
const double *const in, struct findpts_data *const fd)
599589
{
600590
if (fd->fevsetup==0) {
601-
printf("Please call findpt in advance\n");
602-
die(1);
591+
setup_fev_aux(code_base,code_stride,
592+
proc_base,proc_stride,
593+
el_base, el_stride,
594+
r_base, r_stride,
595+
npt, fd);
596+
fd->fevsetup=1;
603597
}
604-
605598
struct array outpt;
606599
/* evaluate points, send back */
607600
{

0 commit comments

Comments
 (0)