Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
moab::TupleList Class Reference

#include <TupleList.hpp>

Classes

class  buffer
 
struct  SortData
 

Public Member Functions

 TupleList (uint mi, uint ml, uint mul, uint mr, uint max)
 
 TupleList ()
 
 ~TupleList ()
 
void initialize (uint mi, uint ml, uint mul, uint mr, uint max)
 
ErrorCode resize (uint max)
 
ErrorCode sort (uint key, TupleList::buffer *buf)
 
void reset ()
 
void reserve ()
 
int find (unsigned int key_num, sint value)
 
int find (unsigned int key_num, slong value)
 
int find (unsigned int key_num, Ulong value)
 
int find (unsigned int key_num, realType value)
 
sint get_sint (unsigned int index, unsigned int m)
 
slong get_int (unsigned int index, unsigned int m)
 
Ulong get_ulong (unsigned int index, unsigned int m)
 
realType get_double (unsigned int index, unsigned int m)
 
ErrorCode get (unsigned int index, const sint *&sp, const slong *&ip, const Ulong *&lp, const realType *&dp)
 
unsigned int push_back (sint *sp, slong *ip, Ulong *lp, realType *dp)
 
void enableWriteAccess ()
 
void disableWriteAccess ()
 
void getTupleSize (uint &mi_out, uint &ml_out, uint &mul_out, uint &mr_out) const
 
void set_n (uint n_in)
 
uint get_n () const
 
uint get_max () const
 
bool get_writeEnabled () const
 
uint inc_n ()
 
void print (const char *) const
 
void print_to_file (const char *) const
 

Public Attributes

sintvi_wr
 
slongvl_wr
 
Ulongvul_wr
 
realTypevr_wr
 
const sintvi_rd
 
slongvl_rd
 
Ulongvul_rd
 
realTypevr_rd
 

Private Types

typedef uint Index
 

Private Member Functions

void permute (uint *perm, void *work)
 

Static Private Member Functions

template<class Value >
static Value radix_count (const Value *A, const Value *end, Index stride, Index count[DIGITS][DIGIT_VALUES])
 
static void radix_offsets (Index *c)
 
template<class Value >
static unsigned radix_zeros (Value bitorkey, Index count[DIGITS][DIGIT_VALUES], unsigned *shift, Index **offsets)
 
template<class Value >
static void radix_index_pass_b (const Value *A, Index n, Index stride, unsigned sh, Index *off, SortData< Value > *out)
 
template<class Value >
static void radix_index_pass_m (const SortData< Value > *src, const SortData< Value > *end, unsigned sh, Index *off, SortData< Value > *out)
 
template<class Value >
static void radix_index_pass_e (const SortData< Value > *src, const SortData< Value > *end, unsigned sh, Index *off, Index *out)
 
template<class Value >
static void radix_index_pass_be (const Value *A, Index n, Index stride, unsigned sh, Index *off, Index *out)
 
template<class Value >
static void radix_index_sort (const Value *A, Index n, Index stride, Index *idx, SortData< Value > *work)
 
template<class Value >
static void merge_index_sort (const Value *A, const Index An, Index stride, Index *idx, SortData< Value > *work)
 
template<class Value >
static void index_sort (const Value *A, Index n, Index stride, Index *idx, SortData< Value > *work)
 

Private Attributes

uint mi
 
uint ml
 
uint mul
 
uint mr
 
uint n
 
uint max
 
sintvi
 
slongvl
 
Ulongvul
 
realTypevr
 
int last_sorted
 
bool writeEnabled
 

Detailed Description

Definition at line 78 of file TupleList.hpp.

Member Typedef Documentation

◆ Index

typedef uint moab::TupleList::Index
private

Definition at line 314 of file TupleList.hpp.

Constructor & Destructor Documentation

◆ TupleList() [1/2]

moab::TupleList::TupleList ( uint  mi,
uint  ml,
uint  mul,
uint  mr,
uint  max 
)

Constructor that takes all parameters and initializes the TupleList

Definition at line 65 of file TupleList.cpp.

66  : vi( NULL ), vl( NULL ), vul( NULL ), vr( NULL ), last_sorted( -1 )
67 {
68  initialize( p_mi, p_ml, p_mul, p_mr, p_max );
69 }

References initialize().

◆ TupleList() [2/2]

moab::TupleList::TupleList ( )

Default constructor (Note: TupleList must be initialized before use!)

Definition at line 71 of file TupleList.cpp.

72  : vi_rd( NULL ), vl_rd( NULL ), vul_rd( NULL ), vr_rd( NULL ), mi( 0 ), ml( 0 ), mul( 0 ), mr( 0 ), n( 0 ),
73  max( 0 ), vi( NULL ), vl( NULL ), vul( NULL ), vr( NULL ), last_sorted( -1 )
74 {
76 }

References disableWriteAccess().

◆ ~TupleList()

moab::TupleList::~TupleList ( )
inline

Definition at line 135 of file TupleList.hpp.

136  {
137  reset();
138  };

References reset().

Member Function Documentation

◆ disableWriteAccess()

◆ enableWriteAccess()

