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 );
206 for(
int i = 0;
i < npt;
i++ )
244 int32_t idim, idat, ndat, same_interval;
245 int32_t *ix, *ix_real, *offset_lcl, acc_mode, ret;
253 if( old_pt[0] == old_pt[0] )
256 for( idim = 0; idim < ndim; idim++ )
258 if( *( pt + idim ) != *( old_pt + idim ) )
270 for( idim = 0; idim < ndim; idim++ )
271 *( old_pt + idim ) = *( pt + idim );
275 if( ( ( ix = (int32_t *) malloc( ndim *
sizeof( int32_t ) ) ) ==
NULL ) ||
276 ( ( ix_real = (int32_t *)
277 malloc( ndim *
sizeof( int32_t ) ) ) ==
NULL ) ||
278 ( ( offset_lcl = (int32_t *)
279 malloc( ndim *
sizeof( int32_t ) ) ) ==
NULL ) )
281 printf(
"%s, %d: Unable to allocate the dim index array\n", __FILE__,
289 ndat = pow( 2., ndim );
293 if( sparse_get_loc( dim_info, ndim, pt, ix, pt_info.
wt, pt_info.
wt_pt )
311 if( prev_int !=
NULL )
315 for( idim = 0; idim < ndim; idim++ )
325 if( same_interval == 1 )
327 found_int = prev_int;
336 valarray<int> ix_val(ndim);
337 for(
int i = 0;
i < ndim;
i++ )
339 found_int = access( ix_val, acc_mode );
353 if( share_gpt( found_int, ix ) != 0 ) {
362 for( idat = 0; idat < ndat; idat++ )
367 valarray<int> ixv_off(ndim);
377 for( idim = 0; idim < ndim; idim++ )
379 ix_real[idim] = ix[idim] + offset_lcl[idim];
380 ixv_off[idim] = ix_real[idim];
391 ret = gpt_add( ixv_off, found_int->
dat_info[idat] );
405 prev_int = found_int;
410 free( ix ); free( ix_real ); free( offset_lcl );
413 for(
int i = 0;
i < ndim;
i++ )
415 for(
int i = 0;
i < ndat;
i++ ) {
429 int32_t dim_mgr::sparse_get_loc(
dim_info_struc **dim_info, int32_t ndim,
430 double *pt, int32_t *ix,
double *wt,
double *wt_pt )
463 int32_t idim, iint, full_len, msk;
467 full_len = pow( 2, ndim );
468 for( idim = 0; idim < full_len; idim++ )
469 *( wt_pt + idim ) = 1.;
473 for( idim = 0; idim < ndim; idim++ )
476 if( ( pt[idim] < dim_info[idim]->
min ) ||
477 ( pt[idim] > dim_info[idim]->
max ) )
483 for( iint = 1; iint < dim_info[idim]->
nvals; iint++ )
485 if( pt[idim] <= dim_info[idim]->dim_coords[iint] )
489 wt[idim] = ( pt[idim] - dim_info[idim]->
dim_coords[iint-1] ) /
490 ( dim_info[idim]->dim_coords[iint] -
491 dim_info[idim]->dim_coords[iint-1] );
501 msk = pow( 2, idim );
502 for( iint = 0; iint < full_len; iint++ )
504 if( ( iint & msk ) == 0 )
505 *( wt_pt + iint ) *= 1. - wt[idim];
507 *( wt_pt + iint ) *= wt[idim];
536 int32_t ndat = pow( 2, ndim );
539 int index = hash_func(
s, hash_tbl_siz );
541 for(
long unsigned int i = 0;
i < hash_tbl[
index].size();
i++)
546 if( ( hash_tbl[
index][
i].ix_arr ==
s ).
min() != 0 )
552 hash_tbl[
index].erase( hash_tbl[
index].begin() +
i );
553 cout <<
"Set is removed" << endl;
560 return hash_tbl[
index][
i].int_str;
581 hash_tbl[
index].push_back(hash_entry);
589 cout <<
"Code should not get here!/n";
617 int index = hash_func(
s, hash_tbl_siz );
619 for(
long unsigned int i = 0;
i < gpt_hash_tbl[
index].size();
i++)
621 if( ( gpt_hash_tbl[
index][
i].ix_arr ==
s ).
min() != 0 )
624 cout << __FILE__ << __LINE__ <<
625 "Error: grid point is already in hash table, Exiting" << endl;
635 gpt_hash_tbl[
index].push_back( hash_entry );
643 int dim_mgr::hash_func(valarray<int>
s, int32_t hash_tbl_siz )
667 if( hash_ifirst == 0 ) {
668 int32_t ndim =
s.size();
670 hash_h_mult = hash_tbl_siz / ( 2 * ndim );
671 hash_h_mult = hash_h_mult - ndim / 2;
674 for(
long unsigned int i = 0;
i <
s.size();
i++ )
675 sum += ( hash_h_mult +
i ) *
s[
i];
676 sum = sum % hash_tbl_siz;
706 valarray<int>
s(ndim);
707 int32_t npt = pow( 2, ndim );
708 ix_off = ( int32_t * ) malloc( ndim *
sizeof(int32_t) );
711 for(
int ipt = 0; ipt < npt; ipt++ )
715 for(
i = 0;
i < ndim;
i++ )
722 int index = hash_func(
s, hash_tbl_siz );
723 for(
i = 0;
i < (int32_t)gpt_hash_tbl[
index].
size();
i++ )
725 if( ( gpt_hash_tbl[
index][
i].ix_arr ==
s ).min() != 0 )
749 int32_t nhash = hash_tbl_siz;
750 int32_t ndat = pow( 2, ndim );
753 for(
int ihash = 0; ihash < nhash; ihash++ )
755 int32_t nentry = hash_tbl[ihash].size();
756 for(
int iint = 0; iint < nentry; iint++ )
764 for(
int idat = 0; idat < ndat; idat++ )
787 hash_tbl[ihash].erase(hash_tbl[ihash].begin() );
794 for(
int ihash = 0; ihash < nhash; ihash++ )
796 int32_t nentry = gpt_hash_tbl[ihash].size();
797 for(
int iint = 0; iint < nentry; iint++ )
799 gpt_hash_tbl[ihash].erase( gpt_hash_tbl[ihash].begin() );
819 int32_t nhash = hash_tbl_siz;
820 int32_t ndat = pow( 2, ndim );
823 for(
int ihash = 0; ihash < nhash; ihash++ )
827 int32_t nentry = hash_tbl[ihash].size();
828 for(
int iint = ( nentry - 1 ); iint >= 0; iint-- )
837 for(
int idat = 0; idat < ndat; idat++ )
856 hash_tbl[ihash].erase(hash_tbl[ihash].begin() + iint);
862 for(
int ihash = 0; ihash < nhash; ihash++ )
865 int32_t nentry = gpt_hash_tbl[ihash].size();
866 for(
int iint = ( nentry - 1 ); iint >= 0; iint-- )
874 free( lcl_info->
dat );
878 gpt_hash_tbl[ihash].erase( gpt_hash_tbl[ihash].begin() + iint );
894 int32_t idepth = (int32_t)pt[0];
895 printf(
"\nCurrent manager state:\n" );
896 printf(
" # of hash tbl bins: %d, # data blobs managed: %d\n",
897 hash_tbl_siz, n_tot_dat_blobs );
900 for(
int ibin = 0; ibin < hash_tbl_siz; ibin++ ) {
902 int32_t n_entry = hash_tbl[ibin].size();
903 printf(
" bin # %d, # entries: %d\n", ibin, n_entry );
905 for(
int ient = 0; ient < n_entry; ient++ ) {
907 printf(
" Entry %d, interval index for this entry:\n ",
909 for(
int ix = 0; ix < ndim; ix++ )
910 printf(
" %d,", hash_tbl[ibin][ient].ix_arr[ix] );
913 printf(
"-------------------------\n" );
914 printf(
"Interval Information:\n" );
916 dump_interval( hash_tbl[ibin][ient].int_str );
917 printf(
"-------------------------\n" );
922 printf(
"\n\nGrid point hash table summary:\n" );
923 for(
int ibin = 0; ibin < hash_tbl_siz; ibin++ )
926 int32_t n_entry = gpt_hash_tbl[ibin].size();
927 printf(
"-------------------------\n" );
928 printf(
" bin # %d, # entries: %d\n", ibin, n_entry );
930 for(
int ient = 0; ient < n_entry; ient++ ) {
932 printf(
" Entry #: %d, Point coords follow\n", ient );
933 for(
int ix = 0; ix < ndim; ix++ )
934 printf(
" %d,", gpt_hash_tbl[ibin][ient].ix_arr[ix] );
936 printf(
"data info Point coords\n" );
937 for(
int ix = 0; ix < ndim; ix++ )
938 printf(
" %d,", gpt_hash_tbl[ibin][ient].dat_info->
ix_arr[ix] );
940 printf(
"data info # intervals pointed to: %d\n",
942 printf(
"data info status: %d\n",
943 gpt_hash_tbl[ibin][ient].dat_info->
dat_status );
944 printf(
"data info address: %ld\n",
945 (
long int)gpt_hash_tbl[ibin][ient].dat_info->
dat );
966 if( interval !=
NULL ) {
967 int32_t npt = pow( 2, ndim );
968 printf(
"Interval address: %ld access ID: %d\n",(
long int)interval,
969 interval->access_id );
970 printf(
" Grid loc (%d dims): ", ndim );
971 for(
int i = 0;
i < ndim;
i++ )
974 for(
int i = 0;
i < npt;
i++ )
977 "# %d data blob, address: %ld, # intervals pointing to it: %d\n",
i,
980 printf(
" status: %d, grid point indexes: \n ",
982 for(
int j = 0;
j < ndim;
j++ )
987 printf(
"Sorry, last interval is NULL (no intervals added yet, " );
988 printf(
"or purge or prune done)\n" );
1014 for( idim = 0; idim < n_dim; idim++ )
1018 offset[idim] = dat_ix % 2;