8 #define PRINT_SEQUENCE_COUNT
10 #ifdef PRINT_SEQUENCE_COUNT
11 #ifndef IS_BUILDING_MB
12 #define IS_BUILDING_MB
15 #ifdef MB_ENTITY_SEQUENCE_HPP
16 #include "EntitySequenceManager.hpp"
31 #define ARRSIZE( A ) ( sizeof( A ) / sizeof( ( A )[0] ) )
49 long* array =
new long[count];
50 for(
long i = 0; i < count; ++i )
53 for(
long i = 0; i < count; ++i )
56 if( count > RAND_MAX )
58 r += RAND_MAX * rand();
59 if( count / RAND_MAX > RAND_MAX )
61 long t = (long)RAND_MAX * rand();
62 r += (long)RAND_MAX *
t;
113 #ifdef PRINT_SEQUENCE_COUNT
135 const char*
order_strs[] = {
"Forward",
"Reverse",
"Random" };
146 inline void delete_vert(
long index,
int percent );
148 inline void delete_elem(
long index,
int percent );
153 std::cerr <<
"Usage: seqperf [-i <intervals>] [-o <order>] [-d <percent>] [-b|-s] [-q <count>]" << std::endl;
154 std::cerr <<
" -i specify size of cubic structured hex mesh in intervals. Default: " <<
default_intervals
156 std::cerr <<
" -o one of \"forward\", \"reverse\", or \"random\". May be specified multiple "
157 "times. Default is all."
159 std::cerr <<
" -d percent of entities to delete. May be specified multiple times. Default is {";
163 std::cerr <<
" -b block creation of mesh" << std::endl;
164 std::cerr <<
" -s single entity mesh creation" << std::endl;
165 std::cerr <<
" -q number of times to repeat queries. Default: " <<
default_query_count << std::endl;
170 std::string
ts( clock_t
t )
172 std::ostringstream s;
173 s << ( (double)
t ) / CLOCKS_PER_SEC <<
's';
178 void TIME(
const char* str,
void ( *func )() )
180 std::cout << str <<
"... " << std::flush;
183 std::cout <<
ts( clock() -
t ) << std::endl;
187 void TIME_QRY(
const char* str,
void ( *func )(
int percent ),
int percent )
189 std::cout << str <<
"... " << std::flush;
192 ( *func )( percent );
193 std::cout <<
ts( clock() -
t ) << std::endl;
197 void TIME_DEL(
const char* str,
void ( *func )(
int ),
int percent )
199 std::cout << str <<
"... " << std::flush;
201 ( *func )( percent );
202 std::cout <<
ts( clock() -
t ) << std::endl;
219 std::cout <<
"Block Entity Creation (all entities in single block of memory)" << std::endl;
223 std::cout <<
"Wrote mesh to file: seqperf.vtk" << std::endl;
227 std::cout <<
"Single Entity Creation (entities grouped in memory blocks of constant size)" << std::endl;
232 std::cout <<
order_strs[order] <<
" order with deletion of " << percent <<
"% of vertices and elements"
242 std::cout <<
" " << num_vert <<
" vertices and " << num_elem <<
" elements remaining" << std::endl;
243 #ifdef PRINT_SEQUENCE_COUNT
245 <<
" element sequences." << std::endl;
257 std::cout <<
"Total time for test: " <<
ts( clock() -
t ) << std::endl << std::endl;
264 if( strncmp( str,
"forward", strlen( str ) ) != 0 )
usage();
267 else if( str[0] !=
'r' )
269 else if( str[1] ==
'e' )
271 if( strncmp( str,
"reverse", strlen( str ) ) != 0 )
usage();
276 if( strncmp( str,
"random", strlen( str ) ) != 0 )
usage();
284 long p = strtol( str, &endptr, 0 );
285 if( !endptr || *endptr || p < 0 || p > 100 )
usage();
287 list.push_back( (
int)p );
293 long p = strtol( str, &endptr, 0 );
294 if( !endptr || *endptr || p < 1 )
usage();
296 if( p != (
long)result )
302 void check_default( std::vector< int >& list,
const int* array,
size_t array_len )
304 if( list.empty() ) std::copy( array, array + array_len, std::back_inserter( list ) );
307 int main(
int argc,
char* argv[] )
310 std::vector< int > createList, orderList, deleteList;
314 for(
int i = 1; i < argc; ++i )
317 if( argv[i][0] !=
'-' || argv[i][1] ==
'\0' || argv[i][2] !=
'\0' )
usage();
319 const char flag = argv[i][1];
323 createList.push_back( 1 );
326 createList.push_back( 0 );
329 if( ++i == argc )
usage();
356 numVert = numSideVert * numSideVert * numSideVert;
358 if(
numVert / numSideVert / numSideVert != numSideVert )
365 <<
numVert <<
" vertices" << std::endl;
369 std::vector< int >::const_iterator i, j, k;
371 for( i = createList.begin(); i != createList.end(); ++i )
373 for( j = deleteList.begin(); j != deleteList.end(); ++j )
375 for( k = orderList.begin(); k != orderList.end(); ++k )
384 std::cout <<
"TOTAL: " <<
ts( clock() -
t ) << std::endl << std::endl;
401 return x + vs * ( y + vs * z );
440 for(
long i = 1; i <
numVert; ++i )
451 std::vector< double* > arrays;
453 if( rval || arrays.size() != 3 )
458 double *x = arrays[0], *y = arrays[1], *z = arrays[2];
459 assert( x && y && z );
461 for(
long i = 0; i <
numVert; ++i )
477 for(
long i = 1; i <
numElem; ++i )
496 for(
long i = 0; i <
numElem; ++i )
506 const long deleted_x = (
numSideInt + 1 ) * ( 100 - percent ) / 100;
508 for( z = 0; z < vert_per_edge; ++z )
510 for( y = 0; y < vert_per_edge; ++y )
512 for( x = 0; x < deleted_x; ++x, ++h )
521 h += ( vert_per_edge - deleted_x );
532 const long deleted_x = (
numSideInt + 1 ) * ( 100 - percent ) / 100;
535 for( z = vert_per_edge - 1; z >= 0; --z )
537 for( y = vert_per_edge - 1; y >= 0; --y )
539 h -= ( vert_per_edge - deleted_x );
540 for( x = deleted_x - 1; x >= 0; --x, --h )
557 for(
long i = 0; i <
numVert; ++i )
578 const long deleted_x = (
numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
580 for( z = 0; z < elem_per_edge; ++z )
582 for( y = 0; y < elem_per_edge; ++y )
584 for( x = 0; x < deleted_x; ++x, ++h )
591 assert( conn && 8 == len );
593 h += ( elem_per_edge - deleted_x );
605 const long deleted_x = (
numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
608 for( z = elem_per_edge - 1; z >= 0; --z )
610 for( y = elem_per_edge - 1; y >= 0; --y )
612 h -= ( elem_per_edge - deleted_x );
613 for( x = deleted_x - 1; x >= 0; --x, --h )
620 assert( conn && 8 == len );
631 for(
long i = 0; i <
numElem; ++i )
640 assert( conn && 8 == len );
678 const long deleted_x = (
numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
680 for( z = 0; z < elem_per_edge; ++z )
682 for( y = 0; y < elem_per_edge; ++y )
684 for( x = 0; x < deleted_x; ++x, ++h )
688 assert( conn && 8 == len );
692 h += ( elem_per_edge - deleted_x );
709 const long deleted_x = (
numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
712 for( z = elem_per_edge - 1; z >= 0; --z )
714 for( y = elem_per_edge - 1; y >= 0; --y )
716 h -= ( elem_per_edge - deleted_x );
717 for( x = deleted_x - 1; x >= 0; --x, --h )
721 assert( conn && 8 == len );
738 for(
long i = 0; i <
numElem; ++i )
744 assert( conn && 8 == len );
753 for(
long i = 0; i <
numVert; ++i )
759 for(
long i =
numVert - 1; i >= 0; --i )
765 for(
long i = 0; i <
numVert; ++i )
771 for(
long i = 0; i <
numElem; ++i )
777 for(
long i =
numElem - 1; i >= 0; --i )
783 for(
long i = 0; i <
numElem; ++i )
795 for(
long i = 0; i <
numVert; ++i )
809 for(
long i = 0; i <
numElem; ++i )
850 #ifdef PRINT_SEQUENCE_COUNT
853 #ifdef MB_ENTITY_SEQUENCE_HPP