◆ find() [1/4]

int moab::TupleList::find ( unsigned int  key_num,
realType  value 
)

Definition at line 330 of file TupleList.cpp.

331 {
332  if( !( key_num > mr ) )
333  {
334  // Sequential search: TupleList cannot be sorted by reals
335  for( uint index = 0; index < n; index++ )
336  {
337  if( vr[index * mr + key_num] == value ) return index;
338  }
339  }
340  return -1; // If the value wasn't present or an invalid key was given
341 }

References mr, n, and vr.

◆ find() [2/4]

int moab::TupleList::find ( unsigned int  key_num,
sint  value 
)

Finds index of the tuple containing 'value' at the key_numth index of said tuple; return -1 if key_num is out of bounds or if 'value' not found Uses binary search if TupleList is sorted by the key_numth field, seqential otherwise (very slow for large TupleLists; please sort before you search)

param key_num index of the tuple where to search for value param value value to search for at the given key_num return the index of the tuple that contains value

Definition at line 236 of file TupleList.cpp.

237 {
238  // we are passing an int, no issue, leave it at long
239  long uvalue = (long)value;
240  if( !( key_num > mi ) )
241  {
242  // Binary search: only if the tuple_list is sorted
243  if( last_sorted == (int)key_num )
244  {
245  int lb = 0, ub = n, index; // lb=lower bound, ub=upper bound, index=mid
246  for( ; lb <= ub; )
247  {
248  index = ( lb + ub ) / 2;
249  if( vi[index * mi + key_num] == uvalue )
250  return index;
251  else if( vi[index * mi + key_num] > uvalue )
252  ub = index - 1;
253  else if( vi[index * mi + key_num] < uvalue )
254  lb = index + 1;
255  }
256  }
257  else
258  {
259  // Sequential search: if tuple_list is not sorted
260  for( uint index = 0; index < n; index++ )
261  {
262  if( vi[index * mi + key_num] == uvalue ) return index;
263  }
264  }
265  }
266  return -1; // If the value wasn't present or an invalid key was given
267 }

References last_sorted, mi, n, and vi.

◆ find() [3/4]

int moab::TupleList::find ( unsigned int  key_num,
slong  value 
)

Definition at line 269 of file TupleList.cpp.

270 {
271  long uvalue = (long)value;
272  if( !( key_num > ml ) )
273  {
274  if( last_sorted - mi == key_num )
275  {
276  int lb = 0, ub = n, index; // lb=lower bound, ub=upper bound, index=mid
277  for( ; lb <= ub; )
278  {
279  index = ( lb + ub ) / 2;
280  if( vl[index * ml + key_num] == uvalue )
281  return index;
282  else if( vl[index * ml + key_num] > uvalue )
283  ub = index - 1;
284  else if( vl[index * ml + key_num] < uvalue )
285  lb = index + 1;
286  }
287  }
288  else
289  {
290  // Sequential search: if tuple_list is not sorted
291  for( uint index = 0; index < n; index++ )
292  {
293  if( vl[index * ml + key_num] == uvalue ) return index;
294  }
295  }
296  }
297  return -1; // If the value wasn't present or an invalid key was given
298 }

References last_sorted, mi, ml, n, and vl.

◆ find() [4/4]

int moab::TupleList::find ( unsigned int  key_num,
Ulong  value 
)

Definition at line 300 of file TupleList.cpp.

301 {
302  if( !( key_num > mul ) )
303  {
304  if( last_sorted - mi - ml == key_num )
305  {
306  int lb = 0, ub = n - 1, index; // lb=lower bound, ub=upper bound, index=mid
307  for( ; lb <= ub; )
308  {
309  index = ( lb + ub ) / 2;
310  if( vul[index * mul + key_num] == value )
311  return index;
312  else if( vul[index * mul + key_num] > value )
313  ub = index - 1;
314  else if( vul[index * mul + key_num] < value )
315  lb = index + 1;
316  }
317  }
318  else
319  {
320  // Sequential search: if tuple_list is not sorted
321  for( uint index = 0; index < n; index++ )
322  {
323  if( vul[index * mul + key_num] == value ) return index;
324  }
325  }
326  }
327  return -1; // If the value wasn't present or an invalid key was given
328 }

References last_sorted, mi, ml, mul, n, and vul.

◆ get()

ErrorCode moab::TupleList::get ( unsigned int  index,
const sint *&  sp,
const slong *&  ip,
const Ulong *&  lp,
const realType *&  dp 
)

get pointers to the data for the index'th tuple; ptr is NULL if that type is not part of this tuple

param index index of the tuple needed param *&sp, *&ip, *&lp, *&dp pointers to each piece of the tuple

Definition at line 367 of file TupleList.cpp.

368 {
369  if( index <= n )
370  {
371  if( mi )
372  *&sp = &vi[index * mi];
373  else
374  *&sp = NULL;
375  if( ml )
376  *&ip = &vl[index * ml];
377  else
378  *&ip = NULL;
379  if( mul )
380  *&lp = &vul[index * mul];
381  else
382  *&lp = NULL;
383  if( mr )
384  *&dp = &vr[index * mr];
385  else
386  *&dp = NULL;
387 
388  return MB_SUCCESS;
389  }
390  return MB_FAILURE;
391 }

