23 const char* InputFile =
STRINGIFY( MESHDIR )
"/ptest.cub";
24 const char* InputMix =
STRINGIFY( MESHDIR )
"/io/mix.h5m";
25 const char* InputOneSide =
STRINGIFY( MESHDIR )
"/io/oneside.h5m";
27 #error Specify MESHDIR to compile test
120 std::ostringstream str;
130 str <<
"READ_DELETE";
133 str <<
"BCAST_DELETE";
137 if( by_rank ) str <<
"PARTITION_BY_RANK;";
140 if( extra_opts ) str << extra_opts <<
";";
144 if(
HyperslabAppend ) str <<
"HYPERSLAB_APPEND;HYPERSLAB_SELECT_LIMIT=2147483647";
149 int main(
int argc,
char* argv[] )
151 int err = MPI_Init( &argc, &argv );
154 for(
int i = 1; i < argc; ++i )
156 if( !strcmp( argv[i],
"-k" ) )
158 else if( !strcmp( argv[i],
"-p" ) )
160 else if( !strcmp( argv[i],
"-R" ) )
167 else if( !strcmp( argv[i],
"-b" ) )
174 else if( !strcmp( argv[i],
"-r" ) )
181 else if( !strcmp( argv[i],
"-w" ) )
188 else if( !strcmp( argv[i],
"-A" ) )
192 std::cerr <<
"Usage: " << argv[0]
193 <<
" [-k] [-p] [-R <intervals>] [-r <level>] [-w <level>] [-b <blocks>] [-A]" << std::endl;
202 printf(
"Rank %2d PID %lu\n",
rank, (
unsigned long)getpid() );
272 Tag sharedp_tag, sharedps_tag, sharedh_tag, sharedhs_tag, pstatus_tag;
284 const char* topo_names_s[] = {
"Vertex",
"Curve",
"Surface",
"Volume" };
286 std::ostringstream
buffer;
288 for(
int t = 0;
t < 4; ++
t )
292 const void* ptr = &
dim;
310 tmp_entities.
clear();
311 rval =
moab.get_entities_by_handle( *j, tmp_entities );
CHECK_ERR( rval );
317 std::vector< char > status_flags(
entities.size(), 0 );
318 std::vector< int > shared_procs(
entities.size(), 0 );
319 rval =
moab.tag_get_data( pstatus_tag,
entities, &status_flags[0] );
325 unsigned num_shared = 0, num_owned = 0;
326 for(
size_t j = 0; j < status_flags.size(); ++j )
334 if( list_non_shared )
335 buffer <<
rank <<
":\t" << topo_names_s[
t] <<
" " <<
id <<
":\t"
336 <<
"not shared" << std::endl;
338 else if( num_shared !=
entities.size() )
340 buffer <<
rank <<
":\t" << topo_names_s[
t] <<
" " <<
id <<
":\t"
341 <<
"ERROR: " << num_shared <<
" of " <<
entities.size() <<
" entities marked as 'shared'"
344 else if( num_owned && num_owned !=
entities.size() )
346 buffer <<
rank <<
":\t" << topo_names_s[
t] <<
" " <<
id <<
":\t"
347 <<
"ERROR: " << num_owned <<
" of " <<
entities.size() <<
" entities owned by this processor"
353 int proc = shared_procs[0];
354 bool all_match =
true;
355 for(
size_t j = 1; j < shared_procs.size(); ++j )
356 if( shared_procs[j] != proc ) all_match =
false;
359 buffer <<
rank <<
":\t" << topo_names_s[
t] <<
" " <<
id <<
":\t"
360 <<
"ERROR: processsor IDs do not match!" << std::endl;
362 else if( proc != -1 )
364 buffer <<
rank <<
":\t" << topo_names_s[
t] <<
" " <<
id <<
":\t"
365 <<
"shared with processor " << proc;
366 if( num_owned )
buffer <<
" (owned by this processor)";
371 buffer <<
rank <<
":\t" << topo_names_s[
t] <<
" " <<
id <<
":\t"
372 <<
"ERROR: no entities!" << std::endl;
377 rval =
moab.tag_get_data( sharedps_tag, &*j, 1, &ent_procs[0] );
CHECK_ERR( rval );
378 for( ++j; j !=
entities.end(); ++j )
380 rval =
moab.tag_get_data( sharedps_tag, &*j, 1, &tmp_ent_procs[0] );
CHECK_ERR( rval );
381 if( ent_procs != tmp_ent_procs ) all_match =
false;
385 buffer <<
rank <<
":\t" << topo_names_s[
t] <<
" " <<
id <<
":\t"
386 <<
"ERROR: processsor IDs do not match!" << std::endl;
390 buffer <<
rank <<
":\t" << topo_names_s[
t] <<
" " <<
id <<
":\t"
393 if( ent_procs[k] != -1 )
buffer << ent_procs[k] <<
", ";
394 if( num_owned )
buffer <<
" (owned by this processor)";
401 for(
int i = 0; i <
size; ++i )
406 std::cout <<
buffer.str();
417 "PARALLEL=READ_DELETE;"
418 "PARTITION=GEOM_DIMENSION;PARTITION_VAL=3;"
419 "PARTITION_DISTRIBUTE;"
420 "PARALLEL_RESOLVE_SHARED_ENTS" );
433 const char* opt =
"PARALLEL=WRITE_PART";
437 std::ostringstream s;
442 rval =
moab.write_file( tmp_filename, 0, opt );
445 std::cerr <<
"Parallel write failed on processor " << procnum << std::endl;
449 if( procnum == 0 &&
KeepTmpFiles ) std::cout <<
"Wrote file: \"" << tmp_filename <<
"\"\n";
454 std::vector< ParallelComm* > pc_list;
456 for( std::vector< ParallelComm* >::iterator vit = pc_list.begin(); vit != pc_list.end(); ++vit )
460 std::vector< Tag > tags;
462 for(
size_t i = 0; i < tags.size(); ++i )
469 rval =
moab.load_file( tmp_filename );
484 rval =
moab.get_entities_by_type( 0,
t, range );
CHECK_ERR( rval );
486 counts[
t] = range.
size();
493 std::map< EntityHandle, EntityHandle > entmap;
501 for( i1 = r1.
begin(); i1 != r1.
end(); ++i1 )
505 for( i2 = r2.
begin(); i2 != r2.
end(); ++i2 )
509 coords2[0] -= coords1[0];
510 coords2[1] -= coords1[1];
511 coords2[2] -= coords1[2];
512 double lensqr = coords2[0] * coords2[0] + coords2[1] * coords2[1] + coords2[2] * coords2[2];
513 if( lensqr < 1e-12 )
break;
521 std::vector< EntityHandle > conn1, conn2;
530 for( i1 = r1.
begin(); i1 != r1.
end(); ++i1 )
534 for( i2 = r2.
begin(); i2 != r2.
end(); ++i2 )
538 if( conn1.size() != conn2.size() )
continue;
539 for( std::vector< EntityHandle >::iterator j = conn2.begin(); j != conn2.end(); ++j )
541 if( conn1 == conn2 )
break;
566 std::fill( all_counts, all_counts +
MBENTITYSET, 0u );
576 rval =
moab.get_number_entities_by_type( 0,
t, file_counts[
t] );
CHECK_ERR( rval );
585 bool all_equal =
true;
587 if( file_counts[
t] != all_counts[
t] ) all_equal =
false;
589 if(
rank == 0 && !all_equal )
591 std::cerr <<
"Type\tPartnd\tWritten" << std::endl;
593 std::cerr <<
CN::EntityTypeName(
t ) <<
'\t' << all_counts[
t] <<
'\t' << file_counts[
t] << std::endl;
617 if( count1 != count2 )
619 std::cerr <<
"Sets differ in number of " <<
CN::EntityTypeName(
t ) <<
" : " << count1 <<
" vs. " << count2
641 if(
rank != 0 )
return;
647 Tag mattag1, mattag2;
659 void* tagdata[] = { &block_id };
660 rval =
moab.get_entities_by_type_and_tag( 0,
MBENTITYSET, &mattag1, tagdata, 1, tmpents );
661 if( tmpents.
size() != 1 ) std::cerr << tmpents.
size() <<
" sets with material set id " << block_id << std::endl;
676 const char*
filename =
"var-len-para.h5m";
677 const char*
tagname =
"ParVar";
688 std::vector< double > coords( 3 *
rank + 3, (
double)
rank );
696 std::vector< int > data;
698 for( i = verts.
begin(); i != verts.
end(); ++i )
701 const int n = h % 7 + 1;
702 data.resize( n + 1 );
704 for(
int j = 0; j < n; ++j )
705 data[j + 1] =
rank + j;
706 const int s = ( n + 1 );
707 const void* ptrarr[] = { &data[0] };
714 const char* opt =
"PARALLEL=WRITE_PART";
718 std::ostringstream s;
759 std::vector< int > vtx_counts( numproc, 0 );
760 for( i = verts.
begin(); i != verts.
end(); ++i )
764 const void* ptrarr[1] = { 0 };
766 const int* tag_data =
reinterpret_cast< const int*
>( ptrarr[0] );
768 CHECK( NULL != tag_data );
770 CHECK( tag_data[1] >= 0 && tag_data[1] < numproc );
771 ++vtx_counts[tag_data[1]];
772 for(
int j = 1; j <
size - 1; ++j )
777 for(
int j = 0; j < numproc; ++j )
791 int blocks_per_cpu = 1,
792 const char* ijk_vert_tag_name = 0,
793 const char* ij_set_tag_name = 0,
794 const char* global_tag_name = 0,
795 const int* global_mesh_value = 0,
796 const int* global_default_value = 0,
797 bool create_bcsets =
false )
803 Tag ijk_vert_tag = 0, ij_set_tag = 0, global_tag = 0;
804 if( ijk_vert_tag_name )
808 if( ij_set_tag_name )
812 if( global_tag_name )
815 global_default_value );
CHECK_ERR( rval );
816 if( global_mesh_value )
823 const int num_blk = num_cpu * blocks_per_cpu;
824 int iv = intervals + 1, ii = num_blk * intervals + 1;
825 std::vector< EntityHandle > verts( iv * iv * ii );
827 for(
int i = 0; i < ii; ++i )
829 for(
int j = 0; j < iv; ++j )
832 for(
int k = 0; k < iv; ++k )
834 const double coords[3] = {
static_cast< double >( i ),
static_cast< double >( j ),
835 static_cast< double >( k ) };
839 int vals[] = { i, j, k };
850 int vals[] = { i, j };
856 const int eb = intervals * intervals * intervals;
857 std::vector< EntityHandle > elems( num_blk * eb );
859 for(
int c = 0; c < num_blk; ++c )
861 for(
int i = c * intervals; i < ( c + 1 ) * intervals; ++i )
863 for(
int j = 0; j < intervals; ++j )
865 for(
int k = 0; k < intervals; ++k )
867 EntityHandle conn[8] = { verts[iv * ( iv * i + j ) + k],
868 verts[iv * ( iv * ( i + 1 ) + j ) + k],
869 verts[iv * ( iv * ( i + 1 ) + j + 1 ) + k],
870 verts[iv * ( iv * i + j + 1 ) + k],
871 verts[iv * ( iv * i + j ) + k + 1],
872 verts[iv * ( iv * ( i + 1 ) + j ) + k + 1],
873 verts[iv * ( iv * ( i + 1 ) + j + 1 ) + k + 1],
874 verts[iv * ( iv * i + j + 1 ) + k + 1] };
885 std::vector< EntityHandle > parts( num_cpu );
886 for(
int i = 0; i < num_cpu; ++i )
889 for(
int j = 0; j < blocks_per_cpu; ++j )
931 const char* file_name = by_rank ?
"test_read_rank.h5m" :
"test_read.h5m";
971 const double x_min = intervals *
rank;
972 const double x_max = intervals * (
rank + 1 );
975 std::vector< double > coords( verts.size() );
977 const double act_x_min = *std::min_element( coords.begin(), coords.end() );
978 const double act_x_max = *std::max_element( coords.begin(), coords.end() );
985 const char file_name[] =
"read_time.h5m";
1003 times[0] = MPI_Wtime();
1007 times[0] = MPI_Wtime() - times[0];
1008 times[1] = double( clock() - tmp_t ) / CLOCKS_PER_SEC;
1015 times[2] = MPI_Wtime();
1018 times[2] = MPI_Wtime() - times[2];
1019 times[3] = double( clock() - tmp_t ) / CLOCKS_PER_SEC;
1026 times[4] = MPI_Wtime();
1029 times[4] = MPI_Wtime() - times[4];
1030 times[5] = double( clock() - tmp_t ) / CLOCKS_PER_SEC;
1033 double max_times[6] = { 0, 0, 0, 0, 0, 0 }, sum_times[6] = { 0, 0, 0, 0, 0, 0 };
1034 MPI_Reduce( times, max_times, 6, MPI_DOUBLE, MPI_MAX, 0,
MPI_COMM_WORLD );
1035 MPI_Reduce( times, sum_times, 6, MPI_DOUBLE, MPI_SUM, 0,
MPI_COMM_WORLD );
1039 printf(
"%12s %12s %12s %12s\n",
"",
"READ_PART",
"READ_DELETE",
"BCAST_DELETE" );
1040 printf(
"%12s %12g %12g %12g\n",
"Max Wall", max_times[0], max_times[2], max_times[4] );
1041 printf(
"%12s %12g %12g %12g\n",
"Total Wall", sum_times[0], sum_times[2], sum_times[4] );
1042 printf(
"%12s %12g %12g %12g\n",
"Max CPU", max_times[1], max_times[3], max_times[5] );
1043 printf(
"%12s %12g %12g %12g\n",
"Total CPU", sum_times[1], sum_times[3], sum_times[5] );
1052 const char tag_name[] =
"test_tag_xx";
1053 const char file_name[] =
"test_read_tags.h5m";
1078 Range verts, tagged;
1092 CHECK( ijk[1] >= 0 );
1094 CHECK( ijk[2] >= 0 );
1105 const char tag_name[] =
"test_tag_g";
1106 const char file_name[] =
"test_read_global_tags.h5m";
1113 const int def_val = 0xdeadcad;
1114 const int global_val = -11;
1117 if( 0 ==
rank )
create_input_file( file_name, 1, numproc, 1, 0, 0, tag_name, &global_val, &def_val );
1133 int mesh_def_val, mesh_gbl_val;
1143 const char tag_name[] =
"test_tag_s";
1144 const char file_name[] =
"test_read_sets.h5m";
1181 CHECK( ij[1] >= 0 );
1202 const char file_name[] =
"test_read_sets.h5m";
1222 int num_ents[3], global_num_ents[3] = { 0, 0, 0 };
1223 Range sets, contents;
1227 ( ( numproc * 4 + 2 ) * ( vints - 2 ) * ( vints - 2 ) + 12 * numproc * ( vints - 2 ) +
1231 for(
int i = 0; i < 3; i++ )
1237 num_ents[i] = contents.
size();
1242 MPI_Reduce( num_ents, global_num_ents, 3, MPI_INT, MPI_SUM, 0,
MPI_COMM_WORLD );
1250 for(
int i = 0; i < 3; i++ )
1252 CHECK_EQUAL( global_num_ents[i], expected_num_ents[i] );
1259 const char file_name[] =
"test_write_different_element_types.h5m";
1269 const int verts[] = { 2, 3, 4, 3, 9, 6, 4, 8, 6, 5, 20, 27 };
1270 const int ntypes =
sizeof( topos ) /
sizeof( topos[0] );
1272 const EntityType mtype = topos[
rank % ntypes];
1273 const int nvert = verts[
rank % ntypes];
1274 std::vector< EntityHandle > conn( nvert );
1275 for(
int i = 0; i < nvert; ++i )
1277 const double coords[] = {
static_cast< double >(
rank ),
static_cast< double >( i ), 0 };
1287 for(
int i = 0; i < ntypes; ++i )
1289 const int num_exp = numproc / ntypes + ( i < ( numproc % ntypes ) ? 1 : 0 );
1298 if( len == verts[i] ) ++num;
1309 int len =
rank % 3 + 1;
1312 std::ostringstream name;
1313 name <<
"TestTag" <<
rank;
1314 const void* defval = 0;
1315 const int defint[] = {
static_cast< int >(
rank ),
static_cast< int >(
rank / 2 ),
static_cast< int >(
rank + 1 ),
1316 static_cast< int >(
rank - 1 ) };
1317 const double defreal[] = { 0.1 *
rank, 1.0 /
rank,
static_cast< double >( -
rank ),
static_cast< double >(
rank ) };
1318 const int defhandle[] = { 0, 0, 0, 0 };
1319 const unsigned char defbit = 0x1;
1320 const char defopq[] =
"Jason";
1350 const char file_name[] =
"test_write_different_tags.h5m";
1357 const int min_tags = 8;
1359 for(
int idx =
rank + numproc; idx < min_tags; idx += numproc )
1366 for(
int i = 0; i < std::max( min_tags, numproc ); ++i )
1373 const char file_name[] =
"test_write_polygons.h5m";
1382 const double r = 0.70710678118654757;
1383 const double points[8][3] = {
1384 { 1, 0,
static_cast< double >(
rank ) },
1385 {
static_cast< double >( r ),
static_cast< double >( r ),
static_cast< double >(
rank ) },
1386 { 0, 1,
static_cast< double >(
rank ) },
1387 {
static_cast< double >( -r ),
static_cast< double >( r ),
static_cast< double >(
rank ) },
1388 { -1, 0,
static_cast< double >(
rank ) },
1389 {
static_cast< double >( -r ),
static_cast< double >( -r ),
static_cast< double >(
rank ) },
1390 { 0, -1,
static_cast< double >(
rank ) },
1391 {
static_cast< double >( r ),
static_cast< double >( -r ),
static_cast< double >(
rank ) } };
1392 const int nvtx =
rank % 4 + 5;
1393 std::vector< EntityHandle > conn( nvtx );
1394 for(
int i = 0; i < nvtx; ++i )
1404 if(
rank != 0 )
return;
1412 std::vector< EntityHandle > poly( numproc, 0 );
1421 int proc = (int)( coords[2] );
1427 for(
int i = 0; i < numproc; ++i )
1439 const char file_name[] =
"test_write_unbalanced.h5m";
1460 const double coords[4][3] = { {
static_cast< double >(
rank ), 0, 0 },
1461 {
static_cast< double >(
rank + 2 ), 0, 0 },
1462 {
static_cast< double >(
rank + 2 ), 2, 0 },
1463 {
static_cast< double >(
rank ), 2, 0 } };
1465 for(
int i = 0; i < 4; ++i )
1486 if(
rank != 0 )
return;
1493 const size_t nquads = numproc / 2;
1494 const size_t nverts = nquads ? 2 + 2 * nquads : 0;
1500 const void* vals[] = { &two };
1524 rval =
moab.load_file( InputMix, 0,
1525 "PARALLEL=READ_PART;"
1526 "PARTITION=PARALLEL_PARTITION;"
1527 "PARALLEL_RESOLVE_SHARED_ENTS" );
CHECK_ERR( rval );
1532 moab.get_entities_by_dimension( 0, 2, elems );
1534 const char*
tagname =
"element_tag";
1535 const double defVal = 0.;
1539 int numElems = (int)elems.
size();
1541 for(
int i = 0; i < numElems; i++ )
1545 moab.get_coords( &elem, 1, xyz );
1547 double fieldValue = sqrt( xyz[0] * xyz[0] + xyz[1] * xyz[1] + xyz[2] * xyz[2] );
1548 moab.tag_set_data( fieldTag, &elem, 1, &fieldValue );
1552 rval =
moab.write_file(
"newfile.h5m", 0,
"PARALLEL=WRITE_PART" );
CHECK_ERR( rval );
1557 rval = moab2.
load_file(
"newfile.h5m", 0,
1558 "PARALLEL=READ_PART;"
1559 "PARTITION=PARALLEL_PARTITION;"
1560 "PARALLEL_RESOLVE_SHARED_ENTS" );
CHECK_ERR( rval );
1582 rval =
moab.load_file( InputOneSide, 0,
1583 "PARALLEL=READ_PART;"
1584 "PARTITION=PARALLEL_PARTITION;"
1585 "PARALLEL_RESOLVE_SHARED_ENTS" );
CHECK_ERR( rval );