28 #define ERROR( a, b ) \
30 std::cerr << ( a ) << std::endl; \
34 #define PRINT_LAST_ERROR \
36 std::string last_error; \
37 result = mbImpl->get_last_error( last_error ); \
38 if( last_error.empty() ) \
39 std::cerr << "(none)" << std::endl; \
41 std::cerr << last_error << std::endl; \
44 if( MB_SUCCESS != result ) \
55 std::vector< std::string >& filenames,
63 bool print_parallel );
73 int main(
int argc,
char** argv )
76 MPI_Init( &argc, &argv );
83 double stime = 0, rtime = 0, dtime = 0, ltime = 0;
84 if( 0 ==
rank ) stime = MPI_Wtime();
88 if( NULL == mbImpl )
return 1;
104 int npos = 1, tag_val, distrib, with_ghosts = 1, resolve_shared = 1, use_mpio = 0;
105 bool print_parallel =
false;
106 const char* tag_name;
107 std::vector< std::string > filenames;
108 int parallel_option = 0;
111 if( !strcmp( argv[npos],
"-p" ) ) print_parallel =
true;
113 while( npos != argc )
116 int this_opt = strtol( argv[npos++], NULL, 0 );
123 parallel_option = this_opt;
128 tag_name =
"MATERIAL_SET";
130 num_files = strtol( argv[npos++], NULL, 0 );
137 while( num_files-- && npos < argc )
138 filenames.push_back( std::string( argv[npos++] ) );
139 if( npos < argc ) tag_name = argv[npos++];
140 if( npos < argc ) tag_val = strtol( argv[npos++], NULL, 0 );
142 distrib = strtol( argv[npos++], NULL, 0 );
145 if( npos < argc ) resolve_shared = strtol( argv[npos++], NULL, 0 );
146 if( npos < argc ) with_ghosts = strtol( argv[npos++], NULL, 0 );
147 if( npos < argc ) use_mpio = strtol( argv[npos++], NULL, 0 );
149 tmp_result =
read_file( mbImpl, filenames, tag_name, tag_val, distrib, parallel_option, resolve_shared,
150 with_ghosts, use_mpio, print_parallel );
154 std::cerr <<
"Couldn't read mesh; error message:" << std::endl;
161 filenames.push_back( argv[npos++] );
162 tmp_result =
test_packing( mbImpl, filenames[0].c_str() );
166 std::cerr <<
"Packing test failed; error message:" << std::endl;
173 tag_name =
"MATERIAL_SET";
179 filenames.push_back( std::string( argv[npos++] ) );
180 tmp_result =
read_file( mbImpl, filenames, tag_name, tag_val, distrib, parallel_option, resolve_shared,
181 with_ghosts, use_mpio, print_parallel );
185 std::cerr <<
"Couldn't read mesh; error message:" << std::endl;
192 std::cerr <<
"Unrecognized option \"" << this_opt <<
"\"; skipping." << std::endl;
193 tmp_result = MB_FAILURE;
196 if( 0 ==
rank ) rtime = MPI_Wtime();
199 if( 0 ==
rank ) dtime = MPI_Wtime();
204 std::cerr <<
"Couldn't delete mesh on rank " <<
rank <<
"; error message: " << std::endl;
207 if( 0 ==
rank ) ltime = MPI_Wtime();
209 if(
MB_SUCCESS == result ) std::cerr <<
"Proc " <<
rank <<
": Success." << std::endl;
212 std::cout <<
"Times: " << dtime - stime <<
" " << rtime - stime <<
" " << ltime - dtime
213 <<
" (total/read/delete)" << std::endl;
224 std::cerr <<
"Usage: " << command <<
" [readpar_option] <opt> <input> [...] where:" << std::endl
225 <<
" readpar_option = 0 (BCAST_DELETE) (default), -1 (READ_DELETE), " << std::endl
226 <<
" -2 (READ_PARALLEL), -3 (BCAST)" << std::endl
227 <<
"opt input" << std::endl
228 <<
"=== =====" << std::endl
229 <<
" 1 <linear_ints> <shared_verts> " << std::endl
230 <<
" 2 <n_ints> " << std::endl
231 <<
" 3* <# files> <file_names...> [<tag_name>=\"MATERIAL_SET\" [tag_val] "
232 "[distribute=1] [resolve_shared=1] [with_ghosts=1] [use_mpio=0]"
234 <<
" 4 <file_name> " << std::endl
235 <<
"*Note: if opt 3 is used, it must be the last one." << std::endl;
244 Range matsets, geomsets, parsets;
246 Tag mtag = 0, gtag = 0, ptag = 0, gidtag;
250 std::cerr <<
"Couldn't get MATERIAL_SET tag." << std::endl;
256 std::cerr <<
"Couldn't get MATERIAL_SET tag." << std::endl;
262 std::cerr <<
"Couldn't PARALLEL_PARTITION tag." << std::endl;
268 std::cerr <<
"Couldn't get GLOBAL_ID tag." << std::endl;
274 std::cerr <<
"Couldn't get number entities by type." << std::endl;
277 std::cout <<
"Proc " <<
rank <<
": Total of " << nsets <<
" entity sets." << std::endl;
279 #define PRINTSETS( a, b, c, p ) \
282 result = mbImpl->get_entities_by_type_and_tag( 0, MBENTITYSET, &( a ), p, 1, b ); \
283 if( !( b ).empty() ) \
285 std::vector< int > ids( ( b ).size() ); \
286 result = mbImpl->tag_get_data( gidtag, b, &ids[0] ); \
287 if( MB_SUCCESS == result ) \
289 std::cout << "Proc " << rank << ": " << ( c ) << " (total " << ( b ).size() << "): " << ids[0]; \
290 for( unsigned int i = 1; i < ( b ).size(); i++ ) \
291 std::cout << ", " << ids[i]; \
292 std::cout << std::endl; \
297 PRINTSETS( mtag, matsets,
"material sets", NULL );
302 PRINTSETS( gtag, geomsets,
"geom sets (vols)", &pval );
305 PRINTSETS( gtag, geomsets,
"geom sets (surfs)", &pval );
308 PRINTSETS( gtag, geomsets,
"geom sets (curves)", &pval );
311 PRINTSETS( gtag, geomsets,
"geom sets (verts)", &pval );
313 PRINTSETS( ptag, parsets,
"partition sets", NULL );
322 std::cout <<
"Total sets (by range): " << parsets.
size() <<
"; sets: " << std::endl;
323 parsets.
print(
" " );
332 std::vector< std::string >& filenames,
333 const char* tag_name,
340 bool print_parallel )
342 std::ostringstream options;
343 switch( parallel_option )
346 options <<
"PARALLEL=BCAST_DELETE;PARTITION=" << tag_name;
349 options <<
"PARALLEL=READ_DELETE;PARTITION=" << tag_name;
352 options <<
"PARALLEL=READ_PART;PARTITION=" << tag_name;
355 options <<
"PARALLEL=BCAST;PARTITION=" << tag_name;
361 if( -1 != tag_val ) options <<
";PARTITION_VAL=" << tag_val;
363 if( 1 == distrib ) options <<
";PARTITION_DISTRIBUTE";
365 if( 1 == resolve_shared ) options <<
";PARALLEL_RESOLVE_SHARED_ENTS";
367 if( 1 == with_ghosts ) options <<
";PARALLEL_GHOSTS=3.0.1";
369 if( 1 == use_mpio ) options <<
";USE_MPIO";
371 options <<
";CPUTIME";
373 if( print_parallel ) options <<
";PRINT_PARALLEL";
375 std::vector< ParallelComm* > pcs( filenames.size() );
378 if( 1 < filenames.size() )
380 for(
unsigned int i = 0; i < filenames.size(); i++ )
383 int index = pcs[i]->get_id();
384 std::ostringstream newopts;
385 newopts << options.str();
386 newopts <<
";PARALLEL_COMM=" << index;
387 result = mbImpl->
load_file( filenames[i].c_str(), 0, newopts.str().c_str() );
399 result = pcs[i]->exchange_tags(
"GLOBAL_ID", tmp_range );
402 std::cerr <<
"Tag exchange didn't work." << std::endl;
409 result = mbImpl->
load_file( filenames[0].c_str(), 0, options.str().c_str() );
410 RRA(
"Failed to load file." );
425 RRA(
"create_meshset failed." );
430 std::cerr <<
"Reading file failed; message:" << std::endl;
436 Range ents, whole_range;
437 std::vector< EntityHandle > new_ents;
439 RRA(
"Getting 3d ents failed." );
446 result = pcomm->
pack_buffer( ents,
false,
true,
false, -1, &buff );
447 RRA(
"Packing buffer count (non-stored handles) failed." );
449 std::vector< std::vector< EntityHandle > > L1hloc, L1hrem;
450 std::vector< std::vector< int > > L1p;
451 std::vector< EntityHandle > L2hloc, L2hrem;
452 std::vector< unsigned int > L2p;
455 result = pcomm->
unpack_buffer( buff.
buff_ptr,
false, -1, -1, L1hloc, L1hrem, L1p, L2hloc, L2hrem, L2p, new_ents );
456 RRA(
"Unpacking buffer (non-stored handles) failed." );
467 Range part_ents, part_verts;
468 for(
unsigned int p = 0; p < pcs.size(); p++ )
471 for(
Range::iterator rit = pcs[p]->partition_sets().begin(); rit != pcs[p]->partition_sets().end(); ++rit )
474 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
477 for(
int i = 0; i < 4; i++ )
479 tmp_result = pcs[p]->get_iface_entities( -1, i, iface_ents[i] );
483 std::cerr <<
"get_iface_entities returned error on proc " << pcs[p]->proc_config().proc_rank()
484 <<
"; message: " << std::endl;
485 std::string last_error;
487 if( last_error.empty() )
488 std::cerr <<
"(none)" << std::endl;
490 std::cerr << last_error << std::endl;
493 if( 0 != i ) iface_ents[4].
merge( iface_ents[i] );
501 std::cerr <<
"Couldn't get non-owned entities." << std::endl;
508 std::cerr <<
"Couldn't get number of vertices." << std::endl;
511 tot_verts -= part_verts.
size();
519 std::cerr <<
"Proc " <<
rank <<
" iface entities: " << std::endl;
520 for(
int i = 0; i < 4; i++ )
521 std::cerr <<
" " << iface_ents[i].
size() <<
" " << i <<
"d iface entities." << std::endl;
522 std::cerr <<
" (" << iface_ents[5].
size() <<
" verts adj to other iface ents)" << std::endl;
523 if( iface_ents[0].
size() != iface_ents[5].
size() )
524 std::cerr <<
"WARNING: number of interface vertices don't agree with "
525 <<
"vertex adjacencies on interface entities." << std::endl;
528 std::cout <<
"Proc " <<
rank <<
" owns " << part_ents.
size() <<
" 3d entities." << std::endl;
531 int num_local[2], num_total[2];
532 num_local[0] = tot_verts;
533 num_local[1] = part_ents.
size();
535 int failure = MPI_Reduce( num_local, num_total, 2, MPI_INT, MPI_SUM, 0,
MPI_COMM_WORLD );
536 if( failure ) result = MB_FAILURE;
540 std::cout <<
"Total # owned vertices = " << num_total[0] << std::endl;
541 std::cout <<
"Total # owned regions = " << num_total[1] << std::endl;