herr_t set_cache_size(hid_t file_id, size_t cache_size) { #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR >= 7 /* MSVS2005 chokes on declarations after statements */ H5AC_cache_config_t config; #endif /* if H5_VERSION < "1.7" */ herr_t code; code = 0; #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR >= 7 config.version = H5AC__CURR_CACHE_CONFIG_VERSION; code = H5Fget_mdc_config(file_id, &config); config.set_initial_size = TRUE; config.initial_size = cache_size; /* config.incr_mode = H5C_incr__off; */ /* config.decr_mode = H5C_decr__off; */ /* printf("Setting cache size to: %d\n", cache_size); */ code = H5Fset_mdc_config(file_id, &config); /* printf("Return code for H5Fset_mdc_config: %d\n", code); */ #endif /* if H5_VERSION < "1.7" */ return code; }
/*------------------------------------------------------------------------- * Function: addrem_records * * Purpose: Adds/removes a specified number of records to random datasets * to the SWMR test file. * * Parameters: hid_t fid * The file ID of the SWMR HDF5 file * * unsigned verbose * Whether or not to emit verbose console messages * * unsigned long nops * # of records to read/write in the datasets * * unsigned long flush_count * # of records to write before flushing the file to disk * * Return: Success: 0 * Failure: -1 * *------------------------------------------------------------------------- */ static int addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long flush_count) { hid_t tid; /* Datatype ID for records */ hid_t mem_sid; /* Memory dataspace ID */ hsize_t start[2] = {0, 0}, count[2] = {1, 1}; /* Hyperslab selection values */ hsize_t dim[2] = {1, 0}; /* Dataspace dimensions */ symbol_t buf[MAX_SIZE_CHANGE]; /* Write buffer */ H5AC_cache_config_t mdc_config_orig; /* Original metadata cache configuration */ H5AC_cache_config_t mdc_config_cork; /* Corked metadata cache configuration */ unsigned long op_to_flush; /* # of operations before flush */ unsigned long u, v; /* Local index variables */ assert(fid > 0); /* Reset the buffer */ memset(&buf, 0, sizeof(buf)); /* Create a dataspace for the record to add */ if((mem_sid = H5Screate_simple(2, count, NULL)) < 0) return -1; /* Create datatype for appending records */ if((tid = create_symbol_datatype()) < 0) return -1; /* Get the current metadata cache configuration, and set up the corked * configuration */ mdc_config_orig.version = H5AC__CURR_CACHE_CONFIG_VERSION; if(H5Fget_mdc_config(fid, &mdc_config_orig) < 0) return -1; memcpy(&mdc_config_cork, &mdc_config_orig, sizeof(mdc_config_cork)); mdc_config_cork.evictions_enabled = FALSE; mdc_config_cork.incr_mode = H5C_incr__off; mdc_config_cork.flash_incr_mode = H5C_flash_incr__off; mdc_config_cork.decr_mode = H5C_decr__off; /* Add and remove records to random datasets, according to frequency * distribution */ op_to_flush = flush_count; for(u=0; u<nops; u++) { symbol_info_t *symbol; /* Symbol to write record to */ hid_t file_sid; /* Dataset's space ID */ /* Get a random dataset, according to the symbol distribution */ symbol = choose_dataset(); /* Decide whether to shrink or expand, and by how much */ count[1] = (hsize_t)random() % (MAX_SIZE_CHANGE * 2) + 1; if(count[1] > MAX_SIZE_CHANGE) { /* Add records */ count[1] -= MAX_SIZE_CHANGE; /* Set the buffer's IDs (equal to its position) */ for(v=0; v<count[1]; v++) buf[v].rec_id = (uint64_t)symbol->nrecords + (uint64_t)v; /* Set the memory space to the correct size */ if(H5Sset_extent_simple(mem_sid, 2, count, NULL) < 0) return -1; /* Get the coordinates to write */ start[1] = symbol->nrecords; /* Cork the metadata cache, to prevent the object header from being * flushed before the data has been written */ /*if(H5Fset_mdc_config(fid, &mdc_config_cork) < 0) return(-1);*/ /* Extend the dataset's dataspace to hold the new record */ symbol->nrecords+= count[1]; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) return -1; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(symbol->dsid)) < 0) return -1; /* Choose the last record in the dataset */ if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) return -1; /* Write record to the dataset */ if(H5Dwrite(symbol->dsid, tid, mem_sid, file_sid, H5P_DEFAULT, &buf) < 0) return -1; /* Uncork the metadata cache */ /*if(H5Fset_mdc_config(fid, &mdc_config_orig) < 0) return -1;*/ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) return -1; } /* end if */ else { /* Shrink the dataset's dataspace */ if(count[1] > symbol->nrecords) symbol->nrecords = 0; else symbol->nrecords -= count[1]; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) return -1; } /* end else */ /* Check for flushing file */ if(flush_count > 0) { /* Decrement count of records to write before flushing */ op_to_flush--; /* Check for counter being reached */ if(0 == op_to_flush) { /* Flush contents of file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) return -1; /* Reset flush counter */ op_to_flush = flush_count; } /* end if */ } /* end if */ } /* end for */ /* Emit informational message */ if(verbose) fprintf(stderr, "Closing datasets\n"); /* Close the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) if(H5Dclose(symbol_info[u][v].dsid) < 0) return -1; return 0; }
/*------------------------------------------------------------------------- * Function: add_records * * Purpose: Writes a specified number of records to random datasets in * the SWMR test file. * * Parameters: hid_t fid * The file ID of the SWMR HDF5 file * * unsigned verbose * Whether or not to emit verbose console messages * * unsigned long nrecords * # of records to write to the datasets * * unsigned long flush_count * # of records to write before flushing the file to disk * * Return: Success: 0 * Failure: -1 * *------------------------------------------------------------------------- */ static int add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long flush_count) { hid_t tid; /* Datatype ID for records */ hid_t mem_sid; /* Memory dataspace ID */ hsize_t start[2] = {0, 0}; /* Hyperslab selection values */ hsize_t count[2] = {1, 1}; /* Hyperslab selection values */ symbol_t record; /* The record to add to the dataset */ H5AC_cache_config_t mdc_config_orig; /* Original metadata cache configuration */ H5AC_cache_config_t mdc_config_cork; /* Corked metadata cache configuration */ unsigned long rec_to_flush; /* # of records left to write before flush */ volatile int dummy; /* Dummy varialbe for busy sleep */ hsize_t dim[2] = {1,0}; /* Dataspace dimensions */ unsigned long u, v; /* Local index variables */ HDassert(fid >= 0); /* Reset the record */ /* (record's 'info' field might need to change for each record written, also) */ HDmemset(&record, 0, sizeof(record)); /* Create a dataspace for the record to add */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) return -1; /* Create datatype for appending records */ if((tid = create_symbol_datatype()) < 0) return -1; /* Get the current metadata cache configuration, and set up the corked * configuration */ mdc_config_orig.version = H5AC__CURR_CACHE_CONFIG_VERSION; if(H5Fget_mdc_config(fid, &mdc_config_orig) < 0) return -1; HDmemcpy(&mdc_config_cork, &mdc_config_orig, sizeof(mdc_config_cork)); mdc_config_cork.evictions_enabled = FALSE; mdc_config_cork.incr_mode = H5C_incr__off; mdc_config_cork.flash_incr_mode = H5C_flash_incr__off; mdc_config_cork.decr_mode = H5C_decr__off; /* Add records to random datasets, according to frequency distribution */ rec_to_flush = flush_count; for(u = 0; u < nrecords; u++) { symbol_info_t *symbol; /* Symbol to write record to */ hid_t file_sid; /* Dataset's space ID */ hid_t aid; /* Attribute ID */ /* Get a random dataset, according to the symbol distribution */ symbol = choose_dataset(); /* Cork the metadata cache, to prevent the object header from being * flushed before the data has been written */ /*if(H5Fset_mdc_config(fid, &mdc_config_cork) < 0) return(-1);*/ /* If this is the first time the dataset has been opened, extend it and * add the sequence attribute */ if(symbol->nrecords == 0) { symbol->nrecords = nrecords / 5; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) return -1; if((file_sid = H5Screate(H5S_SCALAR)) < 0) return -1; if((aid = H5Acreate2(symbol->dsid, "seq", H5T_NATIVE_ULONG, file_sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) return -1; if(H5Sclose(file_sid) < 0) return -1; } /* end if */ else if((aid = H5Aopen(symbol->dsid, "seq", H5P_DEFAULT)) < 0) return -1; /* Get the coordinate to write */ start[1] = (hsize_t)HDrandom() % symbol->nrecords; /* Set the record's ID (equal to its position) */ record.rec_id = start[1]; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(symbol->dsid)) < 0) return -1; /* Choose a random record in the dataset */ if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) return -1; /* Write record to the dataset */ if(H5Dwrite(symbol->dsid, tid, mem_sid, file_sid, H5P_DEFAULT, &record) < 0) return -1; /* Write the sequence number attribute. Since we synchronize the random * number seed, the readers will always generate the same sequence of * randomly chosen datasets and offsets. Therefore, and because of the * flush dependencies on the object header, the reader will be * guaranteed to see the written data if the sequence attribute is >=u. */ if(H5Awrite(aid, H5T_NATIVE_ULONG, &u) < 0) return -1; /* Close the attribute */ if(H5Aclose(aid) < 0) return -1; /* Uncork the metadata cache */ /*if(H5Fset_mdc_config(fid, &mdc_config_orig) < 0) return(-1);*/ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) return -1; /* Check for flushing file */ if(flush_count > 0) { /* Decrement count of records to write before flushing */ rec_to_flush--; /* Check for counter being reached */ if(0 == rec_to_flush) { /* Flush contents of file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) return -1; /* Reset flush counter */ rec_to_flush = flush_count; } /* end if */ } /* end if */ #ifdef OUT /* Busy wait, to let readers catch up */ /* If this is removed, also remove the BUSY_WAIT symbol * at the top of the file. */ dummy = 0; for(v=0; v<BUSY_WAIT; v++) dummy++; if((unsigned long)dummy != v) return -1; #endif /* OUT */ } /* end for */ /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) return -1; /* Close the datatype */ if(H5Tclose(tid) < 0) return -1; /* Emit informational message */ if(verbose) fprintf(stderr, "Closing datasets\n"); /* Close the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) if(H5Dclose(symbol_info[u][v].dsid) < 0) return -1; return 0; }