References MB_SUCCESS, mi, ml, mr, mul, n, vi, vl, vr, and vul.

◆ get_double()

realType moab::TupleList::get_double ( unsigned int  index,
unsigned int  m 
)

Definition at line 361 of file TupleList.cpp.

362 {
363  if( mr > m && n > index ) return vr[index * mr + m];
364  return 0;
365 }

References mr, n, and vr.

◆ get_int()

slong moab::TupleList::get_int ( unsigned int  index,
unsigned int  m 
)

Definition at line 349 of file TupleList.cpp.

350 {
351  if( ml > m && n > index ) return vl[index * ml + m];
352  return 0;
353 }

References ml, n, and vl.

◆ get_max()

◆ get_n()

◆ get_sint()

sint moab::TupleList::get_sint ( unsigned int  index,
unsigned int  m 
)

get the mth number of return type in the index'th tuple returns 0 if m or index is out of bounds

param index index of the tuple within the TupleList param m index of the value within the tuple return the value at the given position

Definition at line 343 of file TupleList.cpp.

344 {
345  if( mi > m && n > index ) return vi[index * mi + m];
346  return 0;
347 }

References mi, n, and vi.

◆ get_ulong()

Ulong moab::TupleList::get_ulong ( unsigned int  index,
unsigned int  m 
)

Definition at line 355 of file TupleList.cpp.

356 {
357  if( mul > m && n > index ) return vul[index * mul + m];
358  return 0;
359 }

References mul, n, and vul.

◆ get_writeEnabled()

bool moab::TupleList::get_writeEnabled ( ) const
inline

◆ getTupleSize()

void moab::TupleList::getTupleSize ( uint mi_out,
uint ml_out,
uint mul_out,
uint mr_out 
) const

◆ inc_n()

◆ index_sort()

template<class Value >
void moab::TupleList::index_sort ( const Value *  A,
Index  n,
Index  stride,
Index idx,
SortData< Value > *  work 
)
staticprivate

Definition at line 843 of file TupleList.cpp.

844 {
845  if( n < DIGIT_VALUES )
846  {
847  if( n == 0 ) return;
848  if( n == 1 )
849  *idx = 0;
850  else
851  merge_index_sort( A, n, stride, idx, work );
852  }
853  else
854  radix_index_sort( A, n, stride, idx, work );
855 }

References DIGIT_VALUES, merge_index_sort(), n, and radix_index_sort().

Referenced by sort().

◆ initialize()

void moab::TupleList::initialize ( uint  mi,
uint  ml,
uint  mul,
uint  mr,
uint  max 
)

Initializes the starting memory to be used by the TupleList Note: TupleLists must be initialized before they can be used

param mi number of signed ints in each tuple param ml number of long ints in each tuple param mul number of unsigned long ints in each tuple param mr number of reals in each tuple param max starting capacity of max tuples in the TupleList

Definition at line 79 of file TupleList.cpp.

80 {
81  this->n = 0;
82  this->max = p_max;
83  this->mi = p_mi;
84  this->ml = p_ml;
85  this->mul = p_mul;
86  this->mr = p_mr;
87  size_t sz;
88 
89  if( max * mi > 0 )
90  {
91  sz = max * mi * sizeof( sint );
92  void* resi = malloc( sz );
93  if( !resi && max * mi > 0 ) fail( "%s: allocation of %d bytes failed\n", __FILE__, (int)sz );
94  vi = (sint*)resi;
95  }
96  else
97  vi = NULL;
98  if( max * ml > 0 )
99  {
100  sz = max * ml * sizeof( slong );
101  void* resl = malloc( sz );
102  if( !resl && max * ml > 0 ) fail( "%s: allocation of %d bytes failed\n", __FILE__, (int)sz );
103  vl = (slong*)resl;
104  }
105  else
106  vl = NULL;
107  if( max * mul > 0 )
108  {
109  sz = max * mul * sizeof( Ulong );
110  void* resu = malloc( sz );
111  if( !resu && max * mul > 0 ) fail( "%s: allocation of %d bytes failed\n", __FILE__, (int)sz );
112  vul = (Ulong*)resu;
113  }
114  else
115  vul = NULL;
116  if( max * mr > 0 )
117  {
118  sz = max * mr * sizeof( realType );
119  void* resr = malloc( sz );
120  if( !resr && max * ml > 0 ) fail( "%s: allocation of %d bytes failed\n", __FILE__, (int)sz );
121  vr = (realType*)resr;
122  }
123  else
124  vr = NULL;
125 
126  // Begin with write access disabled
127  this->disableWriteAccess();
128 
129  // Set read variables
130  vi_rd = vi;
131  vl_rd = vl;
132  vul_rd = vul;
133  vr_rd = vr;
134 }

References disableWriteAccess(), moab::fail(), max, mi, ml, mr, mul, n, sint, slong, vi, vi_rd, vl, vl_rd, vr, vr_rd, vul, and vul_rd.

