34 #include <H5Tpublic.h>
35 #include <H5Ppublic.h>
36 #include <H5Epublic.h>
44 #ifdef MOAB_HAVE_HDF5_PARALLEL
83 #define READ_HDF5_BUFFER_SIZE ( 128 * 1024 * 1024 )
85 #define assert_range( PTR, CNT ) \
86 assert( ( PTR ) >= (void*)dataBuffer ); \
87 assert( ( ( PTR ) + ( CNT ) ) <= (void*)( dataBuffer + bufferSize ) );
94 #if defined( H5E_auto_t_vers ) && H5E_auto_t_vers > 1
97 ReadHDF5::HDF5ErrorHandler* h =
reinterpret_cast< ReadHDF5::HDF5ErrorHandler*
>( data );
99 return ( *h->func )( stack, h->data );
121 for( ++i; i < num_ids && sorted_ids[i] == 1 + sorted_ids[i - 1]; ++i )
123 hint = results.
insert( hint, start, sorted_ids[i - 1] );
132 result.
merge( s, e );
135 #define debug_barrier() debug_barrier_line( __LINE__ )
141 const unsigned threshold = 2;
142 static unsigned long count = 0;
145 dbgOut.
printf( threshold,
"*********** Debug Barrier %lu (@%d)***********\n", ++count, lineno );
172 std::cout <<
"Leaked HDF5 object handle in function at " << __FILE__ <<
":" <<
fileline << std::endl
173 <<
"Open at entrance: " <<
enter_count << std::endl
174 <<
"Open at exit: " << new_count << std::endl;
180 #define CHECK_OPEN_HANDLES
182 #define CHECK_OPEN_HANDLES CheckOpenReadHDF5Handles check_open_handles_( filePtr, __LINE__ )
192 readUtil( NULL ), handleType( 0 ), indepIO( H5P_DEFAULT ), collIO( H5P_DEFAULT ), myPcomm( NULL ),
193 debugTrack( false ), dbgOut( stderr ), nativeParallel( false ), mpiComm( NULL ),
252 #if defined( H5Eget_auto_vers ) && H5Eget_auto_vers > 1
264 #if defined( H5Eset_auto_vers ) && H5Eset_auto_vers > 1
299 if( use_mpio && !parallel )
324 #ifndef MOAB_HAVE_HDF5_PARALLEL
329 MPI_Info info = MPI_INFO_NULL;
334 MPI_Info_create( &info );
335 MPI_Info_set( info,
const_cast< char*
>(
"cb_buffer_size" ),
const_cast< char*
>( cb_size.c_str() ) );
342 MB_SET_ERR( rval,
"Invalid value for PARALLEL_COMM option" );
354 #ifndef H5_MPI_COMPLEX_DERIVED_DATATYPE_WORKS
355 dbgOut.
print( 1,
"H5_MPI_COMPLEX_DERIVED_DATATYPE_WORKS is not defined\n" );
365 unsigned long size = 0;
368 file_prop = H5Pcreate( H5P_FILE_ACCESS );
369 err = H5Pset_fapl_mpio( file_prop, MPI_COMM_SELF, MPI_INFO_NULL );
370 assert( file_prop >= 0 );
373 H5Pclose( file_prop );
395 if( mpi_err || !size )
return MB_FAILURE;
404 file_prop = H5Pcreate( H5P_FILE_ACCESS );
406 assert( file_prop >= 0 );
409 collIO = H5Pcreate( H5P_DATASET_XFER );
411 err = H5Pset_dxpl_mpio(
collIO, H5FD_MPIO_COLLECTIVE );
416 dbgOut.
tprintf( 1,
"Opening \"%s\" for parallel IO\n", filename );
419 H5Pclose( file_prop );
478 dbgOut.
print( 1,
"Using H5S_APPEND for hyperslab selection\n" );
487 #if defined( H5Eget_auto_vers ) && H5Eget_auto_vers > 1
488 herr_t err = H5Eget_auto( H5E_DEFAULT, &handler.
func, &handler.
data );
490 herr_t err = H5Eget_auto( &handler.
func, &handler.
data );
495 #if defined( H5Eget_auto_vers ) && H5Eget_auto_vers > 1
526 const Tag* file_id_tag )
589 dbgOut.
tprintf( 1,
"READ FAILED (ERROR CODE %s): %s\n", ErrorCodeStr[rval], msg.c_str() );
622 dbgOut.
tprint( 1,
"Reading all element connectivity...\n" );
623 std::vector< int > polyhedra;
628 polyhedra.push_back( i );
635 for( std::vector< int >::iterator it = polyhedra.begin(); it != polyhedra.end(); ++it )
675 dbgOut.
tprint( 1,
"Core read finished. Cleaning up...\n" );
701 for(
int i = 0; i < subset_list_length; ++i )
704 rval =
find_int_tag( subset_list[i].tag_name, tag_index );
708 if( !subset_list[i].num_tag_values )
714 std::vector< int > ids( subset_list[i].tag_values,
715 subset_list[i].tag_values + subset_list[i].num_tag_values );
716 std::sort( ids.begin(), ids.end() );
724 file_ids.
swap( tmp_file_ids );
726 file_ids =
intersect( tmp_file_ids, file_ids );
739 dbgOut.
print( 2,
"Ignoring non-set entities with partition set tag\n" );
743 if( tmp_file_ids.
back() >= set_end )
745 dbgOut.
print( 2,
"Ignoring non-set entities with partition set tag\n" );
750 size_t num_per_proc = tmp_file_ids.
size() / num_parts;
751 size_t num_extra = tmp_file_ids.
size() % num_parts;
753 if( part_number < (
long)num_extra )
755 s += ( num_per_proc + 1 ) * part_number;
757 e += ( num_per_proc + 1 );
761 s += num_per_proc * part_number + num_extra;
765 tmp_file_ids.
erase( e, tmp_file_ids.
end() );
766 tmp_file_ids.
erase( tmp_file_ids.
begin(), s );
772 int subset_list_length,
779 static MPEState mpe_event(
"ReadHDF5",
"yellow" );
781 mpe_event.start(
"gather parts" );
785 for(
int i = 0; i < subset_list_length; ++i )
787 dbgOut.
printf( 2,
"Select by \"%s\" with num_tag_values = %d\n", subset_list[i].tag_name,
788 subset_list[i].num_tag_values );
789 if( subset_list[i].num_tag_values )
791 assert( 0 != subset_list[i].tag_values );
792 dbgOut.
printf( 2,
" \"%s\" values = { %d", subset_list[i].tag_name, subset_list[i].tag_values[0] );
798 if( num_parts )
dbgOut.
printf( 2,
"Partition with num_parts = %d and part_number = %d\n", num_parts, part_number );
823 mpe_event.start(
"gather related sets" );
832 const char*
const set_opts[] = {
"NONE",
"SETS",
"CONTENTS", NULL };
834 rval = opts.
match_option(
"CHILDREN", set_opts, child_mode );
836 child_mode = RSM_CONTENTS;
839 MB_SET_ERR( rval,
"Invalid value for 'CHILDREN' option" );
842 rval = opts.
match_option(
"SETS", set_opts, content_mode );
844 content_mode = RSM_CONTENTS;
847 MB_SET_ERR( rval,
"Invalid value for 'SETS' option" );
855 if( content_mode == RSM_CONTENTS || child_mode == RSM_CONTENTS )
892 if( !subset.
empty() ) max_dim = dim;
899 MPI_Allreduce( &send, &max_dim, 1, MPI_INT, MPI_MAX, *
mpiComm );
918 mpe_event.end( rval );
954 mpe_event.end( rval );
959 mpe_event.start(
"read coords" );
960 dbgOut.
tprintf( 1,
"READING NODE COORDINATES (%lu nodes in %lu selects)\n", (
unsigned long)nodes.
size(),
961 (
unsigned long)nodes.
psize() );
967 mpe_event.end( rval );
983 const char*
const options[] = {
"EXPLICIT",
"NODES",
"SIDES", 0 };
984 rval = opts.
match_option(
"ELEMENTS", options, side_mode );
990 side_mode = SM_NODES;
992 side_mode = SM_SIDES;
996 MB_SET_ERR( rval,
"Invalid value for 'ELEMENTS' option" );
999 if( side_mode == SM_SIDES && max_dim == 0 )
1005 for(
int dim = 3; dim >= max_dim; --dim )
1017 mpe_event.end( rval );
1019 if( !ents.
empty() ) max_dim = 3;
1026 Range side_entities;
1027 if( side_mode != SM_EXPLICIT )
1029 if( 0 == max_dim ) max_dim = 4;
1032 for(
int dim = max_dim - 1; dim > 0; --dim )
1043 mpe_event.end( rval );
1057 dbgOut.
tprint( 1,
"UPDATING CONNECTIVITY ARRAYS FOR READ ELEMENTS\n" );
1058 mpe_event.start(
"updating connectivity for elements read before vertices" );
1078 mpe_event.end( rval );
1090 if( side_mode == SM_SIDES )
1093 mpe_event.start(
"cleaning up non-side lower-dim elements" );
1094 dbgOut.
tprint( 1,
"CHECKING FOR AND DELETING NON-SIDE ELEMENTS\n" );
1096 mpe_event.end( rval );
1108 if( content_mode == RSM_SETS || child_mode == RSM_SETS )
1111 mpe_event.start(
"finding recursively contained sets" );
1113 mpe_event.end( rval );
1120 mpe_event.start(
"finding sets containing any read entities" );
1123 bool read_set_containing_parents =
true;
1124 std::string tmp_opt;
1125 rval = opts.
get_option(
"NO_SET_CONTAINING_PARENTS", tmp_opt );
1126 if(
MB_SUCCESS == rval ) read_set_containing_parents =
false;
1131 mpe_event.end( rval );
1138 mpe_event.start(
"reading set contents/parents/children" );
1143 mpe_event.end( rval );
1165 const std::vector< int >& sorted_values,
1171 std::vector< EntityHandle >::iterator iter;
1184 std::vector< EntityHandle > indices;
1188 for( std::vector< int >::reverse_iterator i = grp_indices.rbegin(); i != grp_indices.rend(); ++i )
1196 else if( sets_only )
1200 else if( idx == -1 )
1217 std::sort( indices.begin(), indices.end(), std::greater< EntityHandle >() );
1218 std::transform( indices.begin(), indices.end(),
range_inserter( file_ids ),
1220 std::bind( std::plus< long >(), start_id, std::placeholders::_1 ) );
1237 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1240 std::sort( indices.begin(), indices.end() );
1241 std::vector< EntityHandle > ranges;
1242 iter = indices.begin();
1243 while( iter != indices.end() )
1245 ranges.push_back( *iter );
1247 for( ++iter; iter != indices.end() && ( last + 1 ) == *iter; ++iter, ++last )
1249 ranges.push_back( last );
1252 iter = ranges.begin();
1253 unsigned long offset = 0;
1254 while( iter != ranges.end() )
1265 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1267 offset += end - begin + 1;
1271 assert( offset == indices.size() );
1272 std::sort( indices.begin(), indices.end() );
1276 iter = std::lower_bound( indices.begin(), indices.end(),
1278 indices.erase( iter, indices.end() );
1280 indices.erase( indices.begin(), iter );
1301 else if( idx == -1 )
1310 hint = file_ids.
insert( hint, h, h + ents->
count - 1 );
1326 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1329 hid_t file_type = H5Dget_type( tables[0] );
1330 if( file_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1332 hint = file_ids.
begin();
1335 long remaining = size, offset = 0;
1338 long count = std::min( buffer_size, remaining );
1343 H5Tclose( file_type );
1345 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1350 for(
long i = 0; i < count; ++i )
1357 H5Tclose( file_type );
1365 unsigned long table_size,
1366 const std::vector< int >& sorted_values,
1367 std::vector< EntityHandle >& value_indices )
1374 size_t chunk_size =
bufferSize /
sizeof( int );
1376 size_t remaining = table_size, offset = 0;
1380 size_t count = std::min( chunk_size, remaining );
1386 for(
size_t i = 0; i < count; ++i )
1387 if( std::binary_search( sorted_values.begin(), sorted_values.end(), (
int)
buffer[i] ) )
1388 value_indices.push_back( i + offset );
1422 std::vector< double* > arrays( dim );
1423 const size_t num_nodes = node_file_ids.
size();
1438 for(
int d = 0; d < dim; ++d )
1446 size_t count, offset = 0;
1448 while( !reader.
done() )
1450 dbgOut.
printf( 3,
"Reading chunk %d for dimension %d\n", ++nn, d );
1451 reader.
read( arrays[d] + offset, count );
1454 if( offset != num_nodes )
1465 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1471 long chunk_size =
bufferSize / ( 3 *
sizeof( double ) );
1479 while( !reader.
done() )
1481 dbgOut.
tprintf( 3,
"Reading chunk %d of node coords\n", ++nn );
1486 for(
size_t i = 0; i < count; ++i )
1487 for(
int d = 0; d < dim; ++d )
1488 arrays[d][coffset + i] =
buffer[dim * i + d];
1495 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1499 dbgOut.
print( 3,
"Closing node coordinate table\n" );
1501 for(
int d = dim; d < cdim; ++d )
1502 memset( arrays[d], 0, num_nodes *
sizeof(
double ) );
1504 dbgOut.
printf( 3,
"Updating ID to handle map for %lu nodes\n", (
unsigned long)node_file_ids.
size() );
1534 (
unsigned long)file_ids.
size(), (
unsigned long)file_ids.
psize() );
1542 MB_SET_ERR( MB_FAILURE,
"Unknown element type: \"" << elems.
type <<
"\"" );
1546 const size_t count = file_ids.
size();
1565 while( !reader.
done() )
1571 iter = std::copy(
buffer,
buffer + num_read * nodes_per_elem, iter );
1575 std::sort(
buffer,
buffer + num_read * nodes_per_elem );
1580 assert( iter - array == (ptrdiff_t)count * nodes_per_elem );
1584 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1611 std::vector< IDConnectivity >::iterator i;
1661 const long buffer_size =
bufferSize / ( node_per_elem *
sizeof(
buffer[0] ) );
1664 dbgOut.
printf( 3,
"Reading node-adjacent elements from \"%s\" in %ld chunks\n", group.
handle,
1665 ( remaining + buffer_size - 1 ) / buffer_size );
1668 if( handles_out ) hint = handles_out->
begin();
1671 dbgOut.
printf( 3,
"Reading chunk %d of connectivity data for \"%s\"\n", ++nn, group.
handle );
1674 const long count = std::min( remaining, buffer_size );
1686 for(
long i = 0; i < count; ++i )
1688 for(
int j = 0; j < node_per_elem; ++j )
1697 if( iter[0] ) ++num_elem;
1698 iter += node_per_elem;
1717 for(
long i = 0; i < count; ++i )
1721 iter += node_per_elem;
1726 long*
const end = iter + node_per_elem;
1727 for( ; iter != end; ++iter, ++iter2 )
1730 assert( iter2 - array == num_elem * node_per_elem );
1735 if( handles_out ) hint = handles_out->
insert( hint, handle, handle + num_elem - 1 );
1748 (
unsigned long)elems_in.
size(), (
unsigned long)elems_in.
psize() );
1773 while( !reader.
done() )
1778 std::sort(
buffer,
buffer + num_read * node_per_elem );
1785 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1796 const EntityType type;
1804 virtual ~PolyReader() {}
1827 MB_SET_ERR( MB_FAILURE,
"Unknown element type: \"" << elems.
type <<
"\"" );
1832 long num_poly, num_conn, first_id;
1836 std::string nm( elems.
handle );
1841 return tool.read( offset_reader, connect_reader, file_ids, first_id,
handleType );
1849 Range explicit_ents;
1859 explicit_ents =
subtract( explicit_ents, side_ents );
1862 Range dead_ents( side_ents );
1871 subset.
insert( es, explicit_ents.
end() );
1874 dead_ents =
subtract( dead_ents, adj );
1878 assert( de == dead_ents.
end() );
1884 subset.
insert( es, explicit_ents.
end() );
1887 dead_ents =
subtract( dead_ents, adj );
1891 dbgOut.
printf( 2,
"Deleting %lu elements\n", (
unsigned long)dead_ents.
size() );
1892 dbgOut.
print( 4,
"\tDead entities: ", dead_ents );
1897 while( !dead_ents.
empty() )
1903 if( rit->value <= start && (
EntityID)( start - rit->value ) < rit->count )
break;
1906 EntityID offset = start - rit->value;
1907 EntityID avail = rit->count - offset;
1908 if( avail < count ) count = avail;
1931 std::vector< unsigned > flags( file_ids.
size() );
1933 for(
size_t i = 0; i < flags.size(); ++i, ++si )
1937 if( !file_ids.
empty() )
1996 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2000 hid_t meta_type = H5Dget_type( handle );
2001 size_t size = H5Tget_size( meta_type );
2002 if( size >
sizeof(
long ) )
2003 setMeta =
new long[( num_sets * size + (
sizeof( long ) - 1 ) ) /
sizeof(
long )][4];
2005 setMeta =
new long[num_sets][4];
2011 hid_t ioprop = H5P_DEFAULT;
2012 #ifdef MOAB_HAVE_MPI
2019 if( !bcast ) ioprop =
collIO;
2023 if( !bcast || 0 == rank )
2028 H5Tclose( meta_type );
2030 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2033 H5Tconvert( meta_type, H5T_NATIVE_LONG, num_sets * 4,
setMeta, 0, H5P_DEFAULT );
2037 H5Tclose( meta_type );
2041 #ifdef MOAB_HAVE_MPI
2042 int ierr = MPI_Bcast( (
void*)
setMeta, num_sets * 4, MPI_LONG, 0, comm );
2043 if( MPI_SUCCESS != ierr )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2045 assert( rank == 0 );
2059 if( !child_sets && !contained_sets )
return MB_SUCCESS;
2064 assert( sets_in_out.
empty() );
2068 if( !contained_sets && !child_sets )
return MB_SUCCESS;
2073 if( contained_sets )
2075 long content_len = 0;
2080 cont.
init( content_handle,
true );
2084 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2095 child.
init( child_handle,
true );
2099 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2104 Range children, new_children( sets_in_out );
2105 int iteration_count = 0;
2109 dbgOut.
tprintf( 2,
"Iteration %d of read_set_ids_recursive\n", iteration_count );
2116 if( contained_sets )
2123 children.
erase( it, children.
end() );
2126 new_children =
subtract( children, sets_in_out );
2127 dbgOut.
print_ints( 2,
"Adding additional contained/child sets", new_children );
2128 sets_in_out.
merge( new_children );
2129 }
while( !new_children.
empty() );
2145 long content_len = 0;
2149 hid_t data_type = H5Dget_type( content_handle );
2151 rval =
find_sets_containing( content_handle, data_type, content_len, read_set_containing_parents, sets_out );
2153 H5Tclose( data_type );
2162 const long* contents,
2168 if( !content_len || id_map.
empty() )
return false;
2170 const long* j = contents;
2171 const long*
const end = contents + content_len;
2172 assert( content_len % 2 == 0 );
2175 long start = *( j++ );
2176 long count = *( j++ );
2177 if( id_map.
intersects( start, count ) )
return true;
2182 const long*
const end = contents + content_len;
2183 for(
const long* i = contents; i != end; ++i )
2184 if( id_map.
exists( *i ) )
return true;
2201 bool read_set_containing_parents,
2208 const size_t content_size = H5Tget_size( content_type );
2210 dbgOut.
printf( 2,
"Searching contents of %ld\n", num_sets );
2215 #ifdef MOAB_HAVE_MPI
2228 for(
long i = 0; i < num_sets; ++i )
2232 std::cerr <<
"Invalid data in set contents offsets at position " << i <<
": index " <<
setMeta[i][
CONTENT]
2233 <<
" is less than previous index " << prev << std::endl;
2235 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2241 std::cerr <<
"Maximum set content index " <<
setMeta[num_sets - 1][
CONTENT]
2242 <<
" exceeds contents table length of " << contents_len << std::endl;
2244 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2248 long*
const content_buffer = (
long*)
dataBuffer;
2249 const long content_len =
bufferSize / std::max( content_size,
sizeof(
long ) );
2256 long sets_offset = 0;
2257 long temp_content[4];
2258 while( sets_offset < num_sets )
2260 temp_content[0] = content_len + prev_idx;
2264 assert( sets_count >= 0 && sets_offset + sets_count <= num_sets );
2267 long content_remaining =
setMeta[sets_offset][
CONTENT] - prev_idx;
2268 long content_offset = prev_idx + 1;
2269 while( content_remaining )
2271 long content_count = content_len < content_remaining ? 2 * ( content_len / 2 ) : content_remaining;
2273 dbgOut.
printf( 3,
"Reading chunk %d (%ld values) from set contents table\n", ++mm, content_count );
2274 if( !bcast || 0 == rank )
2278 content_buffer,
collIO, &status );
2280 mhdf_readSetData( contents_handle, content_offset, content_count, content_type, content_buffer,
2284 H5Tconvert( content_type, H5T_NATIVE_LONG, content_count, content_buffer, 0, H5P_DEFAULT );
2288 #ifdef MOAB_HAVE_MPI
2289 int ierr = MPI_Bcast( content_buffer, content_count, MPI_LONG, 0, comm );
2290 if( MPI_SUCCESS != ierr )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2292 assert( rank == 0 );
2296 if( read_set_containing_parents )
2300 tmp_range.
insert( *content_buffer, *( content_buffer + 1 ) );
2302 std::copy( content_buffer, content_buffer + content_count,
range_inserter( tmp_range ) );
2303 tmp_range =
intersect( tmp_range, file_ids );
2307 content_buffer, content_count,
idMap ) )
2310 hint = file_ids.
insert( hint,
id,
id );
2315 content_remaining -= content_count;
2316 content_offset += content_count;
2321 else if(
long read_num =
setMeta[sets_offset + sets_count - 1][
CONTENT] - prev_idx )
2323 assert( sets_count > 0 );
2325 dbgOut.
printf( 3,
"Reading chunk %d (%ld values) from set contents table\n", ++mm, read_num );
2326 if( !bcast || 0 == rank )
2332 mhdf_readSetData( contents_handle, prev_idx + 1, read_num, content_type, content_buffer, &status );
2335 H5Tconvert( content_type, H5T_NATIVE_LONG, read_num, content_buffer, 0, H5P_DEFAULT );
2339 #ifdef MOAB_HAVE_MPI
2340 int ierr = MPI_Bcast( content_buffer, read_num, MPI_LONG, 0, comm );
2341 if( MPI_SUCCESS != ierr )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2343 assert( rank == 0 );
2347 long* buff_iter = content_buffer;
2348 for(
long i = 0; i < sets_count; ++i )
2351 prev_idx += set_size;
2354 if( read_set_containing_parents )
2361 const long* j = buff_iter;
2362 const long*
const end = buff_iter + set_size;
2363 assert( set_size % 2 == 0 );
2366 long start = *( j++ );
2367 long count = *( j++ );
2368 tmp_range.
insert( start, start + count - 1 );
2372 std::copy( buff_iter, buff_iter + set_size,
range_inserter( tmp_range ) );
2373 tmp_range =
intersect( tmp_range, file_ids );
2376 if( !tmp_range.
empty() ||
2380 hint = file_ids.
insert( hint,
id,
id );
2382 buff_iter += set_size;
2386 sets_offset += sets_count;
2400 assert(
length % 2 == 0 );
2401 for(
long i = 0; i <
length; i += 2 )
2402 hint = results.
insert( hint, contents[i], contents[i] + contents[i + 1] - 1 );
2406 std::sort( contents, contents +
length );
2407 for(
long i = 0; i <
length; ++i )
2408 hint = results.
insert( hint, contents[i] );
2417 Range* file_ids_out )
2422 if( file_ids_out ) out_hint = file_ids_out->
begin();
2427 const long TWEAK = 1;
2434 if(
setMeta[second][mode] >= 0 ) hint = data_offsets.
insert( hint, TWEAK,
setMeta[second][mode] + TWEAK );
2442 long idx2 =
setMeta[second][mode];
2443 if( idx2 >= idx1 ) hint = data_offsets.
insert( hint, idx1 + TWEAK, idx2 + TWEAK );
2460 std::vector< EntityHandle > partial;
2463 size_t count, offset;
2481 while( !data.
done() )
2500 if( !partial.empty() )
2502 assert( fileid_iter != set_file_ids.
end() );
2503 size_t num_prev = partial.size();
2506 offset = len - num_prev;
2507 if( offset > count )
2509 partial.insert( partial.end(),
buffer,
buffer + count );
2513 partial.insert( partial.end(),
buffer,
buffer + offset );
2525 if(
setMeta[idx][3] & ranged_flag )
2559 while( offset < count )
2561 assert( fileid_iter != set_file_ids.
end() );
2567 if( offset + len > count )
2569 partial.insert( partial.end(),
buffer + offset,
buffer + count );
2584 if(
setMeta[idx][3] & ranged_flag )
2625 dbgOut.
tprint( 2,
"Reading set contained file IDs\n" );
2638 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2651 hid_t read_type = H5Dget_type( table );
2652 if( read_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2653 const bool convert = !H5Tequal( read_type,
handleType );
2656 size_t chunk_size =
bufferSize / H5Tget_size( read_type );
2657 size_t remaining = table_len;
2658 size_t left_over = 0;
2660 dbgOut.
printf( 3,
"Reading adjacency list in %lu chunks\n",
2661 (
unsigned long)( remaining + chunk_size - 1 ) / chunk_size );
2665 dbgOut.
printf( 3,
"Reading chunk %d of adjacency list\n", ++nn );
2667 size_t count = std::min( chunk_size, remaining );
2677 herr_t err = H5Tconvert( read_type,
handleType, count,
buffer + left_over, 0, H5P_DEFAULT );
2678 if( err < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2683 while( end - iter >= 3 )
2693 if( count2 < 1 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2695 if( end < count2 + iter )
2709 left_over = end - iter;
2712 memmove(
buffer, iter, left_over );
2715 assert( !left_over );
2731 hid_t read_type = -1;
2739 long num_ent, num_val;
2743 if( read_type ) H5Tclose( read_type );
2744 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2748 if( read_type == 0 )
2750 read_type = H5Dget_type( handles[1] );
2751 if( read_type == 0 )
2756 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2764 rval =
read_sparse_tag( tag, read_type, handles[0], handles[1], num_ent );
2769 rval =
read_var_len_tag( tag, read_type, handles[0], handles[1], handles[2], num_ent, num_val );
2774 H5Tclose( read_type );
2789 if( read_type ) H5Tclose( read_type );
2797 const char* name = 0;
2800 if( elem_idx == -2 )
2805 else if( elem_idx == -1 )
2810 else if( elem_idx >= 0 && elem_idx < fileInfo->num_elem_desc )
2817 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2829 if( count > desc->
count )
2833 "Invalid data length for dense tag data: " << name <<
"/" <<
fileInfo->
tags[tag_index].
name );
2837 if( read_type == 0 )
2839 read_type = H5Dget_type( handle );
2840 if( read_type == 0 )
2843 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2852 H5Tclose( read_type );
2865 if( read_type ) H5Tclose( read_type );
2877 bool re_read_default =
false;
2900 if( info.
size < 1 || info.
size > 8 )
2902 MB_SET_ERR( MB_FAILURE,
"Invalid bit tag: class is MB_TAG_BIT, num bits = " << info.
size );
2904 hdf_type = H5Tcopy( H5T_NATIVE_B8 );
2906 if( hdf_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2922 hdf_type = H5Tcopy( hdf_type );
2923 re_read_default =
true;
2932 if( hdf_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2939 hdf_type = H5T_NATIVE_INT;
2943 hdf_type = H5T_NATIVE_DOUBLE;
2947 hdf_type = H5T_NATIVE_UINT;
2955 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2960 hsize_t tmpsize = info.
size;
2961 #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1
2962 hdf_type = H5Tarray_create2( hdf_type, 1, &tmpsize );
2964 hdf_type = H5Tarray_create( hdf_type, 1, &tmpsize, NULL );
2969 hdf_type = H5Tcopy( hdf_type );
2971 if( hdf_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2977 if( re_read_default )
2982 if( hdf_type ) H5Tclose( hdf_type );
2994 if( hdf_type ) H5Tclose( hdf_type );
3003 if( hdf_type ) H5Tclose( hdf_type );
3019 if( hdf_type ) H5Tclose( hdf_type );
3020 MB_SET_ERR( MB_FAILURE,
"Tag type in file does not match type in database for \"" << info.
name <<
"\"" );
3037 if( hdf_type ) H5Tclose( hdf_type );
3046 const char* ent_name,
3047 hid_t hdf_read_type,
3069 hsize_t hdf_size = H5Tget_size( hdf_read_type );
3070 if( hdf_size != (hsize_t)read_size )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3074 Range file_ids, handles;
3079 if( l !=
idMap.
end() && start_id + num_values > l->begin )
3083 size_t beg = std::max( start_id, l->begin );
3084 size_t end = std::min( start_id + num_values, u->begin + u->count ) - 1;
3085 f_ins = file_ids.
insert( f_ins, beg, end );
3086 h_ins = handles.
insert( h_ins, l->value + ( beg - l->begin ), l->value + ( end - l->begin ) );
3090 size_t beg = std::max( start_id, l->begin );
3091 f_ins = file_ids.
insert( f_ins, beg, l->begin + l->count - 1 );
3092 h_ins = handles.
insert( h_ins, l->value + ( beg - l->begin ), l->value + l->count - 1 );
3093 for( ++l; l != u; ++l )
3095 f_ins = file_ids.
insert( f_ins, l->begin, l->begin + l->count - 1 );
3096 h_ins = handles.
insert( h_ins, l->value, l->value + l->count - 1 );
3098 if( u !=
idMap.
end() && u->begin < start_id + num_values )
3100 size_t end = std::min( start_id + num_values, u->begin + u->count - 1 );
3101 f_ins = file_ids.
insert( f_ins, u->begin, end );
3102 h_ins = handles.
insert( h_ins, u->value, u->value + end - u->begin );
3114 std::string tn(
"<error>" );
3120 h_ins = handles.
begin();
3123 reader.
set_file_ids( file_ids, start_id, buffer_size, hdf_read_type );
3124 dbgOut.
printf( 3,
"Reading dense data for tag \"%s\" and group \"%s\" in %lu chunks\n", tn.c_str(), ent_name,
3127 while( !reader.
done() )
3129 dbgOut.
printf( 3,
"Reading chunk %d of \"%s\" data\n", ++nn, tn.c_str() );
3143 ents.
insert( h_ins, end );
3149 dbgOut.
printf( 1,
"Internal error setting data for tag \"%s\"\n", tn.c_str() );
3156 dbgOut.
printf( 1,
"Internal error reading dense data for tag \"%s\"\n", tn.c_str() );
3157 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3170 Range& offset_range,
3171 Range& handle_range,
3172 std::vector< EntityHandle >& handle_vect )
3176 offset_range.
clear();
3177 handle_range.
clear();
3178 handle_vect.clear();
3187 std::string tn( name );
3190 assert( start_offset > 0 );
3195 size_t offset = start_offset;
3198 while( !id_reader.
done() )
3200 dbgOut.
printf( 3,
"Reading chunk %d of \"%s\" IDs\n", ++nn, name );
3202 id_reader.
read( idbuf, count );
3210 for(
size_t i = 0; i < count; ++i )
3214 offset_hint = offset_range.
insert( offset_hint, offset + i );
3215 if( !handle_vect.empty() )
3217 handle_vect.push_back( idbuf[i] );
3219 else if( handle_range.
empty() || idbuf[i] > handle_range.
back() )
3221 handle_hint = handle_range.
insert( handle_hint, idbuf[i] );
3225 handle_vect.resize( handle_range.
size() );
3226 std::copy( handle_range.
begin(), handle_range.
end(), handle_vect.begin() );
3227 handle_range.
clear();
3228 handle_vect.push_back( idbuf[i] );
3229 dbgOut.
print( 2,
"Switching to unordered list for tag handle list\n" );
3239 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3246 hid_t hdf_read_type,
3258 std::vector< EntityHandle > handle_vect;
3259 Range handle_range, offset_range;
3260 std::string tn(
"<error>" );
3279 hsize_t hdf_size = H5Tget_size( hdf_read_type );
3280 if( hdf_size != (hsize_t)read_size )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3283 const int handles_per_tag = read_size /
sizeof(
EntityHandle );
3290 val_reader.
set_file_ids( offset_range, base_offset, chunk_size, hdf_read_type );
3291 dbgOut.
printf( 3,
"Reading sparse values for tag \"%s\" in %lu chunks\n", tn.c_str(),
3295 while( !val_reader.
done() )
3297 dbgOut.
printf( 3,
"Reading chunk %d of \"%s\" values\n", ++nn, tn.c_str() );
3306 if( !handle_vect.empty() )
3315 handle_range.
erase( handle_range.
begin(), handle_range.
begin() + count );
3323 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3330 hid_t hdf_read_type,
3354 hsize_t hdf_size = H5Tget_size( hdf_read_type );
3355 if( hdf_size < 1 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3356 read_size = hdf_size;
3364 std::string tn(
"<error>" );
3372 std::vector< EntityHandle > handle_vect;
3373 Range handle_range, offset_range;
3376 "Reading sparse tag indices failed" );
3382 if( !handle_vect.empty() )
3384 MB_SET_ERR( MB_FAILURE,
"Unordered file ids for variable length tag not supported" );
3412 :
ReadHDF5VarLen( debug_output,
buffer, buffer_size ), tagHandle( tag ), isHandle( is_handle_tag ),
3413 readSize( read_size1 ), readHDF5( owner )
3422 std::vector< unsigned > counts;
3425 MB_CHK_SET_ERR( tool.read_offsets( off_reader, offset_range, base_offset, base_offset, offsets, counts ),
3426 "ReadHDF5 Failure" );
3431 MB_CHK_SET_ERR( tool.read_data( val_reader, offsets, base_offset, hdf_read_type, handle_range, counts, empty ),
3432 "ReadHDF5 Failure" );
3436 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3450 for(
EntityHandle*
const end = array + size; array != end; ++array )
3451 *array = id_map.
find( *array );
3461 for(
size_t i = 0; i < size; ++i )
3464 if( it != id_map.
end() && it->
begin <= (
long)array[i] )
3465 array[new_size++] = it->value + ( array[i] - it->
begin );
3476 for(
size_t i = 0; i < num_ranges; ++i )
3478 long id = ranges[2 * i];
3479 const long end =
id + ranges[2 * i + 1];
3481 if( it == id_map.
end() || it->
begin >
id ) it = id_map.
begin();
3483 if( it == id_map.
end() )
continue;
3484 if( id < it->begin )
id = it->
begin;
3487 if( id < it->begin )
id = it->
begin;
3488 const long off =
id - it->
begin;
3489 long count = std::min( it->count - off, end -
id );
3493 if( count <= 0 )
break;
3494 hint = merge.
insert( hint, it->value + off, it->value + off + count - 1 );
3498 if( ++it == id_map.
end() )
break;
3499 if( it->
begin > end )
break;
3519 size_t count = p->second - p->first + 1;
3520 if( !map.
insert( p->first, start_id, count ).second )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3548 for(
int i = 0; i < qa_len; i++ )
3565 typedef long tag_type;
3569 const long buffer_size =
bufferSize /
sizeof( tag_type );
3572 IDMap::Range range = *i;
3576 tag_type tv = (tag_type)rv;
3583 while( range.count )
3585 long count = buffer_size < range.count ? buffer_size : range.count;
3588 handles.
insert( range.value, range.value + count - 1 );
3589 range.value += count;
3590 range.count -= count;
3591 for(
long j = 0; j < count; ++j )
3592 buffer[j] = (tag_type)range.begin++;
3610 long default_val = 0;
3614 if(
MB_SUCCESS != rval || 0 == setFileIdTag )
return rval;
3616 typedef long tag_type;
3620 const long buffer_size =
bufferSize /
sizeof( tag_type );
3623 IDMap::Range range = *i;
3629 tag_type tv = (tag_type)rv;
3636 while( range.count )
3638 long count = buffer_size < range.count ? buffer_size : range.count;
3641 handles.
insert( range.value, range.value + count - 1 );
3642 range.value += count;
3643 range.count -= count;
3644 for(
long j = 0; j < count; ++j )
3645 buffer[j] = (tag_type)range.begin++;
3655 const char* tag_name,
3657 std::vector< int >& tag_values_out,
3709 long num_ent, num_val;
3711 std::string tn( tag.
name );
3729 const long buffer_size =
bufferSize /
sizeof( long );
3735 while( !ids.
done() )
3737 dbgOut.
printf( 3,
"Reading chunk %d of IDs for \"%s\"\n", ++nn, tag.
name );
3743 for(
size_t j = 0; j < count; ++j )
3745 while( i != file_ids.
end() && (
long)*i <
buffer[j] )
3747 if( i == file_ids.
end() )
break;
3748 if( (
long)*i ==
buffer[j] )
3750 ins = offsets.
insert( ins, j + offset, j + offset );
3758 tag_values.reserve( offsets.
size() );
3759 const size_t data_buffer_size =
bufferSize /
sizeof( int );
3760 int* data_buffer =
reinterpret_cast< int*
>(
dataBuffer );
3762 vals.
set_file_ids( offsets, 0, data_buffer_size, H5T_NATIVE_INT );
3767 while( !vals.
done() )
3769 dbgOut.
printf( 3,
"Reading chunk %d of values for \"%s\"\n", ++nn, tag.
name );
3770 vals.
read( data_buffer, count );
3771 tag_values.insert( tag_values.end(), data_buffer, data_buffer + count );
3776 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3780 std::sort( tag_values.begin(), tag_values.end() );
3781 tag_values.erase( std::unique( tag_values.begin(), tag_values.end() ), tag_values.end() );
3784 std::vector< int > prev_data, curr_data;
3788 const char* gname = 0;
3795 else if( grp == -2 )
3802 assert( grp >= 0 && grp < fileInfo->num_elem_desc );
3810 subset.
merge( s, e );
3821 tag_values.reserve( subset.
size() );
3822 const size_t data_buffer_size =
bufferSize /
sizeof( int );
3823 int* data_buffer =
reinterpret_cast< int*
>(
dataBuffer );
3827 dbgOut.
printf( 3,
"Reading dense data for tag \"%s\" and group \"%s\" in %lu chunks\n", tag.
name,
3832 while( !reader.
done() )
3835 reader.
read( data_buffer, count );
3836 curr_data.insert( curr_data.end(), data_buffer, data_buffer + count );
3841 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3844 std::sort( curr_data.begin(), curr_data.end() );
3845 curr_data.erase( std::unique( curr_data.begin(), curr_data.end() ), curr_data.end() );
3847 tag_values.swap( prev_data );
3848 std::set_union( prev_data.begin(), prev_data.end(), curr_data.begin(), curr_data.end(),
3849 std::back_inserter( tag_values ) );
3878 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3881 hid_t file_type = H5Dget_type( handles[1] );
3882 tag_values.resize( num_val );
3887 H5Tclose( file_type );
3889 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3891 H5Tconvert( file_type, H5T_NATIVE_INT, num_val, &tag_values[0], 0, H5P_DEFAULT );
3892 H5Tclose( file_type );
3901 std::sort( tag_values.begin(), tag_values.end() );
3902 tag_values.erase( std::unique( tag_values.begin(), tag_values.end() ), tag_values.end() );
3905 std::vector< int > prev_data, curr_data;
3909 const char* gname = 0;
3912 else if( grp == -2 )
3922 hid_t file_type = H5Dget_type( handle );
3923 curr_data.resize( num_val );
3928 H5Tclose( file_type );
3930 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3933 H5Tconvert( file_type, H5T_NATIVE_INT, num_val, &curr_data[0], 0, H5P_DEFAULT );
3934 H5Tclose( file_type );
3941 std::sort( curr_data.begin(), curr_data.end() );
3942 curr_data.erase( std::unique( curr_data.begin(), curr_data.end() ), curr_data.end() );
3945 tag_values.swap( prev_data );
3946 std::set_union( prev_data.begin(), prev_data.end(), curr_data.begin(), curr_data.end(),
3947 std::back_inserter( tag_values ) );
3954 #ifdef MOAB_HAVE_MPI
3987 #ifdef MOAB_HAVE_MPI