From ad18b90759cb739c0a12d25b53114fa59cc510de Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 12 Oct 2012 23:19:20 -0500 Subject: [svn-r22898] Purpose: Updates the SWMR testing - All readers/writers now consume and emit their random seeds for debugging. - Output uses unbuffered I/O for more readable output. - The random seeds are now based on a more fine-grained time measurement to ensure each reader has a different random seed. Tested on: jam --- test/swmr_addrem_writer.c | 157 ++++++++++++++++++++++++++----------------- test/swmr_common.c | 33 +++++++--- test/swmr_generator.c | 151 ++++++++++++++++++++++++++---------------- test/swmr_reader.c | 146 +++++++++++++++++++++++----------------- test/swmr_remove_reader.c | 148 ++++++++++++++++++++++++----------------- test/swmr_remove_writer.c | 149 +++++++++++++++++++++++++---------------- test/swmr_sparse_reader.c | 128 +++++++++++++++++++---------------- test/swmr_sparse_writer.c | 134 ++++++++++++++++++++----------------- test/swmr_writer.c | 165 ++++++++++++++++++++++++++++------------------ test/testswmr.sh | 83 ++++++++++++++--------- 10 files changed, 780 insertions(+), 514 deletions(-) diff --git a/test/swmr_addrem_writer.c b/test/swmr_addrem_writer.c index b175a14..b13ff3e 100644 --- a/test/swmr_addrem_writer.c +++ b/test/swmr_addrem_writer.c @@ -1,3 +1,20 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include + #include "swmr_common.h" #define MAX_SIZE_CHANGE 10 @@ -7,28 +24,28 @@ open_skeleton(const char *filename, unsigned verbose) { hid_t fid; /* File ID for new HDF5 file */ hid_t fapl; /* File access property list */ - hid_t sid; /* Dataspace ID */ - hsize_t dim[2]; /* Dataspace dimension */ + hid_t sid; /* Dataspace ID */ + hsize_t dim[2]; /* Dataspace dimension */ unsigned u, v; /* Local index variable */ /* Create file access property list */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) - return(-1); + return -1; #ifdef QAK -/* Increase the initial size of the metadata cache */ -{ - H5AC_cache_config_t mdc_config; - - mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; - H5Pget_mdc_config(fapl, &mdc_config); -printf("mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); -printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); - mdc_config.set_initial_size = 1; - mdc_config.initial_size = 16 * 1024 * 1024; -/* mdc_config.epoch_length = 5000; */ - H5Pset_mdc_config(fapl, &mdc_config); -} + /* Increase the initial size of the metadata cache */ + { + H5AC_cache_config_t mdc_config; + + mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; + H5Pget_mdc_config(fapl, &mdc_config); + fprintf(stderr, "mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); + fprintf(stderr, "mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); + mdc_config.set_initial_size = 1; + mdc_config.initial_size = 16 * 1024 * 1024; + /* mdc_config.epoch_length = 5000; */ + H5Pset_mdc_config(fapl, &mdc_config); + } #endif /* QAK */ #ifdef QAK @@ -37,21 +54,21 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0) - return(-1); + return -1; /* Close file access property list */ if(H5Pclose(fapl) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Opening datasets\n"); + fprintf(stderr, "Opening datasets\n"); /* Open the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) { if((symbol_info[u][v].dsid = H5Dopen2(fid, symbol_info[u][v].name, H5P_DEFAULT)) < 0) - return(-1); + return -1; if((sid = H5Dget_space(symbol_info[u][v].dsid)) < 0) return -1; if(2 != H5Sget_simple_extent_ndims(sid)) @@ -82,17 +99,17 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl /* Create a dataspace for the record to add */ if((mem_sid = H5Screate_simple(2, count, NULL)) < 0) - return(-1); + return -1; /* Create datatype for appending records */ if((tid = create_symbol_datatype()) < 0) - return(-1); + 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); + 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; @@ -110,9 +127,9 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl symbol = choose_dataset(); /* Decide whether to shrink or expand, and by how much */ - count[1] = (hsize_t)random() % (MAX_SIZE_CHANGE * 2) + 1; + count[1] = (hsize_t)random() % (MAX_SIZE_CHANGE * 2) + 1; - if(count[1] > MAX_SIZE_CHANGE) { + if(count[1] > MAX_SIZE_CHANGE) { /* Add records */ count[1] -= MAX_SIZE_CHANGE; @@ -122,7 +139,7 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl /* Set the memory space to the correct size */ if(H5Sset_extent_simple(mem_sid, 2, count, NULL) < 0) - return(-1); + return -1; /* Get the coordinates to write */ start[1] = symbol->nrecords; @@ -136,27 +153,27 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl symbol->nrecords+= count[1]; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) - return(-1); + return -1; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(symbol->dsid)) < 0) - return(-1); + return -1; /* Choose the last record in the dataset */ if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return(-1); + return -1; /* Write record to the dataset */ if(H5Dwrite(symbol->dsid, tid, mem_sid, file_sid, H5P_DEFAULT, &buf) < 0) - return(-1); + return -1; /* Uncork the metadata cache */ /*if(H5Fset_mdc_config(fid, &mdc_config_orig) < 0) - return(-1);*/ + return -1;*/ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return(-1); + return -1; } /* end if */ else { /* Shrink the dataset's dataspace */ @@ -166,7 +183,7 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl symbol->nrecords -= count[1]; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) - return(-1); + return -1; } /* end else */ /* Check for flushing file */ @@ -178,7 +195,7 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl if(0 == op_to_flush) { /* Flush contents of file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) - return(-1); + return -1; /* Reset flush counter */ op_to_flush = flush_count; @@ -188,22 +205,22 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl /* Emit informational message */ if(verbose) - printf("Closing datasets\n"); + 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 -1; - return(0); + return 0; } static void usage(void) { printf("Usage error!\n"); - printf("Usage: swmr_addrem_writer [-q] [-f <# of operations between flushing file contents>] <# of shrinks>\n"); + printf("Usage: swmr_addrem_writer [-q] [-f <# of operations between flushing file contents>] [-r ] <# of shrinks>\n"); printf("<# of operations between flushing file contents> should be 0 (for no flushing) or between 1 and (<# of shrinks> - 1)\n"); printf("Defaults to verbose (no '-q' given) and flushing every 1000 operations('-f 1000')\n"); exit(1); @@ -211,12 +228,14 @@ usage(void) int main(int argc, const char *argv[]) { - hid_t fid; /* File ID for file opened */ - time_t curr_time; /* Current time, for seeding random number generator */ - long nops = 0; /* # of times to grow or shrink the dataset */ - long flush_count = 1000; /* # of records to write between flushing file */ + hid_t fid; /* File ID for file opened */ + long nops = 0; /* # of times to grow or shrink the dataset */ + long flush_count = 1000; /* # of records to write between flushing file */ unsigned verbose = 1; /* Whether to emit some informational messages */ - unsigned u; /* Local index variable */ + unsigned use_seed = 0; /* Set to 1 if a seed was set on the command line */ + unsigned random_seed = 0; /* Random # seed */ + unsigned u; /* Local index variable */ + int temp; /* Parse command line options */ if(argc < 2) @@ -239,6 +258,17 @@ int main(int argc, const char *argv[]) verbose = 0; u++; break; + + /* Random # seed */ + case 'r': + use_seed = 1; + temp = atoi(argv[u + 1]); + if(temp < 0) + usage(); + else + random_seed = (unsigned)temp; + u += 2; + break; default: usage(); @@ -262,63 +292,68 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - printf("Parameters:\n"); - printf("\t# of operations between flushes = %ld\n", flush_count); - printf("\t# of operations = %ld\n", nops); + fprintf(stderr, "Parameters:\n"); + fprintf(stderr, "\t# of operations between flushes = %ld\n", flush_count); + fprintf(stderr, "\t# of operations = %ld\n", nops); } /* end if */ - /* Create randomized set of numbers */ - curr_time = time(NULL); - srandom((unsigned)curr_time); + /* Set the random seed */ + if(0 == use_seed) { + struct timeval t; + gettimeofday(&t, NULL); + random_seed = (unsigned)((t.tv_sec * 1000) + t.tv_usec); + } /* end if */ + srandom(random_seed); + /* ALWAYS emit the random seed for possible debugging */ + fprintf(stderr, "Using writer random seed: %u\n", random_seed); /* Emit informational message */ if(verbose) - printf("Generating symbol names\n"); + fprintf(stderr, "Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Opening skeleton file: %s\n", FILENAME); + fprintf(stderr, "Opening skeleton file: %s\n", FILENAME); /* Open file skeleton */ if((fid = open_skeleton(FILENAME, verbose)) < 0) { - printf("Error opening skeleton file!\n"); + fprintf(stderr, "Error opening skeleton file!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Adding and removing records\n"); + fprintf(stderr, "Adding and removing records\n"); /* Grow and shrink datasets */ if(addrem_records(fid, verbose, (unsigned long)nops, (unsigned long)flush_count) < 0) { - printf("Error adding and removing records from datasets!\n"); + fprintf(stderr, "Error adding and removing records from datasets!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Releasing symbols\n"); + fprintf(stderr, "Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - printf("Error releasing symbols!\n"); + fprintf(stderr, "Error releasing symbols!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Closing objects\n"); + fprintf(stderr, "Closing objects\n"); /* Close objects opened */ if(H5Fclose(fid) < 0) { - printf("Error closing file!\n"); + fprintf(stderr, "Error closing file!\n"); exit(1); } /* end if */ - return(0); + return 0; } - diff --git a/test/swmr_common.c b/test/swmr_common.c index 41a24ac..f857263 100644 --- a/test/swmr_common.c +++ b/test/swmr_common.c @@ -1,3 +1,18 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include "swmr_common.h" static unsigned symbol_mapping[NMAPPING] = {0, 0, 0, 0, 1, 1, 2, 3, 4}; @@ -28,21 +43,21 @@ create_symbol_datatype(void) /* Create opaque datatype to represent other information for this record */ if((opaq_type_id = H5Tcreate(H5T_OPAQUE, DTYPE_SIZE)) < 0) - return(-1); + return -1; /* Create compound datatype for symbol */ if((sym_type_id = H5Tcreate(H5T_COMPOUND, sizeof(symbol_t))) < 0) - return(-1); + return -1; /* Insert fields in symbol datatype */ if(H5Tinsert(sym_type_id, "rec_id", HOFFSET(symbol_t, rec_id), H5T_NATIVE_UINT64) < 0) - return(-1); + return -1; if(H5Tinsert(sym_type_id, "info", HOFFSET(symbol_t, info), opaq_type_id) < 0) - return(-1); + return -1; /* Close opaque datatype */ if(H5Tclose(opaq_type_id) < 0) - return(-1); + return -1; return(sym_type_id); } /* end create_symbol_datatype() */ @@ -52,7 +67,7 @@ generate_name(char *name_buf, unsigned level, unsigned count) { sprintf(name_buf, "%u-%04u", level, count); - return(0); + return 0; } /* end generate_name() */ int @@ -70,10 +85,10 @@ generate_symbols(void) strcpy(symbol_info[u][v].name, name_buf); symbol_info[u][v].dsid = -1; symbol_info[u][v].nrecords = 0; - } /* end for */ + } /* end for */ } /* end for */ - return(0); + return 0; } /* end generate_symbols() */ int @@ -88,6 +103,6 @@ shutdown_symbols(void) free(symbol_info[u]); } /* end for */ - return(0); + return 0; } /* end shutdown_symbols() */ diff --git a/test/swmr_generator.c b/test/swmr_generator.c index 35cd5c6..1da536a 100644 --- a/test/swmr_generator.c +++ b/test/swmr_generator.c @@ -1,10 +1,27 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include + #include "swmr_common.h" #define CHUNK_SIZE 50 static int gen_skeleton(const char *filename, unsigned verbose, int comp_level, - const char *index_type) + const char *index_type, unsigned random_seed) { hid_t fid; /* File ID for new HDF5 file */ hid_t fcpl; /* File creation property list */ @@ -19,34 +36,33 @@ gen_skeleton(const char *filename, unsigned verbose, int comp_level, #ifdef FILLVAL_WORKS symbol_t fillval; /* Dataset fill value */ #endif /* FILLVAL_WORKS */ - unsigned seed; /* Random seed to write to root group attribute */ unsigned u, v; /* Local index variable */ /* Create file access property list */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) - return(-1); + return -1; /* Select the correct index type */ if(strcmp(index_type, "b1")) if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) - return(-1); + return -1; if(!strcmp(index_type, "b2")) max_dims[0] = H5S_UNLIMITED; #ifdef QAK -/* Increase the initial size of the metadata cache */ -{ - H5AC_cache_config_t mdc_config; - - mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; - H5Pget_mdc_config(fapl, &mdc_config); -printf("mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); -printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); - mdc_config.set_initial_size = 1; - mdc_config.initial_size = 16 * 1024 * 1024; -/* mdc_config.epoch_length = 5000; */ - H5Pset_mdc_config(fapl, &mdc_config); -} + /* Increase the initial size of the metadata cache */ + { + H5AC_cache_config_t mdc_config; + + mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; + H5Pget_mdc_config(fapl, &mdc_config); + fprintf(stderr, "mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); + fprintf(stderr, "mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); + mdc_config.set_initial_size = 1; + mdc_config.initial_size = 16 * 1024 * 1024; + /* mdc_config.epoch_length = 5000; */ + H5Pset_mdc_config(fapl, &mdc_config); + } #endif /* QAK */ #ifdef QAK @@ -59,7 +75,7 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length /* Create file creation property list */ if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) - return(-1); + return -1; #ifdef QAK H5Pset_link_phase_change(fcpl, 0, 0); @@ -67,47 +83,46 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length /* Emit informational message */ if(verbose) - printf("Creating file\n"); + fprintf(stderr, "Creating file\n"); /* Create the file */ if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0) - return(-1); + return -1; /* Close file creation property list */ if(H5Pclose(fcpl) < 0) - return(-1); + return -1; /* Close file access property list */ if(H5Pclose(fapl) < 0) - return(-1); + return -1; /* Create attribute with (shared) random number seed - for sparse test */ - seed = (unsigned)time(NULL); if((sid = H5Screate(H5S_SCALAR)) < 0) - return(-1); + return -1; if((aid = H5Acreate2(fid, "seed", H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) - return(-1); - if(H5Awrite(aid, H5T_NATIVE_UINT, &seed) < 0) - return(-1); + return -1; + if(H5Awrite(aid, H5T_NATIVE_UINT, &random_seed) < 0) + return -1; if(H5Sclose(sid) < 0) - return(-1); + return -1; /* Create datatype for creating datasets */ if((tid = create_symbol_datatype()) < 0) - return(-1); + return -1; /* Create dataspace for creating datasets */ if((sid = H5Screate_simple(2, dims, max_dims)) < 0) - return(-1); + return -1; /* Create dataset creation property list */ if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) - return(-1); + return -1; if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0) - return(-1); + return -1; if(comp_level >= 0) { if(H5Pset_deflate(dcpl, (unsigned)comp_level) < 0) - return(-1); + return -1; } /* end if */ #ifdef FILLVAL_WORKS /* Currently fill values do not work because they can bump the dataspace @@ -116,12 +131,12 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length memset(&fillval, 0, sizeof(fillval)); fillval.rec_id = (uint64_t)ULLONG_MAX; if(H5Pset_fill_value(dcpl, tid, &fillval) < 0) - return(-1); + return -1; #endif /* FILLVAL_WORKS */ /* Emit informational message */ if(verbose) - printf("Creating datasets\n"); + fprintf(stderr, "Creating datasets\n"); /* Create the datasets */ for(u = 0; u < NLEVELS; u++) @@ -131,34 +146,35 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length generate_name(name_buf, u, v); if((dsid = H5Dcreate2(fid, name_buf, tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) - return(-1); + return -1; if(H5Dclose(dsid) < 0) - return(-1); + return -1; } /* end for */ /* Emit informational message */ if(verbose) - printf("Closing objects\n"); + fprintf(stderr, "Closing objects\n"); /* Close everythign */ if(H5Pclose(dcpl) < 0) - return(-1); + return -1; if(H5Sclose(sid) < 0) - return(-1); + return -1; if(H5Tclose(tid) < 0) - return(-1); + return -1; if(H5Fclose(fid) < 0) - return(-1); + return -1; - return(0); + return 0; } /* end gen_skeleton() */ static void usage(void) { printf("Usage error!\n"); - printf("Usage: swmr_generator [-q] [-c ] [-i ]\n"); + printf("Usage: swmr_generator [-q] [-c ] [-i ] [-r ]\n"); + printf("NOTE: The random seed option is only used by the sparse test\n"); printf(" should be -1 (for no compression) or 0-9\n"); printf(" should be b1, b2, fa, or ea (fa not yet implemented)\n"); printf("Defaults to verbose (no '-q' given), no compression ('-c -1') and v1 b-tree\n"); @@ -168,10 +184,13 @@ usage(void) int main(int argc, const char *argv[]) { - int comp_level = (-1); /* Compression level (-1 is no compression) */ - unsigned verbose = 1; /* Whether to emit some informational messages */ - const char *index_type = "b1"; /* Chunk index type */ - unsigned u; /* Local index variables */ + int comp_level = -1; /* Compression level (-1 is no compression) */ + unsigned verbose = 1; /* Whether to emit some informational messages */ + const char *index_type = "b1"; /* Chunk index type */ + unsigned use_seed = 0; /* Set to 1 if a seed was set on the command line */ + unsigned random_seed = 0; /* Random # seed */ + unsigned u; /* Local index variables */ + int temp; /* Parse command line options */ if(argc > 1) { @@ -197,6 +216,17 @@ int main(int argc, const char *argv[]) u += 2; break; + /* Random # seed */ + case 'r': + use_seed = 1; + temp = atoi(argv[u + 1]); + if(temp < 0) + usage(); + else + random_seed = (unsigned)temp; + u += 2; + break; + /* Be quiet */ case 'q': verbose = 0; @@ -213,21 +243,30 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - printf("Parameters:\n"); - printf("\tcompression level = %d\n", comp_level); - printf("\tindex_type = %s\n", index_type); + fprintf(stderr, "Parameters:\n"); + fprintf(stderr, "\tcompression level = %d\n", comp_level); + fprintf(stderr, "\tindex_type = %s\n", index_type); } /* end if */ + + /* Set the random seed */ + if(0 == use_seed) { + struct timeval t; + gettimeofday(&t, NULL); + random_seed = (unsigned)((t.tv_sec * 1000) + t.tv_usec); + } /* end if */ + srandom(random_seed); + /* ALWAYS emit the random seed for possible debugging */ + fprintf(stderr, "Using generator random seed (used in sparse test only): %u\n", random_seed); /* Emit informational message */ if(verbose) - printf("Generating skeleton file: %s\n", FILENAME); + fprintf(stderr, "Generating skeleton file: %s\n", FILENAME); /* Generate file skeleton */ - if(gen_skeleton(FILENAME, verbose, comp_level, index_type) < 0) { - printf("Error generating skeleton file!\n"); + if(gen_skeleton(FILENAME, verbose, comp_level, index_type, random_seed) < 0) { + fprintf(stderr, "Error generating skeleton file!\n"); exit(1); } /* end if */ - return(0); + return 0; } - diff --git a/test/swmr_reader.c b/test/swmr_reader.c index cdfc1f9..02eaf9f 100644 --- a/test/swmr_reader.c +++ b/test/swmr_reader.c @@ -1,7 +1,24 @@ -#include "swmr_common.h" +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include +#include + +#include "swmr_common.h" -static hid_t symbol_tid = (-1); +static hid_t symbol_tid = -1; static int check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *record, @@ -14,49 +31,50 @@ check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *recor /* Open dataset for symbol */ if((dsid = H5Dopen2(fid, sym_name, H5P_DEFAULT)) < 0) - return(-1); + return -1; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(dsid)) < 0) - return(-1); + return -1; /* Get the number of elements (= records, for 1-D datasets) */ if((snpoints = H5Sget_simple_extent_npoints(file_sid)) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints); + fprintf(stderr, "Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints); /* Check if there are records for symbol */ if(snpoints > 0) { /* Choose the last record in the dataset */ start[1] = (hsize_t)(snpoints - 1); if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return(-1); + return -1; /* Read record from dataset */ record->rec_id = (uint64_t)ULLONG_MAX; if(H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0) - return(-1); + return -1; /* Verify record value */ if(record->rec_id != start[1]) { - printf("Incorrect record value!\n"); - printf("Symbol = '%s', # of records = %lld, record->rec_id = %llu\n", sym_name, (long long)snpoints, (unsigned long long)record->rec_id); - return(-1); + fprintf(stderr, "*** ERROR ***\n"); + fprintf(stderr, "Incorrect record value!\n"); + fprintf(stderr, "Symbol = '%s', # of records = %lld, record->rec_id = %llu\n", sym_name, (long long)snpoints, (unsigned long long)record->rec_id); + return -1; } /* end if */ } /* end if */ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return(-1); + return -1; /* Close dataset for symbol */ if(H5Dclose(dsid) < 0) - return(-1); + return -1; - return(0); + return 0; } /* end check_dataset() */ static int @@ -76,13 +94,13 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Emit informational message */ if(verbose) - printf("Choosing datasets\n"); + fprintf(stderr, "Choosing datasets\n"); /* Allocate space for 'common' datasets, if any */ if(ncommon > 0) { /* Allocate array to hold pointers to symbols for common datasets */ if(NULL == (sym_com = (symbol_info_t **)malloc(sizeof(symbol_info_t *) * ncommon))) - return(-1); + return -1; /* Open the common datasets */ for(v = 0; v < ncommon; v++) { @@ -95,7 +113,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Emit informational message */ if(verbose) - printf("Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name); + fprintf(stderr, "Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name); } /* end for */ } /* end if */ @@ -103,7 +121,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, if(nrandom > 0) { /* Allocate array to hold pointers to symbols for random datasets */ if(NULL == (sym_rand = (symbol_info_t **)malloc(sizeof(symbol_info_t *) * nrandom))) - return(-1); + return -1; /* Determine the random datasets */ for(v = 0; v < nrandom; v++) { @@ -111,18 +129,18 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Determine the symbol, within all symbols */ if(NULL == (sym = choose_dataset())) - return(-1); + return -1; sym_rand[v] = sym; /* Emit informational message */ if(verbose) - printf("Random symbol #%u = '%s'\n", v, sym->name); + fprintf(stderr, "Random symbol #%u = '%s'\n", v, sym->name); } /* end for */ } /* end if */ /* Create a dataspace for the record to read */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) @@ -138,23 +156,23 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Emit informational message */ if(verbose) - printf("Opening file: %s\n", filename); + fprintf(stderr, "Opening file: %s\n", filename); /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, H5P_DEFAULT)) < 0) - return(-1); + return -1; /* Check 'common' datasets, if any */ if(ncommon > 0) { /* Emit informational message */ if(verbose) - printf("Checking common symbols\n"); + fprintf(stderr, "Checking common symbols\n"); /* Iterate over common datasets */ for(v = 0; v < ncommon; v++) { /* Check common dataset */ if(check_dataset(fid, verbose, sym_com[v]->name, &record, mem_sid) < 0) - return(-1); + return -1; } /* end for */ } /* end if */ @@ -162,23 +180,23 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, if(nrandom > 0) { /* Emit informational message */ if(verbose) - printf("Checking random symbols\n"); + fprintf(stderr, "Checking random symbols\n"); /* Iterate over random datasets */ for(v = 0; v < nrandom; v++) { /* Check random dataset */ if(check_dataset(fid, verbose, sym_rand[v]->name, &record, mem_sid) < 0) - return(-1); + return -1; } /* end for */ } /* end if */ /* Emit informational message */ if(verbose) - printf("Closing file\n"); + fprintf(stderr, "Closing file\n"); /* Close the file */ if(H5Fclose(fid) < 0) - return(-1); + return -1; /* Sleep for the appropriate # of seconds */ sleep(poll_time); @@ -189,11 +207,11 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Closing datasets\n"); + fprintf(stderr, "Closing datasets\n"); /* Close 'random' datasets, if any */ if(nrandom > 0) { @@ -207,7 +225,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, free(sym_com); } /* end if */ - return(0); + return 0; } /* end read_records() */ static void @@ -221,13 +239,15 @@ usage(void) int main(int argc, const char *argv[]) { - long nseconds = 0; /* # of seconds to test */ - int poll_time = 1; /* # of seconds between polling */ - int ncommon = 5; /* # of common symbols to poll */ - int nrandom = 10; /* # of random symbols to poll */ - unsigned verbose = 1; /* Whether to emit some informational messages */ - int random_seed = 0; /* Random # seed */ - unsigned u; /* Local index variables */ + long nseconds = 0; /* # of seconds to test */ + int poll_time = 1; /* # of seconds between polling */ + int ncommon = 5; /* # of common symbols to poll */ + int nrandom = 10; /* # of random symbols to poll */ + unsigned verbose = 1; /* Whether to emit some informational messages */ + unsigned use_seed = 0; /* Set to 1 if a seed was set on the command line */ + unsigned random_seed = 0; /* Random # seed */ + unsigned u; /* Local index variables */ + int temp; /* Parse command line options */ if(argc < 2) @@ -261,9 +281,12 @@ int main(int argc, const char *argv[]) /* Random # seed */ case 'r': - random_seed = atoi(argv[u + 1]); - if(random_seed < 0) + use_seed = 1; + temp = atoi(argv[u + 1]); + if(temp < 0) usage(); + else + random_seed = (unsigned)temp; u += 2; break; @@ -297,57 +320,62 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - printf("Parameters:\n"); - printf("\t# of seconds between polling = %d\n", poll_time); - printf("\t# of common symbols to poll = %d\n", ncommon); - printf("\t# of random symbols to poll = %d\n", nrandom); - printf("\t# of seconds to test = %ld\n", nseconds); + fprintf(stderr, "Parameters:\n"); + fprintf(stderr, "\t# of seconds between polling = %d\n", poll_time); + fprintf(stderr, "\t# of common symbols to poll = %d\n", ncommon); + fprintf(stderr, "\t# of random symbols to poll = %d\n", nrandom); + fprintf(stderr, "\t# of seconds to test = %ld\n", nseconds); } /* end if */ - /* Create randomized set of numbers */ - random_seed += (int)time(NULL); - srandom((unsigned)random_seed); + /* Set the random seed */ + if(0 == use_seed) { + struct timeval t; + gettimeofday(&t, NULL); + random_seed = (unsigned)((t.tv_sec * 1000) + t.tv_usec); + } /* end if */ + srandom(random_seed); + /* ALWAYS emit the random seed for possible debugging */ + fprintf(stderr, "Using reader random seed: %u\n", random_seed); /* Emit informational message */ if(verbose) - printf("Generating symbol names\n"); + fprintf(stderr, "Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) { - printf("Error generating symbol names!\n"); + fprintf(stderr, "Error generating symbol names!\n"); exit(1); } /* end if */ /* Create datatype for creating datasets */ if((symbol_tid = create_symbol_datatype()) < 0) - return(-1); + return -1; /* Reading records from datasets */ if(read_records(FILENAME, verbose, (unsigned long)nseconds, (unsigned)poll_time, (unsigned)ncommon, (unsigned)nrandom) < 0) { - printf("Error reading records from datasets!\n"); + fprintf(stderr, "Error reading records from datasets!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Releasing symbols\n"); + fprintf(stderr, "Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - printf("Error releasing symbols!\n"); + fprintf(stderr, "Error releasing symbols!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Closing objects\n"); + fprintf(stderr, "Closing objects\n"); /* Close objects created */ if(H5Tclose(symbol_tid) < 0) { - printf("Error closing symbol datatype!\n"); + fprintf(stderr, "Error closing symbol datatype!\n"); exit(1); } /* end if */ - return(0); + return 0; } - diff --git a/test/swmr_remove_reader.c b/test/swmr_remove_reader.c index 518ea4e..26c52d8 100644 --- a/test/swmr_remove_reader.c +++ b/test/swmr_remove_reader.c @@ -1,7 +1,24 @@ -#include "swmr_common.h" +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include +#include + +#include "swmr_common.h" -static hid_t symbol_tid = (-1); +static hid_t symbol_tid = -1; static int check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *record, @@ -14,19 +31,19 @@ check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *recor /* Open dataset for symbol */ if((dsid = H5Dopen2(fid, sym_name, H5P_DEFAULT)) < 0) - return(-1); + return -1; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(dsid)) < 0) - return(-1); + return -1; /* Get the number of elements (= records, for 1-D datasets) */ if((snpoints = H5Sget_simple_extent_npoints(file_sid)) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints); + fprintf(stderr, "Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints); /* Check if there are records for symbol */ if(snpoints > 0) { @@ -36,7 +53,7 @@ check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *recor if(start[1] > (hsize_t)(snpoints - 1)) start[1] = (hsize_t)(snpoints - 1); if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return(-1); + return -1; /* Read record from dataset */ #ifdef FILLVAL_WORKS @@ -49,27 +66,28 @@ check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *recor record->rec_id = (uint64_t)0; #endif /* FILLVAL_WORKS */ if(H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0) - return(-1); + return -1; /* Verify record value - note that it may be the fill value, because the * chunk may be deleted before the object header has the updated * dimensions */ if(record->rec_id != start[1] && record->rec_id != (uint64_t)0) { - printf("Incorrect record value!\n"); - printf("Symbol = '%s', # of records = %lld, record->rec_id = %llx\n", sym_name, (long long)snpoints, (unsigned long long)record->rec_id); - return(-1); + fprintf(stderr, "*** ERROR ***\n"); + fprintf(stderr, "Incorrect record value!\n"); + fprintf(stderr, "Symbol = '%s', # of records = %lld, record->rec_id = %llx\n", sym_name, (long long)snpoints, (unsigned long long)record->rec_id); + return -1; } /* end if */ } /* end if */ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return(-1); + return -1; /* Close dataset for symbol */ if(H5Dclose(dsid) < 0) - return(-1); + return -1; - return(0); + return 0; } /* end check_dataset() */ static int @@ -89,13 +107,13 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Emit informational message */ if(verbose) - printf("Choosing datasets\n"); + fprintf(stderr, "Choosing datasets\n"); /* Allocate space for 'common' datasets, if any */ if(ncommon > 0) { /* Allocate array to hold pointers to symbols for common datasets */ if(NULL == (sym_com = (symbol_info_t **)malloc(sizeof(symbol_info_t *) * ncommon))) - return(-1); + return -1; /* Open the common datasets */ for(v = 0; v < ncommon; v++) { @@ -108,7 +126,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Emit informational message */ if(verbose) - printf("Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name); + fprintf(stderr, "Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name); } /* end for */ } /* end if */ @@ -116,7 +134,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, if(nrandom > 0) { /* Allocate array to hold pointers to symbols for random datasets */ if(NULL == (sym_rand = (symbol_info_t **)malloc(sizeof(symbol_info_t *) * nrandom))) - return(-1); + return -1; /* Determine the random datasets */ for(v = 0; v < nrandom; v++) { @@ -124,22 +142,22 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Determine the symbol, within all symbols */ if(NULL == (sym = choose_dataset())) - return(-1); + return -1; sym_rand[v] = sym; /* Emit informational message */ if(verbose) - printf("Random symbol #%u = '%s'\n", v, sym->name); + fprintf(stderr, "Random symbol #%u = '%s'\n", v, sym->name); } /* end for */ } /* end if */ /* Create a dataspace for the record to read */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Reading records\n"); + fprintf(stderr, "Reading records\n"); /* Get the starting time */ start_time = time(NULL); @@ -151,23 +169,23 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Emit informational message */ if(verbose) - printf("Opening file: %s\n", filename); + fprintf(stderr, "Opening file: %s\n", filename); /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, H5P_DEFAULT)) < 0) - return(-1); + return -1; /* Check 'common' datasets, if any */ if(ncommon > 0) { /* Emit informational message */ if(verbose) - printf("Checking common symbols\n"); + fprintf(stderr, "Checking common symbols\n"); /* Iterate over common datasets */ for(v = 0; v < ncommon; v++) { /* Check common dataset */ if(check_dataset(fid, verbose, sym_com[v]->name, &record, mem_sid) < 0) - return(-1); + return -1; } /* end for */ } /* end if */ @@ -175,23 +193,23 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, if(nrandom > 0) { /* Emit informational message */ if(verbose) - printf("Checking random symbols\n"); + fprintf(stderr, "Checking random symbols\n"); /* Iterate over random datasets */ for(v = 0; v < nrandom; v++) { /* Check random dataset */ if(check_dataset(fid, verbose, sym_rand[v]->name, &record, mem_sid) < 0) - return(-1); + return -1; } /* end for */ } /* end if */ /* Emit informational message */ if(verbose) - printf("Closing file\n"); + fprintf(stderr, "Closing file\n"); /* Close the file */ if(H5Fclose(fid) < 0) - return(-1); + return -1; /* Sleep for the appropriate # of seconds */ sleep(poll_time); @@ -202,11 +220,11 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Closing datasets\n"); + fprintf(stderr, "Closing datasets\n"); /* Close 'random' datasets, if any */ if(nrandom > 0) { @@ -220,7 +238,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, free(sym_com); } /* end if */ - return(0); + return 0; } /* end read_records() */ static void @@ -234,13 +252,15 @@ usage(void) int main(int argc, const char *argv[]) { - long nseconds = 0; /* # of seconds to test */ - int poll_time = 1; /* # of seconds between polling */ - int ncommon = 5; /* # of common symbols to poll */ - int nrandom = 10; /* # of random symbols to poll */ - unsigned verbose = 1; /* Whether to emit some informational messages */ - int random_seed = 0; /* Random # seed */ - unsigned u; /* Local index variables */ + long nseconds = 0; /* # of seconds to test */ + int poll_time = 1; /* # of seconds between polling */ + int ncommon = 5; /* # of common symbols to poll */ + int nrandom = 10; /* # of random symbols to poll */ + unsigned verbose = 1; /* Whether to emit some informational messages */ + unsigned use_seed = 0; /* Set to 1 if a seed was set on the command line */ + unsigned random_seed = 0; /* Random # seed */ + unsigned u; /* Local index variables */ + int temp; /* Parse command line options */ if(argc < 2) @@ -274,9 +294,12 @@ int main(int argc, const char *argv[]) /* Random # seed */ case 'r': - random_seed = atoi(argv[u + 1]); - if(random_seed < 0) + use_seed = 1; + temp = atoi(argv[u + 1]); + if(temp < 0) usage(); + else + random_seed = (unsigned)temp; u += 2; break; @@ -310,57 +333,62 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - printf("Parameters:\n"); - printf("\t# of seconds between polling = %d\n", poll_time); - printf("\t# of common symbols to poll = %d\n", ncommon); - printf("\t# of random symbols to poll = %d\n", nrandom); - printf("\t# of seconds to test = %ld\n", nseconds); + fprintf(stderr, "Parameters:\n"); + fprintf(stderr, "\t# of seconds between polling = %d\n", poll_time); + fprintf(stderr, "\t# of common symbols to poll = %d\n", ncommon); + fprintf(stderr, "\t# of random symbols to poll = %d\n", nrandom); + fprintf(stderr, "\t# of seconds to test = %ld\n", nseconds); } /* end if */ - /* Create randomized set of numbers */ - random_seed += (int)time(NULL); - srandom((unsigned)random_seed); + /* Set the random seed */ + if(0 == use_seed) { + struct timeval t; + gettimeofday(&t, NULL); + random_seed = (unsigned)((t.tv_sec * 1000) + t.tv_usec); + } /* end if */ + srandom(random_seed); + /* ALWAYS emit the random seed for possible debugging */ + fprintf(stderr, "Using reader random seed: %u\n", random_seed); /* Emit informational message */ if(verbose) - printf("Generating symbol names\n"); + fprintf(stderr, "Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) { - printf("Error generating symbol names!\n"); + fprintf(stderr, "Error generating symbol names!\n"); exit(1); } /* end if */ /* Create datatype for creating datasets */ if((symbol_tid = create_symbol_datatype()) < 0) - return(-1); + return -1; /* Reading records from datasets */ if(read_records(FILENAME, verbose, (unsigned long)nseconds, (unsigned)poll_time, (unsigned)ncommon, (unsigned)nrandom) < 0) { - printf("Error reading records from datasets!\n"); + fprintf(stderr, "Error reading records from datasets!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Releasing symbols\n"); + fprintf(stderr, "Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - printf("Error releasing symbols!\n"); + fprintf(stderr, "Error releasing symbols!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Closing objects\n"); + fprintf(stderr, "Closing objects\n"); /* Close objects created */ if(H5Tclose(symbol_tid) < 0) { - printf("Error closing symbol datatype!\n"); + fprintf(stderr, "Error closing symbol datatype!\n"); exit(1); } /* end if */ - return(0); + return 0; } - diff --git a/test/swmr_remove_writer.c b/test/swmr_remove_writer.c index 1570438..0a9cdbb 100644 --- a/test/swmr_remove_writer.c +++ b/test/swmr_remove_writer.c @@ -1,3 +1,20 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include + #include "swmr_common.h" #define MAX_REMOVE_SIZE 10 @@ -7,28 +24,28 @@ open_skeleton(const char *filename, unsigned verbose) { hid_t fid; /* File ID for new HDF5 file */ hid_t fapl; /* File access property list */ - hid_t sid; /* Dataspace ID */ + hid_t sid; /* Dataspace ID */ hsize_t dim[2]; /* Dataspace dimensions */ unsigned u, v; /* Local index variable */ /* Create file access property list */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) - return(-1); + return -1; #ifdef QAK /* Increase the initial size of the metadata cache */ -{ - H5AC_cache_config_t mdc_config; - - mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; - H5Pget_mdc_config(fapl, &mdc_config); -printf("mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); -printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); - mdc_config.set_initial_size = 1; - mdc_config.initial_size = 16 * 1024 * 1024; -/* mdc_config.epoch_length = 5000; */ - H5Pset_mdc_config(fapl, &mdc_config); -} + { + H5AC_cache_config_t mdc_config; + + mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; + H5Pget_mdc_config(fapl, &mdc_config); + fprintf(stderr, "mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); + fprintf(stderr, "mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); + mdc_config.set_initial_size = 1; + mdc_config.initial_size = 16 * 1024 * 1024; + /* mdc_config.epoch_length = 5000; */ + H5Pset_mdc_config(fapl, &mdc_config); + } #endif /* QAK */ #ifdef QAK @@ -37,21 +54,21 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0) - return(-1); + return -1; /* Close file access property list */ if(H5Pclose(fapl) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Opening datasets\n"); + fprintf(stderr, "Opening datasets\n"); /* Open the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) { if((symbol_info[u][v].dsid = H5Dopen2(fid, symbol_info[u][v].name, H5P_DEFAULT)) < 0) - return(-1); + return -1; if((sid = H5Dget_space(symbol_info[u][v].dsid)) < 0) return -1; if(2 != H5Sget_simple_extent_ndims(sid)) @@ -61,7 +78,7 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length symbol_info[u][v].nrecords = dim[1]; } /* end for */ - return(fid); + return fid; } static int @@ -75,20 +92,20 @@ remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks, unsigned lon shrink_to_flush = flush_count; for(u = 0; u < nshrinks; u++) { symbol_info_t *symbol; /* Symbol to remove record from */ - hsize_t remove_size; /* Size to reduce dataset dimension by */ + hsize_t remove_size; /* Size to reduce dataset dimension by */ /* Get a random dataset, according to the symbol distribution */ symbol = choose_dataset(); - /* Shrink the dataset's dataspace */ - remove_size = (hsize_t)random() % MAX_REMOVE_SIZE + 1; - if(remove_size > symbol->nrecords) - symbol->nrecords = 0; - else - symbol->nrecords -= remove_size; - dim[1] = symbol->nrecords; - if(H5Dset_extent(symbol->dsid, dim) < 0) - return(-1); + /* Shrink the dataset's dataspace */ + remove_size = (hsize_t)random() % MAX_REMOVE_SIZE + 1; + if(remove_size > symbol->nrecords) + symbol->nrecords = 0; + else + symbol->nrecords -= remove_size; + dim[1] = symbol->nrecords; + if(H5Dset_extent(symbol->dsid, dim) < 0) + return -1; /* Check for flushing file */ if(flush_count > 0) { @@ -99,7 +116,7 @@ remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks, unsigned lon if(0 == shrink_to_flush) { /* Flush contents of file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) - return(-1); + return -1; /* Reset flush counter */ shrink_to_flush = flush_count; @@ -109,22 +126,22 @@ remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks, unsigned lon /* Emit informational message */ if(verbose) - printf("Closing datasets\n"); + 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 -1; - return(0); + return 0; } static void usage(void) { printf("Usage error!\n"); - printf("Usage: swmr_remove_writer [-q] [-f <# of shrinks between flushing file contents>] <# of shrinks>\n"); + printf("Usage: swmr_remove_writer [-q] [-f <# of shrinks between flushing file contents>] [-r ] <# of shrinks>\n"); printf("<# of shrinks between flushing file contents> should be 0 (for no flushing) or between 1 and (<# of shrinks> - 1)\n"); printf("Defaults to verbose (no '-q' given) and flushing every 1000 shrinks('-f 1000')\n"); exit(1); @@ -132,12 +149,14 @@ usage(void) int main(int argc, const char *argv[]) { - hid_t fid; /* File ID for file opened */ - time_t curr_time; /* Current time, for seeding random number generator */ - long nshrinks = 0; /* # of times to shrink the dataset */ - long flush_count = 1000; /* # of records to write between flushing file */ + hid_t fid; /* File ID for file opened */ + long nshrinks = 0; /* # of times to shrink the dataset */ + long flush_count = 1000; /* # of records to write between flushing file */ unsigned verbose = 1; /* Whether to emit some informational messages */ - unsigned u; /* Local index variable */ + unsigned use_seed = 0; /* Set to 1 if a seed was set on the command line */ + unsigned random_seed = 0; /* Random # seed */ + unsigned u; /* Local index variable */ + int temp; /* Parse command line options */ if(argc < 2) @@ -160,6 +179,17 @@ int main(int argc, const char *argv[]) verbose = 0; u++; break; + + /* Random # seed */ + case 'r': + use_seed = 1; + temp = atoi(argv[u + 1]); + if(temp < 0) + usage(); + else + random_seed = (unsigned)temp; + u += 2; + break; default: usage(); @@ -183,63 +213,68 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - printf("Parameters:\n"); - printf("\t# of shrinks between flushes = %ld\n", flush_count); - printf("\t# of shrinks = %ld\n", nshrinks); + fprintf(stderr, "Parameters:\n"); + fprintf(stderr, "\t# of shrinks between flushes = %ld\n", flush_count); + fprintf(stderr, "\t# of shrinks = %ld\n", nshrinks); } /* end if */ - /* Create randomized set of numbers */ - curr_time = time(NULL); - srandom((unsigned)curr_time); + /* Set the random seed */ + if(0 == use_seed) { + struct timeval t; + gettimeofday(&t, NULL); + random_seed = (unsigned)((t.tv_sec * 1000) + t.tv_usec); + } /* end if */ + srandom(random_seed); + /* ALWAYS emit the random seed for possible debugging */ + fprintf(stderr, "Using writer random seed: %u\n", random_seed); /* Emit informational message */ if(verbose) - printf("Generating symbol names\n"); + fprintf(stderr, "Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Opening skeleton file: %s\n", FILENAME); + fprintf(stderr, "Opening skeleton file: %s\n", FILENAME); /* Open file skeleton */ if((fid = open_skeleton(FILENAME, verbose)) < 0) { - printf("Error opening skeleton file!\n"); + fprintf(stderr, "Error opening skeleton file!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Removing records\n"); + fprintf(stderr, "Removing records\n"); /* Remove records from datasets */ if(remove_records(fid, verbose, (unsigned long)nshrinks, (unsigned long)flush_count) < 0) { - printf("Error removing records from datasets!\n"); + fprintf(stderr, "Error removing records from datasets!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Releasing symbols\n"); + fprintf(stderr, "Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - printf("Error releasing symbols!\n"); + fprintf(stderr, "Error releasing symbols!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Closing objects\n"); + fprintf(stderr, "Closing objects\n"); /* Close objects opened */ if(H5Fclose(fid) < 0) { - printf("Error closing file!\n"); + fprintf(stderr, "Error closing file!\n"); exit(1); } /* end if */ - return(0); + return 0; } - diff --git a/test/swmr_sparse_reader.c b/test/swmr_sparse_reader.c index eff199b..052e8c5 100644 --- a/test/swmr_sparse_reader.c +++ b/test/swmr_sparse_reader.c @@ -1,3 +1,18 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include "swmr_common.h" #include @@ -15,21 +30,21 @@ check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t /* Open dataset for symbol */ if((dsid = H5Dopen2(fid, symbol->name, H5P_DEFAULT)) < 0) - return(-1); + return -1; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(dsid)) < 0) - return(-1); + return -1; /* Choose the random record in the dataset (will be the same as chosen by * the writer) */ start[1] = (hsize_t)random() % symbol->nrecords; if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Symbol = '%s', location = %lld\n", symbol->name, (long long)start); + fprintf(stderr, "Symbol = '%s', location = %lld\n", symbol->name, (long long)start); /* Read record from dataset */ #ifdef OHDR_DEPS_WORK @@ -43,7 +58,7 @@ check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t record->rec_id = (uint64_t)0; #endif /* OHDR_DEPS_WORK */ if(H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0) - return(-1); + return -1; /* Verify record value */ if(record->rec_id != start[1] @@ -51,20 +66,21 @@ check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t && record->rec_id != (uint64_t)0 #endif ) { - printf("Incorrect record value!\n"); - printf("Symbol = '%s', location = %lld, record->rec_id = %llu\n", symbol->name, (long long)start, (unsigned long long)record->rec_id); + fprintf(stderr, "*** ERROR ***\n"); + fprintf(stderr, "Incorrect record value!\n"); + fprintf(stderr, "Symbol = '%s', location = %lld, record->rec_id = %llu\n", symbol->name, (long long)start, (unsigned long long)record->rec_id); return(-1); } /* end if */ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return(-1); + return -1; /* Close dataset for symbol */ if(H5Dclose(dsid) < 0) - return(-1); + return -1; - return(0); + return 0; } /* end check_dataset() */ static int @@ -79,24 +95,24 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords, unsigned seed; /* Seed for random number generator */ unsigned iter_to_reopen = reopen_count; /* # of iterations until reopen */ unsigned long u; /* Local index variable */ -hid_t fapl; -fapl = H5Pcreate(H5P_FILE_ACCESS); -H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI); + hid_t fapl; + fapl = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI); /* Emit informational message */ if(verbose) - printf("Opening file: %s\n", filename); + fprintf(stderr, "Opening file: %s\n", filename); /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0) - return(-1); + return -1; /* Seed the random number generator with the attribute in the file */ if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0) - return(-1); + return -1; if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0) - return(-1); + return -1; if(H5Aclose(aid) < 0) - return(-1); + return -1; srandom(seed); /* Reset the record */ @@ -105,11 +121,11 @@ H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI); /* Create a dataspace for the record to read */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Reading records\n"); + fprintf(stderr, "Reading records\n"); /* Get the starting time */ start_time = time(NULL); @@ -131,16 +147,16 @@ H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI); do { /* Check if sequence attribute exists */ if((attr_exists = H5Aexists_by_name(fid, symbol->name, "seq", H5P_DEFAULT)) < 0) - return(-1); + return -1; if(attr_exists) { /* Read sequence number attribute */ if((aid = H5Aopen_by_name(fid, symbol->name, "seq", H5P_DEFAULT, H5P_DEFAULT)) < 0) - return(-1); + return -1; if(H5Aread(aid, H5T_NATIVE_ULONG, &file_u) < 0) - return(-1); + return -1; if(H5Aclose(aid) < 0) - return(-1); + return -1; /* Check if sequence number is at least u - if so, this should * guarantee that this record has been written */ @@ -150,8 +166,8 @@ H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI); /* Check for timeout */ if(time(NULL) >= (time_t)(start_time + (time_t)TIMEOUT)) { - printf("Reader timed out\n"); - return(-1); + fprintf(stderr, "Reader timed out\n"); + return -1; } /* end if */ /* Pause */ @@ -159,52 +175,52 @@ H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI); /* Reopen the file */ if(H5Fclose(fid) < 0) - return(-1); + return -1; if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0) - return(-1); + return -1; iter_to_reopen = reopen_count; } while(1); /* Emit informational message */ if(verbose) - printf("Checking dataset %lu\n", u); + fprintf(stderr, "Checking dataset %lu\n", u); /* Check dataset */ if(check_dataset(fid, verbose, symbol, &record, mem_sid) < 0) - return(-1); + return -1; /* Check for reopen */ iter_to_reopen--; if(iter_to_reopen == 0) { /* Emit informational message */ if(verbose) - printf("Reopening file: %s\n", filename); + fprintf(stderr, "Reopening file: %s\n", filename); /* Reopen the file */ if(H5Fclose(fid) < 0) - return(-1); + return -1; if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0) - return(-1); + return -1; iter_to_reopen = reopen_count; } /* end if */ } /* end while */ /* Close file */ if(H5Fclose(fid) < 0) - return(-1); + return -1; /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) - return(-1); + return -1; - return(0); + return 0; } /* end read_records() */ static void usage(void) { printf("Usage error!\n"); - printf("Usage: swmr_sparse_reader [-q] [-s <# of seconds to wait for writer>] [-r <# of reads between reopens>] <# of records>\n"); + printf("Usage: swmr_sparse_reader [-q] [-s <# of seconds to wait for writer>] [-n <# of reads between reopens>] <# of records>\n"); printf("Defaults to verbose (no '-q' given), 1 second wait ('-s 1') and 1 read between reopens ('-r 1')\n"); printf("Note that the # of records *must* be the same as that supplied to swmr_sparse_writer\n"); exit(1); @@ -212,11 +228,11 @@ usage(void) int main(int argc, const char *argv[]) { - long nrecords = 0; /* # of records to read */ - int poll_time = 1; /* # of seconds to sleep when waiting for writer */ - int reopen_count = 1; /* # of reads between reopens */ - unsigned verbose = 1; /* Whether to emit some informational messages */ - unsigned u; /* Local index variables */ + long nrecords = 0; /* # of records to read */ + int poll_time = 1; /* # of seconds to sleep when waiting for writer */ + int reopen_count = 1; /* # of reads between reopens */ + unsigned verbose = 1; /* Whether to emit some informational messages */ + unsigned u; /* Local index variables */ /* Parse command line options */ if(argc < 2) @@ -227,7 +243,7 @@ int main(int argc, const char *argv[]) if(argv[u][0] == '-') { switch(argv[u][1]) { /* # of reads between reopens */ - case 'r': + case 'n': reopen_count = atoi(argv[u + 1]); if(reopen_count < 0) usage(); @@ -266,52 +282,52 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - printf("Parameters:\n"); - printf("\t# of seconds between polling = %d\n", poll_time); - printf("\t# of reads between reopens = %d\n", reopen_count); - printf("\t# of records to read = %ld\n", nrecords); + fprintf(stderr, "Parameters:\n"); + fprintf(stderr, "\t# of seconds between polling = %d\n", poll_time); + fprintf(stderr, "\t# of reads between reopens = %d\n", reopen_count); + fprintf(stderr, "\t# of records to read = %ld\n", nrecords); } /* end if */ /* Emit informational message */ if(verbose) - printf("Generating symbol names\n"); + fprintf(stderr, "Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) { - printf("Error generating symbol names!\n"); + fprintf(stderr, "Error generating symbol names!\n"); exit(1); } /* end if */ /* Create datatype for creating datasets */ if((symbol_tid = create_symbol_datatype()) < 0) - return(-1); + return -1; /* Reading records from datasets */ if(read_records(FILENAME, verbose, (unsigned long) nrecords, (unsigned)poll_time, (unsigned)reopen_count) < 0) { - printf("Error reading records from datasets!\n"); + fprintf(stderr, "Error reading records from datasets!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Releasing symbols\n"); + fprintf(stderr, "Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - printf("Error releasing symbols!\n"); + fprintf(stderr, "Error releasing symbols!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Closing objects\n"); + fprintf(stderr, "Closing objects\n"); /* Close objects created */ if(H5Tclose(symbol_tid) < 0) { - printf("Error closing symbol datatype!\n"); + fprintf(stderr, "Error closing symbol datatype!\n"); exit(1); } /* end if */ - return(0); + return 0; } diff --git a/test/swmr_sparse_writer.c b/test/swmr_sparse_writer.c index 8afb538..74dbb13 100644 --- a/test/swmr_sparse_writer.c +++ b/test/swmr_sparse_writer.c @@ -1,3 +1,18 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include "swmr_common.h" #define BUSY_WAIT 100000 @@ -13,22 +28,22 @@ open_skeleton(const char *filename, unsigned verbose) /* Create file access property list */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) - return(-1); + return -1; #ifdef QAK -/* Increase the initial size of the metadata cache */ -{ - H5AC_cache_config_t mdc_config; - - mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; - H5Pget_mdc_config(fapl, &mdc_config); -printf("mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); -printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); - mdc_config.set_initial_size = 1; - mdc_config.initial_size = 16 * 1024 * 1024; -/* mdc_config.epoch_length = 5000; */ - H5Pset_mdc_config(fapl, &mdc_config); -} + /* Increase the initial size of the metadata cache */ + { + H5AC_cache_config_t mdc_config; + + mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; + H5Pget_mdc_config(fapl, &mdc_config); + fprintf(stderr, "mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); + fprintf(stderr,"mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); + mdc_config.set_initial_size = 1; + mdc_config.initial_size = 16 * 1024 * 1024; + /* mdc_config.epoch_length = 5000; */ + H5Pset_mdc_config(fapl, &mdc_config); + } #endif /* QAK */ #ifdef QAK @@ -37,11 +52,11 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0) - return(-1); + return -1; /* Close file access property list */ if(H5Pclose(fapl) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) @@ -49,11 +64,11 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length /* Seed the random number generator with the attribute in the file */ if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0) - return(-1); + return -1; if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0) - return(-1); + return -1; if(H5Aclose(aid) < 0) - return(-1); + return -1; srandom(seed); /* Open the datasets */ @@ -64,7 +79,7 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length symbol_info[u][v].nrecords = 0; } /* end for */ - return(fid); + return fid; } static int @@ -87,17 +102,17 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f /* Create a dataspace for the record to add */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) - return(-1); + return -1; /* Create datatype for appending records */ if((tid = create_symbol_datatype()) < 0) - return(-1); + 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); + 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; @@ -126,17 +141,17 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) - return(-1); + return -1; if((file_sid = H5Screate(H5S_SCALAR)) < 0) - return(-1); + return -1; if((aid = H5Acreate2(symbol->dsid, "seq", H5T_NATIVE_ULONG, file_sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) - return(-1); + return -1; if(H5Sclose(file_sid) < 0) - return(-1); + return -1; } /* end if */ else if((aid = H5Aopen(symbol->dsid, "seq", H5P_DEFAULT)) < 0) - return(-1); + return -1; /* Get the coordinate to write */ start[1] = (hsize_t)random() % symbol->nrecords; @@ -146,15 +161,15 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(symbol->dsid)) < 0) - return(-1); + return -1; /* Choose a random record in the dataset */ if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return(-1); + return -1; /* Write record to the dataset */ if(H5Dwrite(symbol->dsid, tid, mem_sid, file_sid, H5P_DEFAULT, &record) < 0) - return(-1); + return -1; /* Write the sequence number attribute. Since we synchronize the random * number seed, the readers will always generate the same sequence of @@ -163,11 +178,11 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f * guaranteed to see the written data if the sequence attribute is >=u. */ if(H5Awrite(aid, H5T_NATIVE_ULONG, &u) < 0) - return(-1); + return -1; /* Close the attribute */ if(H5Aclose(aid) < 0) - return(-1); + return -1; /* Uncork the metadata cache */ /*if(H5Fset_mdc_config(fid, &mdc_config_orig) < 0) @@ -175,7 +190,7 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return(-1); + return -1; /* Check for flushing file */ if(flush_count > 0) { @@ -186,7 +201,7 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f if(0 == rec_to_flush) { /* Flush contents of file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) - return(-1); + return -1; /* Reset flush counter */ rec_to_flush = flush_count; @@ -198,28 +213,28 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f for(v=0; v + #include "swmr_common.h" static hid_t @@ -9,22 +26,22 @@ open_skeleton(const char *filename, unsigned verbose) /* Create file access property list */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) - return(-1); + return -1; #ifdef QAK -/* Increase the initial size of the metadata cache */ -{ - H5AC_cache_config_t mdc_config; - - mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; - H5Pget_mdc_config(fapl, &mdc_config); -printf("mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); -printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); - mdc_config.set_initial_size = 1; - mdc_config.initial_size = 16 * 1024 * 1024; -/* mdc_config.epoch_length = 5000; */ - H5Pset_mdc_config(fapl, &mdc_config); -} + /* Increase the initial size of the metadata cache */ + { + H5AC_cache_config_t mdc_config; + + mdc_config.version = H5AC__CURR_CACHE_CONFIG_VERSION; + H5Pget_mdc_config(fapl, &mdc_config); + fprintf(stderr, "mdc_config.initial_size = %lu\n", (unsigned long)mdc_config.initial_size); + fprintf(stderr, "mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length); + mdc_config.set_initial_size = 1; + mdc_config.initial_size = 16 * 1024 * 1024; + /* mdc_config.epoch_length = 5000; */ + H5Pset_mdc_config(fapl, &mdc_config); + } #endif /* QAK */ #ifdef QAK @@ -33,21 +50,21 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0) - return(-1); + return -1; /* Close file access property list */ if(H5Pclose(fapl) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Opening datasets\n"); + fprintf(stderr, "Opening datasets\n"); /* Open the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) { if((symbol_info[u][v].dsid = H5Dopen2(fid, symbol_info[u][v].name, H5P_DEFAULT)) < 0) - return(-1); + return -1; symbol_info[u][v].nrecords = 0; } /* end for */ @@ -57,15 +74,15 @@ printf("mdc_config.epoch_length = %lu\n", (unsigned long)mdc_config.epoch_length 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 */ + 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 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 */ - unsigned long u, v; /* Local index variables */ + hsize_t dim[2] = {1, 0}; /* Dataspace dimensions */ + 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 */ + unsigned long u, v; /* Local index variables */ /* Reset the record */ /* (record's 'info' field might need to change for each record written, also) */ @@ -73,17 +90,17 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f /* Create a dataspace for the record to add */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) - return(-1); + return -1; /* Create datatype for appending records */ if((tid = create_symbol_datatype()) < 0) - return(-1); + 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); + 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; @@ -114,27 +131,27 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f symbol->nrecords++; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) - return(-1); + return -1; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(symbol->dsid)) < 0) - return(-1); + return -1; /* Choose the last record in the dataset */ if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return(-1); + return -1; /* Write record to the dataset */ if(H5Dwrite(symbol->dsid, tid, mem_sid, file_sid, H5P_DEFAULT, &record) < 0) - return(-1); + return -1; /* Uncork the metadata cache */ /*if(H5Fset_mdc_config(fid, &mdc_config_orig) < 0) - return(-1);*/ + return -1;*/ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return(-1); + return -1; /* Check for flushing file */ if(flush_count > 0) { @@ -145,7 +162,7 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f if(0 == rec_to_flush) { /* Flush contents of file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) - return(-1); + return -1; /* Reset flush counter */ rec_to_flush = flush_count; @@ -155,30 +172,30 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) - return(-1); + return -1; /* Close the datatype */ if(H5Tclose(tid) < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Closing datasets\n"); + 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 -1; - return(0); + return 0; } static void usage(void) { printf("Usage error!\n"); - printf("Usage: swmr_writer [-q] [-f <# of records to write between flushing file contents>] <# of records>\n"); + printf("Usage: swmr_writer [-q] [-f <# of records to write between flushing file contents>] [-r ] <# of records>\n"); printf("<# of records to write between flushing file contents> should be 0 (for no flushing) or between 1 and (<# of records> - 1)\n"); printf("Defaults to verbose (no '-q' given) and flushing every 10000 records('-f 10000')\n"); exit(1); @@ -186,12 +203,14 @@ usage(void) int main(int argc, const char *argv[]) { - hid_t fid; /* File ID for file opened */ - time_t curr_time; /* Current time, for seeding random number generator */ - long nrecords = 0; /* # of records to append */ - long flush_count = 10000; /* # of records to write between flushing file */ + hid_t fid; /* File ID for file opened */ + long nrecords = 0; /* # of records to append */ + long flush_count = 10000; /* # of records to write between flushing file */ unsigned verbose = 1; /* Whether to emit some informational messages */ - unsigned u; /* Local index variable */ + unsigned use_seed = 0; /* Set to 1 if a seed was set on the command line */ + unsigned random_seed = 0; /* Random # seed */ + unsigned u; /* Local index variable */ + int temp; /* Parse command line options */ if(argc < 2) @@ -214,6 +233,17 @@ int main(int argc, const char *argv[]) verbose = 0; u++; break; + + /* Random # seed */ + case 'r': + use_seed = 1; + temp = atoi(argv[u + 1]); + if(temp < 0) + usage(); + else + random_seed = (unsigned)temp; + u += 2; + break; default: usage(); @@ -237,63 +267,68 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - printf("Parameters:\n"); - printf("\t# of records between flushes = %ld\n", flush_count); - printf("\t# of records to write = %ld\n", nrecords); + fprintf(stderr, "Parameters:\n"); + fprintf(stderr, "\t# of records between flushes = %ld\n", flush_count); + fprintf(stderr, "\t# of records to write = %ld\n", nrecords); } /* end if */ - /* Create randomized set of numbers */ - curr_time = time(NULL); - srandom((unsigned)curr_time); + /* Set the random seed */ + if(0 == use_seed) { + struct timeval t; + gettimeofday(&t, NULL); + random_seed = (unsigned)((t.tv_sec * 1000) + t.tv_usec); + } /* end if */ + srandom(random_seed); + /* ALWAYS emit the random seed for possible debugging */ + fprintf(stderr, "Using writer random seed: %u\n", random_seed); /* Emit informational message */ if(verbose) - printf("Generating symbol names\n"); + fprintf(stderr, "Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) - return(-1); + return -1; /* Emit informational message */ if(verbose) - printf("Opening skeleton file: %s\n", FILENAME); + fprintf(stderr, "Opening skeleton file: %s\n", FILENAME); /* Open file skeleton */ if((fid = open_skeleton(FILENAME, verbose)) < 0) { - printf("Error opening skeleton file!\n"); + fprintf(stderr, "Error opening skeleton file!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Adding records\n"); + fprintf(stderr, "Adding records\n"); /* Append records to datasets */ if(add_records(fid, verbose, (unsigned long)nrecords, (unsigned long)flush_count) < 0) { - printf("Error appending records to datasets!\n"); + fprintf(stderr, "Error appending records to datasets!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Releasing symbols\n"); + fprintf(stderr, "Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - printf("Error releasing symbols!\n"); + fprintf(stderr, "Error releasing symbols!\n"); exit(1); } /* end if */ /* Emit informational message */ if(verbose) - printf("Closing objects\n"); + fprintf(stderr, "Closing objects\n"); /* Close objects opened */ if(H5Fclose(fid) < 0) { - printf("Error closing file!\n"); + fprintf(stderr, "Error closing file!\n"); exit(1); } /* end if */ - return(0); + return 0; } - diff --git a/test/testswmr.sh b/test/testswmr.sh index 9ca1e97..d13c6ed 100755 --- a/test/testswmr.sh +++ b/test/testswmr.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash # # Copyright by The HDF Group. # Copyright by the Board of Trustees of the University of Illinois. @@ -23,12 +23,12 @@ ## test parameters ############################################################################### -Nreaders=5 # number of readers to launch +Nreaders=5 # number of readers to launch Nrdrs_spa=3 # number of sparse readers to launch -Nrecords=200000 # number of records to write +Nrecords=200000 # number of records to write Nrecs_rem=40000 # number of times to shrink Nrecs_spa=20000 # number of records to write in the sparse test -Nsecs_add=5 # number of seconds per read interval +Nsecs_add=5 # number of seconds per read interval Nsecs_rem=3 # number of seconds per read interval Nsecs_addrem=8 # number of seconds per read interval nerrors=0 @@ -36,9 +36,9 @@ nerrors=0 ############################################################################### ## short hands and function definitions ############################################################################### -DPRINT=: # Set to "echo Debug:" for debugging printing, - # else ":" for noop. -IFDEBUG=: # Set to null to turn on debugging, else ":" for noop. +DPRINT=: # Set to "echo Debug:" for debugging printing, + # else ":" for noop. +IFDEBUG=: # Set to null to turn on debugging, else ":" for noop. # Print a line-line message left justified in a field of 70 characters # beginning with the word "Testing". @@ -63,8 +63,8 @@ while [ $# -gt 0 ]; do case "$1" in *) # unknown option echo "$0: Unknown option ($1)" - exit 1 - ;; + exit 1 + ;; esac done @@ -74,9 +74,10 @@ do # Try with and without compression for compress in "" "-c 1" do - ############################################################################### - ## Writer test - test expanding the dataset - ############################################################################### + echo + echo "###############################################################################" + echo "## Writer test - test expanding the dataset" + echo "###############################################################################" # Launch the Generator echo launch the swmr_generator @@ -88,16 +89,20 @@ do # Launch the Writer echo launch the swmr_writer - ./swmr_writer $Nrecords & + seed="" # Put -r command here + ./swmr_writer $Nrecords $seed & pid_writer=$! $DPRINT pid_writer=$pid_writer # Launch the Readers - n=0 + #declare -a seeds=( ... ) echo launch $Nreaders swmr_readers pid_readers="" + n=0 while [ $n -lt $Nreaders ]; do - ./swmr_reader -r $n $Nsecs_add & + #seed="-r ${seeds[$n]}" + seed="" + ./swmr_reader $Nsecs_add $seed & pid_readers="$pid_readers $!" n=`expr $n + 1` done @@ -130,22 +135,27 @@ do exit 1 fi - ############################################################################### - ## Remove test - test shrinking the dataset - ############################################################################### + echo + echo "###############################################################################" + echo "## Remove test - test shrinking the dataset" + echo "###############################################################################" # Launch the Remove Writer echo launch the swmr_remove_writer - ./swmr_remove_writer $Nrecs_rem & + seed="" # Put -r command here + ./swmr_remove_writer $Nrecs_rem $seed & pid_writer=$! $DPRINT pid_writer=$pid_writer # Launch the Remove Readers + #declare -a seeds=( ... ) n=0 pid_readers="" echo launch $Nreaders swmr_remove_readers while [ $n -lt $Nreaders ]; do - ./swmr_remove_reader -r $n $Nsecs_rem & + #seed="-r ${seeds[$n]}" + seed="" + ./swmr_remove_reader $Nsecs_rem $seed & pid_readers="$pid_readers $!" n=`expr $n + 1` done @@ -178,9 +188,10 @@ do exit 1 fi - ############################################################################### - ## Add/remove test - randomly grow or shrink the dataset - ############################################################################### + echo + echo "###############################################################################" + echo "## Add/remove test - randomly grow or shrink the dataset" + echo "###############################################################################" # Launch the Generator echo launch the swmr_generator @@ -192,7 +203,8 @@ do # Launch the Writer (not in parallel - just to rebuild the datasets) echo launch the swmr_writer - ./swmr_writer $Nrecords + seed="" # Put -r command here + ./swmr_writer $Nrecords $seed if test $? -ne 0; then echo writer had error nerrors=`expr $nerrors + 1` @@ -200,16 +212,20 @@ do # Launch the Add/Remove Writer echo launch the swmr_addrem_writer - ./swmr_addrem_writer $Nrecords & + seed="" # Put -r command here + ./swmr_addrem_writer $Nrecords $seed & pid_writer=$! $DPRINT pid_writer=$pid_writer # Launch the Add/Remove Readers + #declare -a seeds=( ... ) n=0 pid_readers="" echo launch $Nreaders swmr_remove_readers while [ $n -lt $Nreaders ]; do - ./swmr_remove_reader -r $n $Nsecs_addrem & + #seed="-r ${seeds[$n]}" + seed="" + ./swmr_remove_reader $Nsecs_addrem $seed & pid_readers="$pid_readers $!" n=`expr $n + 1` done @@ -242,13 +258,17 @@ do exit 1 fi - ############################################################################### - ## Sparse writer test - test writing to random locations in the dataset - ############################################################################### + echo + echo "###############################################################################" + echo "## Sparse writer test - test writing to random locations in the dataset" + echo "###############################################################################" # Launch the Generator + # NOTE: Random seed is shared between readers and writers and is + # created by the generator. echo launch the swmr_generator - ./swmr_generator $compress $index_type + seed="" # Put -r command here + ./swmr_generator $compress $index_type $seed if test $? -ne 0; then echo generator had error nerrors=`expr $nerrors + 1` @@ -256,7 +276,7 @@ do # Launch the Sparse writer echo launch the swmr_sparse_writer - nice -n 20 ./swmr_sparse_writer -q $Nrecs_spa & + nice -n 20 ./swmr_sparse_writer $Nrecs_spa & pid_writer=$! $DPRINT pid_writer=$pid_writer @@ -265,6 +285,7 @@ do pid_readers="" echo launch $Nrdrs_spa swmr_sparse_readers while [ $n -lt $Nrdrs_spa ]; do + # The sparse writer spits out a LOT of data so it's set to 'quiet' ./swmr_sparse_reader -q $Nrecs_spa & pid_readers="$pid_readers $!" n=`expr $n + 1` -- cgit v0.12