void DCDataSet::append(size_t count, size_t offset, size_t stride, const void* data) throw (DCException) { log_msg(2, "DCDataSet::append"); if (!opened) throw DCException(getExceptionString("append: Dataset has not been opened/created.")); log_msg(3, "logical_size = %s", getLogicalSize().toString().c_str()); Dimensions target_offset(getLogicalSize()); // extend size (dataspace) of existing dataset with count elements getLogicalSize()[0] += count; hsize_t * max_dims = new hsize_t[ndims]; for (size_t i = 0; i < ndims; ++i) max_dims[i] = H5F_UNLIMITED; if (H5Sset_extent_simple(dataspace, 1, getLogicalSize().getPointer(), max_dims) < 0) throw DCException(getExceptionString("append: Failed to set new extent")); delete[] max_dims; max_dims = NULL; log_msg(3, "logical_size = %s", getLogicalSize().toString().c_str()); if (H5Dset_extent(dataset, getLogicalSize().getPointer()) < 0) throw DCException(getExceptionString("append: Failed to extend dataset")); // select the region in the target DataSpace to write to Dimensions dim_data(count, 1, 1); if (H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, target_offset.getPointer(), NULL, dim_data.getPointer(), NULL) < 0 || H5Sselect_valid(dataspace) < 0) throw DCException(getExceptionString("append: Invalid target hyperslap selection")); // append data to the dataset. // select the region in the source DataSpace to read from Dimensions dim_src(offset + count * stride, 1, 1); hid_t dsp_src = H5Screate_simple(1, dim_src.getPointer(), NULL); if (dsp_src < 0) throw DCException(getExceptionString("append: Failed to create src dataspace while appending")); if (H5Sselect_hyperslab(dsp_src, H5S_SELECT_SET, Dimensions(offset, 0, 0).getPointer(), Dimensions(stride, 1, 1).getPointer(), dim_data.getPointer(), NULL) < 0 || H5Sselect_valid(dsp_src) < 0) throw DCException(getExceptionString("append: Invalid source hyperslap selection")); if (!data || (count == 0)) { H5Sselect_none(dataspace); data = NULL; } if (H5Dwrite(dataset, this->datatype, dsp_src, dataspace, dsetWriteProperties, data) < 0) throw DCException(getExceptionString("append: Failed to append dataset")); H5Sclose(dsp_src); }
int_f nh5sselect_none_c ( hid_t_f *space_id ) { int ret_value = 0; hid_t c_space_id; c_space_id = *space_id; if ( H5Sselect_none(c_space_id) < 0 ) ret_value = -1; return ret_value; }
herr_t readNext2dCharTimeFrame(char *tframe,hid_t dataset_id,int nx, int ny, int ntimes) { static int cur_frame_t = 0; // current frame static hsize_t start[] = {0,0,0}; // offset static hsize_t count[3]; // array to hold number of elements to be written static hid_t mem_dataspace_id; // dataspace for memory static hsize_t mem_start[] = {0,0}; // offset in memory static hsize_t mem_count[2]; // dimensions of memory static herr_t ret; static hsize_t dataspace_id; if(cur_frame_t == ntimes) return -1; if(!cur_frame_t) { dataspace_id = H5Dget_space(dataset_id); // get the dataspace of the given dataset count[0] = 1; count[1] = ny; count[2] = nx; // specify number of elements to be selected mem_count[0] = ny; mem_count[1] = nx; mem_dataspace_id = H5Screate_simple(2, mem_count, NULL); // create dataspace for memory } else start[0] += 1; ret = H5Sselect_hyperslab(dataspace_id, H5S_SELECT_SET, start, NULL, count, NULL); ret = H5Sselect_hyperslab(mem_dataspace_id, H5S_SELECT_SET, mem_start, NULL, mem_count, NULL); ret = H5Dread(dataset_id, H5T_NATIVE_CHAR , mem_dataspace_id, dataspace_id, H5P_DEFAULT, tframe); ret = H5Sselect_none(dataspace_id); // forget selection for dataset ++cur_frame_t; if(cur_frame_t == ntimes) { // final frame? close dataspaces ret = H5Sclose(dataspace_id); ret = H5Sclose(mem_dataspace_id); } return ret; }
void DCDataSet::write(Dimensions srcBuffer, Dimensions srcStride, Dimensions srcOffset, Dimensions srcData, Dimensions dstOffset, const void* data) throw (DCException) { log_msg(2, "DCDataSet::write (%s)", name.c_str()); if (!opened) throw DCException(getExceptionString("write: Dataset has not been opened/created")); log_msg(3, " ndims = %llu\n" " logical_size = %s\n" " physical_size = %s\n" " src_buffer = %s\n" " src_stride = %s\n" " src_data = %s\n" " src_offset = %s\n" " dst_offset = %s\n", (long long unsigned) ndims, getLogicalSize().toString().c_str(), getPhysicalSize().toString().c_str(), srcBuffer.toString().c_str(), srcStride.toString().c_str(), srcData.toString().c_str(), srcOffset.toString().c_str(), dstOffset.toString().c_str()); // swap dimensions if necessary srcBuffer.swapDims(ndims); srcStride.swapDims(ndims); srcData.swapDims(ndims); srcOffset.swapDims(ndims); dstOffset.swapDims(ndims); // dataspace to read from hid_t dsp_src; if (getLogicalSize().getScalarSize() != 0) { dsp_src = H5Screate_simple(ndims, srcBuffer.getPointer(), NULL); if (dsp_src < 0) throw DCException(getExceptionString("write: Failed to create source dataspace")); if (H5Sselect_hyperslab(dsp_src, H5S_SELECT_SET, srcOffset.getPointer(), srcStride.getPointer(), srcData.getPointer(), NULL) < 0 || H5Sselect_valid(dsp_src) <= 0) throw DCException(getExceptionString("write: Invalid source hyperslap selection")); if (srcData.getScalarSize() == 0) H5Sselect_none(dsp_src); // dataspace to write to if (H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, dstOffset.getPointer(), NULL, srcData.getPointer(), NULL) < 0 || H5Sselect_valid(dataspace) <= 0) throw DCException(getExceptionString("write: Invalid target hyperslap selection")); if (!data || (srcData.getScalarSize() == 0)) { H5Sselect_none(dataspace); data = NULL; } // write data to the dataset if (H5Dwrite(dataset, this->datatype, dsp_src, dataspace, dsetWriteProperties, data) < 0) throw DCException(getExceptionString("write: Failed to write dataset")); H5Sclose(dsp_src); } }
void DCDataSet::read(Dimensions dstBuffer, Dimensions dstOffset, Dimensions srcSize, Dimensions srcOffset, Dimensions& sizeRead, uint32_t& srcNDims, void* dst) throw (DCException) { log_msg(2, "DCDataSet::read (%s)", name.c_str()); if (!opened) throw DCException(getExceptionString("read: Dataset has not been opened/created")); if (dstBuffer.getScalarSize() == 0) dstBuffer.set(srcSize); // dst buffer is allowed to be NULL // in this case, only the size of the dataset is returned // if the dataset is empty, return just its size as there is nothing to read if ((dst != NULL) && (getNDims() > 0)) { log_msg(3, " ndims = %llu\n" " logical_size = %s\n" " physical_size = %s\n" " dstBuffer = %s\n" " dstOffset = %s\n" " srcSize = %s\n" " srcOffset = %s\n", (long long unsigned) ndims, getLogicalSize().toString().c_str(), getPhysicalSize().toString().c_str(), dstBuffer.toString().c_str(), dstOffset.toString().c_str(), srcSize.toString().c_str(), srcOffset.toString().c_str()); dstBuffer.swapDims(ndims); dstOffset.swapDims(ndims); srcSize.swapDims(ndims); srcOffset.swapDims(ndims); hid_t dst_dataspace = H5Screate_simple(ndims, dstBuffer.getPointer(), NULL); if (dst_dataspace < 0) throw DCException(getExceptionString("read: Failed to create target dataspace")); if (H5Sselect_hyperslab(dst_dataspace, H5S_SELECT_SET, dstOffset.getPointer(), NULL, srcSize.getPointer(), NULL) < 0 || H5Sselect_valid(dst_dataspace) <= 0) throw DCException(getExceptionString("read: Target dataspace hyperslab selection is not valid!")); if (H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, srcOffset.getPointer(), NULL, srcSize.getPointer(), NULL) < 0 || H5Sselect_valid(dataspace) <= 0) throw DCException(getExceptionString("read: Source dataspace hyperslab selection is not valid!")); if (srcSize.getScalarSize() == 0) H5Sselect_none(dataspace); if (H5Dread(dataset, this->datatype, dst_dataspace, dataspace, dsetReadProperties, dst) < 0) throw DCException(getExceptionString("read: Failed to read dataset")); H5Sclose(dst_dataspace); srcSize.swapDims(ndims); } // swap dimensions if necessary sizeRead.set(srcSize); srcNDims = this->ndims; log_msg(3, " returns ndims = %llu", (long long unsigned) ndims); log_msg(3, " returns sizeRead = %s", sizeRead.toString().c_str()); }
/***************************************************************************** This function generates attributes, groups, and datasets of many types. Parameters: fname: file_name. ngrps: number of top level groups. ndsets: number of datasets. attrs: number of attributes. nrow: number of rows in a dataset. chunk: chunk size (single number). vlen: max vlen size. comp: use latest format. latest: use gzip comnpression. Return: Non-negative on success/Negative on failure Programmer: Peter Cao <*****@*****.**>, Jan. 2013 ****************************************************************************/ herr_t create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsize_t nrows, hsize_t dim0, hsize_t chunk, int vlen, int compressed, int latest) { int i, j, k; hid_t fid, sid_null, sid_scalar, sid_1d, sid_2d, did, aid, sid_2, sid_large, fapl=H5P_DEFAULT, dcpl=H5P_DEFAULT, gid1, gid2, cmp_tid, tid_str, tid_enum, tid_array_f, tid_vlen_i, tid_vlen_s; char name[32], tmp_name1[32], tmp_name2[32], tmp_name3[32]; hsize_t dims[1]={dim0}, dims2d[2]={dim0, (dim0/4+1)}, dims_array[1]={FIXED_LEN}, dim1[1]={2}; char *enum_names[4] = {"SOLID", "LIQUID", "GAS", "PLASMA"}; test_comp_t *buf_comp=NULL, *buf_comp_large=NULL; int *buf_int=NULL; float (*buf_float_a)[FIXED_LEN]=NULL; double **buf_double2d=NULL; hvl_t *buf_vlen_i=NULL; char (*buf_str)[FIXED_LEN]; char **buf_vlen_s=NULL; hobj_ref_t buf_ref[2]; hdset_reg_ref_t buf_reg_ref[2]; size_t offset, len; herr_t status; char *names[NTYPES] = { "int", "ulong", "float", "double", "fixed string", "enum", "fixed float array", "vlen int array", "vlen strings"}; hid_t types[NTYPES] = { H5T_NATIVE_INT, H5T_NATIVE_UINT64, H5T_NATIVE_FLOAT, H5T_NATIVE_DOUBLE, tid_str, tid_enum, tid_array_f, tid_vlen_i, tid_vlen_s}; hsize_t coords[4][2] = { {0, 1}, {3, 5}, {1, 0}, {2, 4}}, start=0, stride=1, count=1; if (nrows < NROWS) nrows = NROWS; if (ngrps<NGROUPS) ngrps=NGROUPS; if (ndsets<NDSETS) ndsets=NDSETS; if (nattrs<NATTRS) nattrs=NATTRS; if (dim0<DIM0) dim0=DIM0; if (chunk>dim0) chunk=dim0/4; if (chunk<1) chunk = 1; if (vlen<1) vlen = MAXVLEN; /* create fixed string datatype */ types[4] = tid_str = H5Tcopy (H5T_C_S1); H5Tset_size (tid_str, FIXED_LEN); /* create enum datatype */ types[5] = tid_enum = H5Tenum_create(H5T_NATIVE_INT); for (i = (int) SOLID; i <= (int) PLASMA; i++) { phase_t val = (phase_t) i; status = H5Tenum_insert (tid_enum, enum_names[i], &val); } /* create float array datatype */ types[6] = tid_array_f = H5Tarray_create (H5T_NATIVE_FLOAT, 1, dims_array); /* create variable length integer datatypes */ types[7] = tid_vlen_i = H5Tvlen_create (H5T_NATIVE_INT); /* create variable length string datatype */ types[8] = tid_vlen_s = H5Tcopy (H5T_C_S1); H5Tset_size (tid_vlen_s, H5T_VARIABLE); /* create compound datatypes */ cmp_tid = H5Tcreate (H5T_COMPOUND, sizeof (test_comp_t)); offset = 0; for (i=0; i<NTYPES-2; i++) { H5Tinsert(cmp_tid, names[i], offset, types[i]); offset += H5Tget_size(types[i]); } H5Tinsert(cmp_tid, names[7], offset, types[7]); offset += sizeof (hvl_t); H5Tinsert(cmp_tid, names[8], offset, types[8]); /* create dataspace */ sid_1d = H5Screate_simple (1, dims, NULL); sid_2d = H5Screate_simple (2, dims2d, NULL); sid_2 = H5Screate_simple (1, dim1, NULL); sid_large = H5Screate_simple (1, &nrows, NULL); sid_null = H5Screate (H5S_NULL); sid_scalar = H5Screate (H5S_SCALAR); /* create fid access property */ fapl = H5Pcreate (H5P_FILE_ACCESS); H5Pset_libver_bounds (fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST); /* create dataset creation property */ dcpl = H5Pcreate (H5P_DATASET_CREATE); /* set dataset chunk */ if (chunk>0) { H5Pset_chunk (dcpl, 1, &chunk); } /* set dataset compression */ if (compressed) { if (chunk<=0) { chunk = dim0/10+1;; H5Pset_chunk (dcpl, 1, &chunk); } H5Pset_shuffle (dcpl); H5Pset_deflate (dcpl, 6); } /* allocate buffers */ buf_comp = (test_comp_t *)calloc(dim0, sizeof(test_comp_t)); buf_comp_large = (test_comp_t *)calloc(nrows, sizeof(test_comp_t)); buf_int = (int *)calloc(dim0, sizeof(int)); buf_float_a = malloc(dim0*sizeof(*buf_float_a)); buf_vlen_i = (hvl_t *)calloc(dim0, sizeof (hvl_t)); buf_vlen_s = (char **)calloc(dim0, sizeof(char *)); buf_str = malloc(dim0*sizeof (*buf_str)); /* allocate array of doulbe pointers */ buf_double2d = (double **)calloc(dims2d[0],sizeof(double *)); /* allocate a contigous chunk of memory for the data */ buf_double2d[0] = (double *)calloc( dims2d[0]*dims2d[1],sizeof(double) ); /* assign memory city to pointer array */ for (i=1; i <dims2d[0]; i++) buf_double2d[i] = buf_double2d[0]+i*dims2d[1]; /* fill buffer values */ len = 1; for (i=0; i<dims[0]; i++) { buf_comp[i].i = buf_int[i] = i-2147483648; buf_comp[i].l = 0xffffffffffffffff-i; buf_comp[i].f = 1.0/(i+1.0); buf_comp[i].d = 987654321.0*i+1.0/(i+1.0); buf_comp[i].e = (phase_t) (i % (int) (PLASMA + 1)); for (j=0; j<FIXED_LEN; j++) { buf_comp[i].f_array[j] = buf_float_a[i][j] = i*100+j; buf_str[i][j] = 'a' + (i%26); } buf_str[i][FIXED_LEN-1] = 0; strcpy(buf_comp[i].s, buf_str[i]); len = (1-cos(i/8.0))/2*vlen+1; if (!i) len = vlen; buf_vlen_i[i].len = len; buf_vlen_i[i].p = (int *)calloc(len, sizeof(int)); for (j=0; j<len; j++) ((int*)(buf_vlen_i[i].p))[j] = i*100+j; buf_comp[i].i_vlen = buf_vlen_i[i]; buf_vlen_s[i] = (char *)calloc(len, sizeof(char)); for (j=0; j<len-1; j++) buf_vlen_s[i][j] = j%26+'A'; buf_comp[i].s_vlen = buf_vlen_s[i]; for (j=0; j<dims2d[1]; j++) buf_double2d[i][j] = i+j/10000.0; } for (i=0; i<nrows; i++) { buf_comp_large[i].i = i-2147483648; buf_comp_large[i].l = 0xffffffffffffffff-i; buf_comp_large[i].f = 1.0/(i+1.0); buf_comp_large[i].d = 987654321.0*i+1.0/(i+1.0); buf_comp_large[i].e = (phase_t) (i % (int) (PLASMA + 1)); for (j=0; j<FIXED_LEN-1; j++) { buf_comp_large[i].f_array[j] = i*100+j; buf_comp_large[i].s[j] = 'a' + (i%26); } len = i%vlen+1; buf_comp_large[i].i_vlen.len = len; buf_comp_large[i].i_vlen.p = (int *)calloc(len, sizeof(int)); for (j=0; j<len; j++) ((int*)(buf_comp_large[i].i_vlen.p))[j] = i*100+j; buf_comp_large[i].s_vlen = (char *)calloc(i+2, sizeof(char)); for (j=0; j<i+1; j++) (buf_comp_large[i].s_vlen)[j] = j%26+'A'; } /* create file */ if (latest) fid = H5Fcreate (fname, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); else fid = H5Fcreate (fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); add_attrs(fid, 0); sprintf(name, "a cmp ds of %d rows", nrows); did = H5Dcreate (fid, name, cmp_tid, sid_large, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite (did, cmp_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_comp_large); add_attrs(did, 0); H5Dclose(did); // /* add attributes*/ gid1 = H5Gcreate (fid, "attributes", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (nattrs<1) nattrs = 1; i=0; while (i<nattrs) i += add_attrs(gid1, i); H5Gclose(gid1); /* add many sub groups to a group*/ gid1 = H5Gcreate (fid, "groups", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); add_attrs(gid1, 0); for (i=0; i<ngrps; i++) { /* create sub groups */ sprintf(name, "g%02d", i); gid2 = H5Gcreate (gid1, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (i<10) add_attrs(gid2, 0); H5Gclose(gid2); } H5Gclose(gid1); /* add many datasets to a group */ gid1 = H5Gcreate (fid, "datasets", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); add_attrs(gid1, 0); for (j=0; j<ndsets; j+=12) { /* 1 add a null dataset */ sprintf(name, "%05d null dataset", j); did = H5Dcreate (gid1, name, H5T_STD_I32LE, sid_null, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (!j) add_attrs(did, j); H5Dclose(did); /* 2 add scalar int point */ sprintf(name, "%05d scalar int point", j); did = H5Dcreate (gid1, name, H5T_NATIVE_INT, sid_scalar, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite (did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &j); if (!j) add_attrs(did, j); H5Dclose(did); /* 3 scalar vlen string */ sprintf(name, "%05d scalar vlen string", j); did = H5Dcreate (gid1, name, tid_vlen_s, sid_scalar, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite (did, tid_vlen_s, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buf_vlen_s[0]); if (!j) add_attrs(did, j); H5Dclose(did); /* 4 add fixed-length float array */ sprintf(name, "%05d fixed-length float array", j); did = H5Dcreate (gid1, name, tid_array_f, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite (did, tid_array_f, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_float_a); if (!j) add_attrs(did, j); H5Dclose(did); /* 5 add fixed-length strings */ sprintf(name, "%05d fixed-length strings", j); did = H5Dcreate (gid1, name, tid_str, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite (did, tid_str, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_str); if (!j) add_attrs(did, j); H5Dclose(did); /* 6 add compound data */ sprintf(name, "%05d compund data", j); did = H5Dcreate (gid1, name, cmp_tid, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite (did, cmp_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_comp); if (!j) add_attrs(did, j); H5Dclose(did); /* 7 add 2D double */ sprintf(name, "%05d 2D double", j); strcpy (tmp_name1, name); did = H5Dcreate (gid1, name, H5T_NATIVE_DOUBLE, sid_2d, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite (did, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_double2d[0]); if (!j) add_attrs(did, j); H5Dclose(did); /* 8 add 1D int array */ sprintf(name, "%05d 1D int array", j); did = H5Dcreate (gid1, name, H5T_NATIVE_INT, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite (did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_int); if (!j) add_attrs(did, j); H5Dclose(did); /* 9 add vlen int array */ sprintf(name, "%05d vlen int array", j); strcpy (tmp_name2, name); did = H5Dcreate (gid1, name, tid_vlen_i, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite (did, tid_vlen_i, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_vlen_i); if (!j) add_attrs(did, j); H5Dclose(did); /* 10 add vlen strings */ sprintf(name, "%05d vlen strings", j); strcpy (tmp_name3, name); did = H5Dcreate (gid1, name, tid_vlen_s, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite (did, tid_vlen_s, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_vlen_s); if (!j) add_attrs(did, j); H5Dclose(did); /* 11 add object refs */ H5Rcreate(&buf_ref[0],gid1, ".", H5R_OBJECT, -1); H5Rcreate(&buf_ref[1],gid1, tmp_name3, H5R_OBJECT, -1); sprintf(name, "%05d obj refs", j); did = H5Dcreate (gid1, name, H5T_STD_REF_OBJ, sid_2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite (did, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_ref); if (!j) add_attrs(did, j); H5Dclose(did); /* 12 add region refs */ H5Sselect_elements (sid_2d, H5S_SELECT_SET, 4, coords[0]); H5Rcreate(&buf_reg_ref[0],gid1, tmp_name1, H5R_DATASET_REGION, sid_2d); H5Sselect_none(sid_2d); count = dims[0]/2+1; H5Sselect_hyperslab (sid_1d, H5S_SELECT_SET, &start, &stride, &count,NULL); H5Rcreate(&buf_reg_ref[1],gid1, tmp_name2, H5R_DATASET_REGION, sid_1d); H5Sselect_none(sid_1d); sprintf(name, "%05d region refs", j); did = H5Dcreate (gid1, name, H5T_STD_REF_DSETREG, sid_2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite (did, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_reg_ref); if (!j) add_attrs(did, j); H5Dclose(did); } H5Gclose(gid1); H5Tclose (tid_array_f); H5Tclose (tid_vlen_i); H5Tclose (tid_vlen_s); H5Tclose (tid_enum); H5Tclose (tid_str); H5Tclose (cmp_tid); H5Pclose (dcpl); H5Pclose (fapl); H5Sclose (sid_1d); H5Sclose (sid_2d); H5Sclose (sid_2); H5Sclose (sid_large); H5Sclose (sid_null); H5Sclose (sid_scalar); H5Fclose (fid); for (i=0; i<dims[0]; i++) { if (buf_vlen_i[i].p) free(buf_vlen_i[i].p); if (buf_vlen_s[i]) free(buf_vlen_s[i]); } for (i=0; i<nrows; i++) { if (buf_comp_large[i].i_vlen.p) free(buf_comp_large[i].i_vlen.p); if (buf_comp_large[i].s_vlen) free(buf_comp_large[i].s_vlen); } free (buf_comp); free (buf_comp_large); free (buf_int); free (buf_float_a); free (buf_double2d[0]); free (buf_double2d); free (buf_str); free(buf_vlen_i); free(buf_vlen_s); return 0; }
/* We will read dataset back from the file to the dataset in memory with these dataspace parameters. */ #define MSPACE_RANK 2 #define MSPACE_DIM1 8 #define MSPACE_DIM2 9 #define NPOINTS 4 /* Number of points that will be selected and overwritten */ int main (void) { hid_t file, dataset; /* File and dataset identifiers */ hid_t mid1, mid2, mid, fid; /* Dataspace identifiers */ hid_t plist; /* Dataset property list identifier */ hsize_t dim1[] = {MSPACE1_DIM}; /* Dimension size of the first dataset (in memory) */ hsize_t dim2[] = {MSPACE2_DIM}; /* Dimension size of the second dataset (in memory */ hsize_t fdim[] = {FSPACE_DIM1, FSPACE_DIM2}; /* Dimension sizes of the dataset (on disk) */ hsize_t mdim[] = {MSPACE_DIM1, MSPACE_DIM2}; /* Dimension sizes of the dataset in memory when we read selection from the dataset on the disk */ hsize_t start[2]; /* Start of hyperslab */ hsize_t stride[2]; /* Stride of hyperslab */ hsize_t count[2]; /* Block count */ hsize_t block[2]; /* Block sizes */ hsize_t coord[NPOINTS][FSPACE_RANK]; /* Array to store selected points from the file dataspace */ herr_t ret; unsigned i,j; int fillvalue = 0; /* Fill value for the dataset */ int matrix_out[MSPACE_DIM1][MSPACE_DIM2]; /* Buffer to read from the dataset */ int vector[MSPACE1_DIM]; int values[] = {53, 59, 61, 67}; /* New values to be written */ /* * Buffers' initialization. */ vector[0] = vector[MSPACE1_DIM - 1] = -1; for(i = 1; i < MSPACE1_DIM - 1; i++) vector[i] = i; /* * Create a file. */ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create property list for a dataset and set up fill values. */ plist = H5Pcreate(H5P_DATASET_CREATE); ret = H5Pset_fill_value(plist, H5T_NATIVE_INT, &fillvalue); /* * Create dataspace for the dataset in the file. */ fid = H5Screate_simple(FSPACE_RANK, fdim, NULL); /* * Create dataset in the file. Notice that creation * property list plist is used. */ dataset = H5Dcreate2(file, "Matrix in file", H5T_NATIVE_INT, fid, H5P_DEFAULT, plist, H5P_DEFAULT); /* * Select hyperslab for the dataset in the file, using 3x2 blocks, * (4,3) stride and (2,4) count starting at the position (0,1). */ start[0] = 0; start[1] = 1; stride[0] = 4; stride[1] = 3; count[0] = 2; count[1] = 4; block[0] = 3; block[1] = 2; ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block); /* * Create dataspace for the first dataset. */ mid1 = H5Screate_simple(MSPACE1_RANK, dim1, NULL); /* * Select hyperslab. * We will use 48 elements of the vector buffer starting at the second element. * Selected elements are 1 2 3 . . . 48 */ start[0] = 1; stride[0] = 1; count[0] = 48; block[0] = 1; ret = H5Sselect_hyperslab(mid1, H5S_SELECT_SET, start, stride, count, block); /* * Write selection from the vector buffer to the dataset in the file. * * File dataset should look like this: * 0 1 2 0 3 4 0 5 6 0 7 8 * 0 9 10 0 11 12 0 13 14 0 15 16 * 0 17 18 0 19 20 0 21 22 0 23 24 * 0 0 0 0 0 0 0 0 0 0 0 0 * 0 25 26 0 27 28 0 29 30 0 31 32 * 0 33 34 0 35 36 0 37 38 0 39 40 * 0 41 42 0 43 44 0 45 46 0 47 48 * 0 0 0 0 0 0 0 0 0 0 0 0 */ ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid1, fid, H5P_DEFAULT, vector); /* * Reset the selection for the file dataspace fid. */ ret = H5Sselect_none(fid); /* * Create dataspace for the second dataset. */ mid2 = H5Screate_simple(MSPACE2_RANK, dim2, NULL); /* * Select sequence of NPOINTS points in the file dataspace. */ coord[0][0] = 0; coord[0][1] = 0; coord[1][0] = 3; coord[1][1] = 3; coord[2][0] = 3; coord[2][1] = 5; coord[3][0] = 5; coord[3][1] = 6; ret = H5Sselect_elements(fid, H5S_SELECT_SET, NPOINTS, (const hsize_t *)coord); /* * Write new selection of points to the dataset. */ ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid2, fid, H5P_DEFAULT, values); /* * File dataset should look like this: * 53 1 2 0 3 4 0 5 6 0 7 8 * 0 9 10 0 11 12 0 13 14 0 15 16 * 0 17 18 0 19 20 0 21 22 0 23 24 * 0 0 0 59 0 61 0 0 0 0 0 0 * 0 25 26 0 27 28 0 29 30 0 31 32 * 0 33 34 0 35 36 67 37 38 0 39 40 * 0 41 42 0 43 44 0 45 46 0 47 48 * 0 0 0 0 0 0 0 0 0 0 0 0 * */ /* * Close memory file and memory dataspaces. */ ret = H5Sclose(mid1); ret = H5Sclose(mid2); ret = H5Sclose(fid); /* * Close dataset. */ ret = H5Dclose(dataset); /* * Close the file. */ ret = H5Fclose(file); /* * Open the file. */ file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT); /* * Open the dataset. */ dataset = H5Dopen2(file, "Matrix in file", H5P_DEFAULT); /* * Get dataspace of the open dataset. */ fid = H5Dget_space(dataset); /* * Select first hyperslab for the dataset in the file. The following * elements are selected: * 10 0 11 12 * 18 0 19 20 * 0 59 0 61 * */ start[0] = 1; start[1] = 2; block[0] = 1; block[1] = 1; stride[0] = 1; stride[1] = 1; count[0] = 3; count[1] = 4; ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block); /* * Add second selected hyperslab to the selection. * The following elements are selected: * 19 20 0 21 22 * 0 61 0 0 0 * 27 28 0 29 30 * 35 36 67 37 38 * 43 44 0 45 46 * 0 0 0 0 0 * Note that two hyperslabs overlap. Common elements are: * 19 20 * 0 61 */ start[0] = 2; start[1] = 4; block[0] = 1; block[1] = 1; stride[0] = 1; stride[1] = 1; count[0] = 6; count[1] = 5; ret = H5Sselect_hyperslab(fid, H5S_SELECT_OR, start, stride, count, block); /* * Create memory dataspace. */ mid = H5Screate_simple(MSPACE_RANK, mdim, NULL); /* * Select two hyperslabs in memory. Hyperslabs has the same * size and shape as the selected hyperslabs for the file dataspace. */ start[0] = 0; start[1] = 0; block[0] = 1; block[1] = 1; stride[0] = 1; stride[1] = 1; count[0] = 3; count[1] = 4; ret = H5Sselect_hyperslab(mid, H5S_SELECT_SET, start, stride, count, block); start[0] = 1; start[1] = 2; block[0] = 1; block[1] = 1; stride[0] = 1; stride[1] = 1; count[0] = 6; count[1] = 5; ret = H5Sselect_hyperslab(mid, H5S_SELECT_OR, start, stride, count, block); /* * Initialize data buffer. */ for (i = 0; i < MSPACE_DIM1; i++) { for (j = 0; j < MSPACE_DIM2; j++) matrix_out[i][j] = 0; } /* * Read data back to the buffer matrix_out. */ ret = H5Dread(dataset, H5T_NATIVE_INT, mid, fid, H5P_DEFAULT, matrix_out); /* * Display the result. Memory dataset is: * * 10 0 11 12 0 0 0 0 0 * 18 0 19 20 0 21 22 0 0 * 0 59 0 61 0 0 0 0 0 * 0 0 27 28 0 29 30 0 0 * 0 0 35 36 67 37 38 0 0 * 0 0 43 44 0 45 46 0 0 * 0 0 0 0 0 0 0 0 0 * 0 0 0 0 0 0 0 0 0 */ for(i = 0; i < MSPACE_DIM1; i++) { for(j = 0; j < MSPACE_DIM2; j++) printf("%3d ", matrix_out[i][j]); printf("\n"); } /* * Close memory file and memory dataspaces. */ ret = H5Sclose(mid); ret = H5Sclose(fid); /* * Close dataset. */ ret = H5Dclose(dataset); /* * Close property list */ ret = H5Pclose(plist); /* * Close the file. */ ret = H5Fclose(file); return 0; }
int main (void) { hid_t vfile, file, src_space, mem_space, vspace, vdset, dset; /* Handles */ hid_t dcpl, dapl; herr_t status; hsize_t vdsdims[3] = {4*DIM0_1, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, dims[3] = {DIM0_1, DIM1, DIM2}, memdims[3] = {DIM0_1, DIM1, DIM2}, extdims[3] = {0, DIM1, DIM2}, /* Dimensions of the extended source datasets */ chunk_dims[3] = {DIM0_1, DIM1, DIM2}, dims_max[3] = {DIM0, DIM1, DIM2}, vdsdims_out[3], vdsdims_max_out[3], start[3], /* Hyperslab parameters */ stride[3], count[3], src_count[3], block[3]; hsize_t start_out[3], /* Hyperslab parameter out */ stride_out[3], count_out[3], block_out[3]; int i, j; H5D_layout_t layout; /* Storage layout */ size_t num_map; /* Number of mappings */ ssize_t len; /* Length of the string; also a return value */ char *filename; char *dsetname; int wdata[DIM0_1*DIM1*DIM2]; /* * Create source files and datasets. This step is optional. */ for (i=0; i < PLANE_STRIDE; i++) { /* * Initialize data for i-th source dataset. */ for (j = 0; j < DIM0_1*DIM1*DIM2; j++) wdata[j] = i+1; /* * Create the source files and datasets. Write data to each dataset and * close all resources. */ file = H5Fcreate (SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); src_space = H5Screate_simple (RANK, dims, dims_max); dcpl = H5Pcreate(H5P_DATASET_CREATE); status = H5Pset_chunk (dcpl, RANK, chunk_dims); dset = H5Dcreate2 (file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT, dcpl, H5P_DEFAULT); status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); status = H5Sclose (src_space); status = H5Pclose (dcpl); status = H5Dclose (dset); status = H5Fclose (file); } vfile = H5Fcreate (VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* Create VDS dataspace. */ vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max); /* Create dataspaces for the source dataset. */ src_space = H5Screate_simple (RANK, dims, dims_max); /* Create VDS creation property */ dcpl = H5Pcreate (H5P_DATASET_CREATE); /* Initialize hyperslab values */ start[0] = 0; start[1] = 0; start[2] = 0; stride[0] = PLANE_STRIDE; /* we will select every fifth plane in VDS */ stride[1] = 1; stride[2] = 1; count[0] = H5S_UNLIMITED; count[1] = 1; count[2] = 1; src_count[0] = H5S_UNLIMITED; src_count[1] = 1; src_count[2] = 1; block[0] = 1; block[1] = DIM1; block[2] = DIM2; /* * Build the mappings * */ status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, src_count, block); for (i=0; i < PLANE_STRIDE; i++) { status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block); status = H5Pset_virtual (dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space); start[0]++; } H5Sselect_none(vspace); /* Create a virtual dataset */ vdset = H5Dcreate2 (vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); status = H5Sclose (vspace); status = H5Sclose (src_space); status = H5Pclose (dcpl); /* Let's add data to the source datasets and check new dimensions for VDS */ /* We will add only one plane to the first source dataset, two planes to the second one, three to the third, and four to the forth. */ for (i=0; i < PLANE_STRIDE; i++) { /* * Initialize data for i-th source dataset. */ for (j = 0; j < (i+1)*DIM1*DIM2; j++) wdata[j] = 10*(i+1); /* * Open the source files and datasets. Appen data to each dataset and * close all resources. */ file = H5Fopen (SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT); dset = H5Dopen2 (file, SRC_DATASET[i], H5P_DEFAULT); extdims[0] = DIM0_1+i+1; status = H5Dset_extent (dset, extdims); src_space = H5Dget_space (dset); start[0] = DIM0_1; start[1] = 0; start[2] = 0; count[0] = 1; count[1] = 1; count[2] = 1; block[0] = i+1; block[1] = DIM1; block[2] = DIM2; memdims[0] = i+1; mem_space = H5Screate_simple(RANK, memdims, NULL); status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, count, block); status = H5Dwrite (dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT, wdata); status = H5Sclose (src_space); status = H5Dclose (dset); status = H5Fclose (file); } status = H5Dclose (vdset); status = H5Fclose (vfile); /* * Now we begin the read section of this example. */ /* * Open file and dataset using the default properties. */ vfile = H5Fopen (VFILE, H5F_ACC_RDONLY, H5P_DEFAULT); /* * Open VDS using different access properties to use max or * min extents depending on the sizes of the underlying datasets */ dapl = H5Pcreate (H5P_DATASET_ACCESS); for(i = 0; i < 2; i++) { status = H5Pset_virtual_view (dapl, i ? H5D_VDS_LAST_AVAILABLE : H5D_VDS_FIRST_MISSING); vdset = H5Dopen2 (vfile, DATASET, dapl); /* Let's get space of the VDS and its dimension; we should get 32(or 20)x10x10 */ vspace = H5Dget_space (vdset); H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out); printf ("VDS dimensions, bounds = H5D_VDS_%s: ", i ? "LAST_AVAILABLE" : "FIRST_MISSING"); for (j=0; j<RANK; j++) printf (" %d ", (int)vdsdims_out[j]); printf ("\n"); /* Close */ status = H5Dclose (vdset); status = H5Sclose (vspace); } status = H5Pclose (dapl); vdset = H5Dopen2 (vfile, DATASET, H5P_DEFAULT); /* * Get creation property list and mapping properties. */ dcpl = H5Dget_create_plist (vdset); /* * Get storage layout. */ layout = H5Pget_layout (dcpl); if (H5D_VIRTUAL == layout) printf(" Dataset has a virtual layout \n"); else printf(" Wrong layout found \n"); /* * Find number of mappings. */ status = H5Pget_virtual_count (dcpl, &num_map); printf(" Number of mappings is %lu\n", (unsigned long)num_map); /* * Get mapping parameters for each mapping. */ for (i = 0; i < (int)num_map; i++) { printf(" Mapping %d \n", i); printf(" Selection in the virtual dataset \n"); /* Get selection in the virttual dataset */ vspace = H5Pget_virtual_vspace (dcpl, (size_t)i); if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) { if (H5Sis_regular_hyperslab(vspace)) { status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out); printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]); printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]); printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]); printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]); } } /* Get source file name */ len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0); filename = (char *)malloc((size_t)len*sizeof(char)+1); H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1); printf(" Source filename %s\n", filename); /* Get source dataset name */ len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0); dsetname = (char *)malloc((size_t)len*sizeof(char)+1); H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1); printf(" Source dataset name %s\n", dsetname); /* Get selection in the source dataset */ printf(" Selection in the source dataset \n"); src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i); if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) { if (H5Sis_regular_hyperslab(src_space)) { status = H5Sget_regular_hyperslab (src_space, start_out, stride_out, count_out, block_out); printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]); printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]); printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]); printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]); } } H5Sclose(vspace); H5Sclose(src_space); free(filename); free(dsetname); } /* * Close and release resources. */ status = H5Pclose (dcpl); status = H5Dclose (vdset); status = H5Fclose (vfile); return 0; }
int main (void) { hid_t vfile, file, src_space, mem_space, vspace, vdset, dset; /* Handles */ hid_t dcpl; herr_t status; hsize_t vdsdims[3] = {4*DIM0_1, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, dims[3] = {DIM0_1, DIM1, DIM2}, extdims[3] = {2*DIM0_1, DIM1, DIM2}, chunk_dims[3] = {DIM0_1, DIM1, DIM2}, dims_max[3] = {DIM0, DIM1, DIM2}, vdsdims_out[3], vdsdims_max_out[3], start[3], /* Hyperslab parameters */ stride[3], count[3], src_count[3], block[3]; hsize_t start_out[3], /* Hyperslab parameter out */ stride_out[3], count_out[3], block_out[3]; int i, j, k; H5D_layout_t layout; /* Storage layout */ size_t num_map; /* Number of mappings */ ssize_t len; /* Length of the string; also a return value */ char *filename; char *dsetname; int wdata[DIM0_1*DIM1*DIM2]; int rdata[80][10][10]; int a_rdata[20][10][10]; /* * Create source files and datasets. This step is optional. */ for (i=0; i < PLANE_STRIDE; i++) { /* * Initialize data for i-th source dataset. */ for (j = 0; j < DIM0_1*DIM1*DIM2; j++) wdata[j] = i+1; /* * Create the source files and datasets. Write data to each dataset and * close all resources. */ file = H5Fcreate (SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); src_space = H5Screate_simple (RANK, dims, dims_max); dcpl = H5Pcreate(H5P_DATASET_CREATE); status = H5Pset_chunk (dcpl, RANK, chunk_dims); dset = H5Dcreate2 (file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT, dcpl, H5P_DEFAULT); status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); status = H5Sclose (src_space); status = H5Pclose (dcpl); status = H5Dclose (dset); status = H5Fclose (file); } vfile = H5Fcreate (VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* Create VDS dataspace. */ vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max); /* Create dataspaces for the source dataset. */ src_space = H5Screate_simple (RANK, dims, dims_max); /* Create VDS creation property */ dcpl = H5Pcreate (H5P_DATASET_CREATE); /* Initialize hyperslab values */ start[0] = 0; start[1] = 0; start[2] = 0; stride[0] = PLANE_STRIDE; /* we will select every fifth plane in VDS */ stride[1] = 1; stride[2] = 1; count[0] = H5S_UNLIMITED; count[1] = 1; count[2] = 1; src_count[0] = H5S_UNLIMITED; src_count[1] = 1; src_count[2] = 1; block[0] = 1; block[1] = DIM1; block[2] = DIM2; /* * Build the mappings * */ status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, src_count, block); for (i=0; i < PLANE_STRIDE; i++) { status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block); status = H5Pset_virtual (dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space); start[0]++; } H5Sselect_none(vspace); /* Create a virtual dataset */ vdset = H5Dcreate2 (vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); status = H5Sclose (vspace); status = H5Sclose (src_space); status = H5Pclose (dcpl); /* Let's get space of the VDS and its dimension; we should get 40x10x10 */ vspace = H5Dget_space (vdset); H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out); printf ("VDS dimensions first time \n"); printf (" Current: "); for (i=0; i<RANK; i++) printf (" %d ", (int)vdsdims_out[i]); printf ("\n"); /* Let's add data to the source datasets and check new dimensions for VDS */ for (i=0; i < PLANE_STRIDE; i++) { /* * Initialize data for i-th source dataset. */ for (j = 0; j < DIM0_1*DIM1*DIM2; j++) wdata[j] = 10*(i+1); /* * Create the source files and datasets. Write data to each dataset and * close all resources. */ file = H5Fopen (SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT); dset = H5Dopen2 (file, SRC_DATASET[i], H5P_DEFAULT); status = H5Dset_extent (dset, extdims); src_space = H5Dget_space (dset); start[0] = DIM0_1; start[1] = 0; start[2] = 0; count[0] = 1; count[1] = 1; count[2] = 1; block[0] = DIM0_1; block[1] = DIM1; block[2] = DIM2; mem_space = H5Screate_simple(RANK, dims, NULL); status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, count, block); status = H5Dwrite (dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT, wdata); status = H5Sclose (src_space); status = H5Dclose (dset); status = H5Fclose (file); } status = H5Dclose (vdset); status = H5Fclose (vfile); /* * Now we begin the read section of this example. */ /* * Open file and dataset using the default properties. */ vfile = H5Fopen (VFILE, H5F_ACC_RDONLY, H5P_DEFAULT); vdset = H5Dopen2 (vfile, DATASET, H5P_DEFAULT); /* * Get creation property list and mapping properties. */ dcpl = H5Dget_create_plist (vdset); /* * Get storage layout. */ layout = H5Pget_layout (dcpl); if (H5D_VIRTUAL == layout) printf(" Dataset has a virtual layout \n"); else printf(" Wrong layout found \n"); /* * Find number of mappings. */ status = H5Pget_virtual_count (dcpl, &num_map); printf(" Number of mappings is %lu\n", (unsigned long)num_map); /* * Get mapping parameters for each mapping. */ for (i = 0; i < (int)num_map; i++) { printf(" Mapping %d \n", i); printf(" Selection in the virtual dataset \n"); /* Get selection in the virttual dataset */ vspace = H5Pget_virtual_vspace (dcpl, (size_t)i); if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) { if (H5Sis_regular_hyperslab(vspace)) { status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out); printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]); printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]); printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]); printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]); } } /* Get source file name */ len = H5Pget_virtual_filename (dcpl, (size_t)i, NULL, 0); filename = (char *)malloc((size_t)len*sizeof(char)+1); H5Pget_virtual_filename (dcpl, (size_t)i, filename, len+1); printf(" Source filename %s\n", filename); /* Get source dataset name */ len = H5Pget_virtual_dsetname (dcpl, (size_t)i, NULL, 0); dsetname = (char *)malloc((size_t)len*sizeof(char)+1); H5Pget_virtual_dsetname (dcpl, (size_t)i, dsetname, len+1); printf(" Source dataset name %s\n", dsetname); /* Get selection in the source dataset */ printf(" Selection in the source dataset \n"); src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i); if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) { if (H5Sis_regular_hyperslab(src_space)) { status = H5Sget_regular_hyperslab (src_space, start_out, stride_out, count_out, block_out); printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1], (unsigned long long)start_out[2]); printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1], (unsigned long long)stride_out[2]); printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1], (unsigned long long)count_out[2]); printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1], (unsigned long long)block_out[2]); } } H5Sclose(vspace); H5Sclose(src_space); free(filename); free(dsetname); } /* * Read data from VDS. */ vspace = H5Dget_space (vdset); H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out); printf ("VDS dimensions second time \n"); printf (" Current: "); for (i=0; i<RANK; i++) printf (" %d ", (int)vdsdims_out[i]); printf ("\n"); /* Read all VDS data */ /* EIP We should be able to do it by using H5S_ALL instead of making selection * or using H5Sselect_all from vspace. */ start[0] = 0; start[1] = 0; start[2] = 0; count[0] = 1; count[1] = 1; count[2] = 1; block[0] = vdsdims_out[0]; block[1] = vdsdims_out[1]; block[2] = vdsdims_out[2]; status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, NULL, count, block); mem_space = H5Screate_simple(RANK, vdsdims_out, NULL); status = H5Dread (vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT, rdata); printf (" All data: \n"); for (i=0; i < (int)vdsdims_out[0]; i++) { for (j=0; j < (int)vdsdims_out[1]; j++) { printf ("(%d, %d, 0)", i, j); for (k=0; k < (int)vdsdims_out[2]; k++) printf (" %d ", rdata[i][j][k]); printf ("\n"); } } /* Read VDS, but only data mapeed to dataset a.h5 */ start[0] = 0; start[1] = 0; start[2] = 0; stride[0] = PLANE_STRIDE; stride[1] = 1; stride[2] = 1; count[0] = 2*DIM0_1; count[1] = 1; count[2] = 1; block[0] = 1; block[1] = vdsdims_out[1]; block[2] = vdsdims_out[2]; dims[0] = 2*DIM0_1; status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block); mem_space = H5Screate_simple(RANK, dims, NULL); status = H5Dread (vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT, a_rdata); printf (" All data: \n"); for (i=0; i < 2*DIM0_1; i++) { for (j=0; j < (int)vdsdims_out[1]; j++) { printf ("(%d, %d, 0)", i, j); for (k=0; k < (int)vdsdims_out[2]; k++) printf (" %d ", a_rdata[i][j][k]); printf ("\n"); } } /* * Close and release resources. */ status = H5Sclose(mem_space); status = H5Pclose (dcpl); status = H5Dclose (vdset); status = H5Fclose (vfile); return 0; }
int main(void) { hid_t file_id; /* file identifier */ hid_t space_id; /* dataspace identifiers */ hid_t spacer_id; hid_t dsetv_id; /*dataset identifiers*/ hid_t dsetr_id; hsize_t dims[2] = {2,9}; hsize_t dimsr[1] = {2}; int rank = 2; int rankr =1; herr_t status; hdset_reg_ref_t ref[2]; hdset_reg_ref_t ref_out[2]; int data[2][9] = {{1,1,2,3,3,4,5,5,6},{1,2,2,3,4,4,5,6,6}}; int data_out[2][9] = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0}}; hsize_t start[2]; hsize_t count[2]; hsize_t coord[2][3] = {{0, 0, 1}, {6, 0, 8}}; unsigned num_points = 3; int i, j; size_t name_size1, name_size2; char buf1[10], buf2[10]; /* * Create file with default file access and file creation properties. */ file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Create dataspace for datasets. */ space_id = H5Screate_simple(rank, dims, NULL); spacer_id = H5Screate_simple(rankr, dimsr, NULL); /* * Create integer dataset. */ dsetv_id = H5Dcreate2(file_id, dsetnamev, H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); /* * Write data to the dataset. */ status = H5Dwrite(dsetv_id, H5T_NATIVE_INT, H5S_ALL , H5S_ALL, H5P_DEFAULT,data); status = H5Dclose(dsetv_id); /* * Dataset with references. */ dsetr_id = H5Dcreate2(file_id, dsetnamer, H5T_STD_REF_DSETREG, spacer_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); /* * Create a reference to the hyperslab. */ start[0] = 0; start[1] = 3; count[0] = 2; count[1] = 3; status = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start, NULL, count, NULL); status = H5Rcreate(&ref[0], file_id, dsetnamev, H5R_DATASET_REGION, space_id); /* * Create a reference to elements selection. */ status = H5Sselect_none(space_id); status = H5Sselect_elements(space_id, H5S_SELECT_SET, num_points, (const hsize_t *)coord); status = H5Rcreate(&ref[1], file_id, dsetnamev, H5R_DATASET_REGION, space_id); /* * Write dataset with the references. */ status = H5Dwrite(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT,ref); /* * Close all objects. */ status = H5Sclose(space_id); status = H5Sclose(spacer_id); status = H5Dclose(dsetr_id); status = H5Fclose(file_id); /* * Reopen the file to read selections back. */ file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT); /* * Reopen the dataset with object references and read references * to the buffer. */ dsetr_id = H5Dopen2(file_id, dsetnamer, H5P_DEFAULT); status = H5Dread(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_out); /* * Dereference the first reference. */ dsetv_id = H5Rdereference2(dsetr_id, H5P_DEFAULT, H5R_DATASET_REGION, &ref_out[0]); /* * Get name of the dataset the first region reference points to * using H5Rget_name */ name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char*)buf1, 10); printf(" Dataset's name (returned by H5Rget_name) the reference points to is %s, name length is %d\n", buf1, (int)name_size1); /* * Get name of the dataset the first region reference points to * using H5Iget_name */ name_size2 = H5Iget_name(dsetv_id, (char*)buf2, 10); printf(" Dataset's name (returned by H5Iget_name) the reference points to is %s, name length is %d\n", buf2, (int)name_size2); space_id = H5Rget_region(dsetr_id, H5R_DATASET_REGION,&ref_out[0]); /* * Read and display hyperslab selection from the dataset. */ status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id, H5P_DEFAULT, data_out); printf("Selected hyperslab: "); for (i = 0; i <= 1; i++) { printf("\n"); for (j = 0; j <= 8; j++) printf("%d ", data_out[i][j]); } printf("\n"); /* * Close dataspace and the dataset. */ status = H5Sclose(space_id); status = H5Dclose(dsetv_id); /* * Initialize data_out array again to get point selection. */ for (i = 0; i <= 1; i++) for (j = 0; j <= 8; j++) data_out[i][j] = 0; /* * Dereference the second reference. */ dsetv_id = H5Rdereference2(dsetr_id, H5P_DEFAULT, H5R_DATASET_REGION, &ref_out[1]); space_id = H5Rget_region(dsetv_id, H5R_DATASET_REGION,&ref_out[1]); /* * Read selected data from the dataset. */ status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id, H5P_DEFAULT, data_out); printf("Selected points: "); for (i = 0; i <= 1; i++) { printf("\n"); for (j = 0; j <= 8; j++) printf("%d ", data_out[i][j]); } printf("\n"); /* * Close dataspace and the dataset. */ status = H5Sclose(space_id); status = H5Dclose(dsetv_id); status = H5Dclose(dsetr_id); status = H5Fclose(file_id); return 0; }
escdf_errno_t utils_hdf5_read_dataset(hid_t dtset_id, void *buf, hid_t mem_type_id, const hsize_t *start, const hsize_t *count, const hsize_t *stride) { hid_t memspace_id, diskspace_id, plist; herr_t err_id; hssize_t len; /* disk use the start, count and stride. */ if ((diskspace_id = H5Dget_space(dtset_id)) < 0) { RETURN_WITH_ERROR(diskspace_id); } if (start && count) { if ((err_id = H5Sselect_hyperslab(diskspace_id, H5S_SELECT_SET, start, stride, count, NULL)) < 0) { H5Sclose(diskspace_id); RETURN_WITH_ERROR(err_id); } } else { if ((err_id = H5Sselect_all(diskspace_id)) < 0) { H5Sclose(diskspace_id); RETURN_WITH_ERROR(err_id); } } if ((len = H5Sget_select_npoints(diskspace_id)) < 0) { H5Sclose(diskspace_id); RETURN_WITH_ERROR(len); } if (!len) { if ((err_id = H5Sselect_none(diskspace_id)) < 0) { H5Sclose(diskspace_id); RETURN_WITH_ERROR(err_id); } } /* create dataspace for memory and disk. */ /* memory is a flat array with the size on the slice. */ if ((memspace_id = H5Screate_simple(1, &len, NULL)) < 0) { H5Sclose(diskspace_id); RETURN_WITH_ERROR(memspace_id); } /* Read */ plist = H5Pcreate(H5P_DATASET_XFER); /* H5Pset_dxpl_mpio(plist, H5FD_MPIO_COLLECTIVE); */ if ((err_id = H5Dread(dtset_id, mem_type_id, memspace_id, diskspace_id, plist, buf)) < 0) { H5Pclose(plist); H5Sclose(diskspace_id); H5Sclose(memspace_id); RETURN_WITH_ERROR(err_id); } H5Pclose(plist); H5Sclose(diskspace_id); H5Sclose(memspace_id); return ESCDF_SUCCESS; }
/* * A test for issue HDFFV-10501. A parallel hang was reported which occurred * in linked-chunk I/O when collective metadata reads are enabled and some ranks * do not have any selection in a dataset's dataspace, while others do. The ranks * which have no selection during the read/write operation called H5D__chunk_addrmap() * to retrieve the lowest chunk address, since we require that the read/write be done * in strictly non-decreasing order of chunk address. For version 1 and 2 B-trees, * this caused the non-participating ranks to issue a collective MPI_Bcast() call * which the other ranks did not issue, thus causing a hang. * * However, since these ranks are not actually reading/writing anything, this call * can simply be removed and the address used for the read/write can be set to an * arbitrary number (0 was chosen). */ void test_partial_no_selection_coll_md_read(void) { const char *filename; hsize_t *dataset_dims = NULL; hsize_t max_dataset_dims[PARTIAL_NO_SELECTION_DATASET_NDIMS]; hsize_t sel_dims[1]; hsize_t chunk_dims[PARTIAL_NO_SELECTION_DATASET_NDIMS] = { PARTIAL_NO_SELECTION_Y_DIM_SCALE, PARTIAL_NO_SELECTION_X_DIM_SCALE }; hsize_t start[PARTIAL_NO_SELECTION_DATASET_NDIMS]; hsize_t stride[PARTIAL_NO_SELECTION_DATASET_NDIMS]; hsize_t count[PARTIAL_NO_SELECTION_DATASET_NDIMS]; hsize_t block[PARTIAL_NO_SELECTION_DATASET_NDIMS]; hid_t file_id = -1; hid_t fapl_id = -1; hid_t dset_id = -1; hid_t dcpl_id = -1; hid_t dxpl_id = -1; hid_t fspace_id = -1; hid_t mspace_id = -1; int mpi_rank, mpi_size; void *data = NULL; void *read_buf = NULL; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); filename = GetTestParameters(); fapl_id = create_faccess_plist(MPI_COMM_WORLD, MPI_INFO_NULL, facc_type); VRFY((fapl_id >= 0), "create_faccess_plist succeeded"); /* * Even though the testphdf5 framework currently sets collective metadata reads * on the FAPL, we call it here just to be sure this is futureproof, since * demonstrating this issue relies upon it. */ VRFY((H5Pset_all_coll_metadata_ops(fapl_id, true) >= 0), "Set collective metadata reads succeeded"); file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); VRFY((file_id >= 0), "H5Fcreate succeeded"); dataset_dims = malloc(PARTIAL_NO_SELECTION_DATASET_NDIMS * sizeof(*dataset_dims)); VRFY((dataset_dims != NULL), "malloc succeeded"); dataset_dims[0] = PARTIAL_NO_SELECTION_Y_DIM_SCALE * mpi_size; dataset_dims[1] = PARTIAL_NO_SELECTION_X_DIM_SCALE * mpi_size; max_dataset_dims[0] = H5S_UNLIMITED; max_dataset_dims[1] = H5S_UNLIMITED; fspace_id = H5Screate_simple(PARTIAL_NO_SELECTION_DATASET_NDIMS, dataset_dims, max_dataset_dims); VRFY((fspace_id >= 0), "H5Screate_simple succeeded"); /* * Set up chunking on the dataset in order to reproduce the problem. */ dcpl_id = H5Pcreate(H5P_DATASET_CREATE); VRFY((dcpl_id >= 0), "H5Pcreate succeeded"); VRFY((H5Pset_chunk(dcpl_id, PARTIAL_NO_SELECTION_DATASET_NDIMS, chunk_dims) >= 0), "H5Pset_chunk succeeded"); dset_id = H5Dcreate2(file_id, PARTIAL_NO_SELECTION_DATASET_NAME, H5T_NATIVE_INT, fspace_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT); VRFY((dset_id >= 0), "H5Dcreate2 succeeded"); /* * Setup hyperslab selection to split the dataset among the ranks. * * The ranks will write rows across the dataset. */ start[0] = PARTIAL_NO_SELECTION_Y_DIM_SCALE * mpi_rank; start[1] = 0; stride[0] = PARTIAL_NO_SELECTION_Y_DIM_SCALE; stride[1] = PARTIAL_NO_SELECTION_X_DIM_SCALE; count[0] = 1; count[1] = mpi_size; block[0] = PARTIAL_NO_SELECTION_Y_DIM_SCALE; block[1] = PARTIAL_NO_SELECTION_X_DIM_SCALE; VRFY((H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) >= 0), "H5Sselect_hyperslab succeeded"); sel_dims[0] = count[1] * (PARTIAL_NO_SELECTION_Y_DIM_SCALE * PARTIAL_NO_SELECTION_X_DIM_SCALE); mspace_id = H5Screate_simple(1, sel_dims, NULL); VRFY((mspace_id >= 0), "H5Screate_simple succeeded"); data = calloc(1, count[1] * (PARTIAL_NO_SELECTION_Y_DIM_SCALE * PARTIAL_NO_SELECTION_X_DIM_SCALE) * sizeof(int)); VRFY((data != NULL), "calloc succeeded"); dxpl_id = H5Pcreate(H5P_DATASET_XFER); VRFY((dxpl_id >= 0), "H5Pcreate succeeded"); /* * Enable collective access for the data transfer. */ VRFY((H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_COLLECTIVE) >= 0), "H5Pset_dxpl_mpio succeeded"); VRFY((H5Dwrite(dset_id, H5T_NATIVE_INT, mspace_id, fspace_id, dxpl_id, data) >= 0), "H5Dwrite succeeded"); VRFY((H5Fflush(file_id, H5F_SCOPE_GLOBAL) >= 0), "H5Fflush succeeded"); /* * Ensure that linked-chunk I/O is performed since this is * the particular code path where the issue lies and we don't * want the library doing multi-chunk I/O behind our backs. */ VRFY((H5Pset_dxpl_mpio_chunk_opt(dxpl_id, H5FD_MPIO_CHUNK_ONE_IO) >= 0), "H5Pset_dxpl_mpio_chunk_opt succeeded"); read_buf = malloc(count[1] * (PARTIAL_NO_SELECTION_Y_DIM_SCALE * PARTIAL_NO_SELECTION_X_DIM_SCALE) * sizeof(int)); VRFY((read_buf != NULL), "malloc succeeded"); /* * Make sure to call H5Sselect_none() on the non-participating process. */ if (PARTIAL_NO_SELECTION_NO_SEL_PROCESS) { VRFY((H5Sselect_none(fspace_id) >= 0), "H5Sselect_none succeeded"); VRFY((H5Sselect_none(mspace_id) >= 0), "H5Sselect_none succeeded"); } /* * Finally have each rank read their section of data back from the dataset. */ VRFY((H5Dread(dset_id, H5T_NATIVE_INT, mspace_id, fspace_id, dxpl_id, read_buf) >= 0), "H5Dread succeeded"); /* * Check data integrity just to be sure. */ if (!PARTIAL_NO_SELECTION_NO_SEL_PROCESS) { VRFY((!memcmp(data, read_buf, count[1] * (PARTIAL_NO_SELECTION_Y_DIM_SCALE * PARTIAL_NO_SELECTION_X_DIM_SCALE) * sizeof(int))), "memcmp succeeded"); } if (dataset_dims) { free(dataset_dims); dataset_dims = NULL; } if (data) { free(data); data = NULL; } if (read_buf) { free(read_buf); read_buf = NULL; } VRFY((H5Sclose(fspace_id) >= 0), "H5Sclose succeeded"); VRFY((H5Sclose(mspace_id) >= 0), "H5Sclose succeeded"); VRFY((H5Pclose(dcpl_id) >= 0), "H5Pclose succeeded"); VRFY((H5Pclose(dxpl_id) >= 0), "H5Pclose succeeded"); VRFY((H5Dclose(dset_id) >= 0), "H5Dclose succeeded"); VRFY((H5Pclose(fapl_id) >= 0), "H5Pclose succeeded"); VRFY((H5Fclose(file_id) >= 0), "H5Fclose succeeded"); }
void io_mode_confusion(void) { /* * HDF5 APIs definitions */ const int rank = 1; const char *dataset_name = "IntArray"; hid_t file_id, dset_id; /* file and dataset identifiers */ hid_t filespace, memspace; /* file and memory dataspace */ /* identifiers */ hsize_t dimsf[1]; /* dataset dimensions */ int data[N] = {1}; /* pointer to data buffer to write */ hsize_t coord[N] = {0L,1L,2L,3L}; hsize_t start[1]; hsize_t stride[1]; hsize_t count[1]; hsize_t block[1]; hid_t plist_id; /* property list identifier */ herr_t status; /* * MPI variables */ int mpi_size, mpi_rank; /* * test bed related variables */ const char * fcn_name = "io_mode_confusion"; const hbool_t verbose = FALSE; const H5Ptest_param_t * pt; char * filename; pt = GetTestParameters(); filename = pt->name; MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); /* * Set up file access property list with parallel I/O access */ if ( verbose ) HDfprintf(stdout, "%0d:%s: Setting up property list.\n", mpi_rank, fcn_name); plist_id = H5Pcreate(H5P_FILE_ACCESS); VRFY((plist_id != -1), "H5Pcreate() failed"); status = H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL); VRFY(( status >= 0 ), "H5Pset_fapl_mpio() failed"); /* * Create a new file collectively and release property list identifier. */ if ( verbose ) HDfprintf(stdout, "%0d:%s: Creating new file.\n", mpi_rank, fcn_name); file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, plist_id); VRFY(( file_id >= 0 ), "H5Fcreate() failed"); status = H5Pclose(plist_id); VRFY(( status >= 0 ), "H5Pclose() failed"); /* * Create the dataspace for the dataset. */ if ( verbose ) HDfprintf(stdout, "%0d:%s: Creating the dataspace for the dataset.\n", mpi_rank, fcn_name); dimsf[0] = N; filespace = H5Screate_simple(rank, dimsf, NULL); VRFY(( filespace >= 0 ), "H5Screate_simple() failed."); /* * Create the dataset with default properties and close filespace. */ if ( verbose ) HDfprintf(stdout, "%0d:%s: Creating the dataset, and closing filespace.\n", mpi_rank, fcn_name); dset_id = H5Dcreate(file_id, dataset_name, H5T_NATIVE_INT, filespace, H5P_DEFAULT); VRFY(( dset_id >= 0 ), "H5Dcreate() failed"); status = H5Sclose(filespace); VRFY(( status >= 0 ), "H5Sclose() failed"); if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling H5Screate_simple().\n", mpi_rank, fcn_name); memspace = H5Screate_simple(rank, dimsf, NULL); VRFY(( memspace >= 0 ), "H5Screate_simple() failed."); if( mpi_rank == 0 ) { if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling H5Sselect_all(memspace).\n", mpi_rank, fcn_name); status = H5Sselect_all(memspace); VRFY(( status >= 0 ), "H5Sselect_all() failed"); } else { if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling H5Sselect_none(memspace).\n", mpi_rank, fcn_name); status = H5Sselect_none(memspace); VRFY(( status >= 0 ), "H5Sselect_none() failed"); } if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling MPI_Barrier().\n", mpi_rank, fcn_name); MPI_Barrier(MPI_COMM_WORLD); if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling H5Dget_space().\n", mpi_rank, fcn_name); filespace = H5Dget_space(dset_id); VRFY(( filespace >= 0 ), "H5Dget_space() failed"); start[0] = 0L; stride[0] = 1; count[0] = 1; block[0] = N; if ( mpi_rank == 0 ) { /* select all */ if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling H5Sselect_elements() -- set up hang?\n", mpi_rank, fcn_name); status = H5Sselect_elements(filespace, H5S_SELECT_SET, N, (const hsize_t **)&coord); VRFY(( status >= 0 ), "H5Sselect_elements() failed"); } else { /* select nothing */ if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling H5Sselect_none().\n", mpi_rank, fcn_name); status = H5Sselect_none(filespace); VRFY(( status >= 0 ), "H5Sselect_none() failed"); } if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling MPI_Barrier().\n", mpi_rank, fcn_name); MPI_Barrier(MPI_COMM_WORLD); if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling H5Pcreate().\n", mpi_rank, fcn_name); plist_id = H5Pcreate(H5P_DATASET_XFER); VRFY(( plist_id != -1 ), "H5Pcreate() failed"); if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling H5Pset_dxpl_mpio().\n", mpi_rank, fcn_name); status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE); VRFY(( status >= 0 ), "H5Pset_dxpl_mpio() failed"); if ( verbose ) HDfprintf(stdout, "%0d:%s: Calling H5Dwrite() -- hang here?.\n", mpi_rank, fcn_name); status = H5Dwrite(dset_id, H5T_NATIVE_INT, memspace, filespace, plist_id, data); if ( verbose ) HDfprintf(stdout, "%0d:%s: Returned from H5Dwrite(), status=%d.\n", mpi_rank, fcn_name, status); VRFY(( status >= 0 ), "H5Dwrite() failed"); /* * Close/release resources. */ if ( verbose ) HDfprintf(stdout, "%0d:%s: Cleaning up from test.\n", mpi_rank, fcn_name); status = H5Dclose(dset_id); VRFY(( status >= 0 ), "H5Dclose() failed"); status = H5Sclose(filespace); VRFY(( status >= 0 ), "H5Dclose() failed"); status = H5Sclose(memspace); VRFY(( status >= 0 ), "H5Sclose() failed"); status = H5Pclose(plist_id); VRFY(( status >= 0 ), "H5Pclose() failed"); status = H5Fclose(file_id); VRFY(( status >= 0 ), "H5Fclose() failed"); if ( verbose ) HDfprintf(stdout, "%0d:%s: Done.\n", mpi_rank, fcn_name); return; } /* io_mode_confusion() */