Referenced by moab::ParallelComm::augment_default_sets_with_ghosts(), moab::ParCommGraph::compute_partition(), moab::ParallelComm::delete_entities(), moab::ParallelComm::exchange_owned_mesh(), moab::ParCommGraph::form_tuples_to_migrate_mesh(), moab::ParallelComm::get_sent_ents(), iMOAB_SetDoubleTagStorageWithGid(), moab::gs_data::initialize(), moab::Coupler::interpolate(), moab::DataCoupler::interpolate(), moab::SpatialLocator::locate_points(), moab::Coupler::locate_points(), main(), moab::ParallelMergeMesh::PerformMerge(), moab::TempestOnlineMap::ReadParallelMap(), moab::ParallelComm::resolve_shared_ents(), moab::ParallelComm::send_entities(), moab::ScdInterface::tag_shared_vertices(), TupleList(), moab::unpack_tuples(), unpack_tuples(), and moab::TempestOnlineMap::WriteSCRIPMapFile().

◆ merge_index_sort()

template<class Value >
void moab::TupleList::merge_index_sort ( const Value *  A,
const Index  An,
Index  stride,
Index idx,
SortData< Value > *  work 
)
staticprivate

Definition at line 752 of file TupleList.cpp.

753 {
754  SortData< Value >* const buf[2] = { work + An, work };
755  Index n = An, base = -n, odd = 0, c = 0, b = 1;
756  Index i = 0;
757  for( ;; )
758  {
759  SortData< Value >* p;
760  if( ( c & 1 ) == 0 )
761  {
762  base += n, n += ( odd & 1 ), c |= 1, b ^= 1;
763  while( n > 3 )
764  odd <<= 1, odd |= ( n & 1 ), n >>= 1, c <<= 1, b ^= 1;
765  }
766  else
767  base -= n - ( odd & 1 ), n <<= 1, n -= ( odd & 1 ), odd >>= 1, c >>= 1;
768  if( c == 0 ) break;
769  p = buf[b] + base;
770  if( n == 2 )
771  {
772  Value v[2];
773  v[0] = *A, A += stride, v[1] = *A, A += stride;
774  if( v[1] < v[0] )
775  p[0].v = v[1], p[0].i = i + 1, p[1].v = v[0], p[1].i = i;
776  else
777  p[0].v = v[0], p[0].i = i, p[1].v = v[1], p[1].i = i + 1;
778  i += 2;
779  }
780  else if( n == 3 )
781  {
782  Value v[3];
783  v[0] = *A, A += stride, v[1] = *A, A += stride, v[2] = *A, A += stride;
784  if( v[1] < v[0] )
785  {
786  if( v[2] < v[1] )
787  p[0].v = v[2], p[1].v = v[1], p[2].v = v[0], p[0].i = i + 2, p[1].i = i + 1, p[2].i = i;
788  else
789  {
790  if( v[2] < v[0] )
791  p[0].v = v[1], p[1].v = v[2], p[2].v = v[0], p[0].i = i + 1, p[1].i = i + 2, p[2].i = i;
792  else
793  p[0].v = v[1], p[1].v = v[0], p[2].v = v[2], p[0].i = i + 1, p[1].i = i, p[2].i = i + 2;
794  }
795  }
796  else
797  {
798  if( v[2] < v[0] )
799  p[0].v = v[2], p[1].v = v[0], p[2].v = v[1], p[0].i = i + 2, p[1].i = i, p[2].i = i + 1;
800  else
801  {
802  if( v[2] < v[1] )
803  p[0].v = v[0], p[1].v = v[2], p[2].v = v[1], p[0].i = i, p[1].i = i + 2, p[2].i = i + 1;
804  else
805  p[0].v = v[0], p[1].v = v[1], p[2].v = v[2], p[0].i = i, p[1].i = i + 1, p[2].i = i + 2;
806  }
807  }
808  i += 3;
809  }
810  else
811  {
812  const Index na = n >> 1, nb = ( n + 1 ) >> 1;
813  const SortData< Value >*ap = buf[b ^ 1] + base, *ae = ap + na;
814  SortData< Value >*bp = p + na, *be = bp + nb;
815  for( ;; )
816  {
817  if( bp->v < ap->v )
818  {
819  *p++ = *bp++;
820  if( bp != be ) continue;
821  do
822  *p++ = *ap++;
823  while( ap != ae );
824  break;
825  }
826  else
827  {
828  *p++ = *ap++;
829  if( ap == ae ) break;
830  }
831  }
832  }
833  }
834  {
835  const SortData< Value >*p = buf[0], *pe = p + An;
836  do
837  *idx++ = ( p++ )->i;
838  while( p != pe );
839  }
840 }

References moab::TupleList::SortData< Value >::i, n, and moab::TupleList::SortData< Value >::v.

Referenced by index_sort().

◆ permute()

void moab::TupleList::permute ( uint perm,
void *  work 
)
private

Definition at line 510 of file TupleList.cpp.

