28 this->hash_tbl_siz = hash_tbl_siz;
29 this->const_hlp(ndim);
40 hash_tbl_siz = hash_tbl_sz;
41 this->const_hlp(ndim);
42 this->hash_tbl_siz = hash_tbl_siz;
52 void dim_mgr::const_hlp(int32_t ndim) {
60 for(
int i = 0;
i < ndim;
i++ )
65 dim_info[
i]->
type = 0;
68 hash_tbl =
new vector <hash_entry_struc>[hash_tbl_siz];
69 gpt_hash_tbl =
new vector <gpt_hash_struc>[hash_tbl_siz];
72 int ncorner = pow( 2, ndim );
73 pt_info.
pt_status = (int32_t *)malloc( ncorner *
sizeof(int32_t ) );
74 pt_info.
pt_base_loc = (int32_t *)malloc( ndim *
sizeof(int32_t ) );
75 pt_info.
wt = (
double *)malloc( ndim *
sizeof(
double) );
76 pt_info.
wt_pt = (
double *)malloc( ncorner *
sizeof(
double) );
77 pt_info.
dat_ptrs = (
void **)malloc( ncorner *
sizeof(
void *) );
85 delete[] gpt_hash_tbl;
86 for(
int i = 0;
i < ndim;
i++ )
88 if( dim_info[
i]->
type == 1 )
89 free( dim_info[
i]->dim_coords );
96 free( pt_info.
wt_pt );
114 n_tot_dat_blobs += nptadd;
141 double min,
double max ) {
143 if( dim_info ==
NULL ) {
144 cout << __FILE__ << __LINE__ <<
" dim_info array is null\n";
147 if( dim_info[dim_num]->
nvals != 0 ) {
148 cout << __FILE__ << __LINE__ <<
" dim_info array entry " << dim_num <<
149 " is filled already\n";
153 dim_info[dim_num]->
min =
min;
154 dim_info[dim_num]->
max =
max;
155 dim_info[dim_num]->
type = 0;
173 double *dim_coords ) {
175 if( dim_info ==
NULL ) {
176 cout << __FILE__ << __LINE__ <<
" dim_info array is null\n";
179 if( dim_info[dim_num]->dim_coords !=
NULL ) {
180 cout << __FILE__ << __LINE__ <<
" dim_info array entry " << dim_num <<
181 " is filled already\n";
185 dim_info[dim_num]->
min = dim_coords[0];
186 dim_info[dim_num]->
max = dim_coords[
nvals - 1 ];
187 dim_info[dim_num]->
type = 1;
189 (
double *)malloc(
nvals *
sizeof(
double ) );
191 dim_info[dim_num]->dim_coords[
i] = dim_coords[
i];
203 int32_t npt = pow( 2, ndim );
210 for(
int i = 0;
i < npt;
i++ )
249 int32_t idim, idat, ndat, same_interval;
250 int32_t *ix, *ix_real, *offset_lcl, acc_mode, ret;
258 if( old_pt[0] == old_pt[0] )
261 for( idim = 0; idim < ndim; idim++ )
263 if( *( pt + idim ) != *( old_pt + idim ) )
275 for( idim = 0; idim < ndim; idim++ )
276 *( old_pt + idim ) = *( pt + idim );
280 if( ( ( ix = (int32_t *) malloc( ndim *
sizeof( int32_t ) ) ) ==
NULL ) ||
281 ( ( ix_real = (int32_t *)
282 malloc( ndim *
sizeof( int32_t ) ) ) ==
NULL ) ||
283 ( ( offset_lcl = (int32_t *)
284 malloc( ndim *
sizeof( int32_t ) ) ) ==
NULL ) )
286 printf(
"%s, %d: Unable to allocate the dim index array\n", __FILE__,
294 ndat = pow( 2., ndim );
298 if( sparse_get_loc( dim_info, ndim, pt, ix, pt_info.
wt, pt_info.
wt_pt )
316 if( prev_int !=
NULL )
320 for( idim = 0; idim < ndim; idim++ )
330 if( same_interval == 1 )
332 found_int = prev_int;
341 valarray<int> ix_val(ndim);
342 for(
int i = 0;
i < ndim;
i++ )
344 found_int = access( ix_val, acc_mode );
358 if( share_gpt( found_int, ix ) != 0 ) {
367 for( idat = 0; idat < ndat; idat++ )
372 valarray<int> ixv_off(ndim);
382 for( idim = 0; idim < ndim; idim++ )
384 ix_real[idim] = ix[idim] + offset_lcl[idim];
385 ixv_off[idim] = ix_real[idim];
396 ret = gpt_add( ixv_off, found_int->
dat_info[idat] );
410 prev_int = found_int;
415 free( ix ); free( ix_real ); free( offset_lcl );
418 for(
int i = 0;
i < ndim;
i++ )
420 for(
int i = 0;
i < ndat;
i++ ) {
434 int32_t dim_mgr::sparse_get_loc(
dim_info_struc **dim_info, int32_t ndim,
435 double *pt, int32_t *ix,
double *wt,
double *wt_pt )
468 int32_t idim, iint, full_len, msk;
472 full_len = pow( 2, ndim );
473 for( idim = 0; idim < full_len; idim++ )
474 *( wt_pt + idim ) = 1.;
478 for( idim = 0; idim < ndim; idim++ )
481 if( ( pt[idim] < dim_info[idim]->
min ) ||
482 ( pt[idim] > dim_info[idim]->
max ) )
488 for( iint = 1; iint < dim_info[idim]->
nvals; iint++ )
490 if( pt[idim] <= dim_info[idim]->dim_coords[iint] )
494 wt[idim] = ( pt[idim] - dim_info[idim]->
dim_coords[iint-1] ) /
495 ( dim_info[idim]->dim_coords[iint] -
496 dim_info[idim]->dim_coords[iint-1] );
506 msk = pow( 2, idim );
507 for( iint = 0; iint < full_len; iint++ )
509 if( ( iint & msk ) == 0 )
510 *( wt_pt + iint ) *= 1. - wt[idim];
512 *( wt_pt + iint ) *= wt[idim];
541 int32_t ndat = pow( 2, ndim );
544 int index = hash_func(
s, hash_tbl_siz );
546 for(
long unsigned int i = 0;
i < hash_tbl[
index].size();
i++)
551 if( ( hash_tbl[
index][
i].ix_arr ==
s ).
min() != 0 )
557 hash_tbl[
index].erase( hash_tbl[
index].begin() +
i );
558 cout <<
"Set is removed" << endl;
565 return hash_tbl[
index][
i].int_str;
586 hash_tbl[
index].push_back(hash_entry);
594 cout <<
"Code should not get here!/n";
622 int index = hash_func(
s, hash_tbl_siz );
624 for(
long unsigned int i = 0;
i < gpt_hash_tbl[
index].size();
i++)
626 if( ( gpt_hash_tbl[
index][
i].ix_arr ==
s ).
min() != 0 )
629 cout << __FILE__ << __LINE__ <<
630 "Error: grid point is already in hash table, Exiting" << endl;
640 gpt_hash_tbl[
index].push_back( hash_entry );
648 int dim_mgr::hash_func(valarray<int>
s, int32_t hash_tbl_siz )
672 if( hash_ifirst == 0 ) {
673 int32_t ndim =
s.size();
675 hash_h_mult = hash_tbl_siz / ( 2 * ndim );
676 hash_h_mult = hash_h_mult - ndim / 2;
679 for(
long unsigned int i = 0;
i <
s.size();
i++ )
680 sum += ( hash_h_mult +
i ) *
s[
i];
681 sum = sum % hash_tbl_siz;
711 valarray<int>
s(ndim);
712 int32_t npt = pow( 2, ndim );
713 ix_off = ( int32_t * ) malloc( ndim *
sizeof(int32_t) );
716 for(
int ipt = 0; ipt < npt; ipt++ )
720 for(
i = 0;
i < ndim;
i++ )
727 int index = hash_func(
s, hash_tbl_siz );
728 for(
i = 0;
i < (int32_t)gpt_hash_tbl[
index].
size();
i++ )
730 if( ( gpt_hash_tbl[
index][
i].ix_arr ==
s ).min() != 0 )
754 int32_t nhash = hash_tbl_siz;
755 int32_t ndat = pow( 2, ndim );
758 for(
int ihash = 0; ihash < nhash; ihash++ )
760 int32_t nentry = hash_tbl[ihash].size();
761 for(
int iint = 0; iint < nentry; iint++ )
769 for(
int idat = 0; idat < ndat; idat++ )
792 hash_tbl[ihash].erase(hash_tbl[ihash].begin() );
799 for(
int ihash = 0; ihash < nhash; ihash++ )
801 int32_t nentry = gpt_hash_tbl[ihash].size();
802 for(
int iint = 0; iint < nentry; iint++ )
804 gpt_hash_tbl[ihash].erase( gpt_hash_tbl[ihash].begin() );
824 int32_t nhash = hash_tbl_siz;
825 int32_t ndat = pow( 2, ndim );
828 for(
int ihash = 0; ihash < nhash; ihash++ )
832 int32_t nentry = hash_tbl[ihash].size();
833 for(
int iint = ( nentry - 1 ); iint >= 0; iint-- )
842 for(
int idat = 0; idat < ndat; idat++ )
861 hash_tbl[ihash].erase(hash_tbl[ihash].begin() + iint);
867 for(
int ihash = 0; ihash < nhash; ihash++ )
870 int32_t nentry = gpt_hash_tbl[ihash].size();
871 for(
int iint = ( nentry - 1 ); iint >= 0; iint-- )
879 free( lcl_info->
dat );
883 gpt_hash_tbl[ihash].erase( gpt_hash_tbl[ihash].begin() + iint );
899 int32_t idepth = (int32_t)pt[0];
900 printf(
"\nCurrent manager state:\n" );
901 printf(
" # of hash tbl bins: %d, # data blobs managed: %d\n",
902 hash_tbl_siz, n_tot_dat_blobs );
905 for(
int ibin = 0; ibin < hash_tbl_siz; ibin++ ) {
907 int32_t n_entry = hash_tbl[ibin].size();
908 printf(
" bin # %d, # entries: %d\n", ibin, n_entry );
910 for(
int ient = 0; ient < n_entry; ient++ ) {
912 printf(
" Entry %d, interval index for this entry:\n ",
914 for(
int ix = 0; ix < ndim; ix++ )
915 printf(
" %d,", hash_tbl[ibin][ient].ix_arr[ix] );
918 printf(
"-------------------------\n" );
919 printf(
"Interval Information:\n" );
921 dump_interval( hash_tbl[ibin][ient].int_str );
922 printf(
"-------------------------\n" );
927 printf(
"\n\nGrid point hash table summary:\n" );
928 for(
int ibin = 0; ibin < hash_tbl_siz; ibin++ )
931 int32_t n_entry = gpt_hash_tbl[ibin].size();
932 printf(
"-------------------------\n" );
933 printf(
" bin # %d, # entries: %d\n", ibin, n_entry );
935 for(
int ient = 0; ient < n_entry; ient++ ) {
937 printf(
" Entry #: %d, Point coords follow\n", ient );
938 for(
int ix = 0; ix < ndim; ix++ )
939 printf(
" %d,", gpt_hash_tbl[ibin][ient].ix_arr[ix] );
941 printf(
"data info Point coords\n" );
942 for(
int ix = 0; ix < ndim; ix++ )
943 printf(
" %d,", gpt_hash_tbl[ibin][ient].dat_info->
ix_arr[ix] );
945 printf(
"data info # intervals pointed to: %d\n",
947 printf(
"data info status: %d\n",
948 gpt_hash_tbl[ibin][ient].dat_info->
dat_status );
949 printf(
"data info address: %ld\n",
950 (
long int)gpt_hash_tbl[ibin][ient].dat_info->
dat );
971 if( interval !=
NULL ) {
972 int32_t npt = pow( 2, ndim );
973 printf(
"Interval address: %ld access ID: %d\n",(
long int)interval,
974 interval->access_id );
975 printf(
" Grid loc (%d dims): ", ndim );
976 for(
int i = 0;
i < ndim;
i++ )
979 for(
int i = 0;
i < npt;
i++ )
982 "# %d data blob, address: %ld, # intervals pointing to it: %d\n",
i,
985 printf(
" status: %d, grid point indexes: \n ",
987 for(
int j = 0;
j < ndim;
j++ )
992 printf(
"Sorry, last interval is NULL (no intervals added yet, " );
993 printf(
"or purge or prune done)\n" );
1019 for( idim = 0; idim < n_dim; idim++ )
1023 offset[idim] = dat_ix % 2;