From debeaf6e6438cfacd102db792b87d31a6fd3ac3d Mon Sep 17 00:00:00 2001 From: MuQun Yang Date: Mon, 19 Nov 2001 16:29:26 -0500 Subject: [svn-r4612] Purpose: A new feature Description: While testing h4toh5 utility with real NASA files, we find an example that the data array(one SDS) is so big that it exceeds the physical memory of some machine(>128 MB) and the conversion failed. Before the smart hyperslab operation is out, I am dividing the whole SDS into smaller hyperslabs with each hyperslab propotational to the original SDS array dimensions. For example, a three dimension array with 1000*1000*1000 elements, I can divide them into eight 500*500*500 pieces. I can read and write each piece and remember their starting and ending points. In this way, the memory allocation failure can be avoided; however, it may not be the efficient way. I've tested this feature using SDS without chunking. It works fine. However, when testing SDS with chunking, it is extremely slow. This happens to be a bug in HDF5 library now. Quincey may fix this later and give me a more efficient way to handle the problem. Currently all my testing files are with UNLIMITED dimensions, so in HDF5 the chunking feature will be required. SO by default, this feature will not be turned on. Solution: see the above Platforms tested: linux 2.2.18 --- tools/h4toh5/h4toh5main.h | 1 + tools/h4toh5/h4toh5sds.c | 254 ++++++++++++++++++++++++++++++++++++++++++---- tools/h4toh5/h4toh5user.h | 2 + tools/h4toh5/h4toh5util.h | 4 + 4 files changed, 240 insertions(+), 21 deletions(-) create mode 100644 tools/h4toh5/h4toh5user.h diff --git a/tools/h4toh5/h4toh5main.h b/tools/h4toh5/h4toh5main.h index 2802caa..1898c19 100644 --- a/tools/h4toh5/h4toh5main.h +++ b/tools/h4toh5/h4toh5main.h @@ -37,6 +37,7 @@ Author: Kent Yang(ymuqun@ncsa.uiuc.edu) #include "h4toh5util.h" #include #include +#include "h4toh5user.h" #endif /* For windows support.*/ diff --git a/tools/h4toh5/h4toh5sds.c b/tools/h4toh5/h4toh5sds.c index 3163c0b..d464fdf 100644 --- a/tools/h4toh5/h4toh5sds.c +++ b/tools/h4toh5/h4toh5sds.c @@ -63,7 +63,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup,int int32 sds_ref; int sds_empty; int32 istat; - int i; + int i,j; int32 num_sdsattrs; void* sds_data; @@ -84,21 +84,41 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup,int int16 special_code; int32 access_id; uint16 sd_ref; - int gzip_level; - /* define varibles for hdf5. */ + int gzip_level; + /* define variables for hdf5. */ hid_t h5dset; hid_t h5d_sid; hid_t h5ty_id; hid_t h5_memtype; hid_t create_plist; -/* hid_t write_plist; */ + hid_t write_plist; hsize_t h5dims[MAX_VAR_DIMS]; hsize_t max_h5dims[MAX_VAR_DIMS]; -/* hsize_t bufsize; */ + hsize_t bufsize; char* h5csds_name; herr_t ret; + /* define variables to handle transformation when the maximum memory + buffer is set by users. */ + + int NUM_HSLAB_PERD; + int32* h4slab_start; + int32* h4slab_stride; + int32* h4slab_stop; + int32* h4slab_dims; + int32* h4slab_edges; + hsize_t* h5slab_offset; + hsize_t* h5slab_count; + int h4slab_count,h4slab_index; + int32 slabsize; + int32 count_slabdata; + hid_t slabmemspace; + + /* if(memsize <=0) slabsize = -1;*/ + if(MEMOPT != 0) + slabsize = SLABSIZE*1000000; + else slabsize = 0; special_code = -1; /* zeroing out the memory for sdsname and sdslabel.*/ @@ -112,7 +132,6 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup,int } /*check whether the sds is created with unlimited dimension. */ - /*obtain name,rank,dimsizes,datatype and num of attributes of sds */ if (SDgetinfo(sds_id,sdsname,&sds_rank,sds_dimsizes,&sds_dtype, @@ -203,7 +222,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup,int } } - sds_data = malloc(h4memsize*count_sdsdata); + /* sds_data = malloc(h4memsize*count_sdsdata); if(sds_data == NULL) { printf("error in allocating memory. \n"); @@ -222,6 +241,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup,int free(sds_data); return FAIL; } + */ /* obtaining reference number and name of h5 dataset corresponding to sds. */ @@ -442,10 +462,32 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup,int H5Pclose(create_plist); return FAIL; } - /* comment this out. + + if(count_sdsdata*h4memsize <= slabsize || MEMOPT==0) { + + sds_data = malloc(h4memsize*count_sdsdata); + + if(sds_data == NULL) { + printf("error in allocating memory. \n"); + free(sds_start); + free(sds_edge); + free(sds_stride); + return FAIL; + } + istat = SDreaddata(sds_id, sds_start, sds_stride, sds_edge, + (VOIDP)sds_data); + if (istat == FAIL) { + printf("unable to read data from h5dset. \n"); + free(sds_start); + free(sds_edge); + free(sds_stride); + free(sds_data); + return FAIL; + } + write_plist = H5Pcreate(H5P_DATASET_XFER); bufsize = h4memsize; - for(i=1;isds_dimsizes[i]) + h4slab_stop[i] = sds_dimsizes[i]; + printf("h4slab_start[%d] %d\n",i,h4slab_start[i]); + printf("h4slab_stop[%d] %d\n",i,h4slab_stop[i]); + } + count_slabdata = 1; + for(i=0;i