Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
mbmem.cpp
Go to the documentation of this file.
00001 #include "moab/Core.hpp"
00002 #include "moab/Range.hpp"
00003 #include "moab/CN.hpp"
00004 
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <sstream>
00008 #include <string>
00009 #include <cstdio>
00010 #include <cstdlib>
00011 
00012 #ifndef _WIN32
00013 #include <sys/times.h>
00014 #include <sys/resource.h>
00015 #include <unistd.h>
00016 #endif
00017 
00018 static void usage( const char* argv0, bool help = false )
00019 {
00020     std::ostream& str = help ? std::cout : std::cerr;
00021     str << "Usage: " << argv0 << " [-H|-b|-k|-m] <filename> [<filename> ...]" << std::endl
00022         << "       " << argv0 << " [-H|-b|-k|-m] -T" << std::endl;
00023     if( !help )
00024     {
00025         str << "       " << argv0 << " -h" << std::endl;
00026         std::exit( 1 );
00027     }
00028 
00029     std::cerr << "  -H : human readable units" << std::endl
00030               << "  -b : bytes" << std::endl
00031               << "  -k : kilobytes (1 kB == 1024 bytes)" << std::endl
00032               << "  -m : megabytes (1 MB == 1024 kB)" << std::endl
00033               << "  -g : gigabytes (1 GB == 1024 MB)" << std::endl
00034               << "  -T : test mode" << std::endl
00035               << std::endl;
00036     std::exit( 0 );
00037 }
00038 
00039 enum Units
00040 {
00041     HUMAN,
00042     BYTES,
00043     KILOBYTES,
00044     MEGABYTES,
00045     GIGABYTES
00046 };
00047 Units UNITS = HUMAN;
00048 
00049 // The core functionality of this example
00050 static void print_memory_stats( moab::Interface& mb,
00051                                 bool per_type = true,
00052                                 bool per_tag  = true,
00053                                 bool totals   = true,
00054                                 bool sysstats = true );
00055 
00056 // Generate a series of meshes for testing
00057 static void do_test_mode();
00058 
00059 // main routine: read any specified files and call print_memory_stats
00060 int main( int argc, char* argv[] )
00061 {
00062     moab::ErrorCode rval;
00063     bool no_more_flags = false;
00064     bool test_mode     = false;
00065     std::vector< int > input_file_list;
00066 
00067     // load each file specified on command line
00068     for( int i = 1; i < argc; ++i )
00069     {
00070         if( !no_more_flags && argv[i][0] == '-' )
00071         {
00072             if( !strcmp( argv[i], "-H" ) )
00073                 UNITS = HUMAN;
00074             else if( !strcmp( argv[i], "-b" ) )
00075                 UNITS = BYTES;
00076             else if( !strcmp( argv[i], "-k" ) )
00077                 UNITS = KILOBYTES;
00078             else if( !strcmp( argv[i], "-m" ) )
00079                 UNITS = MEGABYTES;
00080             else if( !strcmp( argv[i], "-g" ) )
00081                 UNITS = GIGABYTES;
00082             else if( !strcmp( argv[i], "-T" ) )
00083                 test_mode = true;
00084             else if( !strcmp( argv[i], "-h" ) )
00085                 usage( argv[0], true );
00086             else if( !strcmp( argv[i], "--" ) )
00087                 no_more_flags = true;
00088             else
00089             {
00090                 std::cerr << argv[0] << ": Invalid flag: \"" << argv[i] << "\"." << std::endl << std::endl;
00091                 usage( argv[0] );
00092             }
00093         }
00094         else
00095         {
00096             input_file_list.push_back( i );
00097         }
00098     }
00099 
00100     if( test_mode )
00101     {
00102         do_test_mode();
00103         if( input_file_list.empty() ) return 0;
00104     }
00105 
00106     moab::Core mbcore;
00107     moab::Interface& mb = mbcore;
00108     for( std::vector< int >::iterator it = input_file_list.begin(); it != input_file_list.end(); ++it )
00109     {
00110         rval = mb.load_file( argv[*it] );
00111 
00112         // if file load failed, print some info and exit
00113         if( moab::MB_SUCCESS != rval )
00114         {
00115             std::string message;
00116             mb.get_last_error( message );
00117             std::cerr << mb.get_error_string( rval ) << ": " << message << std::endl
00118                       << argv[*it] << ": Failed to read file." << std::endl;
00119             return 1;
00120         }
00121 
00122         std::cout << "Loaded file: " << argv[*it] << std::endl;
00123     }
00124 
00125     // print summary of MOAB's memory use
00126     print_memory_stats( mb );
00127     return 0;
00128 }
00129 
00130 // struct to store memory stats
00131 struct MemStats
00132 {
00133     unsigned long long total_storage;
00134     unsigned long long total_amortized;
00135     unsigned long long entity_storage;
00136     unsigned long long entity_amortized;
00137     unsigned long long adjacency_storage;
00138     unsigned long long adjacency_amortized;
00139     unsigned long long tag_storage;
00140     unsigned long long tag_amortized;
00141 };
00142 
00143 // test if MemStats object indicates no memory
00144 static bool is_zero( const MemStats& stats );
00145 
00146 // populdate a MemStats structg by calling
00147 // moab::Interface::estimated_memory_use
00148 static void get_mem_stats( moab::Interface& mb, MemStats& data, moab::EntityType type = moab::MBMAXTYPE );
00149 
00150 // Formatted string representation of memory size value
00151 static std::string memstr( unsigned long long val );
00152 
00153 // Get string describing tag data type
00154 static std::string tag_type_string( moab::Interface& mb, moab::Tag tag );
00155 
00156 // Get string representation of tag storage type
00157 static std::string tag_storage_string( moab::Interface& mb, moab::Tag tag );
00158 
00159 // Center
00160 static std::string center( const char* str, size_t width );
00161 
00162 void print_memory_stats( moab::Interface& mb, bool per_type, bool per_tag, bool totals, bool sysstats )
00163 {
00164     moab::ErrorCode rval;
00165     const char ANON_TAG_NAME[]   = "(anonymous)";
00166     const int TYPE_WIDTH         = 10;
00167     const int MEM_WIDTH          = 7;
00168     const int MEM2_WIDTH         = 2 * MEM_WIDTH + 1;
00169     const int MIN_TAG_NAME_WIDTH = strlen( ANON_TAG_NAME );
00170     const int DTYPE_WIDTH        = 12;
00171     const int STORAGE_WIDTH      = 8;
00172 
00173     // per-entity-type table header
00174     MemStats stats;
00175 
00176     if( per_type )
00177     {
00178 
00179         std::cout.fill( ' ' );
00180         std::cout << std::left << std::setw( TYPE_WIDTH ) << "Type" << ' ' << center( "Total", MEM2_WIDTH ) << ' '
00181                   << center( "Entity", MEM2_WIDTH ) << ' ' << center( "Adjacency", MEM2_WIDTH ) << ' '
00182                   << center( "Tag", MEM2_WIDTH ) << ' ' << std::endl
00183                   << std::setw( TYPE_WIDTH ) << " ";
00184         for( int i = 0; i < 4; ++i )
00185             std::cout << ' ' << std::left << std::setw( MEM_WIDTH ) << "Used" << ' ' << std::left
00186                       << std::setw( MEM_WIDTH ) << "Alloc";
00187         std::cout << std::endl;
00188         std::cout.fill( '-' );
00189         std::cout << std::setw( TYPE_WIDTH ) << '-';
00190         for( int i = 0; i < 8; ++i )
00191             std::cout << ' ' << std::setw( MEM_WIDTH ) << '-';
00192         std::cout.fill( ' ' );
00193         std::cout << std::endl;
00194 
00195         // per-entity-type memory use
00196         for( moab::EntityType t = moab::MBVERTEX; t != moab::MBMAXTYPE; ++t )
00197         {
00198             get_mem_stats( mb, stats, t );
00199             if( is_zero( stats ) ) continue;  // skip types with no allocated memory
00200 
00201             std::cout << std::left << std::setw( TYPE_WIDTH ) << moab::CN::EntityTypeName( t ) << ' ' << std::right
00202                       << std::setw( MEM_WIDTH ) << memstr( stats.total_storage ) << ' ' << std::right
00203                       << std::setw( MEM_WIDTH ) << memstr( stats.total_amortized ) << ' ' << std::right
00204                       << std::setw( MEM_WIDTH ) << memstr( stats.entity_storage ) << ' ' << std::right
00205                       << std::setw( MEM_WIDTH ) << memstr( stats.entity_amortized ) << ' ' << std::right
00206                       << std::setw( MEM_WIDTH ) << memstr( stats.adjacency_storage ) << ' ' << std::right
00207                       << std::setw( MEM_WIDTH ) << memstr( stats.adjacency_amortized ) << ' ' << std::right
00208                       << std::setw( MEM_WIDTH ) << memstr( stats.tag_storage ) << ' ' << std::right
00209                       << std::setw( MEM_WIDTH ) << memstr( stats.tag_amortized ) << std::endl;
00210         }
00211     }  // end per_type
00212 
00213     if( per_tag )
00214     {
00215         // get list of tags
00216         std::vector< moab::Tag > tags;
00217         std::vector< moab::Tag >::const_iterator ti;
00218         mb.tag_get_tags( tags );
00219 
00220         // figure out required field with to fit longest tag name
00221         unsigned maxlen = MIN_TAG_NAME_WIDTH;
00222         for( ti = tags.begin(); ti != tags.end(); ++ti )
00223         {
00224             std::string name;
00225             rval = mb.tag_get_name( *ti, name );
00226             if( moab::MB_SUCCESS != rval ) continue;
00227             if( name.size() > maxlen ) maxlen = name.size();
00228         }
00229 
00230         // print header for per-tag data
00231         if( !tags.empty() )
00232         {
00233             std::cout.fill( ' ' );
00234             std::cout << std::endl
00235                       << std::left << std::setw( maxlen ) << "Tag Name" << ' ' << std::left << std::setw( DTYPE_WIDTH )
00236                       << "Type" << ' ' << std::left << std::setw( STORAGE_WIDTH ) << "Storage" << ' ' << std::left
00237                       << std::setw( MEM_WIDTH ) << "Used" << ' ' << std::left << std::setw( MEM_WIDTH ) << "Alloc"
00238                       << std::endl;
00239             std::cout.fill( '-' );
00240             std::cout << std::setw( maxlen ) << '-' << ' ' << std::setw( DTYPE_WIDTH ) << '-' << ' '
00241                       << std::setw( STORAGE_WIDTH ) << '-' << ' ' << std::setw( MEM_WIDTH ) << '-' << ' '
00242                       << std::setw( MEM_WIDTH ) << '-' << std::endl;
00243             std::cout.fill( ' ' );
00244         }
00245 
00246         // print per-tag memory use
00247         for( ti = tags.begin(); ti != tags.end(); ++ti )
00248         {
00249             std::string name;
00250             rval = mb.tag_get_name( *ti, name );
00251             if( moab::MB_SUCCESS != rval || name.empty() ) name = ANON_TAG_NAME;
00252 
00253             unsigned long long occupied, allocated;
00254             mb.estimated_memory_use( 0, 0, 0, 0, 0, 0, 0, 0, &*ti, 1, &occupied, &allocated );
00255 
00256             std::cout << std::left << std::setw( maxlen ) << name << ' ' << std::right << std::setw( DTYPE_WIDTH )
00257                       << tag_type_string( mb, *ti ) << ' ' << std::right << std::setw( STORAGE_WIDTH )
00258                       << tag_storage_string( mb, *ti ) << ' ' << std::right << std::setw( MEM_WIDTH )
00259                       << memstr( occupied ) << ' ' << std::right << std::setw( MEM_WIDTH ) << memstr( allocated )
00260                       << std::endl;
00261         }
00262     }  // end per_tag
00263 
00264     if( totals )
00265     {
00266         // print summary of overall memory use
00267         get_mem_stats( mb, stats );
00268         std::cout << std::endl
00269                   << "TOTAL: (Used/Allocated)" << std::endl
00270                   << "memory:    " << memstr( stats.total_storage ) << "/" << memstr( stats.total_amortized )
00271                   << std::endl
00272                   << "entity:    " << memstr( stats.entity_storage ) << "/" << memstr( stats.entity_amortized )
00273                   << std::endl
00274                   << "adjacency: " << memstr( stats.adjacency_storage ) << "/" << memstr( stats.adjacency_amortized )
00275                   << std::endl
00276                   << "tag:       " << memstr( stats.tag_storage ) << "/" << memstr( stats.tag_amortized ) << std::endl
00277                   << std::endl;
00278 
00279     }  // end totals
00280 
00281     if( sysstats )
00282     {
00283         std::FILE* filp = std::fopen( "/proc/self/stat", "r" );
00284         unsigned long long vsize;
00285         long rss;
00286         if( filp && 2 == std::fscanf( filp,
00287                                       "%*d "   // pid
00288                                       "%*s "   // comm
00289                                       "%*c "   // state
00290                                       "%*d "   // ppid
00291                                       "%*d "   // pgrp
00292                                       "%*d "   // session
00293                                       "%*d "   // tty_nr
00294                                       "%*d "   // tpgid
00295                                       "%*u "   // flags
00296                                       "%*u "   // minflt
00297                                       "%*u "   // cminflt
00298                                       "%*u "   // majflt
00299                                       "%*u "   // cmajflt
00300                                       "%*u "   // utime
00301                                       "%*u "   // stime
00302                                       "%*d "   // cutime
00303                                       "%*d "   // cstime
00304                                       "%*d "   // priority
00305                                       "%*d "   // nice
00306                                       "%*d "   // num_threads
00307                                       "%*d "   // itrealvalue
00308                                       "%*u "   // starttime
00309                                       "%llu "  // vsize
00310                                       "%ld",   // rss
00311                                       &vsize, &rss ) )
00312         {
00313 #ifndef _WIN32
00314             long long tmprss = rss * getpagesize();
00315 #endif
00316             std::cout << std::endl
00317                       << "SYSTEM:" << std::endl
00318                       << "Virtual memory:    " << memstr( vsize )
00319 #ifndef _WIN32
00320                       << std::endl
00321                       << "Resident set size: " << memstr( tmprss )
00322 #endif
00323                       << std::endl;
00324         }
00325         else
00326         {
00327 #ifndef _WIN32
00328             struct rusage sysdata;
00329             if( getrusage( RUSAGE_SELF, &sysdata ) )
00330             {
00331                 std::cerr << "getrusage failed" << std::endl;
00332             }
00333             else
00334             {
00335                 rss              = sysdata.ru_maxrss;
00336                 long long tmprss = rss * getpagesize();
00337                 std::cerr << std::endl
00338                           << "SYSTEM:" << std::endl
00339                           << "Resident set size: " << memstr( tmprss ) << std::endl;
00340             }
00341 #endif
00342         }
00343         if( filp ) fclose( filp );
00344     }  // end sysstats
00345 }
00346 
00347 bool is_zero( const MemStats& stats )
00348 {
00349     return stats.total_amortized == 0;
00350 }
00351 
00352 void get_mem_stats( moab::Interface& mb, MemStats& data, moab::EntityType type )
00353 {
00354     if( type != moab::MBMAXTYPE )
00355     {
00356         moab::Range range;
00357         mb.get_entities_by_type( 0, type, range );
00358         mb.estimated_memory_use( range, &data.total_storage, &data.total_amortized, &data.entity_storage,
00359                                  &data.entity_amortized, &data.adjacency_storage, &data.adjacency_amortized, 0, 0,
00360                                  &data.tag_storage, &data.tag_amortized );
00361     }
00362     else
00363     {
00364         mb.estimated_memory_use( 0, 0, &data.total_storage, &data.total_amortized, &data.entity_storage,
00365                                  &data.entity_amortized, &data.adjacency_storage, &data.adjacency_amortized, 0, 0,
00366                                  &data.tag_storage, &data.tag_amortized );
00367     }
00368 }
00369 
00370 // rounded division
00371 static unsigned long long rdiv( unsigned long long num, unsigned long long den )
00372 {
00373     return ( num + den / 2 ) / den;
00374 }
00375 
00376 std::string memstr( unsigned long long val )
00377 {
00378     const unsigned long long kb = 1024;
00379     const unsigned long long mb = kb * kb;
00380     const unsigned long long gb = kb * mb;
00381     const unsigned long long tb = kb * gb;
00382 
00383     std::ostringstream s;
00384     if( UNITS == HUMAN )
00385     {
00386         if( val >= 10 * tb )
00387             s << rdiv( val, tb ) << "TB";
00388         else if( val >= 10 * gb )
00389             s << rdiv( val, gb ) << "GB";
00390         else if( val >= 10 * mb )
00391             s << rdiv( val, mb ) << "MB";
00392         else if( val >= 10 * kb )
00393             s << rdiv( val, kb ) << "kB";
00394         else if( val > 0 )
00395             s << val << " B";
00396         else
00397             s << "0  ";
00398     }
00399     else
00400     {
00401         unsigned long long den = 1;
00402         switch( UNITS )
00403         {
00404             case BYTES:
00405                 den = 1;
00406                 break;
00407             case KILOBYTES:
00408                 den = kb;
00409                 break;
00410             case MEGABYTES:
00411                 den = mb;
00412                 break;
00413             case GIGABYTES:
00414                 den = gb;
00415                 break;
00416             case HUMAN:
00417                 break;  // handled above, list here to suppress warning
00418         }
00419 
00420         s << rdiv( val, den );
00421     }
00422     return s.str();
00423 }
00424 
00425 std::string tag_type_string( moab::Interface& mb, moab::Tag tag )
00426 {
00427     moab::ErrorCode rval;
00428     std::ostringstream s;
00429 
00430     moab::DataType type;
00431     rval = mb.tag_get_data_type( tag, type );
00432     if( moab::MB_SUCCESS != rval ) return std::string();
00433 
00434     int typesize;
00435     std::string typestr;
00436     switch( type )
00437     {
00438         case moab::MB_TYPE_INTEGER:
00439             typestr  = "int";
00440             typesize = sizeof( int );
00441             break;
00442         case moab::MB_TYPE_DOUBLE:
00443             typestr  = "double";
00444             typesize = sizeof( double );
00445             break;
00446         case moab::MB_TYPE_HANDLE:
00447             typestr  = "handle";
00448             typesize = sizeof( moab::EntityHandle );
00449             break;
00450         case moab::MB_TYPE_BIT:
00451             typesize = 1;
00452             typestr  = "bits";
00453             break;
00454         case moab::MB_TYPE_OPAQUE:
00455             typesize = 1;
00456             typestr  = "bytes";
00457             break;
00458         default:
00459             typesize = 1;
00460             typestr  = "???";
00461             break;
00462     }
00463 
00464     int size;
00465     rval = mb.tag_get_length( tag, size );
00466     if( moab::MB_VARIABLE_DATA_LENGTH == rval )
00467         s << "VAR " << typestr;
00468     else if( moab::MB_SUCCESS == rval )
00469         s << size / typesize << " " << typestr;
00470     // else do nothing
00471 
00472     return s.str();
00473 }
00474 
00475 std::string tag_storage_string( moab::Interface& mb, moab::Tag tag )
00476 {
00477     moab::ErrorCode rval;
00478     moab::TagType type;
00479     rval = mb.tag_get_type( tag, type );
00480     if( moab::MB_SUCCESS != rval ) return std::string();
00481 
00482     switch( type )
00483     {
00484         case moab::MB_TAG_DENSE:
00485             return "dense";
00486         case moab::MB_TAG_SPARSE:
00487             return "sparse";
00488         case moab::MB_TAG_BIT:
00489             return "bit";
00490         default:
00491             return "(none)";
00492     }
00493 }
00494 
00495 std::string center( const char* str, size_t width )
00496 {
00497     std::string text( str );
00498     if( text.size() >= width ) return text;
00499 
00500     width -= text.size();
00501     if( 1u == width )
00502     {
00503         text += " ";
00504         return text;
00505     }
00506 
00507     std::ostringstream s;
00508     s << std::setw( width / 2 ) << ' ' << text << std::setw( width / 2 + width % 2 ) << ' ';
00509     return s.str();
00510 }
00511 
00512 void do_test_mode()
00513 {
00514     const char prefix[] = "****************";
00515     moab::Core mbcore;
00516     moab::Interface& mb = mbcore;
00517     moab::ErrorCode rval;
00518     moab::Range handles;
00519     moab::EntityHandle h;
00520     moab::Range::iterator jt, it;
00521     const unsigned N = 1000;
00522 
00523     // creating some vertices
00524     double coords[3] = { 1, 2, 3 };
00525     for( unsigned i = 0; i < N; ++i )
00526         mb.create_vertex( coords, h );
00527     std::cout << std::endl << prefix << "Created " << N << " vertices" << std::endl;
00528     print_memory_stats( mb, true, false, true, true );
00529 
00530     for( unsigned i = 0; i < N; ++i )
00531         mb.create_vertex( coords, h );
00532     std::cout << std::endl << prefix << "Created another " << N << " vertices" << std::endl;
00533     print_memory_stats( mb, true, false, true, true );
00534 
00535     for( int i = 0; i < 100; ++i )
00536     {
00537         for( unsigned j = 0; j < N; ++j )
00538             mb.create_vertex( coords, h );
00539     }
00540     std::cout << std::endl << prefix << "Created another " << 100 * N << " vertices" << std::endl;
00541     print_memory_stats( mb, true, false, true, true );
00542 
00543     // create some elements
00544     handles.clear();
00545     mb.get_entities_by_type( 0, moab::MBVERTEX, handles );
00546     it = handles.begin();
00547     for( unsigned i = 0; i < N - 2; ++i, ++it )
00548     {
00549         jt = it;
00550         moab::EntityHandle conn[3];
00551         conn[0] = *jt;
00552         ++jt;
00553         conn[1] = *jt;
00554         ++jt;
00555         conn[2] = *jt;
00556         ++jt;
00557         mb.create_element( moab::MBTRI, conn, 3, h );
00558     }
00559     std::cout << std::endl << prefix << "Created " << N - 2 << " triangles" << std::endl;
00560     print_memory_stats( mb, true, false, true, true );
00561 
00562     it = handles.begin();
00563     for( unsigned i = 0; i < N - 3; ++i, ++it )
00564     {
00565         jt = it;
00566         moab::EntityHandle conn[4];
00567         conn[0] = *jt;
00568         ++jt;
00569         conn[1] = *jt;
00570         ++jt;
00571         conn[2] = *jt;
00572         ++jt;
00573         conn[3] = *jt;
00574         ++jt;
00575         mb.create_element( moab::MBQUAD, conn, 4, h );
00576     }
00577     std::cout << std::endl << prefix << "Created " << N - 3 << " quads" << std::endl;
00578     print_memory_stats( mb, true, false, true, true );
00579 
00580     for( int i = 0; i < 100; ++i )
00581     {
00582         it = handles.begin();
00583         for( unsigned j = 0; j < N - 3; ++j, ++it )
00584         {
00585             jt = it;
00586             moab::EntityHandle conn[4];
00587             conn[0] = *jt;
00588             ++jt;
00589             conn[1] = *jt;
00590             ++jt;
00591             conn[2] = *jt;
00592             ++jt;
00593             conn[3] = *jt;
00594             ++jt;
00595             mb.create_element( moab::MBQUAD, conn, 4, h );
00596         }
00597     }
00598     std::cout << std::endl << prefix << "Created another " << 100 * ( N - 3 ) << " quads" << std::endl;
00599     print_memory_stats( mb, true, false, true, true );
00600 
00601     // set global ID
00602     moab::Tag tag;
00603     rval = mb.tag_get_handle( "GLOBAL_ID", 1, moab::MB_TYPE_INTEGER, tag );
00604     if( moab::MB_SUCCESS != rval )
00605     {
00606         std::cerr << "Failed to get GLOBAL_ID tag handle" << std::endl;
00607         return;
00608     }
00609     handles.clear();
00610     mb.get_entities_by_type( 0, moab::MBVERTEX, handles );
00611     int id = 1;
00612     for( it = handles.begin(); it != handles.end(); ++it )
00613     {
00614         mb.tag_set_data( tag, &*it, 1, &id );
00615         ++id;
00616     }
00617     std::cout << std::endl << prefix << "Set global ID tag on " << handles.size() << " vertices" << std::endl;
00618     print_memory_stats( mb, true, true, true, true );
00619 
00620     handles.clear();
00621     mb.get_entities_by_type( 0, moab::MBQUAD, handles );
00622     id = 1;
00623     for( it = handles.begin(); it != handles.end(); ++it )
00624     {
00625         mb.tag_set_data( tag, &*it, 1, &id );
00626         ++id;
00627     }
00628     std::cout << std::endl << prefix << "Set global ID tag on " << handles.size() << " quads" << std::endl;
00629     print_memory_stats( mb, true, true, true, true );
00630 
00631     // create and set a sparse tag
00632     mb.tag_get_handle( "mem_test_tag", 3, moab::MB_TYPE_DOUBLE, tag, moab::MB_TAG_SPARSE | moab::MB_TAG_CREAT );
00633     handles.clear();
00634     mb.get_entities_by_type( 0, moab::MBVERTEX, handles );
00635     for( it = handles.begin(); it != handles.end(); ++it )
00636     {
00637         mb.get_coords( &*it, 1, coords );
00638         mb.tag_set_data( tag, &*it, 1, coords );
00639     }
00640     std::cout << std::endl
00641               << prefix << "Copied vertex coords to sparse tag for " << handles.size() << " vertices" << std::endl;
00642     print_memory_stats( mb, true, true, true, true );
00643 
00644     // create and set bit tag
00645     mb.tag_get_handle( "mem_test_bit", 1, moab::MB_TYPE_BIT, tag, moab::MB_TAG_CREAT );
00646     handles.clear();
00647     mb.get_entities_by_type( 0, moab::MBTRI, handles );
00648     for( it = handles.begin(); it != handles.end(); ++it )
00649     {
00650         char byte = '\001';
00651         mb.tag_set_data( tag, &*it, 1, &byte );
00652     }
00653     std::cout << std::endl << prefix << "Set 1-bit tag for " << handles.size() << " triangles" << std::endl;
00654     print_memory_stats( mb, true, true, true, true );
00655 
00656     // create vertex to element adjacency data
00657     handles.clear();
00658     mb.get_entities_by_type( 0, moab::MBVERTEX, handles );
00659     std::vector< moab::EntityHandle > adj_vec;
00660     mb.get_adjacencies( &*handles.begin(), 1, 2, false, adj_vec );
00661     std::cout << std::endl << prefix << "Created vertex-to-element adjacencies" << std::endl;
00662     print_memory_stats( mb, true, false, true, true );
00663     std::cout << std::endl;
00664 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines