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 if( h->func ) result = ( *h->func )( stack, h->data );
MB_CHK_ERR_CONT( MB_FAILURE );
119 for( ++i; i < num_ids && sorted_ids[i] == 1 + sorted_ids[i - 1]; ++i )
121 hint = results.
insert( hint, start, sorted_ids[i - 1] );
130 result.
merge( s, e );
133 #define debug_barrier() debug_barrier_line( __LINE__ )
139 const unsigned threshold = 2;
140 static unsigned long count = 0;
143 dbgOut.
printf( threshold,
"*********** Debug Barrier %lu (@%d)***********\n", ++count, lineno );
170 std::cout <<
"Leaked HDF5 object handle in function at " << __FILE__ <<
":" <<
fileline << std::endl
171 <<
"Open at entrance: " <<
enter_count << std::endl
172 <<
"Open at exit: " << new_count << std::endl;
178 #define CHECK_OPEN_HANDLES
180 #define CHECK_OPEN_HANDLES CheckOpenReadHDF5Handles check_open_handles_( filePtr, __LINE__ )
190 readUtil( NULL ), handleType( 0 ), indepIO( H5P_DEFAULT ), collIO( H5P_DEFAULT ), myPcomm( NULL ),
191 debugTrack( false ), dbgOut( stderr ), nativeParallel( false ), mpiComm( NULL ),
250 #if defined( H5Eget_auto_vers ) && H5Eget_auto_vers > 1
262 #if defined( H5Eset_auto_vers ) && H5Eset_auto_vers > 1
297 if( use_mpio && !parallel )
322 #ifndef MOAB_HAVE_HDF5_PARALLEL
327 MPI_Info info = MPI_INFO_NULL;
332 MPI_Info_create( &info );
333 MPI_Info_set( info,
const_cast< char*
>(
"cb_buffer_size" ),
const_cast< char*
>( cb_size.c_str() ) );
340 MB_SET_ERR( rval,
"Invalid value for PARALLEL_COMM option" );
352 #ifndef H5_MPI_COMPLEX_DERIVED_DATATYPE_WORKS
353 dbgOut.
print( 1,
"H5_MPI_COMPLEX_DERIVED_DATATYPE_WORKS is not defined\n" );
363 unsigned long size = 0;
366 file_prop = H5Pcreate( H5P_FILE_ACCESS );
367 err = H5Pset_fapl_mpio( file_prop, MPI_COMM_SELF, MPI_INFO_NULL );
368 assert( file_prop >= 0 );
371 H5Pclose( file_prop );
393 if( mpi_err || !
size )
return MB_FAILURE;
402 file_prop = H5Pcreate( H5P_FILE_ACCESS );
404 assert( file_prop >= 0 );
407 collIO = H5Pcreate( H5P_DATASET_XFER );
409 err = H5Pset_dxpl_mpio(
collIO, H5FD_MPIO_COLLECTIVE );
414 dbgOut.
tprintf( 1,
"Opening \"%s\" for parallel IO\n", filename );
417 H5Pclose( file_prop );
476 dbgOut.
print( 1,
"Using H5S_APPEND for hyperslab selection\n" );
485 #if defined( H5Eget_auto_vers ) && H5Eget_auto_vers > 1
486 herr_t err = H5Eget_auto( H5E_DEFAULT, &handler.
func, &handler.
data );
488 herr_t err = H5Eget_auto( &handler.
func, &handler.
data );
493 #if defined( H5Eget_auto_vers ) && H5Eget_auto_vers > 1
524 const Tag* file_id_tag )
587 dbgOut.
tprintf( 1,
"READ FAILED (ERROR CODE %s): %s\n", ErrorCodeStr[rval], msg.c_str() );
620 dbgOut.
tprint( 1,
"Reading all element connectivity...\n" );
621 std::vector< int > polyhedra;
626 polyhedra.push_back( i );
633 for( std::vector< int >::iterator it = polyhedra.begin(); it != polyhedra.end(); ++it )
673 dbgOut.
tprint( 1,
"Core read finished. Cleaning up...\n" );
699 for(
int i = 0; i < subset_list_length; ++i )
702 rval =
find_int_tag( subset_list[i].tag_name, tag_index );
706 if( !subset_list[i].num_tag_values )
712 std::vector< int > ids( subset_list[i].tag_values,
713 subset_list[i].tag_values + subset_list[i].num_tag_values );
714 std::sort( ids.begin(), ids.end() );
722 file_ids.
swap( tmp_file_ids );
724 file_ids =
intersect( tmp_file_ids, file_ids );
737 dbgOut.
print( 2,
"Ignoring non-set entities with partition set tag\n" );
741 if( tmp_file_ids.
back() >= set_end )
743 dbgOut.
print( 2,
"Ignoring non-set entities with partition set tag\n" );
748 size_t num_per_proc = tmp_file_ids.
size() / num_parts;
749 size_t num_extra = tmp_file_ids.
size() % num_parts;
751 if( part_number < (
long)num_extra )
753 s += ( num_per_proc + 1 ) * part_number;
755 e += ( num_per_proc + 1 );
759 s += num_per_proc * part_number + num_extra;
763 tmp_file_ids.
erase( e, tmp_file_ids.
end() );
764 tmp_file_ids.
erase( tmp_file_ids.
begin(), s );
770 int subset_list_length,
777 static MPEState mpe_event(
"ReadHDF5",
"yellow" );
779 mpe_event.start(
"gather parts" );
783 for(
int i = 0; i < subset_list_length; ++i )
785 dbgOut.
printf( 2,
"Select by \"%s\" with num_tag_values = %d\n", subset_list[i].tag_name,
786 subset_list[i].num_tag_values );
787 if( subset_list[i].num_tag_values )
789 assert( 0 != subset_list[i].tag_values );
790 dbgOut.
printf( 2,
" \"%s\" values = { %d", subset_list[i].tag_name, subset_list[i].tag_values[0] );
796 if( num_parts )
dbgOut.
printf( 2,
"Partition with num_parts = %d and part_number = %d\n", num_parts, part_number );
821 mpe_event.start(
"gather related sets" );
830 const char*
const set_opts[] = {
"NONE",
"SETS",
"CONTENTS", NULL };
832 rval = opts.
match_option(
"CHILDREN", set_opts, child_mode );
834 child_mode = RSM_CONTENTS;
837 MB_SET_ERR( rval,
"Invalid value for 'CHILDREN' option" );
840 rval = opts.
match_option(
"SETS", set_opts, content_mode );
842 content_mode = RSM_CONTENTS;
845 MB_SET_ERR( rval,
"Invalid value for 'SETS' option" );
853 if( content_mode == RSM_CONTENTS || child_mode == RSM_CONTENTS )
890 if( !subset.
empty() ) max_dim =
dim;
897 MPI_Allreduce( &send, &max_dim, 1, MPI_INT, MPI_MAX, *
mpiComm );
916 mpe_event.end( rval );
952 mpe_event.end( rval );
957 mpe_event.start(
"read coords" );
958 dbgOut.
tprintf( 1,
"READING NODE COORDINATES (%lu nodes in %lu selects)\n", (
unsigned long)nodes.
size(),
959 (
unsigned long)nodes.
psize() );
965 mpe_event.end( rval );
981 const char*
const options[] = {
"EXPLICIT",
"NODES",
"SIDES", 0 };
982 rval = opts.
match_option(
"ELEMENTS", options, side_mode );
988 side_mode = SM_NODES;
990 side_mode = SM_SIDES;
994 MB_SET_ERR( rval,
"Invalid value for 'ELEMENTS' option" );
997 if( side_mode == SM_SIDES && max_dim == 0 )
1003 for(
int dim = 3;
dim >= max_dim; --
dim )
1015 mpe_event.end( rval );
1017 if( !ents.
empty() ) max_dim = 3;
1024 Range side_entities;
1025 if( side_mode != SM_EXPLICIT )
1027 if( 0 == max_dim ) max_dim = 4;
1030 for(
int dim = max_dim - 1;
dim > 0; --
dim )
1041 mpe_event.end( rval );
1055 dbgOut.
tprint( 1,
"UPDATING CONNECTIVITY ARRAYS FOR READ ELEMENTS\n" );
1056 mpe_event.start(
"updating connectivity for elements read before vertices" );
1076 mpe_event.end( rval );
1088 if( side_mode == SM_SIDES )
1091 mpe_event.start(
"cleaning up non-side lower-dim elements" );
1092 dbgOut.
tprint( 1,
"CHECKING FOR AND DELETING NON-SIDE ELEMENTS\n" );
1094 mpe_event.end( rval );
1106 if( content_mode == RSM_SETS || child_mode == RSM_SETS )
1109 mpe_event.start(
"finding recursively contained sets" );
1111 mpe_event.end( rval );
1118 mpe_event.start(
"finding sets containing any read entities" );
1121 bool read_set_containing_parents =
true;
1122 std::string tmp_opt;
1123 rval = opts.
get_option(
"NO_SET_CONTAINING_PARENTS", tmp_opt );
1124 if(
MB_SUCCESS == rval ) read_set_containing_parents =
false;
1129 mpe_event.end( rval );
1136 mpe_event.start(
"reading set contents/parents/children" );
1141 mpe_event.end( rval );
1163 const std::vector< int >& sorted_values,
1169 std::vector< EntityHandle >::iterator iter;
1182 std::vector< EntityHandle > indices;
1186 for( std::vector< int >::reverse_iterator i = grp_indices.rbegin(); i != grp_indices.rend(); ++i )
1194 else if( sets_only )
1198 else if( idx == -1 )
1215 std::sort( indices.begin(), indices.end(), std::greater< EntityHandle >() );
1216 std::transform( indices.begin(), indices.end(),
range_inserter( file_ids ),
1218 std::bind( std::plus< long >(), start_id, std::placeholders::_1 ) );
1235 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1238 std::sort( indices.begin(), indices.end() );
1239 std::vector< EntityHandle > ranges;
1240 iter = indices.begin();
1241 while( iter != indices.end() )
1243 ranges.push_back( *iter );
1245 for( ++iter; iter != indices.end() && ( last + 1 ) == *iter; ++iter, ++last )
1247 ranges.push_back( last );
1250 iter = ranges.begin();
1251 unsigned long offset = 0;
1252 while( iter != ranges.end() )
1263 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1265 offset += end - begin + 1;
1269 assert( offset == indices.size() );
1270 std::sort( indices.begin(), indices.end() );
1274 iter = std::lower_bound( indices.begin(), indices.end(),
1276 indices.erase( iter, indices.end() );
1278 indices.erase( indices.begin(), iter );
1299 else if( idx == -1 )
1308 hint = file_ids.
insert( hint, h, h + ents->
count - 1 );
1324 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1327 hid_t file_type = H5Dget_type( tables[0] );
1328 if( file_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1330 hint = file_ids.
begin();
1333 long remaining =
size, offset = 0;
1336 long count = std::min( buffer_size, remaining );
1341 H5Tclose( file_type );
1343 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1348 for(
long i = 0; i < count; ++i )
1355 H5Tclose( file_type );
1363 unsigned long table_size,
1364 const std::vector< int >& sorted_values,
1365 std::vector< EntityHandle >& value_indices )
1372 size_t chunk_size =
bufferSize /
sizeof( int );
1374 size_t remaining = table_size, offset = 0;
1378 size_t count = std::min( chunk_size, remaining );
1384 for(
size_t i = 0; i < count; ++i )
1385 if( std::binary_search( sorted_values.begin(), sorted_values.end(), (
int)
buffer[i] ) )
1386 value_indices.push_back( i + offset );
1420 std::vector< double* > arrays(
dim );
1421 const size_t num_nodes = node_file_ids.
size();
1436 for(
int d = 0; d <
dim; ++d )
1444 size_t count, offset = 0;
1446 while( !reader.
done() )
1448 dbgOut.
printf( 3,
"Reading chunk %d for dimension %d\n", ++nn, d );
1449 reader.
read( arrays[d] + offset, count );
1452 if( offset != num_nodes )
1463 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1469 long chunk_size =
bufferSize / ( 3 *
sizeof( double ) );
1477 while( !reader.
done() )
1479 dbgOut.
tprintf( 3,
"Reading chunk %d of node coords\n", ++nn );
1484 for(
size_t i = 0; i < count; ++i )
1485 for(
int d = 0; d <
dim; ++d )
1486 arrays[d][coffset + i] =
buffer[
dim * i + d];
1493 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1497 dbgOut.
print( 3,
"Closing node coordinate table\n" );
1499 for(
int d =
dim; d < cdim; ++d )
1500 memset( arrays[d], 0, num_nodes *
sizeof(
double ) );
1502 dbgOut.
printf( 3,
"Updating ID to handle map for %lu nodes\n", (
unsigned long)node_file_ids.
size() );
1532 (
unsigned long)file_ids.
size(), (
unsigned long)file_ids.
psize() );
1540 MB_SET_ERR( MB_FAILURE,
"Unknown element type: \"" << elems.
type <<
"\"" );
1544 const size_t count = file_ids.
size();
1563 while( !reader.
done() )
1569 iter = std::copy(
buffer,
buffer + num_read * nodes_per_elem, iter );
1573 std::sort(
buffer,
buffer + num_read * nodes_per_elem );
1578 assert( iter - array == (ptrdiff_t)count * nodes_per_elem );
1582 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1609 std::vector< IDConnectivity >::iterator i;
1659 const long buffer_size =
bufferSize / ( node_per_elem *
sizeof(
buffer[0] ) );
1662 dbgOut.
printf( 3,
"Reading node-adjacent elements from \"%s\" in %ld chunks\n", group.
handle,
1663 ( remaining + buffer_size - 1 ) / buffer_size );
1666 if( handles_out ) hint = handles_out->
begin();
1669 dbgOut.
printf( 3,
"Reading chunk %d of connectivity data for \"%s\"\n", ++nn, group.
handle );
1672 const long count = std::min( remaining, buffer_size );
1684 for(
long i = 0; i < count; ++i )
1686 for(
int j = 0; j < node_per_elem; ++j )
1695 if( iter[0] ) ++num_elem;
1696 iter += node_per_elem;
1715 for(
long i = 0; i < count; ++i )
1719 iter += node_per_elem;
1724 long*
const end = iter + node_per_elem;
1725 for( ; iter != end; ++iter, ++iter2 )
1728 assert( iter2 - array == num_elem * node_per_elem );
1733 if( handles_out ) hint = handles_out->
insert( hint, handle, handle + num_elem - 1 );
1746 (
unsigned long)elems_in.
size(), (
unsigned long)elems_in.
psize() );
1771 while( !reader.
done() )
1776 std::sort(
buffer,
buffer + num_read * node_per_elem );
1783 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1794 const EntityType type;
1802 virtual ~PolyReader() {}
1825 MB_SET_ERR( MB_FAILURE,
"Unknown element type: \"" << elems.
type <<
"\"" );
1830 long num_poly, num_conn, first_id;
1834 std::string nm( elems.
handle );
1839 return tool.read( offset_reader, connect_reader, file_ids, first_id,
handleType );
1847 Range explicit_ents;
1857 explicit_ents =
subtract( explicit_ents, side_ents );
1860 Range dead_ents( side_ents );
1869 subset.
insert( es, explicit_ents.
end() );
1872 dead_ents =
subtract( dead_ents, adj );
1876 assert( de == dead_ents.
end() );
1882 subset.
insert( es, explicit_ents.
end() );
1885 dead_ents =
subtract( dead_ents, adj );
1889 dbgOut.
printf( 2,
"Deleting %lu elements\n", (
unsigned long)dead_ents.
size() );
1890 dbgOut.
print( 4,
"\tDead entities: ", dead_ents );
1895 while( !dead_ents.
empty() )
1901 if( rit->value <= start && (
EntityID)( start - rit->value ) < rit->count )
break;
1904 EntityID offset = start - rit->value;
1905 EntityID avail = rit->count - offset;
1906 if( avail < count ) count = avail;
1929 std::vector< unsigned > flags( file_ids.
size() );
1931 for(
size_t i = 0; i < flags.size(); ++i, ++si )
1935 if( !file_ids.
empty() )
1994 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
1998 hid_t meta_type = H5Dget_type( handle );
1999 size_t size = H5Tget_size( meta_type );
2000 if(
size >
sizeof(
long ) )
2001 setMeta =
new long[( num_sets *
size + (
sizeof( long ) - 1 ) ) /
sizeof(
long )][4];
2003 setMeta =
new long[num_sets][4];
2009 hid_t ioprop = H5P_DEFAULT;
2010 #ifdef MOAB_HAVE_MPI
2017 if( !bcast ) ioprop =
collIO;
2021 if( !bcast || 0 == rank )
2026 H5Tclose( meta_type );
2028 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2031 H5Tconvert( meta_type, H5T_NATIVE_LONG, num_sets * 4,
setMeta, 0, H5P_DEFAULT );
2035 H5Tclose( meta_type );
2039 #ifdef MOAB_HAVE_MPI
2040 int ierr = MPI_Bcast( (
void*)
setMeta, num_sets * 4, MPI_LONG, 0, comm );
2041 if( MPI_SUCCESS != ierr )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2043 assert( rank == 0 );
2057 if( !child_sets && !contained_sets )
return MB_SUCCESS;
2062 assert( sets_in_out.
empty() );
2066 if( !contained_sets && !child_sets )
return MB_SUCCESS;
2071 if( contained_sets )
2073 long content_len = 0;
2078 cont.
init( content_handle,
true );
2082 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2093 child.init( child_handle,
true );
2097 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2103 int iteration_count = 0;
2107 dbgOut.
tprintf( 2,
"Iteration %d of read_set_ids_recursive\n", iteration_count );
2114 if( contained_sets )
2125 dbgOut.
print_ints( 2,
"Adding additional contained/child sets", new_children );
2126 sets_in_out.
merge( new_children );
2127 }
while( !new_children.
empty() );
2143 long content_len = 0;
2147 hid_t data_type = H5Dget_type( content_handle );
2149 rval =
find_sets_containing( content_handle, data_type, content_len, read_set_containing_parents, sets_out );
2151 H5Tclose( data_type );
2160 const long* contents,
2166 if( !content_len || id_map.
empty() )
return false;
2168 const long* j = contents;
2169 const long*
const end = contents + content_len;
2170 assert( content_len % 2 == 0 );
2173 long start = *( j++ );
2174 long count = *( j++ );
2175 if( id_map.
intersects( start, count ) )
return true;
2180 const long*
const end = contents + content_len;
2181 for(
const long* i = contents; i != end; ++i )
2182 if( id_map.
exists( *i ) )
return true;
2199 bool read_set_containing_parents,
2206 const size_t content_size = H5Tget_size( content_type );
2208 dbgOut.
printf( 2,
"Searching contents of %ld\n", num_sets );
2213 #ifdef MOAB_HAVE_MPI
2226 for(
long i = 0; i < num_sets; ++i )
2230 std::cerr <<
"Invalid data in set contents offsets at position " << i <<
": index " <<
setMeta[i][
CONTENT]
2231 <<
" is less than previous index " << prev << std::endl;
2233 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2239 std::cerr <<
"Maximum set content index " <<
setMeta[num_sets - 1][
CONTENT]
2240 <<
" exceeds contents table length of " << contents_len << std::endl;
2242 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2246 long*
const content_buffer = (
long*)
dataBuffer;
2247 const long content_len =
bufferSize / std::max( content_size,
sizeof(
long ) );
2254 long sets_offset = 0;
2255 long temp_content[4];
2256 while( sets_offset < num_sets )
2258 temp_content[0] = content_len + prev_idx;
2262 assert( sets_count >= 0 && sets_offset + sets_count <= num_sets );
2265 long content_remaining =
setMeta[sets_offset][
CONTENT] - prev_idx;
2266 long content_offset = prev_idx + 1;
2267 while( content_remaining )
2269 long content_count = content_len < content_remaining ? 2 * ( content_len / 2 ) : content_remaining;
2271 dbgOut.
printf( 3,
"Reading chunk %d (%ld values) from set contents table\n", ++mm, content_count );
2272 if( !bcast || 0 == rank )
2276 content_buffer,
collIO, &status );
2278 mhdf_readSetData( contents_handle, content_offset, content_count, content_type, content_buffer,
2282 H5Tconvert( content_type, H5T_NATIVE_LONG, content_count, content_buffer, 0, H5P_DEFAULT );
2286 #ifdef MOAB_HAVE_MPI
2287 int ierr = MPI_Bcast( content_buffer, content_count, MPI_LONG, 0, comm );
2288 if( MPI_SUCCESS != ierr )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2290 assert( rank == 0 );
2294 if( read_set_containing_parents )
2298 tmp_range.
insert( *content_buffer, *( content_buffer + 1 ) );
2300 std::copy( content_buffer, content_buffer + content_count,
range_inserter( tmp_range ) );
2301 tmp_range =
intersect( tmp_range, file_ids );
2305 content_buffer, content_count,
idMap ) )
2308 hint = file_ids.
insert( hint,
id,
id );
2313 content_remaining -= content_count;
2314 content_offset += content_count;
2319 else if(
long read_num =
setMeta[sets_offset + sets_count - 1][
CONTENT] - prev_idx )
2321 assert( sets_count > 0 );
2323 dbgOut.
printf( 3,
"Reading chunk %d (%ld values) from set contents table\n", ++mm, read_num );
2324 if( !bcast || 0 == rank )
2330 mhdf_readSetData( contents_handle, prev_idx + 1, read_num, content_type, content_buffer, &status );
2333 H5Tconvert( content_type, H5T_NATIVE_LONG, read_num, content_buffer, 0, H5P_DEFAULT );
2337 #ifdef MOAB_HAVE_MPI
2338 int ierr = MPI_Bcast( content_buffer, read_num, MPI_LONG, 0, comm );
2339 if( MPI_SUCCESS != ierr )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2341 assert( rank == 0 );
2345 long* buff_iter = content_buffer;
2346 for(
long i = 0; i < sets_count; ++i )
2349 prev_idx += set_size;
2352 if( read_set_containing_parents )
2359 const long* j = buff_iter;
2360 const long*
const end = buff_iter + set_size;
2361 assert( set_size % 2 == 0 );
2364 long start = *( j++ );
2365 long count = *( j++ );
2366 tmp_range.
insert( start, start + count - 1 );
2370 std::copy( buff_iter, buff_iter + set_size,
range_inserter( tmp_range ) );
2371 tmp_range =
intersect( tmp_range, file_ids );
2374 if( !tmp_range.
empty() ||
2378 hint = file_ids.
insert( hint,
id,
id );
2380 buff_iter += set_size;
2384 sets_offset += sets_count;
2398 assert(
length % 2 == 0 );
2399 for(
long i = 0; i <
length; i += 2 )
2400 hint = results.
insert( hint, contents[i], contents[i] + contents[i + 1] - 1 );
2404 std::sort( contents, contents +
length );
2405 for(
long i = 0; i <
length; ++i )
2406 hint = results.
insert( hint, contents[i] );
2415 Range* file_ids_out )
2420 if( file_ids_out ) out_hint = file_ids_out->
begin();
2425 const long TWEAK = 1;
2432 if(
setMeta[second][mode] >= 0 ) hint = data_offsets.
insert( hint, TWEAK,
setMeta[second][mode] + TWEAK );
2440 long idx2 =
setMeta[second][mode];
2441 if( idx2 >= idx1 ) hint = data_offsets.
insert( hint, idx1 + TWEAK, idx2 + TWEAK );
2458 std::vector< EntityHandle > partial;
2461 size_t count, offset;
2479 while( !data.
done() )
2498 if( !partial.empty() )
2500 assert( fileid_iter != set_file_ids.
end() );
2501 size_t num_prev = partial.size();
2504 offset = len - num_prev;
2505 if( offset > count )
2507 partial.insert( partial.end(),
buffer,
buffer + count );
2511 partial.insert( partial.end(),
buffer,
buffer + offset );
2523 if(
setMeta[idx][3] & ranged_flag )
2557 while( offset < count )
2559 assert( fileid_iter != set_file_ids.
end() );
2565 if( offset + len > count )
2567 partial.insert( partial.end(),
buffer + offset,
buffer + count );
2582 if(
setMeta[idx][3] & ranged_flag )
2623 dbgOut.
tprint( 2,
"Reading set contained file IDs\n" );
2636 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2649 hid_t read_type = H5Dget_type( table );
2650 if( read_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2651 const bool convert = !H5Tequal( read_type,
handleType );
2654 size_t chunk_size =
bufferSize / H5Tget_size( read_type );
2655 size_t remaining = table_len;
2656 size_t left_over = 0;
2658 dbgOut.
printf( 3,
"Reading adjacency list in %lu chunks\n",
2659 (
unsigned long)( remaining + chunk_size - 1 ) / chunk_size );
2663 dbgOut.
printf( 3,
"Reading chunk %d of adjacency list\n", ++nn );
2665 size_t count = std::min( chunk_size, remaining );
2675 herr_t err = H5Tconvert( read_type,
handleType, count,
buffer + left_over, 0, H5P_DEFAULT );
2676 if( err < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2681 while( end - iter >= 3 )
2691 if( count2 < 1 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2693 if( end < count2 + iter )
2707 left_over = end - iter;
2710 memmove(
buffer, iter, left_over );
2713 assert( !left_over );
2729 hid_t read_type = -1;
2737 long num_ent, num_val;
2741 if( read_type ) H5Tclose( read_type );
2742 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2746 if( read_type == 0 )
2748 read_type = H5Dget_type( handles[1] );
2749 if( read_type == 0 )
2754 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2762 rval =
read_sparse_tag( tag, read_type, handles[0], handles[1], num_ent );
2767 rval =
read_var_len_tag( tag, read_type, handles[0], handles[1], handles[2], num_ent, num_val );
2772 H5Tclose( read_type );
2787 if( read_type ) H5Tclose( read_type );
2795 const char* name = 0;
2798 if( elem_idx == -2 )
2803 else if( elem_idx == -1 )
2808 else if( elem_idx >= 0 && elem_idx < fileInfo->num_elem_desc )
2815 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2827 if( count > desc->
count )
2831 "Invalid data length for dense tag data: " << name <<
"/" <<
fileInfo->
tags[tag_index].
name );
2835 if( read_type == 0 )
2837 read_type = H5Dget_type( handle );
2838 if( read_type == 0 )
2841 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2850 H5Tclose( read_type );
2863 if( read_type ) H5Tclose( read_type );
2875 bool re_read_default =
false;
2898 if( info.
size < 1 || info.
size > 8 )
2900 MB_SET_ERR( MB_FAILURE,
"Invalid bit tag: class is MB_TAG_BIT, num bits = " << info.
size );
2902 hdf_type = H5Tcopy( H5T_NATIVE_B8 );
2904 if( hdf_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2920 hdf_type = H5Tcopy( hdf_type );
2921 re_read_default =
true;
2930 if( hdf_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2937 hdf_type = H5T_NATIVE_INT;
2941 hdf_type = H5T_NATIVE_DOUBLE;
2945 hdf_type = H5T_NATIVE_UINT;
2953 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2958 hsize_t tmpsize = info.
size;
2959 #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1
2960 hdf_type = H5Tarray_create2( hdf_type, 1, &tmpsize );
2962 hdf_type = H5Tarray_create( hdf_type, 1, &tmpsize, NULL );
2967 hdf_type = H5Tcopy( hdf_type );
2969 if( hdf_type < 0 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
2975 if( re_read_default )
2980 if( hdf_type ) H5Tclose( hdf_type );
2992 if( hdf_type ) H5Tclose( hdf_type );
3001 if( hdf_type ) H5Tclose( hdf_type );
3017 if( hdf_type ) H5Tclose( hdf_type );
3018 MB_SET_ERR( MB_FAILURE,
"Tag type in file does not match type in database for \"" << info.
name <<
"\"" );
3035 if( hdf_type ) H5Tclose( hdf_type );
3044 const char* ent_name,
3045 hid_t hdf_read_type,
3067 hsize_t hdf_size = H5Tget_size( hdf_read_type );
3068 if( hdf_size != (hsize_t)read_size )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3072 Range file_ids, handles;
3077 if( l !=
idMap.
end() && start_id + num_values > l->begin )
3081 size_t beg = std::max( start_id, l->begin );
3082 size_t end = std::min( start_id + num_values, u->begin + u->count ) - 1;
3083 f_ins = file_ids.
insert( f_ins, beg, end );
3084 h_ins = handles.
insert( h_ins, l->value + ( beg - l->begin ), l->value + ( end - l->begin ) );
3088 size_t beg = std::max( start_id, l->begin );
3089 f_ins = file_ids.
insert( f_ins, beg, l->begin + l->count - 1 );
3090 h_ins = handles.
insert( h_ins, l->value + ( beg - l->begin ), l->value + l->count - 1 );
3091 for( ++l; l != u; ++l )
3093 f_ins = file_ids.
insert( f_ins, l->begin, l->begin + l->count - 1 );
3094 h_ins = handles.
insert( h_ins, l->value, l->value + l->count - 1 );
3096 if( u !=
idMap.
end() && u->begin < start_id + num_values )
3098 size_t end = std::min( start_id + num_values, u->begin + u->count - 1 );
3099 f_ins = file_ids.
insert( f_ins, u->begin, end );
3100 h_ins = handles.
insert( h_ins, u->value, u->value + end - u->begin );
3112 std::string tn(
"<error>" );
3118 h_ins = handles.
begin();
3121 reader.
set_file_ids( file_ids, start_id, buffer_size, hdf_read_type );
3122 dbgOut.
printf( 3,
"Reading dense data for tag \"%s\" and group \"%s\" in %lu chunks\n", tn.c_str(), ent_name,
3125 while( !reader.
done() )
3127 dbgOut.
printf( 3,
"Reading chunk %d of \"%s\" data\n", ++nn, tn.c_str() );
3141 ents.
insert( h_ins, end );
3147 dbgOut.
printf( 1,
"Internal error setting data for tag \"%s\"\n", tn.c_str() );
3154 dbgOut.
printf( 1,
"Internal error reading dense data for tag \"%s\"\n", tn.c_str() );
3155 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3168 Range& offset_range,
3169 Range& handle_range,
3170 std::vector< EntityHandle >& handle_vect )
3174 offset_range.
clear();
3175 handle_range.
clear();
3176 handle_vect.clear();
3185 std::string tn( name );
3188 assert( start_offset > 0 );
3193 size_t offset = start_offset;
3196 while( !id_reader.
done() )
3198 dbgOut.
printf( 3,
"Reading chunk %d of \"%s\" IDs\n", ++nn, name );
3200 id_reader.
read( idbuf, count );
3208 for(
size_t i = 0; i < count; ++i )
3212 offset_hint = offset_range.
insert( offset_hint, offset + i );
3213 if( !handle_vect.empty() )
3215 handle_vect.push_back( idbuf[i] );
3217 else if( handle_range.
empty() || idbuf[i] > handle_range.
back() )
3219 handle_hint = handle_range.
insert( handle_hint, idbuf[i] );
3223 handle_vect.resize( handle_range.
size() );
3224 std::copy( handle_range.
begin(), handle_range.
end(), handle_vect.begin() );
3225 handle_range.
clear();
3226 handle_vect.push_back( idbuf[i] );
3227 dbgOut.
print( 2,
"Switching to unordered list for tag handle list\n" );
3237 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3244 hid_t hdf_read_type,
3256 std::vector< EntityHandle > handle_vect;
3257 Range handle_range, offset_range;
3258 std::string tn(
"<error>" );
3277 hsize_t hdf_size = H5Tget_size( hdf_read_type );
3278 if( hdf_size != (hsize_t)read_size )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3281 const int handles_per_tag = read_size /
sizeof(
EntityHandle );
3288 val_reader.
set_file_ids( offset_range, base_offset, chunk_size, hdf_read_type );
3289 dbgOut.
printf( 3,
"Reading sparse values for tag \"%s\" in %lu chunks\n", tn.c_str(),
3293 while( !val_reader.
done() )
3295 dbgOut.
printf( 3,
"Reading chunk %d of \"%s\" values\n", ++nn, tn.c_str() );
3304 if( !handle_vect.empty() )
3313 handle_range.
erase( handle_range.
begin(), handle_range.
begin() + count );
3321 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3328 hid_t hdf_read_type,
3356 hsize_t hdf_size = H5Tget_size( hdf_read_type );
3357 if( hdf_size < 1 )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3358 read_size = hdf_size;
3366 std::string tn(
"<error>" );
3374 std::vector< EntityHandle > handle_vect;
3375 Range handle_range, offset_range;
3376 rval =
read_sparse_tag_indices( tn.c_str(), ent_table, base_offset, offset_range, handle_range, handle_vect );
3382 if( !handle_vect.empty() )
3384 MB_SET_ERR( MB_FAILURE,
"Unordered file ids for variable length tag not supported" );
3413 :
ReadHDF5VarLen( debug_output,
buffer, buffer_size ), tagHandle( tag ), isHandle( is_handle_tag ),
3414 readSize( read_size1 ), readHDF5( owner )
3423 std::vector< unsigned > counts;
3426 rval = tool.read_offsets( off_reader, offset_range, base_offset, base_offset, offsets, counts );
3432 rval = tool.read_data( val_reader, offsets, base_offset, hdf_read_type, handle_range, counts, empty );
3437 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3452 *array = id_map.
find( *array );
3462 for(
size_t i = 0; i <
size; ++i )
3465 if( it != id_map.
end() && it->
begin <= (
long)array[i] )
3466 array[new_size++] = it->value + ( array[i] - it->
begin );
3477 for(
size_t i = 0; i < num_ranges; ++i )
3479 long id = ranges[2 * i];
3480 const long end =
id + ranges[2 * i + 1];
3482 if( it == id_map.
end() || it->
begin >
id ) it = id_map.
begin();
3484 if( it == id_map.
end() )
continue;
3485 if( id < it->begin )
id = it->
begin;
3488 if( id < it->begin )
id = it->
begin;
3489 const long off =
id - it->
begin;
3490 long count = std::min( it->count - off, end -
id );
3494 if( count <= 0 )
break;
3495 hint = merge.
insert( hint, it->value + off, it->value + off + count - 1 );
3499 if( ++it == id_map.
end() )
break;
3500 if( it->
begin > end )
break;
3520 size_t count = p->second - p->first + 1;
3521 if( !map.
insert( p->first, start_id, count ).second )
MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3549 for(
int i = 0; i < qa_len; i++ )
3566 typedef long tag_type;
3570 const long buffer_size =
bufferSize /
sizeof( tag_type );
3573 IDMap::Range range = *i;
3577 tag_type tv = (tag_type)rv;
3584 while( range.count )
3586 long count = buffer_size < range.count ? buffer_size : range.count;
3589 handles.
insert( range.value, range.value + count - 1 );
3590 range.value += count;
3591 range.count -= count;
3592 for(
long j = 0; j < count; ++j )
3593 buffer[j] = (tag_type)range.begin++;
3611 long default_val = 0;
3615 if(
MB_SUCCESS != rval || 0 == setFileIdTag )
return rval;
3617 typedef long tag_type;
3621 const long buffer_size =
bufferSize /
sizeof( tag_type );
3624 IDMap::Range range = *i;
3630 tag_type tv = (tag_type)rv;
3637 while( range.count )
3639 long count = buffer_size < range.count ? buffer_size : range.count;
3642 handles.
insert( range.value, range.value + count - 1 );
3643 range.value += count;
3644 range.count -= count;
3645 for(
long j = 0; j < count; ++j )
3646 buffer[j] = (tag_type)range.begin++;
3656 const char* tag_name,
3658 std::vector< int >& tag_values_out,
3710 long num_ent, num_val;
3712 std::string tn( tag.
name );
3730 const long buffer_size =
bufferSize /
sizeof( long );
3736 while( !ids.
done() )
3738 dbgOut.
printf( 3,
"Reading chunk %d of IDs for \"%s\"\n", ++nn, tag.
name );
3744 for(
size_t j = 0; j < count; ++j )
3746 while( i != file_ids.
end() && (
long)*i <
buffer[j] )
3748 if( i == file_ids.
end() )
break;
3749 if( (
long)*i ==
buffer[j] )
3751 ins = offsets.
insert( ins, j + offset, j + offset );
3759 tag_values.reserve( offsets.
size() );
3760 const size_t data_buffer_size =
bufferSize /
sizeof( int );
3761 int* data_buffer =
reinterpret_cast< int*
>(
dataBuffer );
3763 vals.
set_file_ids( offsets, 0, data_buffer_size, H5T_NATIVE_INT );
3768 while( !vals.
done() )
3770 dbgOut.
printf( 3,
"Reading chunk %d of values for \"%s\"\n", ++nn, tag.
name );
3771 vals.
read( data_buffer, count );
3772 tag_values.insert( tag_values.end(), data_buffer, data_buffer + count );
3777 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3781 std::sort( tag_values.begin(), tag_values.end() );
3782 tag_values.erase( std::unique( tag_values.begin(), tag_values.end() ), tag_values.end() );
3785 std::vector< int > prev_data, curr_data;
3789 const char* gname = 0;
3796 else if( grp == -2 )
3803 assert( grp >= 0 && grp < fileInfo->num_elem_desc );
3811 subset.
merge( s, e );
3822 tag_values.reserve( subset.
size() );
3823 const size_t data_buffer_size =
bufferSize /
sizeof( int );
3824 int* data_buffer =
reinterpret_cast< int*
>(
dataBuffer );
3828 dbgOut.
printf( 3,
"Reading dense data for tag \"%s\" and group \"%s\" in %lu chunks\n", tag.
name,
3833 while( !reader.
done() )
3836 reader.
read( data_buffer, count );
3837 curr_data.insert( curr_data.end(), data_buffer, data_buffer + count );
3842 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3845 std::sort( curr_data.begin(), curr_data.end() );
3846 curr_data.erase( std::unique( curr_data.begin(), curr_data.end() ), curr_data.end() );
3848 tag_values.swap( prev_data );
3849 std::set_union( prev_data.begin(), prev_data.end(), curr_data.begin(), curr_data.end(),
3850 std::back_inserter( tag_values ) );
3879 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3882 hid_t file_type = H5Dget_type( handles[1] );
3883 tag_values.resize( num_val );
3888 H5Tclose( file_type );
3890 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3892 H5Tconvert( file_type, H5T_NATIVE_INT, num_val, &tag_values[0], 0, H5P_DEFAULT );
3893 H5Tclose( file_type );
3902 std::sort( tag_values.begin(), tag_values.end() );
3903 tag_values.erase( std::unique( tag_values.begin(), tag_values.end() ), tag_values.end() );
3906 std::vector< int > prev_data, curr_data;
3910 const char* gname = 0;
3913 else if( grp == -2 )
3923 hid_t file_type = H5Dget_type( handle );
3924 curr_data.resize( num_val );
3929 H5Tclose( file_type );
3931 MB_SET_ERR( MB_FAILURE,
"ReadHDF5 Failure" );
3934 H5Tconvert( file_type, H5T_NATIVE_INT, num_val, &curr_data[0], 0, H5P_DEFAULT );
3935 H5Tclose( file_type );
3942 std::sort( curr_data.begin(), curr_data.end() );
3943 curr_data.erase( std::unique( curr_data.begin(), curr_data.end() ), curr_data.end() );
3946 tag_values.swap( prev_data );
3947 std::set_union( prev_data.begin(), prev_data.end(), curr_data.begin(), curr_data.end(),
3948 std::back_inserter( tag_values ) );
3955 #ifdef MOAB_HAVE_MPI
3988 #ifdef MOAB_HAVE_MPI