511 {
512  const unsigned int_size = mi * sizeof( sint ), long_size = ml * sizeof( slong ), Ulong_size = mul * sizeof( Ulong ),
513  real_size = mr * sizeof( realType );
514  if( mi )
515  {
516  uint *p = perm, *pe = p + n;
517  char* sorted = (char*)work;
518  while( p != pe )
519  memcpy( (void*)sorted, &vi[mi * ( *p++ )], int_size ), sorted += int_size;
520  memcpy( vi, work, int_size * n );
521  }
522  if( ml )
523  {
524  uint *p = perm, *pe = p + n;
525  char* sorted = (char*)work;
526  while( p != pe )
527  memcpy( (void*)sorted, &vl[ml * ( *p++ )], long_size ), sorted += long_size;
528  memcpy( vl, work, long_size * n );
529  }
530  if( mul )
531  {
532  uint *p = perm, *pe = p + n;
533  char* sorted = (char*)work;
534  while( p != pe )
535  memcpy( (void*)sorted, &vul[mul * ( *p++ )], Ulong_size ), sorted += Ulong_size;
536  memcpy( vul, work, Ulong_size * n );
537  }
538  if( mr )
539  {
540  uint *p = perm, *pe = p + n;
541  char* sorted = (char*)work;
542  while( p != pe )
543  memcpy( (void*)sorted, &vr[mr * ( *p++ )], real_size ), sorted += real_size;
544  memcpy( vr, work, real_size * n );
545  }
546 }

References mi, ml, mr, mul, n, sint, vi, vl, vr, and vul.

Referenced by sort().

◆ print()

void moab::TupleList::print ( const char *  name) const

Definition at line 453 of file TupleList.cpp.

454 {
455  std::cout << "Printing Tuple " << name << "===================" << std::endl;
456  unsigned long i = 0, l = 0, ul = 0, r = 0;
457  for( uint k = 0; k < n; k++ )
458  {
459  for( uint j = 0; j < mi; j++ )
460  {
461  std::cout << vi[i++] << " | ";
462  }
463  for( uint j = 0; j < ml; j++ )
464  {
465  std::cout << vl[l++] << " | ";
466  }
467  for( uint j = 0; j < mul; j++ )
468  {
469  std::cout << vul[ul++] << " | ";
470  }
471  for( uint j = 0; j < mr; j++ )
472  {
473  std::cout << vr[r++] << " | ";
474  }
475  std::cout << std::endl;
476  }
477  std::cout << "=======================================" << std::endl << std::endl;
478 }

References mi, ml, mr, mul, n, vi, vl, vr, and vul.

Referenced by moab::ParallelComm::augment_default_sets_with_ghosts(), and main().

◆ print_to_file()

void moab::TupleList::print_to_file ( const char *  filename) const

Definition at line 479 of file TupleList.cpp.

480 {
481  std::ofstream ofs;
482  ofs.open( filename, std::ofstream::out | std::ofstream::app );
483 
484  ofs << "Printing Tuple " << filename << "===================" << std::endl;
485  unsigned long i = 0, l = 0, ul = 0, r = 0;
486  for( uint k = 0; k < n; k++ )
487  {
488  for( uint j = 0; j < mi; j++ )
489  {
490  ofs << vi[i++] << " | ";
491  }
492  for( uint j = 0; j < ml; j++ )
493  {
494  ofs << vl[l++] << " | ";
495  }
496  for( uint j = 0; j < mul; j++ )
497  {
498  ofs << vul[ul++] << " | ";
499  }
500  for( uint j = 0; j < mr; j++ )
501  {
502  ofs << vr[r++] << " | ";
503  }
504  ofs << std::endl;
505  }
506  ofs << "=======================================" << std::endl << std::endl;
507 
508  ofs.close();
509 }

References mi, ml, mr, mul, n, vi, vl, vr, and vul.

Referenced by moab::ParCommGraph::compute_partition().

◆ push_back()

unsigned int moab::TupleList::push_back ( sint sp,
slong ip,
Ulong lp,
realType dp 
)

push back a new tuple on the TupleList;

param *sp pointer to a list of signed ints param *ip pointer to a list of signed longs param *lp pointer to a list of unsigned longs param *dp pointer to a list of reals return index of that tuple

Definition at line 393 of file TupleList.cpp.

394 {
395  reserve();
396  if( mi ) memcpy( &vi[mi * ( n - 1 )], sp, mi * sizeof( sint ) );
397  if( ml ) memcpy( &vl[ml * ( n - 1 )], ip, ml * sizeof( long ) );
398  if( mul ) memcpy( &vul[mul * ( n - 1 )], lp, mul * sizeof( Ulong ) );
399  if( mr ) memcpy( &vr[mr * ( n - 1 )], dp, mr * sizeof( realType ) );
400 
401  last_sorted = -1;
402  return n - 1;
403 }

References last_sorted, mi, ml, mr, mul, n, reserve(), vi, vl, vr, and vul.

◆ radix_count()

template<class Value >
Value moab::TupleList::radix_count ( const Value *  A,
const Value *  end,
Index  stride,
Index  count[DIGITS][DIGIT_VALUES] 
)
staticprivate

Definition at line 614 of file TupleList.cpp.

