Changeset 3293
- Timestamp:
- 11/06/09 11:44:56 (2 weeks ago)
- Files:
-
- 1 modified
-
MOAB/trunk/tools/mbperf/mbperf.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
MOAB/trunk/tools/mbperf/mbperf.cpp
r3103 r3293 31 31 #include <stdio.h> 32 32 #include <iostream> 33 #include <iomanip> 33 34 #include <time.h> 34 35 #include <unistd.h> … … 47 48 48 49 double LENGTH = 1.0; 49 50 void testA(const int nelem, const double *coords); 51 void testB(const int nelem, const double *coords, const MBEntityHandle *connect); 52 void testC(const int nelem, const double *coords); 50 const int DEFAULT_INTERVALS = 50; 51 52 53 void testA(const int nelem); 54 void testB(const int nelem); 55 void testC(const int nelem); 53 56 void print_time(const bool print_em, double &tot_time, double &utime, double &stime, 54 57 double &mem); 55 void query_vert_to_elem( );56 void query_elem_to_vert( );57 void query_struct_elem_to_vert( );58 void query_vert_to_elem(MBInterface*); 59 void query_elem_to_vert(MBInterface*); 60 void query_struct_elem_to_vert(MBInterface*); 58 61 void get_time_mem(double &tot_time, double &user_time, 59 62 double &sys_time, double &tot_mem); … … 106 109 } 107 110 108 void build_coords(const int nelem, double *&coords)111 void build_coords(const int nelem, std::vector<double>& coords) 109 112 { 110 113 double ttime0, ttime1, utime1, stime1, mem1; … … 116 119 int numv_sq = numv*numv; 117 120 int tot_numv = numv*numv*numv; 118 coords = new double[3*tot_numv];121 coords.resize(3*tot_numv); 119 122 120 123 // use FORTRAN-like indexing … … 249 252 } 250 253 251 void build_connect(const int nelem, const MBEntityHandle vstart, MBEntityHandle *&connect) 252 { 253 // allocate the memory 254 int nume_tot = nelem*nelem*nelem; 255 connect = new MBEntityHandle[8*nume_tot]; 256 254 void build_connect(const int nelem, const MBEntityHandle vstart, MBEntityHandle *connect) 255 { 257 256 MBEntityHandle vijk; 258 257 int numv = nelem + 1; … … 277 276 } 278 277 279 MBInterface *gMB; 278 typedef void (*test_func_t)( int ); 279 const struct { 280 std::string testName; 281 std::string testDesc; 282 test_func_t testFunc; 283 } TestList[] = { 284 { "struct", "Conn. and adj. query time for structured mesh", &testA }, 285 { "bulk", "Conn. and adj. query time for bulk-created mesh", &testB }, 286 { "indiv", "Conn. and adj. query time for per-entity created mesh", &testC }, 287 // { "skin", "Test skin time", &skin_time }, 288 // { "skin_adj", "Test skin time using vertex-to-element adjacencies", &skin_adj }, 289 }; 290 291 const int TestListSize = sizeof(TestList)/sizeof(TestList[0]); 292 293 void usage( const char* argv0, bool error = true ) 294 { 295 std::ostream& str = error ? std::cerr : std::cout; 296 str << "Usage: " << argv0 << " -i <ints_per_side> <test_name> [<test_name2> ...]" << std::endl; 297 str << " " << argv0 << " [-h|-l]" << std::endl; 298 if (error) 299 return; 300 str << " -i : specify interverals per side (num hex = ints^3, default: " << DEFAULT_INTERVALS << std::endl; 301 str << " -h : print this help text." << std::endl; 302 str << " -l : list available tests" << std::endl; 303 } 304 305 void list_tests( ) 306 { 307 unsigned max_test_name = 0, max_test_desc = 0; 308 for (int i = 0; i < TestListSize; ++i) { 309 if (TestList[i].testName.size() > max_test_name) 310 max_test_name = TestList[i].testName.size(); 311 if (TestList[i].testDesc.size() > max_test_desc) 312 max_test_desc = TestList[i].testDesc.size(); 313 } 314 std::cout << std::setw(max_test_name) << "NAME" << " " 315 << std::setw(max_test_desc) << std::left << "DESCRIPTION" << std::endl 316 << std::setfill('-') << std::setw(max_test_name) << "" << " " 317 << std::setfill('-') << std::setw(max_test_desc) << "" 318 << std::setfill(' ') << std::endl; 319 for (int i = 0; i < TestListSize; ++i) 320 std::cout << std::setw(max_test_name) << TestList[i].testName << " : " 321 << std::setw(max_test_desc) << std::left << TestList[i].testDesc << std::endl; 322 } 323 280 324 int main(int argc, char* argv[]) 281 325 { 282 int nelem = 20; 283 if (argc < 3) { 284 std::cout << "Usage: " << argv[0] << " <ints_per_side> <A|B|C>" << std::endl; 326 int intervals = DEFAULT_INTERVALS; 327 std::vector<test_func_t> test_list; 328 bool did_help = false; 329 bool expect_ints = false; 330 for (int i = 1; i < argc; ++i) { 331 if (expect_ints) { 332 expect_ints = false; 333 char* endptr; 334 intervals = strtol( argv[i], &endptr, 0 ); 335 if (intervals < 1) { 336 usage(argv[0]); 337 std::cerr << "Invalid interval count: " << intervals << std::endl; 338 return 1; 339 } 340 } 341 else if (*argv[i] == '-') { // flag 342 for (int j = 1; argv[i][j]; ++j) { 343 switch (argv[i][j]) { 344 case 'i': expect_ints = true; break; 345 case 'h': did_help = true; usage(argv[0],false); break; 346 case 'l': did_help = true; list_tests(); break; 347 default: 348 usage(argv[0]); 349 std::cerr << "Invalid option: -" << argv[i][j] << std::endl; 350 return 1; 351 } 352 } 353 } 354 else { 355 int j = -1; 356 do { 357 ++j; 358 if (j >= TestListSize) { 359 usage(argv[0]); 360 std::cerr << "Invalid test name: " << argv[i] << std::endl; 361 return 1; 362 } 363 } while (TestList[j].testName == argv[i]); 364 test_list.push_back( TestList[j].testFunc ); 365 } 366 } 367 368 // error if no input 369 if (test_list.empty() && !did_help) { 370 usage(argv[0]); 371 std::cerr << "No tests specified" << std::endl; 285 372 return 1; 286 373 } 287 374 288 char which_test = '\0'; 289 290 sscanf(argv[1], "%d", &nelem); 291 sscanf(argv[2], "%c", &which_test); 292 293 if (which_test != 'A' && which_test != 'B' && which_test != 'C') { 294 std::cout << "Must indicate A or B or C for test." << std::endl; 295 return 1; 296 } 297 298 std::cout << "number of elements: " << nelem << "; test " 299 << which_test << std::endl; 300 301 gMB = new MBCore(); 302 303 // pre-build the coords array 304 double *coords = NULL; 305 build_coords(nelem, coords); 306 assert(NULL != coords); 307 308 MBEntityHandle *connect = NULL; 309 build_connect(nelem, 1, connect); 310 311 switch (which_test) { 312 case 'A': 313 // test A: create structured mesh 314 testA(nelem, coords); 315 break; 316 317 case 'B': 318 // test B: create mesh using bulk interface 319 testB(nelem, coords, connect); 320 break; 321 322 case 'C': 323 // test C: create mesh using individual interface 324 testC(nelem, coords); 325 break; 375 // now run the tests 376 for (std::vector<test_func_t>::iterator i = test_list.begin(); i != test_list.end(); ++i) { 377 test_func_t fptr = *i; 378 fptr(intervals); 326 379 } 327 380 … … 329 382 } 330 383 331 void query_elem_to_vert( )384 void query_elem_to_vert(MBInterface* gMB) 332 385 { 333 386 MBRange all_hexes; … … 352 405 } 353 406 354 void query_vert_to_elem( )407 void query_vert_to_elem(MBInterface* gMB) 355 408 { 356 409 MBRange all_verts; … … 365 418 } 366 419 367 void query_struct_elem_to_vert( )420 void query_struct_elem_to_vert(MBInterface* gMB) 368 421 { 369 422 // assumes brick mapped mesh with handles starting at zero … … 455 508 #endif 456 509 457 void testA(const int nelem, const double *coords) 458 { 510 void testA( int nelem ) 511 { 512 MBCore moab; 513 MBInterface* gMB = &moab; 459 514 double ttime0, ttime1, ttime2, ttime3, utime, stime, mem; 460 515 … … 467 522 ScdVertexData *vseq = NULL; 468 523 StructuredElementSeq *eseq = NULL; 469 SequenceManager *seq_mgr = dynamic_cast<MBCore*>(gMB)->sequence_manager();524 SequenceManager *seq_mgr = moab.sequence_manager(); 470 525 HomCoord vseq_minmax[2] = {HomCoord(0,0,0), 471 526 HomCoord(nelem, nelem, nelem)}; … … 489 544 assert(MB_SUCCESS == result); 490 545 546 std::vector<double> coords; 547 build_coords(nelem, coords); 548 491 549 // set the coordinates of the vertices 492 550 MBEntityHandle handle; … … 504 562 505 563 // query the mesh 2 ways 506 query_struct_elem_to_vert( );564 query_struct_elem_to_vert(gMB); 507 565 508 566 print_time(false, ttime2, utime, stime, mem); 509 567 std::cout << "After E-v query; memory = " << mem/1.0e6 << " MB." << std::endl; 510 568 511 query_vert_to_elem( );569 query_vert_to_elem(gMB); 512 570 513 571 print_time(false, ttime3, utime, stime, mem); … … 522 580 } 523 581 524 void testB(const int nelem, const double *coords, const MBEntityHandle *connect) 525 { 582 void testB(const int nelem) 583 { 584 MBCore moab; 585 MBInterface* gMB = &moab; 526 586 double ttime0, ttime1, ttime2, ttime3, utime, stime, mem; 527 587 … … 545 605 coord_arrays[0] && coord_arrays[1] && coord_arrays[2]); 546 606 // memcpy the coordinate data into place 547 memcpy(coord_arrays[0], coords, sizeof(double)*num_verts); 607 std::vector<double> coords; 608 build_coords(nelem, coords); 609 memcpy(coord_arrays[0], &coords[0], sizeof(double)*num_verts); 548 610 memcpy(coord_arrays[1], &coords[num_verts], sizeof(double)*num_verts); 549 611 memcpy(coord_arrays[2], &coords[2*num_verts], sizeof(double)*num_verts); … … 552 614 result = readMeshIface->get_element_array(num_elems, 8, MBHEX, 1, estart, conn); 553 615 assert(MB_SUCCESS == result); 554 memcpy(conn, connect, num_elems*8*sizeof(MBEntityHandle));616 build_connect(nelem, vstart, conn); 555 617 result = readMeshIface->update_adjacencies(estart, num_elems, 8, conn); 556 618 assert(MB_SUCCESS == result); … … 560 622 561 623 // query the mesh 2 ways 562 query_elem_to_vert( );624 query_elem_to_vert(gMB); 563 625 564 626 print_time(false, ttime2, utime, stime, mem); 565 627 std::cout << "After E-v query; memory = " << mem/1.0e6 << " MB." << std::endl; 566 628 567 query_vert_to_elem( );629 query_vert_to_elem(gMB); 568 630 569 631 print_time(false, ttime3, utime, stime, mem); … … 578 640 } 579 641 580 void testC(const int nelem, const double *coords) 581 { 642 void testC(const int nelem) 643 { 644 MBCore moab; 645 MBInterface* gMB = &moab; 582 646 double ttime0, ttime1, ttime2, ttime3, utime, stime, mem; 583 647 … … 587 651 // create the vertices; assume we don't need to keep a list of vertex handles, since they'll 588 652 // be created in sequence 653 std::vector<double> coords; 654 build_coords(nelem, coords); 589 655 int numv = nelem + 1; 590 656 int numv_sq = numv*numv; … … 629 695 630 696 // query the mesh 2 ways 631 query_elem_to_vert( );697 query_elem_to_vert(gMB); 632 698 633 699 print_time(false, ttime2, utime, stime, mem); 634 700 std::cout << "After E-v query; memory = " << mem/1.0e6 << " MB." << std::endl; 635 701 636 query_vert_to_elem( );702 query_vert_to_elem(gMB); 637 703 638 704 print_time(false, ttime3, utime, stime, mem);
![(please configure the [header_logo] section in trac.ini)](/projects/ITAPS/chrome/common/trac_banner.png)