615 {
616  Value bitorkey = 0;
617  memset( count, 0, COUNT_SIZE * sizeof( Index ) );
618  do
619  {
620  Value val = *A;
621  bitorkey |= val;
622  COUNT_DIGIT_64( DIGITS, 0 );
623  // above macro expands to:
624  // if(DIGITS> 0) count[ 0][val&DIGIT_MASK]++, val>>=DIGIT_BITS;
625  // if(DIGITS> 1) count[ 1][val&DIGIT_MASK]++, val>>=DIGIT_BITS;
626  // ...
627  // if(DIGITS>63) count[63][val&DIGIT_MASK]++, val>>=DIGIT_BITS;
628 
629  } while( A += stride, A != end );
630  return bitorkey;
631 }

References COUNT_DIGIT_64, COUNT_SIZE, and DIGITS.

Referenced by radix_index_sort().

◆ radix_index_pass_b()

template<class Value >
void moab::TupleList::radix_index_pass_b ( const Value *  A,
Index  n,
Index  stride,
unsigned  sh,
Index off,
SortData< Value > *  out 
)
staticprivate

Definition at line 662 of file TupleList.cpp.

668 {
669  Index i = 0;
670  do
671  {
672  Value v = *A;
673  SortData< Value >* d = &out[off[( v >> sh ) & DIGIT_MASK]++];
674  d->v = v, d->i = i++;
675  } while( A += stride, i != n );
676 }

References DIGIT_MASK, moab::TupleList::SortData< Value >::i, n, and moab::TupleList::SortData< Value >::v.

Referenced by radix_index_sort().

◆ radix_index_pass_be()

template<class Value >
void moab::TupleList::radix_index_pass_be ( const Value *  A,
Index  n,
Index  stride,
unsigned  sh,
Index off,
Index out 
)
staticprivate

Definition at line 705 of file TupleList.cpp.

706 {
707  Index i = 0;
708  do
709  out[off[( *A >> sh ) & DIGIT_MASK]++] = i++;
710  while( A += stride, i != n );
711 }

References DIGIT_MASK, and n.

Referenced by radix_index_sort().

◆ radix_index_pass_e()

template<class Value >
void moab::TupleList::radix_index_pass_e ( const SortData< Value > *  src,
const SortData< Value > *  end,
unsigned  sh,
Index off,
Index out 
)
staticprivate

Definition at line 693 of file TupleList.cpp.

698 {
699  do
700  out[off[( src->v >> sh ) & DIGIT_MASK]++] = src->i;
701  while( ++src != end );
702 }

References DIGIT_MASK, moab::TupleList::SortData< Value >::i, and moab::TupleList::SortData< Value >::v.

Referenced by radix_index_sort().

◆ radix_index_pass_m()

template<class Value >
void moab::TupleList::radix_index_pass_m ( const SortData< Value > *  src,
const SortData< Value > *  end,
unsigned  sh,
Index off,
SortData< Value > *  out 
)
staticprivate

Definition at line 679 of file TupleList.cpp.

684 {
685  do
686  {
687  SortData< Value >* d = &out[off[( src->v >> sh ) & DIGIT_MASK]++];
688  d->v = src->v, d->i = src->i;
689  } while( ++src != end );
690 }

References DIGIT_MASK, moab::TupleList::SortData< Value >::i, and moab::TupleList::SortData< Value >::v.

Referenced by radix_index_sort().

◆ radix_index_sort()

template<class Value >
void moab::TupleList::radix_index_sort ( const Value *  A,
Index  n,
Index  stride,
Index idx,
SortData< Value > *  work 
)
staticprivate

Definition at line 714 of file TupleList.cpp.

715 {
716  Index count[DIGITS][DIGIT_VALUES];
717  Value bitorkey = radix_count( A, A + n * stride, stride, count );
718  unsigned shift[DIGITS];
719  Index* offsets[DIGITS];
720  unsigned digits = radix_zeros( bitorkey, count, shift, offsets );
721  if( digits == 0 )
722  {
723  Index i = 0;
724  do
725  *idx++ = i++;
726  while( i != n );
727  }
728  else if( digits == 1 )
729  {
730  radix_index_pass_be( A, n, stride, shift[0], offsets[0], idx );
731  }
732  else
733  {
734  SortData< Value >*src, *dst;
735  unsigned d;
736  if( ( digits & 1 ) == 0 )
737  dst = work, src = dst + n;
738  else
739  src = work, dst = src + n;
740  radix_index_pass_b( A, n, stride, shift[0], offsets[0], src );
741  for( d = 1; d != digits - 1; ++d )
742  {
743  SortData< Value >* t;
744  radix_index_pass_m( src, src + n, shift[d], offsets[d], dst );
745  t = src, src = dst, dst = t;
746  }
747  radix_index_pass_e( src, src + n, shift[d], offsets[d], idx );
748  }
749 }

References DIGIT_VALUES, DIGITS, n, radix_count(), radix_index_pass_b(), radix_index_pass_be(), radix_index_pass_e(), radix_index_pass_m(), radix_zeros(), and t.

Referenced by index_sort().

◆ radix_offsets()

void moab::TupleList::radix_offsets ( Index c)
staticprivate

Definition at line 641 of file TupleList.cpp.

642 {
643  Index sum = 0, t, *ce = c + DIGIT_VALUES;
644  do
645  t = *c, *c++ = sum, sum += t;
646  while( c != ce );
647 }

References DIGIT_VALUES, moab::sum(), and t.

Referenced by radix_zeros().

◆ radix_zeros()

template<class Value >
unsigned moab::TupleList::radix_zeros ( Value  bitorkey,
Index  count[DIGITS][DIGIT_VALUES],
unsigned *  shift,
Index **  offsets 
)
staticprivate

Definition at line 650 of file TupleList.cpp.

651 {
652  unsigned digits = 0, sh = 0;
653  Index* c = &count[0][0];
654  do
655  {
656  if( bitorkey & DIGIT_MASK ) *shift++ = sh, *offsets++ = c, ++digits, radix_offsets( c );
657  } while( bitorkey >>= DIGIT_BITS, sh += DIGIT_BITS, c += DIGIT_VALUES, sh != VALUE_BITS );
658  return digits;
659 }

References DIGIT_BITS, DIGIT_MASK, DIGIT_VALUES, radix_offsets(), and VALUE_BITS.

Referenced by radix_index_sort().

◆ reserve()

void moab::TupleList::reserve ( )

Adds one to the total number of in-use tuples and resizes if necessary

Definition at line 226 of file TupleList.cpp.

227 {
228  n++;
229  while( n > max )
230  resize( ( max ? max + max / 2 + 1 : 2 ) );
231  last_sorted = -1;
232 }

References last_sorted, max, n, and resize().

Referenced by iMOAB_SetDoubleTagStorageWithGid(), and push_back().

◆ reset()

void moab::TupleList::reset ( )

Frees all allocated memory in use by the TupleList

Definition at line 205 of file TupleList.cpp.

206 {
207  // free up the pointers
208  free( vi );
209  free( vl );
210  free( vul );
211  free( vr );
212  // Set them all to null
213  vr = NULL;
214  vi = NULL;
215  vul = NULL;
216  vl = NULL;
217  // Set the read and write pointers to null
219  vi_rd = NULL;
220  vl_rd = NULL;
221  vul_rd = NULL;
222  vr_rd = NULL;
223 }

References disableWriteAccess(), vi, vi_rd, vl, vl_rd, vr, vr_rd, vul, and vul_rd.

Referenced by moab::ParallelMergeMesh::CleanUp(), moab::ParallelComm::exchange_ghost_cells(), moab::ParallelComm::exchange_owned_mesh(), moab::Coupler::get_matching_entities(), moab::gs_data::initialize(), moab::Coupler::locate_points(), moab::ParallelMergeMesh::PerformMerge(), moab::TempestOnlineMap::ReadParallelMap(), moab::ParallelComm::resolve_shared_ents(), moab::ParallelComm::send_entities(), and ~TupleList().

◆ resize()

ErrorCode moab::TupleList::resize ( uint  max)

Resizes the TupleList to a new max

param max the new max capacity of the TupleList

Definition at line 137 of file TupleList.cpp.

138 {
139  this->max = maxIn;
140  size_t sz;
141 
142  if( vi || ( max * mi > 0 ) )
143  {
144  sz = max * mi * sizeof( sint );
145  void* resi = realloc( vi, sz );
146  if( !resi && max * mi > 0 )
147  {
148  fail( "%s: allocation of %d bytes failed\n", __FILE__, (int)sz );
150  }
151  vi = (sint*)resi;
152  }
153  if( vl || ( max * ml > 0 ) )
154  {
155  sz = max * ml * sizeof( slong );
156  void* resl = realloc( vl, sz );
157  if( !resl && max * ml > 0 )
158  {
159  fail( "%s: allocation of %d bytes failed\n", __FILE__, (int)sz );
161  }
162  vl = (slong*)resl;
163  }
164  if( vul || ( max * mul > 0 ) )
165  {
166  sz = max * mul * sizeof( Ulong );
167  void* resu = realloc( vul, sz );
168  if( !resu && max * mul > 0 )
169  {
170  fail( "%s: allocation of %d bytes failed\n", __FILE__, (int)sz );
172  }
173  vul = (Ulong*)resu;
174  }
175  if( vr || ( max * mr > 0 ) )
176  {
177  sz = max * mr * sizeof( realType );
178  void* resr = realloc( vr, sz );
179  if( !resr && max * mr > 0 )
180  {
181  fail( "%s: allocation of %d bytes failed\n", __FILE__, (int)sz );
183  }
184  vr = (realType*)resr;
185  }
186 
187  // Set read variables
188  vi_rd = vi;
189  vl_rd = vl;
190  vul_rd = vul;
191  vr_rd = vr;
192 
193  // Set the write variables if necessary
194  if( writeEnabled )
195  {
196  vi_wr = vi;
197  vl_wr = vl;
198  vul_wr = vul;
199  vr_wr = vr;
200  }
201  return moab::MB_SUCCESS;
202 }

References moab::fail(), max, MB_MEMORY_ALLOCATION_FAILED, MB_SUCCESS, mi, ml, mr, mul, sint, slong, vi, vi_rd, vi_wr, vl, vl_rd, vl_wr, vr, vr_rd, vr_wr, vul, vul_rd, vul_wr, and writeEnabled.

Referenced by moab::ParallelComm::augment_default_sets_with_ghosts(), moab::Coupler::consolidate_tuples(), moab::gs_data::initialize(), moab::Coupler::locate_points(), moab::ParallelMergeMesh::PopulateMyMatches(), moab::ParallelMergeMesh::PopulateMyTup(), reserve(), and moab::Coupler::test_local_box().

◆ set_n()

void moab::TupleList::set_n ( uint  n_in)

Definition at line 443 of file TupleList.cpp.

444 {
445  // Check for direct write access;
446  if( !writeEnabled )
447  {
449  }
450  n = n_in;
451 }

References enableWriteAccess(), n, and writeEnabled.

Referenced by moab::Coupler::consolidate_tuples(), moab::DataCoupler::interpolate(), moab::SpatialLocator::locate_points(), moab::Coupler::locate_points(), main(), moab::unpack_tuples(), and unpack_tuples().

◆ sort()

ErrorCode moab::TupleList::sort ( uint  key,
TupleList::buffer buf 
)

Sorts the TupleList by 'key' if key<mi: key represents the key'th index in vi if mi<key<ml: key represents the (key-mi)'th index in vl if ml<key<mul: key represents the (key-mi-ml)'th index in vul

param key index to be sorted by param *buf buffer space used for sorting

Definition at line 550 of file TupleList.cpp.

551 {
552  const unsigned int_size = mi * sizeof( sint );
553  const unsigned long_size = ml * sizeof( slong );
554  const unsigned Ulong_size = mul * sizeof( Ulong );
555  const unsigned real_size = mr * sizeof( realType );
556  const unsigned width = umax_2( umax_2( int_size, long_size ), umax_2( Ulong_size, real_size ) );
557  unsigned data_size = key >= mi ? sizeof( SortData< long > ) : sizeof( SortData< uint > );
558 #if defined( WIN32 ) || defined( _WIN32 )
559  if( key >= mi + ml ) data_size = sizeof( SortData< Ulong > );
560 #endif
561 
562  uint work_min = n * umax_2( 2 * data_size, sizeof( sint ) + width );
563  uint* work;
564  buf->buffer_reserve( work_min );
565  work = (uint*)buf->ptr;
566  if( key < mi )
567  index_sort( (uint*)&vi[key], n, mi, work, (SortData< uint >*)work );
568  else if( key < mi + ml )
569  index_sort( (long*)&vl[key - mi], n, ml, work, (SortData< long >*)work );
570  else if( key < mi + ml + mul )
571  index_sort( (Ulong*)&vul[key - mi - ml], n, mul, work, (SortData< Ulong >*)work );
572  else
573  return MB_NOT_IMPLEMENTED;
574 
575  permute( work, work + n );
576 
577  if( !writeEnabled ) last_sorted = key;
578  return MB_SUCCESS;
579 }

References index_sort(), last_sorted, MB_NOT_IMPLEMENTED, MB_SUCCESS, mi, ml, mr, mul, n, permute(), moab::TupleList::buffer::ptr, sint, slong, umax_2, vi, vl, vul, and writeEnabled.

Referenced by moab::Coupler::consolidate_tuples(), moab::ParallelComm::exchange_owned_mesh(), moab::ParallelComm::get_sent_ents(), iMOAB_SetDoubleTagStorageWithGid(), moab::gs_data::initialize(), moab::TempestOnlineMap::ReadParallelMap(), moab::ParallelComm::resolve_shared_ents(), moab::ParallelComm::send_entities(), moab::ParallelMergeMesh::SortMyMatches(), and moab::ScdInterface::tag_shared_vertices().

Member Data Documentation

◆ last_sorted

int moab::TupleList::last_sorted
private

Definition at line 309 of file TupleList.hpp.

Referenced by enableWriteAccess(), find(), push_back(), reserve(), and sort().

◆ max

uint moab::TupleList::max
private

Definition at line 296 of file TupleList.hpp.

Referenced by get_max(), initialize(), reserve(), and resize().

◆ mi

uint moab::TupleList::mi
private

◆ ml

uint moab::TupleList::ml
private

◆ mr

uint moab::TupleList::mr
private

◆ mul

uint moab::TupleList::mul
private

◆ n

◆ vi

sint* moab::TupleList::vi
private

◆ vi_rd

◆ vi_wr

◆ vl

slong* moab::TupleList::vl
private

◆ vl_rd

◆ vl_wr

◆ vr

realType* moab::TupleList::vr
private

◆ vr_rd

◆ vr_wr

◆ vul

Ulong* moab::TupleList::vul
private

◆ vul_rd

◆ vul_wr

◆ writeEnabled

bool moab::TupleList::writeEnabled
private

The documentation for this class was generated from the following files: