summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVailin Choi <vchoi@hdfgroup.org>2015-07-08 03:06:03 (GMT)
committerVailin Choi <vchoi@hdfgroup.org>2015-07-08 03:06:03 (GMT)
commitb1b903ac3f54bde09af3cb39b58ba40df8124984 (patch)
treecaabea60f53dc4c5fa516b2d3becab7088345163 /test
parent29bb203283e7991a7d9ec89aeb4807aed03b3b74 (diff)
downloadhdf5-b1b903ac3f54bde09af3cb39b58ba40df8124984.zip
hdf5-b1b903ac3f54bde09af3cb39b58ba40df8124984.tar.gz
hdf5-b1b903ac3f54bde09af3cb39b58ba40df8124984.tar.bz2
[svn-r27345] Bring revision #24678 from revise_chksum_retry branch to revise_chunks.
Tested on jam, koala, ostrich, moohan.
Diffstat (limited to 'test')
-rw-r--r--[-rwxr-xr-x]test/flushrefresh.c0
-rw-r--r--test/swmr_addrem_writer.c916
-rw-r--r--test/swmr_remove_reader.c1044
-rw-r--r--test/swmr_remove_writer.c748
-rw-r--r--test/swmr_sparse_reader.c902
-rw-r--r--test/swmr_sparse_writer.c908
6 files changed, 2259 insertions, 2259 deletions
diff --git a/test/flushrefresh.c b/test/flushrefresh.c
index 7686fe3..7686fe3 100755..100644
--- a/test/flushrefresh.c
+++ b/test/flushrefresh.c
diff --git a/test/swmr_addrem_writer.c b/test/swmr_addrem_writer.c
index 13b7cda..5b5aad6 100644
--- a/test/swmr_addrem_writer.c
+++ b/test/swmr_addrem_writer.c
@@ -1,458 +1,458 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * 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. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/*-------------------------------------------------------------------------
- *
- * Created: swmr_addrem_writer.c
- *
- * Purpose: Adds and removes data to a randomly selected subset of the
- * datasets in the SWMR test file.
- *
- * This program is intended to run concurrently with the
- * swmr_reader program. It is also run AFTER a sequential
- * (not concurrent!) invoking of swmr_writer so the writer
- * can dump a bunch of data into the datasets. Otherwise,
- * there wouldn't be much to shrink :)
- *
- *-------------------------------------------------------------------------
- */
-
-/***********/
-/* Headers */
-/***********/
-
-#include <assert.h>
-#include <sys/time.h>
-
-#include "swmr_common.h"
-
-/****************/
-/* Local Macros */
-/****************/
-
-/* The maximum # of records to add/remove from the dataset in one step */
-#define MAX_SIZE_CHANGE 10
-
-/********************/
-/* Local Prototypes */
-/********************/
-
-static hid_t open_skeleton(const char *filename, unsigned verbose);
-static int addrem_records(hid_t fid, unsigned verbose, unsigned long nops,
- unsigned long flush_count);
-static void usage(void);
-
-
-/*-------------------------------------------------------------------------
- * Function: open_skeleton
- *
- * Purpose: Opens the SWMR HDF5 file and datasets.
- *
- * Parameters: const char *filename
- * The filename of the SWMR HDF5 file to open
- *
- * unsigned verbose
- * Whether or not to emit verbose console messages
- *
- * Return: Success: The file ID of the opened SWMR file
- * The dataset IDs are stored in a global array
- *
- * Failure: -1
- *
- *-------------------------------------------------------------------------
- */
-static hid_t
-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 */
- unsigned u, v; /* Local index variable */
-
- assert(filename);
-
- /* Create file access property list */
- if((fapl = h5_fileaccess()) < 0)
- return -1;
-
- /* Set to use the latest library format */
- if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
- 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);
- 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
- H5Pset_fapl_log(fapl, "append.log", H5FD_LOG_ALL, (size_t)(512 * 1024 * 1024));
-#endif /* QAK */
-
- /* Open the file */
- if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0)
- return -1;
-
- /* Close file access property list */
- if(H5Pclose(fapl) < 0)
- return -1;
-
- /* Emit informational message */
- if(verbose)
- 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;
- if((sid = H5Dget_space(symbol_info[u][v].dsid)) < 0)
- return -1;
- if(2 != H5Sget_simple_extent_ndims(sid))
- return -1;
- if(H5Sget_simple_extent_dims(sid, dim, NULL) < 0)
- return -1;
- symbol_info[u][v].nrecords = dim[1];
- } /* end for */
-
- return fid;
-}
-
-
-/*-------------------------------------------------------------------------
- * 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;
-}
-
-static void
-usage(void)
-{
- printf("\n");
- printf("Usage error!\n");
- printf("\n");
- printf("Usage: swmr_addrem_writer [-q] [-f <# of operations between flushing\n");
- printf(" file contents>] [-r <random seed>] <# of operations>\n");
- printf("\n");
- printf("<# of operations between flushing file contents> should be 0 (for\n");
- printf("no flushing) or between 1 and (<# of operations> - 1).\n");
- printf("\n");
- printf("<# of operations> must be specified.\n");
- printf("\n");
- printf("Defaults to verbose (no '-q' given), flushing every 1000 operations\n");
- printf("('-f 1000'), and will generate a random seed (no -r given).\n");
- printf("\n");
- exit(1);
-}
-
-int main(int argc, const char *argv[])
-{
- 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 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)
- usage();
- if(argc > 1) {
- u = 1;
- while(u < (unsigned)argc) {
- if(argv[u][0] == '-') {
- switch(argv[u][1]) {
- /* # of records to write between flushing file */
- case 'f':
- flush_count = atol(argv[u + 1]);
- if(flush_count < 0)
- usage();
- u += 2;
- break;
-
- /* Be quiet */
- case 'q':
- 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();
- break;
- } /* end switch */
- } /* end if */
- else {
- /* Get the number of records to append */
- nops = atol(argv[u]);
- if(nops <= 0)
- usage();
-
- u++;
- } /* end else */
- } /* end while */
- } /* end if */
- if(nops <= 0)
- usage();
- if(flush_count >= nops)
- usage();
-
- /* Emit informational message */
- if(verbose) {
- 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 */
-
- /* 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)
- fprintf(stderr, "Generating symbol names\n");
-
- /* Generate dataset names */
- if(generate_symbols() < 0)
- return -1;
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Opening skeleton file: %s\n", FILENAME);
-
- /* Open file skeleton */
- if((fid = open_skeleton(FILENAME, verbose)) < 0) {
- fprintf(stderr, "Error opening skeleton file!\n");
- exit(1);
- } /* end if */
-
- /* Send a message to indicate "H5Fopen" is complete--releasing the file lock */
- h5_send_message(WRITER_MESSAGE);
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Adding and removing records\n");
-
- /* Grow and shrink datasets */
- if(addrem_records(fid, verbose, (unsigned long)nops, (unsigned long)flush_count) < 0) {
- fprintf(stderr, "Error adding and removing records from datasets!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Releasing symbols\n");
-
- /* Clean up the symbols */
- if(shutdown_symbols() < 0) {
- fprintf(stderr, "Error releasing symbols!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Closing objects\n");
-
- /* Close objects opened */
- if(H5Fclose(fid) < 0) {
- fprintf(stderr, "Error closing file!\n");
- exit(1);
- } /* end if */
-
- return 0;
-}
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*-------------------------------------------------------------------------
+ *
+ * Created: swmr_addrem_writer.c
+ *
+ * Purpose: Adds and removes data to a randomly selected subset of the
+ * datasets in the SWMR test file.
+ *
+ * This program is intended to run concurrently with the
+ * swmr_reader program. It is also run AFTER a sequential
+ * (not concurrent!) invoking of swmr_writer so the writer
+ * can dump a bunch of data into the datasets. Otherwise,
+ * there wouldn't be much to shrink :)
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/***********/
+/* Headers */
+/***********/
+
+#include <assert.h>
+#include <sys/time.h>
+
+#include "swmr_common.h"
+
+/****************/
+/* Local Macros */
+/****************/
+
+/* The maximum # of records to add/remove from the dataset in one step */
+#define MAX_SIZE_CHANGE 10
+
+/********************/
+/* Local Prototypes */
+/********************/
+
+static hid_t open_skeleton(const char *filename, unsigned verbose);
+static int addrem_records(hid_t fid, unsigned verbose, unsigned long nops,
+ unsigned long flush_count);
+static void usage(void);
+
+
+/*-------------------------------------------------------------------------
+ * Function: open_skeleton
+ *
+ * Purpose: Opens the SWMR HDF5 file and datasets.
+ *
+ * Parameters: const char *filename
+ * The filename of the SWMR HDF5 file to open
+ *
+ * unsigned verbose
+ * Whether or not to emit verbose console messages
+ *
+ * Return: Success: The file ID of the opened SWMR file
+ * The dataset IDs are stored in a global array
+ *
+ * Failure: -1
+ *
+ *-------------------------------------------------------------------------
+ */
+static hid_t
+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 */
+ unsigned u, v; /* Local index variable */
+
+ assert(filename);
+
+ /* Create file access property list */
+ if((fapl = h5_fileaccess()) < 0)
+ return -1;
+
+ /* Set to use the latest library format */
+ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
+ 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);
+ 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
+ H5Pset_fapl_log(fapl, "append.log", H5FD_LOG_ALL, (size_t)(512 * 1024 * 1024));
+#endif /* QAK */
+
+ /* Open the file */
+ if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0)
+ return -1;
+
+ /* Close file access property list */
+ if(H5Pclose(fapl) < 0)
+ return -1;
+
+ /* Emit informational message */
+ if(verbose)
+ 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;
+ if((sid = H5Dget_space(symbol_info[u][v].dsid)) < 0)
+ return -1;
+ if(2 != H5Sget_simple_extent_ndims(sid))
+ return -1;
+ if(H5Sget_simple_extent_dims(sid, dim, NULL) < 0)
+ return -1;
+ symbol_info[u][v].nrecords = dim[1];
+ } /* end for */
+
+ return fid;
+}
+
+
+/*-------------------------------------------------------------------------
+ * 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;
+}
+
+static void
+usage(void)
+{
+ printf("\n");
+ printf("Usage error!\n");
+ printf("\n");
+ printf("Usage: swmr_addrem_writer [-q] [-f <# of operations between flushing\n");
+ printf(" file contents>] [-r <random seed>] <# of operations>\n");
+ printf("\n");
+ printf("<# of operations between flushing file contents> should be 0 (for\n");
+ printf("no flushing) or between 1 and (<# of operations> - 1).\n");
+ printf("\n");
+ printf("<# of operations> must be specified.\n");
+ printf("\n");
+ printf("Defaults to verbose (no '-q' given), flushing every 1000 operations\n");
+ printf("('-f 1000'), and will generate a random seed (no -r given).\n");
+ printf("\n");
+ exit(1);
+}
+
+int main(int argc, const char *argv[])
+{
+ 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 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)
+ usage();
+ if(argc > 1) {
+ u = 1;
+ while(u < (unsigned)argc) {
+ if(argv[u][0] == '-') {
+ switch(argv[u][1]) {
+ /* # of records to write between flushing file */
+ case 'f':
+ flush_count = atol(argv[u + 1]);
+ if(flush_count < 0)
+ usage();
+ u += 2;
+ break;
+
+ /* Be quiet */
+ case 'q':
+ 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();
+ break;
+ } /* end switch */
+ } /* end if */
+ else {
+ /* Get the number of records to append */
+ nops = atol(argv[u]);
+ if(nops <= 0)
+ usage();
+
+ u++;
+ } /* end else */
+ } /* end while */
+ } /* end if */
+ if(nops <= 0)
+ usage();
+ if(flush_count >= nops)
+ usage();
+
+ /* Emit informational message */
+ if(verbose) {
+ 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 */
+
+ /* 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)
+ fprintf(stderr, "Generating symbol names\n");
+
+ /* Generate dataset names */
+ if(generate_symbols() < 0)
+ return -1;
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Opening skeleton file: %s\n", FILENAME);
+
+ /* Open file skeleton */
+ if((fid = open_skeleton(FILENAME, verbose)) < 0) {
+ fprintf(stderr, "Error opening skeleton file!\n");
+ exit(1);
+ } /* end if */
+
+ /* Send a message to indicate "H5Fopen" is complete--releasing the file lock */
+ h5_send_message(WRITER_MESSAGE);
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Adding and removing records\n");
+
+ /* Grow and shrink datasets */
+ if(addrem_records(fid, verbose, (unsigned long)nops, (unsigned long)flush_count) < 0) {
+ fprintf(stderr, "Error adding and removing records from datasets!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Releasing symbols\n");
+
+ /* Clean up the symbols */
+ if(shutdown_symbols() < 0) {
+ fprintf(stderr, "Error releasing symbols!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Closing objects\n");
+
+ /* Close objects opened */
+ if(H5Fclose(fid) < 0) {
+ fprintf(stderr, "Error closing file!\n");
+ exit(1);
+ } /* end if */
+
+ return 0;
+}
diff --git a/test/swmr_remove_reader.c b/test/swmr_remove_reader.c
index 05b580d..a273ce3 100644
--- a/test/swmr_remove_reader.c
+++ b/test/swmr_remove_reader.c
@@ -1,522 +1,522 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * 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. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/*-------------------------------------------------------------------------
- *
- * Created: swmr_remove_reader.c
- *
- * Purpose: Reads data from a randomly selected subset of the datasets
- * in the SWMR test file. Unlike the regular reader, these
- * datasets will be shrinking.
- *
- * This program is intended to run concurrently with the
- * swmr_remove_writer program.
- *
- *-------------------------------------------------------------------------
- */
-
-/***********/
-/* Headers */
-/***********/
-
-#include <assert.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#include "swmr_common.h"
-
-/*******************/
-/* Local Variables */
-/*******************/
-
-static hid_t symbol_tid = -1;
-
-/********************/
-/* Local Prototypes */
-/********************/
-
-static int check_dataset(hid_t fid, unsigned verbose, const char *sym_name,
- symbol_t *record, hid_t rec_sid);
-static int read_records(const char *filename, unsigned verbose, unsigned long nseconds,
- unsigned poll_time, unsigned ncommon, unsigned nrandom);
-static void usage(void);
-
-
-/*-------------------------------------------------------------------------
- * Function: check_dataset
- *
- * Purpose: For a given dataset, checks to make sure that the stated
- * and actual sizes are the same. If they are not, then
- * we have an inconsistent dataset due to a SWMR error.
- *
- * Parameters: hid_t fid
- * The SWMR test file's ID.
- *
- * unsigned verbose
- * Whether verbose console output is desired.
- *
- * const char *sym_name
- * The name of the dataset from which to read.
- *
- * symbol_t *record
- * Memory for the record. Must be pre-allocated.
- *
- * hid_t rec_sid
- * The memory dataspace for access. It's always the same so
- * there is no need to re-create it every time this function
- * is called.
- *
- * Return: Success: 0
- * Failure: -1
- *
- *-------------------------------------------------------------------------
- */
-static int
-check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *record,
- hid_t rec_sid)
-{
- hid_t dsid; /* Dataset ID */
- hid_t file_sid; /* Dataset's space ID */
- hssize_t snpoints; /* Number of elements in dataset */
- hsize_t start[2] = {0, 0}, count[2] = {1, 1}; /* Hyperslab selection values */
-
- assert(fid >= 0);
- assert(sym_name);
- assert(record);
- assert(rec_sid >= 0);
-
- /* Open dataset for symbol */
- if((dsid = H5Dopen2(fid, sym_name, H5P_DEFAULT)) < 0)
- return -1;
-
- /* Get the dataset's dataspace */
- if((file_sid = H5Dget_space(dsid)) < 0)
- return -1;
-
- /* Get the number of elements (= records, for 1-D datasets) */
- if((snpoints = H5Sget_simple_extent_npoints(file_sid)) < 0)
- return -1;
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints);
-
- /* Check if there are records for symbol */
- if(snpoints > 0) {
- /* Choose a random record in the dataset, choosing the last record half
- * the time */
- start[1] = (hsize_t)(random() % (snpoints * 2));
- 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;
-
- /* Read record from dataset */
-#ifdef FILLVAL_WORKS
- /* When shrinking the dataset, we cannot guarantee that the buffer will
- * even be touched, unless there is a fill value. Since fill values do
- * not work with SWMR currently (see note in swmr_generator.c), we
- * simply initialize rec_id to 0. */
- record->rec_id = (uint64_t)ULLONG_MAX - 1;
-#else /* FILLVAL_WORKS */
- record->rec_id = (uint64_t)0;
-#endif /* FILLVAL_WORKS */
- if(H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0)
- 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) {
- 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;
-
- /* Close dataset for symbol */
- if(H5Dclose(dsid) < 0)
- return -1;
-
- return 0;
-} /* end check_dataset() */
-
-
-/*-------------------------------------------------------------------------
- * Function: read_records
- *
- * Purpose: For a given dataset, checks to make sure that the stated
- * and actual sizes are the same. If they are not, then
- * we have an inconsistent dataset due to a SWMR error.
- *
- * The "common" datasets are a random selection from among
- * the level 0 datasets. The "random" datasets are a random
- * selection from among all the file's datasets. This scheme
- * ensures that the level 0 datasets are interrogated vigorously.
- *
- * Parameters: const char *filename
- * The SWMR test file's name.
- *
- * unsigned verbose
- * Whether verbose console output is desired.
- *
- * unsigned long nseconds
- * The amount of time to read records (ns).
- *
- * unsigned poll_time
- * The amount of time to sleep (s).
- *
- * unsigned ncommon
- * The number of common/non-random datasets that will be opened.
- *
- * unsigned nrandom
- * The number of random datasets that will be opened.
- *
- * Return: Success: 0
- * Failure: -1
- *
- *-------------------------------------------------------------------------
- */
-static int
-read_records(const char *filename, unsigned verbose, unsigned long nseconds,
- unsigned poll_time, unsigned ncommon, unsigned nrandom)
-{
- time_t start_time; /* Starting time */
- time_t curr_time; /* Current time */
- symbol_info_t **sym_com = NULL; /* Pointers to array of common dataset IDs */
- symbol_info_t **sym_rand = NULL; /* Pointers to array of random dataset IDs */
- hid_t mem_sid; /* Memory dataspace ID */
- hid_t fid; /* SWMR test file ID */
- hid_t fapl; /* File access property list */
- symbol_t record; /* The record to add to the dataset */
- unsigned v; /* Local index variable */
-
- assert(filename);
- assert(nseconds != 0);
- assert(poll_time != 0);
-
- /* Reset the record */
- /* (record's 'info' field might need to change for each record written, also) */
- memset(&record, 0, sizeof(record));
-
- /* Emit informational message */
- if(verbose)
- 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;
-
- /* Open the common datasets */
- for(v = 0; v < ncommon; v++) {
- unsigned offset; /* Offset of symbol to use */
-
- /* Determine the offset of the symbol, within level 0 symbols */
- /* (level 0 symbols are the most common symbols) */
- offset = (unsigned)(random() % symbol_count[0]);
- sym_com[v] = &symbol_info[0][offset];
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name);
- } /* end for */
- } /* end if */
-
- /* Allocate space for 'random' datasets, if any */
- 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;
-
- /* Determine the random datasets */
- for(v = 0; v < nrandom; v++) {
- symbol_info_t *sym; /* Symbol to use */
-
- /* Determine the symbol, within all symbols */
- if(NULL == (sym = choose_dataset()))
- return -1;
- sym_rand[v] = sym;
-
- /* Emit informational message */
- if(verbose)
- 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;
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Reading records\n");
-
- /* Get the starting time */
- start_time = time(NULL);
- curr_time = start_time;
-
- /* Create file access property list */
- if((fapl = h5_fileaccess()) < 0)
- return -1;
-
- /* Loop over reading records until [at least] the correct # of seconds have passed */
- while(curr_time < (time_t)(start_time + (time_t)nseconds)) {
-
- /* Emit informational message */
- if(verbose)
- 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;
-
- /* Check 'common' datasets, if any */
- if(ncommon > 0) {
- /* Emit informational message */
- if(verbose)
- 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;
- memset(&record, 0, sizeof(record));
- } /* end for */
- } /* end if */
-
- /* Check 'random' datasets, if any */
- if(nrandom > 0) {
- /* Emit informational message */
- if(verbose)
- 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;
- memset(&record, 0, sizeof(record));
- } /* end for */
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Closing file\n");
-
- /* Close the file */
- if(H5Fclose(fid) < 0)
- return -1;
-
- /* Sleep for the appropriate # of seconds */
- sleep(poll_time);
-
- /* Retrieve the current time */
- curr_time = time(NULL);
- } /* end while */
-
- /* Close the fapl */
- if(H5Pclose(fapl) < 0)
- return -1;
-
- /* Close the memory dataspace */
- if(H5Sclose(mem_sid) < 0)
- return -1;
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Closing datasets\n");
-
- /* Close 'random' datasets, if any */
- if(nrandom > 0) {
- /* Release array holding dataset ID's for random datasets */
- free(sym_rand);
- } /* end if */
-
- /* Close 'common' datasets, if any */
- if(ncommon > 0) {
- /* Release array holding dataset ID's for common datasets */
- free(sym_com);
- } /* end if */
-
- return 0;
-} /* end read_records() */
-
-static void
-usage(void)
-{
- printf("\n");
- printf("Usage error!\n");
- printf("\n");
- printf("Usage: swmr_remove_reader [-q] [-s <# of seconds to sleep between\n");
- printf(" polling>] [-h <# of common symbols to poll>] [-l <# of random symbols\n");
- printf(" to poll>] [-r <random seed>] <# of seconds to test>\n");
- printf("\n");
- printf("Defaults to verbose (no '-q' given), 1 second between polling ('-s 1'),\n");
- printf("5 common symbols to poll ('-h 5'), 10 random symbols to poll ('-l 10'),\n");
- printf("and will generate a random seed (no -r given).\n");
- printf("\n");
- exit(1);
-}
-
-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 */
- 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)
- usage();
- if(argc > 1) {
- u = 1;
- while(u < (unsigned)argc) {
- if(argv[u][0] == '-') {
- switch(argv[u][1]) {
- /* # of common symbols to poll */
- case 'h':
- ncommon = atoi(argv[u + 1]);
- if(ncommon < 0)
- usage();
- u += 2;
- break;
-
- /* # of random symbols to poll */
- case 'l':
- nrandom = atoi(argv[u + 1]);
- if(nrandom < 0)
- usage();
- u += 2;
- break;
-
- /* Be quiet */
- case 'q':
- 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;
-
- /* # of seconds between polling */
- case 's':
- poll_time = atoi(argv[u + 1]);
- if(poll_time < 0)
- usage();
- u += 2;
- break;
-
- default:
- usage();
- break;
- } /* end switch */
- } /* end if */
- else {
- /* Get the number of records to append */
- nseconds = atol(argv[u]);
- if(nseconds <= 0)
- usage();
-
- u++;
- } /* end else */
- } /* end while */
- } /* end if */
- if(nseconds <= 0)
- usage();
- if(poll_time >= nseconds)
- usage();
-
- /* Emit informational message */
- if(verbose) {
- 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 */
-
- /* 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)
- fprintf(stderr, "Generating symbol names\n");
-
- /* Generate dataset names */
- if(generate_symbols() < 0) {
- 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;
-
- /* Reading records from datasets */
- if(read_records(FILENAME, verbose, (unsigned long)nseconds, (unsigned)poll_time, (unsigned)ncommon, (unsigned)nrandom) < 0) {
- fprintf(stderr, "Error reading records from datasets!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Releasing symbols\n");
-
- /* Clean up the symbols */
- if(shutdown_symbols() < 0) {
- fprintf(stderr, "Error releasing symbols!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Closing objects\n");
-
- /* Close objects created */
- if(H5Tclose(symbol_tid) < 0) {
- fprintf(stderr, "Error closing symbol datatype!\n");
- exit(1);
- } /* end if */
-
- return 0;
-}
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*-------------------------------------------------------------------------
+ *
+ * Created: swmr_remove_reader.c
+ *
+ * Purpose: Reads data from a randomly selected subset of the datasets
+ * in the SWMR test file. Unlike the regular reader, these
+ * datasets will be shrinking.
+ *
+ * This program is intended to run concurrently with the
+ * swmr_remove_writer program.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/***********/
+/* Headers */
+/***********/
+
+#include <assert.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include "swmr_common.h"
+
+/*******************/
+/* Local Variables */
+/*******************/
+
+static hid_t symbol_tid = -1;
+
+/********************/
+/* Local Prototypes */
+/********************/
+
+static int check_dataset(hid_t fid, unsigned verbose, const char *sym_name,
+ symbol_t *record, hid_t rec_sid);
+static int read_records(const char *filename, unsigned verbose, unsigned long nseconds,
+ unsigned poll_time, unsigned ncommon, unsigned nrandom);
+static void usage(void);
+
+
+/*-------------------------------------------------------------------------
+ * Function: check_dataset
+ *
+ * Purpose: For a given dataset, checks to make sure that the stated
+ * and actual sizes are the same. If they are not, then
+ * we have an inconsistent dataset due to a SWMR error.
+ *
+ * Parameters: hid_t fid
+ * The SWMR test file's ID.
+ *
+ * unsigned verbose
+ * Whether verbose console output is desired.
+ *
+ * const char *sym_name
+ * The name of the dataset from which to read.
+ *
+ * symbol_t *record
+ * Memory for the record. Must be pre-allocated.
+ *
+ * hid_t rec_sid
+ * The memory dataspace for access. It's always the same so
+ * there is no need to re-create it every time this function
+ * is called.
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *record,
+ hid_t rec_sid)
+{
+ hid_t dsid; /* Dataset ID */
+ hid_t file_sid; /* Dataset's space ID */
+ hssize_t snpoints; /* Number of elements in dataset */
+ hsize_t start[2] = {0, 0}, count[2] = {1, 1}; /* Hyperslab selection values */
+
+ assert(fid >= 0);
+ assert(sym_name);
+ assert(record);
+ assert(rec_sid >= 0);
+
+ /* Open dataset for symbol */
+ if((dsid = H5Dopen2(fid, sym_name, H5P_DEFAULT)) < 0)
+ return -1;
+
+ /* Get the dataset's dataspace */
+ if((file_sid = H5Dget_space(dsid)) < 0)
+ return -1;
+
+ /* Get the number of elements (= records, for 1-D datasets) */
+ if((snpoints = H5Sget_simple_extent_npoints(file_sid)) < 0)
+ return -1;
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints);
+
+ /* Check if there are records for symbol */
+ if(snpoints > 0) {
+ /* Choose a random record in the dataset, choosing the last record half
+ * the time */
+ start[1] = (hsize_t)(random() % (snpoints * 2));
+ 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;
+
+ /* Read record from dataset */
+#ifdef FILLVAL_WORKS
+ /* When shrinking the dataset, we cannot guarantee that the buffer will
+ * even be touched, unless there is a fill value. Since fill values do
+ * not work with SWMR currently (see note in swmr_generator.c), we
+ * simply initialize rec_id to 0. */
+ record->rec_id = (uint64_t)ULLONG_MAX - 1;
+#else /* FILLVAL_WORKS */
+ record->rec_id = (uint64_t)0;
+#endif /* FILLVAL_WORKS */
+ if(H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0)
+ 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) {
+ 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;
+
+ /* Close dataset for symbol */
+ if(H5Dclose(dsid) < 0)
+ return -1;
+
+ return 0;
+} /* end check_dataset() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: read_records
+ *
+ * Purpose: For a given dataset, checks to make sure that the stated
+ * and actual sizes are the same. If they are not, then
+ * we have an inconsistent dataset due to a SWMR error.
+ *
+ * The "common" datasets are a random selection from among
+ * the level 0 datasets. The "random" datasets are a random
+ * selection from among all the file's datasets. This scheme
+ * ensures that the level 0 datasets are interrogated vigorously.
+ *
+ * Parameters: const char *filename
+ * The SWMR test file's name.
+ *
+ * unsigned verbose
+ * Whether verbose console output is desired.
+ *
+ * unsigned long nseconds
+ * The amount of time to read records (ns).
+ *
+ * unsigned poll_time
+ * The amount of time to sleep (s).
+ *
+ * unsigned ncommon
+ * The number of common/non-random datasets that will be opened.
+ *
+ * unsigned nrandom
+ * The number of random datasets that will be opened.
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+read_records(const char *filename, unsigned verbose, unsigned long nseconds,
+ unsigned poll_time, unsigned ncommon, unsigned nrandom)
+{
+ time_t start_time; /* Starting time */
+ time_t curr_time; /* Current time */
+ symbol_info_t **sym_com = NULL; /* Pointers to array of common dataset IDs */
+ symbol_info_t **sym_rand = NULL; /* Pointers to array of random dataset IDs */
+ hid_t mem_sid; /* Memory dataspace ID */
+ hid_t fid; /* SWMR test file ID */
+ hid_t fapl; /* File access property list */
+ symbol_t record; /* The record to add to the dataset */
+ unsigned v; /* Local index variable */
+
+ assert(filename);
+ assert(nseconds != 0);
+ assert(poll_time != 0);
+
+ /* Reset the record */
+ /* (record's 'info' field might need to change for each record written, also) */
+ memset(&record, 0, sizeof(record));
+
+ /* Emit informational message */
+ if(verbose)
+ 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;
+
+ /* Open the common datasets */
+ for(v = 0; v < ncommon; v++) {
+ unsigned offset; /* Offset of symbol to use */
+
+ /* Determine the offset of the symbol, within level 0 symbols */
+ /* (level 0 symbols are the most common symbols) */
+ offset = (unsigned)(random() % symbol_count[0]);
+ sym_com[v] = &symbol_info[0][offset];
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name);
+ } /* end for */
+ } /* end if */
+
+ /* Allocate space for 'random' datasets, if any */
+ 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;
+
+ /* Determine the random datasets */
+ for(v = 0; v < nrandom; v++) {
+ symbol_info_t *sym; /* Symbol to use */
+
+ /* Determine the symbol, within all symbols */
+ if(NULL == (sym = choose_dataset()))
+ return -1;
+ sym_rand[v] = sym;
+
+ /* Emit informational message */
+ if(verbose)
+ 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;
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Reading records\n");
+
+ /* Get the starting time */
+ start_time = time(NULL);
+ curr_time = start_time;
+
+ /* Create file access property list */
+ if((fapl = h5_fileaccess()) < 0)
+ return -1;
+
+ /* Loop over reading records until [at least] the correct # of seconds have passed */
+ while(curr_time < (time_t)(start_time + (time_t)nseconds)) {
+
+ /* Emit informational message */
+ if(verbose)
+ 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;
+
+ /* Check 'common' datasets, if any */
+ if(ncommon > 0) {
+ /* Emit informational message */
+ if(verbose)
+ 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;
+ memset(&record, 0, sizeof(record));
+ } /* end for */
+ } /* end if */
+
+ /* Check 'random' datasets, if any */
+ if(nrandom > 0) {
+ /* Emit informational message */
+ if(verbose)
+ 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;
+ memset(&record, 0, sizeof(record));
+ } /* end for */
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Closing file\n");
+
+ /* Close the file */
+ if(H5Fclose(fid) < 0)
+ return -1;
+
+ /* Sleep for the appropriate # of seconds */
+ sleep(poll_time);
+
+ /* Retrieve the current time */
+ curr_time = time(NULL);
+ } /* end while */
+
+ /* Close the fapl */
+ if(H5Pclose(fapl) < 0)
+ return -1;
+
+ /* Close the memory dataspace */
+ if(H5Sclose(mem_sid) < 0)
+ return -1;
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Closing datasets\n");
+
+ /* Close 'random' datasets, if any */
+ if(nrandom > 0) {
+ /* Release array holding dataset ID's for random datasets */
+ free(sym_rand);
+ } /* end if */
+
+ /* Close 'common' datasets, if any */
+ if(ncommon > 0) {
+ /* Release array holding dataset ID's for common datasets */
+ free(sym_com);
+ } /* end if */
+
+ return 0;
+} /* end read_records() */
+
+static void
+usage(void)
+{
+ printf("\n");
+ printf("Usage error!\n");
+ printf("\n");
+ printf("Usage: swmr_remove_reader [-q] [-s <# of seconds to sleep between\n");
+ printf(" polling>] [-h <# of common symbols to poll>] [-l <# of random symbols\n");
+ printf(" to poll>] [-r <random seed>] <# of seconds to test>\n");
+ printf("\n");
+ printf("Defaults to verbose (no '-q' given), 1 second between polling ('-s 1'),\n");
+ printf("5 common symbols to poll ('-h 5'), 10 random symbols to poll ('-l 10'),\n");
+ printf("and will generate a random seed (no -r given).\n");
+ printf("\n");
+ exit(1);
+}
+
+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 */
+ 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)
+ usage();
+ if(argc > 1) {
+ u = 1;
+ while(u < (unsigned)argc) {
+ if(argv[u][0] == '-') {
+ switch(argv[u][1]) {
+ /* # of common symbols to poll */
+ case 'h':
+ ncommon = atoi(argv[u + 1]);
+ if(ncommon < 0)
+ usage();
+ u += 2;
+ break;
+
+ /* # of random symbols to poll */
+ case 'l':
+ nrandom = atoi(argv[u + 1]);
+ if(nrandom < 0)
+ usage();
+ u += 2;
+ break;
+
+ /* Be quiet */
+ case 'q':
+ 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;
+
+ /* # of seconds between polling */
+ case 's':
+ poll_time = atoi(argv[u + 1]);
+ if(poll_time < 0)
+ usage();
+ u += 2;
+ break;
+
+ default:
+ usage();
+ break;
+ } /* end switch */
+ } /* end if */
+ else {
+ /* Get the number of records to append */
+ nseconds = atol(argv[u]);
+ if(nseconds <= 0)
+ usage();
+
+ u++;
+ } /* end else */
+ } /* end while */
+ } /* end if */
+ if(nseconds <= 0)
+ usage();
+ if(poll_time >= nseconds)
+ usage();
+
+ /* Emit informational message */
+ if(verbose) {
+ 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 */
+
+ /* 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)
+ fprintf(stderr, "Generating symbol names\n");
+
+ /* Generate dataset names */
+ if(generate_symbols() < 0) {
+ 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;
+
+ /* Reading records from datasets */
+ if(read_records(FILENAME, verbose, (unsigned long)nseconds, (unsigned)poll_time, (unsigned)ncommon, (unsigned)nrandom) < 0) {
+ fprintf(stderr, "Error reading records from datasets!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Releasing symbols\n");
+
+ /* Clean up the symbols */
+ if(shutdown_symbols() < 0) {
+ fprintf(stderr, "Error releasing symbols!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Closing objects\n");
+
+ /* Close objects created */
+ if(H5Tclose(symbol_tid) < 0) {
+ fprintf(stderr, "Error closing symbol datatype!\n");
+ exit(1);
+ } /* end if */
+
+ return 0;
+}
diff --git a/test/swmr_remove_writer.c b/test/swmr_remove_writer.c
index d22f900..a31fa9a 100644
--- a/test/swmr_remove_writer.c
+++ b/test/swmr_remove_writer.c
@@ -1,374 +1,374 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * 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. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/*-------------------------------------------------------------------------
- *
- * Created: swmr_remove_writer.c
- *
- * Purpose: Removes data from a randomly selected subset of the datasets
- * in the SWMR test file.
- *
- * This program is intended to run concurrently with the
- * swmr_remove_reader program. It is also run AFTER a sequential
- * (not concurrent!) invoking of swmr_writer so the writer
- * can dump a bunch of data into the datasets. Otherwise,
- * there wouldn't be much to shrink :)
- *
- *-------------------------------------------------------------------------
- */
-
-/***********/
-/* Headers */
-/***********/
-
-#include <assert.h>
-#include <sys/time.h>
-
-#include "swmr_common.h"
-
-/****************/
-/* Local Macros */
-/****************/
-
-/* The maximum number of records to remove in one step */
-#define MAX_REMOVE_SIZE 10
-
-/********************/
-/* Local Prototypes */
-/********************/
-
-static hid_t open_skeleton(const char *filename, unsigned verbose);
-static int remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks,
- unsigned long flush_count);
-static void usage(void);
-
-
-/*-------------------------------------------------------------------------
- * Function: open_skeleton
- *
- * Purpose: Opens the SWMR HDF5 file and datasets.
- *
- * Parameters: const char *filename
- * The filename of the SWMR HDF5 file to open
- *
- * unsigned verbose
- * Whether or not to emit verbose console messages
- *
- * Return: Success: The file ID of the opened SWMR file
- * The dataset IDs are stored in a global array
- *
- * Failure: -1
- *
- *-------------------------------------------------------------------------
- */
-static hid_t
-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 dimensions */
- unsigned u, v; /* Local index variable */
-
- assert(filename);
-
- /* Create file access property list */
- if((fapl = h5_fileaccess()) < 0)
- return -1;
-
- /* Set to use the latest library format */
- if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
- 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);
- 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
- H5Pset_fapl_log(fapl, "append.log", H5FD_LOG_ALL, (size_t)(512 * 1024 * 1024));
-#endif /* QAK */
-
- /* Open the file */
- if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0)
- return -1;
-
- /* Close file access property list */
- if(H5Pclose(fapl) < 0)
- return -1;
-
- /* Emit informational message */
- if(verbose)
- 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;
- if((sid = H5Dget_space(symbol_info[u][v].dsid)) < 0)
- return -1;
- if(2 != H5Sget_simple_extent_ndims(sid))
- return -1;
- if(H5Sget_simple_extent_dims(sid, dim, NULL) < 0)
- return -1;
- symbol_info[u][v].nrecords = dim[1];
- } /* end for */
-
- return fid;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: remove_records
- *
- * Purpose: Removes a specified number of records from 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 nshrinks
- * # of records to remove from the datasets
- *
- * unsigned long flush_count
- * # of records to write before flushing the file to disk
- *
- * Return: Success: 0
- * Failure: -1
- *
- *-------------------------------------------------------------------------
- */
-static int
-remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks, unsigned long flush_count)
-{
- unsigned long shrink_to_flush; /* # of removals before flush */
- hsize_t dim[2] = {1,0}; /* Dataspace dimensions */
- unsigned long u, v; /* Local index variables */
-
- assert(fid >= 0);
-
- /* Remove records from random datasets, according to frequency distribution */
- 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 */
-
- /* 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;
-
- /* Check for flushing file */
- if(flush_count > 0) {
- /* Decrement count of records to write before flushing */
- shrink_to_flush--;
-
- /* Check for counter being reached */
- if(0 == shrink_to_flush) {
- /* Flush contents of file */
- if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
- return -1;
-
- /* Reset flush counter */
- shrink_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;
-}
-
-static void
-usage(void)
-{
- printf("\n");
- printf("Usage error!\n");
- printf("\n");
- printf("Usage: swmr_remove_writer [-q] [-f <# of shrinks between flushing\n");
- printf(" file contents>] [-r <random seed>] <# of shrinks>\n");
- printf("\n");
- printf("<# of shrinks between flushing file contents> should be 0 (for no\n");
- printf("flushing) or between 1 and (<# of shrinks> - 1)\n");
- printf("\n");
- printf("Defaults to verbose (no '-q' given), flushing every 1000 shrinks\n");
- printf("('-f 1000'), and will generate a random seed (no -r given).\n");
- printf("\n");
- exit(1);
-}
-
-int main(int argc, const char *argv[])
-{
- 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 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)
- usage();
- if(argc > 1) {
- u = 1;
- while(u < (unsigned)argc) {
- if(argv[u][0] == '-') {
- switch(argv[u][1]) {
- /* # of records to write between flushing file */
- case 'f':
- flush_count = atol(argv[u + 1]);
- if(flush_count < 0)
- usage();
- u += 2;
- break;
-
- /* Be quiet */
- case 'q':
- verbose = 0;
- u++;
- break;
-
- /* Random # seed */
- case 'r':
- use_seed = 1;
- temp = atoi(argv[u + 1]);
- random_seed = (unsigned)temp;
- u += 2;
- break;
-
- default:
- usage();
- break;
- } /* end switch */
- } /* end if */
- else {
- /* Get the number of records to append */
- nshrinks = atol(argv[u]);
- if(nshrinks <= 0)
- usage();
-
- u++;
- } /* end else */
- } /* end while */
- } /* end if */
- if(nshrinks <= 0)
- usage();
- if(flush_count >= nshrinks)
- usage();
-
- /* Emit informational message */
- if(verbose) {
- 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 */
-
- /* 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)
- fprintf(stderr, "Generating symbol names\n");
-
- /* Generate dataset names */
- if(generate_symbols() < 0)
- return -1;
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Opening skeleton file: %s\n", FILENAME);
-
- /* Open file skeleton */
- if((fid = open_skeleton(FILENAME, verbose)) < 0) {
- fprintf(stderr, "Error opening skeleton file!\n");
- exit(1);
- } /* end if */
-
- /* Send a message to indicate "H5Fopen" is complete--releasing the file lock */
- h5_send_message(WRITER_MESSAGE);
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Removing records\n");
-
- /* Remove records from datasets */
- if(remove_records(fid, verbose, (unsigned long)nshrinks, (unsigned long)flush_count) < 0) {
- fprintf(stderr, "Error removing records from datasets!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Releasing symbols\n");
-
- /* Clean up the symbols */
- if(shutdown_symbols() < 0) {
- fprintf(stderr, "Error releasing symbols!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Closing objects\n");
-
- /* Close objects opened */
- if(H5Fclose(fid) < 0) {
- fprintf(stderr, "Error closing file!\n");
- exit(1);
- } /* end if */
-
- return 0;
-}
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*-------------------------------------------------------------------------
+ *
+ * Created: swmr_remove_writer.c
+ *
+ * Purpose: Removes data from a randomly selected subset of the datasets
+ * in the SWMR test file.
+ *
+ * This program is intended to run concurrently with the
+ * swmr_remove_reader program. It is also run AFTER a sequential
+ * (not concurrent!) invoking of swmr_writer so the writer
+ * can dump a bunch of data into the datasets. Otherwise,
+ * there wouldn't be much to shrink :)
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/***********/
+/* Headers */
+/***********/
+
+#include <assert.h>
+#include <sys/time.h>
+
+#include "swmr_common.h"
+
+/****************/
+/* Local Macros */
+/****************/
+
+/* The maximum number of records to remove in one step */
+#define MAX_REMOVE_SIZE 10
+
+/********************/
+/* Local Prototypes */
+/********************/
+
+static hid_t open_skeleton(const char *filename, unsigned verbose);
+static int remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks,
+ unsigned long flush_count);
+static void usage(void);
+
+
+/*-------------------------------------------------------------------------
+ * Function: open_skeleton
+ *
+ * Purpose: Opens the SWMR HDF5 file and datasets.
+ *
+ * Parameters: const char *filename
+ * The filename of the SWMR HDF5 file to open
+ *
+ * unsigned verbose
+ * Whether or not to emit verbose console messages
+ *
+ * Return: Success: The file ID of the opened SWMR file
+ * The dataset IDs are stored in a global array
+ *
+ * Failure: -1
+ *
+ *-------------------------------------------------------------------------
+ */
+static hid_t
+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 dimensions */
+ unsigned u, v; /* Local index variable */
+
+ assert(filename);
+
+ /* Create file access property list */
+ if((fapl = h5_fileaccess()) < 0)
+ return -1;
+
+ /* Set to use the latest library format */
+ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
+ 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);
+ 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
+ H5Pset_fapl_log(fapl, "append.log", H5FD_LOG_ALL, (size_t)(512 * 1024 * 1024));
+#endif /* QAK */
+
+ /* Open the file */
+ if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0)
+ return -1;
+
+ /* Close file access property list */
+ if(H5Pclose(fapl) < 0)
+ return -1;
+
+ /* Emit informational message */
+ if(verbose)
+ 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;
+ if((sid = H5Dget_space(symbol_info[u][v].dsid)) < 0)
+ return -1;
+ if(2 != H5Sget_simple_extent_ndims(sid))
+ return -1;
+ if(H5Sget_simple_extent_dims(sid, dim, NULL) < 0)
+ return -1;
+ symbol_info[u][v].nrecords = dim[1];
+ } /* end for */
+
+ return fid;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: remove_records
+ *
+ * Purpose: Removes a specified number of records from 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 nshrinks
+ * # of records to remove from the datasets
+ *
+ * unsigned long flush_count
+ * # of records to write before flushing the file to disk
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks, unsigned long flush_count)
+{
+ unsigned long shrink_to_flush; /* # of removals before flush */
+ hsize_t dim[2] = {1,0}; /* Dataspace dimensions */
+ unsigned long u, v; /* Local index variables */
+
+ assert(fid >= 0);
+
+ /* Remove records from random datasets, according to frequency distribution */
+ 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 */
+
+ /* 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;
+
+ /* Check for flushing file */
+ if(flush_count > 0) {
+ /* Decrement count of records to write before flushing */
+ shrink_to_flush--;
+
+ /* Check for counter being reached */
+ if(0 == shrink_to_flush) {
+ /* Flush contents of file */
+ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
+ return -1;
+
+ /* Reset flush counter */
+ shrink_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;
+}
+
+static void
+usage(void)
+{
+ printf("\n");
+ printf("Usage error!\n");
+ printf("\n");
+ printf("Usage: swmr_remove_writer [-q] [-f <# of shrinks between flushing\n");
+ printf(" file contents>] [-r <random seed>] <# of shrinks>\n");
+ printf("\n");
+ printf("<# of shrinks between flushing file contents> should be 0 (for no\n");
+ printf("flushing) or between 1 and (<# of shrinks> - 1)\n");
+ printf("\n");
+ printf("Defaults to verbose (no '-q' given), flushing every 1000 shrinks\n");
+ printf("('-f 1000'), and will generate a random seed (no -r given).\n");
+ printf("\n");
+ exit(1);
+}
+
+int main(int argc, const char *argv[])
+{
+ 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 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)
+ usage();
+ if(argc > 1) {
+ u = 1;
+ while(u < (unsigned)argc) {
+ if(argv[u][0] == '-') {
+ switch(argv[u][1]) {
+ /* # of records to write between flushing file */
+ case 'f':
+ flush_count = atol(argv[u + 1]);
+ if(flush_count < 0)
+ usage();
+ u += 2;
+ break;
+
+ /* Be quiet */
+ case 'q':
+ verbose = 0;
+ u++;
+ break;
+
+ /* Random # seed */
+ case 'r':
+ use_seed = 1;
+ temp = atoi(argv[u + 1]);
+ random_seed = (unsigned)temp;
+ u += 2;
+ break;
+
+ default:
+ usage();
+ break;
+ } /* end switch */
+ } /* end if */
+ else {
+ /* Get the number of records to append */
+ nshrinks = atol(argv[u]);
+ if(nshrinks <= 0)
+ usage();
+
+ u++;
+ } /* end else */
+ } /* end while */
+ } /* end if */
+ if(nshrinks <= 0)
+ usage();
+ if(flush_count >= nshrinks)
+ usage();
+
+ /* Emit informational message */
+ if(verbose) {
+ 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 */
+
+ /* 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)
+ fprintf(stderr, "Generating symbol names\n");
+
+ /* Generate dataset names */
+ if(generate_symbols() < 0)
+ return -1;
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Opening skeleton file: %s\n", FILENAME);
+
+ /* Open file skeleton */
+ if((fid = open_skeleton(FILENAME, verbose)) < 0) {
+ fprintf(stderr, "Error opening skeleton file!\n");
+ exit(1);
+ } /* end if */
+
+ /* Send a message to indicate "H5Fopen" is complete--releasing the file lock */
+ h5_send_message(WRITER_MESSAGE);
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Removing records\n");
+
+ /* Remove records from datasets */
+ if(remove_records(fid, verbose, (unsigned long)nshrinks, (unsigned long)flush_count) < 0) {
+ fprintf(stderr, "Error removing records from datasets!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Releasing symbols\n");
+
+ /* Clean up the symbols */
+ if(shutdown_symbols() < 0) {
+ fprintf(stderr, "Error releasing symbols!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Closing objects\n");
+
+ /* Close objects opened */
+ if(H5Fclose(fid) < 0) {
+ fprintf(stderr, "Error closing file!\n");
+ exit(1);
+ } /* end if */
+
+ return 0;
+}
diff --git a/test/swmr_sparse_reader.c b/test/swmr_sparse_reader.c
index 614d7b3..c7841a9 100644
--- a/test/swmr_sparse_reader.c
+++ b/test/swmr_sparse_reader.c
@@ -1,451 +1,451 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * 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. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/*-------------------------------------------------------------------------
- *
- * Created: swmr_sparse_reader.c
- *
- * Purpose: Reads data from a randomly selected subset of the datasets
- * in the SWMR test file. Unlike the regular reader, these
- * datasets will be shrinking.
- *
- * This program is intended to run concurrently with the
- * swmr_sparse_writer program.
- *
- *-------------------------------------------------------------------------
- */
-
-/***********/
-/* Headers */
-/***********/
-
-#include <assert.h>
-#include "swmr_common.h"
-
-#include <unistd.h>
-
-/****************/
-/* Local Macros */
-/****************/
-
-#define TIMEOUT 300
-
-/*******************/
-/* Local Variables */
-/*******************/
-
-static hid_t symbol_tid = (-1);
-
-/********************/
-/* Local Prototypes */
-/********************/
-
-static int check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol,
- symbol_t *record, hid_t rec_sid);
-static int read_records(const char *filename, unsigned verbose, unsigned long nrecords,
- unsigned poll_time, unsigned reopen_count);
-static void usage(void);
-
-
-/*-------------------------------------------------------------------------
- * Function: check_dataset
- *
- * Purpose: For a given dataset, checks to make sure that the stated
- * and actual sizes are the same. If they are not, then
- * we have an inconsistent dataset due to a SWMR error.
- *
- * Parameters: hid_t fid
- * The SWMR test file's ID.
- *
- * unsigned verbose
- * Whether verbose console output is desired.
- *
- * const symbol_info_t *symbol
- * The dataset from which to read (the ID is in the struct).
- * Must be pre-allocated.
- *
- * symbol_t *record
- * Memory for the record. Must be pre-allocated.
- *
- * hid_t rec_sid
- * The memory dataspace for access. It's always the same so
- * there is no need to re-create it every time this function
- * is called.
- *
- * Return: Success: 0
- * Failure: -1
- *
- *-------------------------------------------------------------------------
- */
-static int
-check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t *record,
- hid_t rec_sid)
-{
- hid_t dsid; /* Dataset ID */
- hid_t file_sid; /* Dataset's space ID */
- hsize_t start[2] = {0, 0}; /* Hyperslab selection values */
- hsize_t count[2] = {1, 1}; /* Hyperslab selection values */
-
- assert(fid >= 0);
- assert(symbol);
- assert(record);
- assert(rec_sid >= 0);
-
- /* Open dataset for symbol */
- if((dsid = H5Dopen2(fid, symbol->name, H5P_DEFAULT)) < 0)
- return -1;
-
- /* Get the dataset's dataspace */
- if((file_sid = H5Dget_space(dsid)) < 0)
- 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;
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Symbol = '%s', location = %lld\n", symbol->name, (long long)start);
-
- /* 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;
-
- /* Verify record value */
- if(record->rec_id != start[1]) {
- 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;
-
- /* Close dataset for symbol */
- if(H5Dclose(dsid) < 0)
- return -1;
-
- return 0;
-} /* end check_dataset() */
-
-
-/*-------------------------------------------------------------------------
- * Function: read_records
- *
- * Purpose: For a given dataset, checks to make sure that the stated
- * and actual sizes are the same. If they are not, then
- * we have an inconsistent dataset due to a SWMR error.
- *
- * Parameters: const char *filename
- * The SWMR test file's name.
- *
- * unsigned verbose
- * Whether verbose console output is desired.
- *
- * unsigned long nrecords
- * The total number of records to read.
- *
- * unsigned poll_time
- * The amount of time to sleep (s).
- *
- * unsigned reopen_count
- *
- *
- * Return: Success: 0
- * Failure: -1
- *
- *-------------------------------------------------------------------------
- */
-static int
-read_records(const char *filename, unsigned verbose, unsigned long nrecords,
- unsigned poll_time, unsigned reopen_count)
-{
- hid_t fid; /* File ID */
- hid_t aid; /* Attribute ID */
- time_t start_time; /* Starting time */
- hid_t mem_sid; /* Memory dataspace ID */
- symbol_t record; /* The record to add to the dataset */
- 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;
-
- assert(filename);
- assert(poll_time != 0);
-
- /* Create file access property list */
- if((fapl = h5_fileaccess()) < 0)
- return -1;
-
- H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI);
-
- /* Emit informational message */
- if(verbose)
- 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;
-
- /* Seed the random number generator with the attribute in the file */
- if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0)
- return -1;
- if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0)
- return -1;
- if(H5Aclose(aid) < 0)
- return -1;
- srandom(seed);
-
- /* Reset the record */
- /* (record's 'info' field might need to change for each record written, also) */
- memset(&record, 0, sizeof(record));
-
- /* Create a dataspace for the record to read */
- if((mem_sid = H5Screate(H5S_SCALAR)) < 0)
- return -1;
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Reading records\n");
-
- /* Get the starting time */
- start_time = time(NULL);
-
- /* Read records */
- for(u = 0; u < nrecords; u++) {
- symbol_info_t *symbol = NULL; /* Symbol (dataset) */
- htri_t attr_exists; /* Whether the sequence number attribute exists */
- unsigned long file_u; /* Attribute sequence number (writer's "u") */
-
- /* Get a random dataset, according to the symbol distribution */
- symbol = choose_dataset();
-
- /* Fill in "nrecords" field. Note that this depends on the writer
- * using the same algorithm and "nrecords" */
- symbol->nrecords = nrecords / 5;
-
- /* Wait until we can read the dataset */
- do {
- /* Check if sequence attribute exists */
- if((attr_exists = H5Aexists_by_name(fid, symbol->name, "seq", H5P_DEFAULT)) < 0)
- 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;
- if(H5Aread(aid, H5T_NATIVE_ULONG, &file_u) < 0)
- return -1;
- if(H5Aclose(aid) < 0)
- return -1;
-
- /* Check if sequence number is at least u - if so, this should
- * guarantee that this record has been written */
- if(file_u >= u)
- break;
- } /* end if */
-
- /* Check for timeout */
- if(time(NULL) >= (time_t)(start_time + (time_t)TIMEOUT)) {
- fprintf(stderr, "Reader timed out\n");
- return -1;
- } /* end if */
-
- /* Pause */
- sleep(poll_time);
-
- /* Retrieve and print the collection of metadata read retries */
- if(print_metadata_retries_info(fid) < 0)
- fprintf(stderr, "Warning: could not obtain metadata retries info\n");
-
- /* Reopen the file */
- if(H5Fclose(fid) < 0)
- return -1;
- if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
- return -1;
- iter_to_reopen = reopen_count;
- } while(1);
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Checking dataset %lu\n", u);
-
- /* Check dataset */
- if(check_dataset(fid, verbose, symbol, &record, mem_sid) < 0)
- return -1;
- memset(&record, 0, sizeof(record));
-
- /* Check for reopen */
- iter_to_reopen--;
- if(iter_to_reopen == 0) {
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Reopening file: %s\n", filename);
-
- /* Retrieve and print the collection of metadata read retries */
- if(print_metadata_retries_info(fid) < 0)
- fprintf(stderr, "Warning: could not obtain metadata retries info\n");
-
- /* Reopen the file */
- if(H5Fclose(fid) < 0)
- return -1;
- if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
- return -1;
- iter_to_reopen = reopen_count;
- } /* end if */
- } /* end while */
-
- /* Retrieve and print the collection of metadata read retries */
- if(print_metadata_retries_info(fid) < 0)
- fprintf(stderr, "Warning: could not obtain metadata retries info\n");
-
- /* Close file */
- if(H5Fclose(fid) < 0)
- return -1;
-
- /* Close the memory dataspace */
- if(H5Sclose(mem_sid) < 0)
- return -1;
-
- return 0;
-} /* end read_records() */
-
-static void
-usage(void)
-{
- printf("\n");
- printf("Usage error!\n");
- printf("\n");
- printf("Usage: swmr_sparse_reader [-q] [-s <# of seconds to wait for writer>]\n");
- printf(" [-n <# of reads between reopens>] <# of records>\n");
- printf("\n");
- printf("Defaults to verbose (no '-q' given), 1 second wait ('-s 1') and 1 read\n");
- printf("between reopens ('-r 1')\n");
- printf("\n");
- printf("Note that the # of records *must* be the same as that supplied to\n");
- printf("swmr_sparse_writer\n");
- printf("\n");
- exit(1);
-} /* end usage() */
-
-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 */
-
- /* Parse command line options */
- if(argc < 2)
- usage();
- if(argc > 1) {
- u = 1;
- while(u < (unsigned)argc) {
- if(argv[u][0] == '-') {
- switch(argv[u][1]) {
- /* # of reads between reopens */
- case 'n':
- reopen_count = atoi(argv[u + 1]);
- if(reopen_count < 0)
- usage();
- u += 2;
- break;
-
- /* Be quiet */
- case 'q':
- verbose = 0;
- u++;
- break;
-
- /* # of seconds between polling */
- case 's':
- poll_time = atoi(argv[u + 1]);
- if(poll_time < 0)
- usage();
- u += 2;
- break;
-
- default:
- usage();
- break;
- } /* end switch */
- } /* end if */
- else {
- /* Get the number of records to read */
- nrecords = atol(argv[u]);
- if(nrecords <= 0)
- usage();
-
- u++;
- } /* end else */
- } /* end while */
- } /* end if */
-
- /* Emit informational message */
- if(verbose) {
- 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)
- fprintf(stderr, "Generating symbol names\n");
-
- /* Generate dataset names */
- if(generate_symbols() < 0) {
- 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;
-
- /* Reading records from datasets */
- if(read_records(FILENAME, verbose, (unsigned long) nrecords, (unsigned)poll_time, (unsigned)reopen_count) < 0) {
- fprintf(stderr, "Error reading records from datasets!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Releasing symbols\n");
-
- /* Clean up the symbols */
- if(shutdown_symbols() < 0) {
- fprintf(stderr, "Error releasing symbols!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Closing objects\n");
-
- /* Close objects created */
- if(H5Tclose(symbol_tid) < 0) {
- fprintf(stderr, "Error closing symbol datatype!\n");
- exit(1);
- } /* end if */
-
- return 0;
-}
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*-------------------------------------------------------------------------
+ *
+ * Created: swmr_sparse_reader.c
+ *
+ * Purpose: Reads data from a randomly selected subset of the datasets
+ * in the SWMR test file. Unlike the regular reader, these
+ * datasets will be shrinking.
+ *
+ * This program is intended to run concurrently with the
+ * swmr_sparse_writer program.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/***********/
+/* Headers */
+/***********/
+
+#include <assert.h>
+#include "swmr_common.h"
+
+#include <unistd.h>
+
+/****************/
+/* Local Macros */
+/****************/
+
+#define TIMEOUT 300
+
+/*******************/
+/* Local Variables */
+/*******************/
+
+static hid_t symbol_tid = (-1);
+
+/********************/
+/* Local Prototypes */
+/********************/
+
+static int check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol,
+ symbol_t *record, hid_t rec_sid);
+static int read_records(const char *filename, unsigned verbose, unsigned long nrecords,
+ unsigned poll_time, unsigned reopen_count);
+static void usage(void);
+
+
+/*-------------------------------------------------------------------------
+ * Function: check_dataset
+ *
+ * Purpose: For a given dataset, checks to make sure that the stated
+ * and actual sizes are the same. If they are not, then
+ * we have an inconsistent dataset due to a SWMR error.
+ *
+ * Parameters: hid_t fid
+ * The SWMR test file's ID.
+ *
+ * unsigned verbose
+ * Whether verbose console output is desired.
+ *
+ * const symbol_info_t *symbol
+ * The dataset from which to read (the ID is in the struct).
+ * Must be pre-allocated.
+ *
+ * symbol_t *record
+ * Memory for the record. Must be pre-allocated.
+ *
+ * hid_t rec_sid
+ * The memory dataspace for access. It's always the same so
+ * there is no need to re-create it every time this function
+ * is called.
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t *record,
+ hid_t rec_sid)
+{
+ hid_t dsid; /* Dataset ID */
+ hid_t file_sid; /* Dataset's space ID */
+ hsize_t start[2] = {0, 0}; /* Hyperslab selection values */
+ hsize_t count[2] = {1, 1}; /* Hyperslab selection values */
+
+ assert(fid >= 0);
+ assert(symbol);
+ assert(record);
+ assert(rec_sid >= 0);
+
+ /* Open dataset for symbol */
+ if((dsid = H5Dopen2(fid, symbol->name, H5P_DEFAULT)) < 0)
+ return -1;
+
+ /* Get the dataset's dataspace */
+ if((file_sid = H5Dget_space(dsid)) < 0)
+ 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;
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Symbol = '%s', location = %lld\n", symbol->name, (long long)start);
+
+ /* 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;
+
+ /* Verify record value */
+ if(record->rec_id != start[1]) {
+ 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;
+
+ /* Close dataset for symbol */
+ if(H5Dclose(dsid) < 0)
+ return -1;
+
+ return 0;
+} /* end check_dataset() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: read_records
+ *
+ * Purpose: For a given dataset, checks to make sure that the stated
+ * and actual sizes are the same. If they are not, then
+ * we have an inconsistent dataset due to a SWMR error.
+ *
+ * Parameters: const char *filename
+ * The SWMR test file's name.
+ *
+ * unsigned verbose
+ * Whether verbose console output is desired.
+ *
+ * unsigned long nrecords
+ * The total number of records to read.
+ *
+ * unsigned poll_time
+ * The amount of time to sleep (s).
+ *
+ * unsigned reopen_count
+ *
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+read_records(const char *filename, unsigned verbose, unsigned long nrecords,
+ unsigned poll_time, unsigned reopen_count)
+{
+ hid_t fid; /* File ID */
+ hid_t aid; /* Attribute ID */
+ time_t start_time; /* Starting time */
+ hid_t mem_sid; /* Memory dataspace ID */
+ symbol_t record; /* The record to add to the dataset */
+ 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;
+
+ assert(filename);
+ assert(poll_time != 0);
+
+ /* Create file access property list */
+ if((fapl = h5_fileaccess()) < 0)
+ return -1;
+
+ H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI);
+
+ /* Emit informational message */
+ if(verbose)
+ 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;
+
+ /* Seed the random number generator with the attribute in the file */
+ if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0)
+ return -1;
+ if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0)
+ return -1;
+ if(H5Aclose(aid) < 0)
+ return -1;
+ srandom(seed);
+
+ /* Reset the record */
+ /* (record's 'info' field might need to change for each record written, also) */
+ memset(&record, 0, sizeof(record));
+
+ /* Create a dataspace for the record to read */
+ if((mem_sid = H5Screate(H5S_SCALAR)) < 0)
+ return -1;
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Reading records\n");
+
+ /* Get the starting time */
+ start_time = time(NULL);
+
+ /* Read records */
+ for(u = 0; u < nrecords; u++) {
+ symbol_info_t *symbol = NULL; /* Symbol (dataset) */
+ htri_t attr_exists; /* Whether the sequence number attribute exists */
+ unsigned long file_u; /* Attribute sequence number (writer's "u") */
+
+ /* Get a random dataset, according to the symbol distribution */
+ symbol = choose_dataset();
+
+ /* Fill in "nrecords" field. Note that this depends on the writer
+ * using the same algorithm and "nrecords" */
+ symbol->nrecords = nrecords / 5;
+
+ /* Wait until we can read the dataset */
+ do {
+ /* Check if sequence attribute exists */
+ if((attr_exists = H5Aexists_by_name(fid, symbol->name, "seq", H5P_DEFAULT)) < 0)
+ 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;
+ if(H5Aread(aid, H5T_NATIVE_ULONG, &file_u) < 0)
+ return -1;
+ if(H5Aclose(aid) < 0)
+ return -1;
+
+ /* Check if sequence number is at least u - if so, this should
+ * guarantee that this record has been written */
+ if(file_u >= u)
+ break;
+ } /* end if */
+
+ /* Check for timeout */
+ if(time(NULL) >= (time_t)(start_time + (time_t)TIMEOUT)) {
+ fprintf(stderr, "Reader timed out\n");
+ return -1;
+ } /* end if */
+
+ /* Pause */
+ sleep(poll_time);
+
+ /* Retrieve and print the collection of metadata read retries */
+ if(print_metadata_retries_info(fid) < 0)
+ fprintf(stderr, "Warning: could not obtain metadata retries info\n");
+
+ /* Reopen the file */
+ if(H5Fclose(fid) < 0)
+ return -1;
+ if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
+ return -1;
+ iter_to_reopen = reopen_count;
+ } while(1);
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Checking dataset %lu\n", u);
+
+ /* Check dataset */
+ if(check_dataset(fid, verbose, symbol, &record, mem_sid) < 0)
+ return -1;
+ memset(&record, 0, sizeof(record));
+
+ /* Check for reopen */
+ iter_to_reopen--;
+ if(iter_to_reopen == 0) {
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Reopening file: %s\n", filename);
+
+ /* Retrieve and print the collection of metadata read retries */
+ if(print_metadata_retries_info(fid) < 0)
+ fprintf(stderr, "Warning: could not obtain metadata retries info\n");
+
+ /* Reopen the file */
+ if(H5Fclose(fid) < 0)
+ return -1;
+ if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
+ return -1;
+ iter_to_reopen = reopen_count;
+ } /* end if */
+ } /* end while */
+
+ /* Retrieve and print the collection of metadata read retries */
+ if(print_metadata_retries_info(fid) < 0)
+ fprintf(stderr, "Warning: could not obtain metadata retries info\n");
+
+ /* Close file */
+ if(H5Fclose(fid) < 0)
+ return -1;
+
+ /* Close the memory dataspace */
+ if(H5Sclose(mem_sid) < 0)
+ return -1;
+
+ return 0;
+} /* end read_records() */
+
+static void
+usage(void)
+{
+ printf("\n");
+ printf("Usage error!\n");
+ printf("\n");
+ printf("Usage: swmr_sparse_reader [-q] [-s <# of seconds to wait for writer>]\n");
+ printf(" [-n <# of reads between reopens>] <# of records>\n");
+ printf("\n");
+ printf("Defaults to verbose (no '-q' given), 1 second wait ('-s 1') and 1 read\n");
+ printf("between reopens ('-r 1')\n");
+ printf("\n");
+ printf("Note that the # of records *must* be the same as that supplied to\n");
+ printf("swmr_sparse_writer\n");
+ printf("\n");
+ exit(1);
+} /* end usage() */
+
+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 */
+
+ /* Parse command line options */
+ if(argc < 2)
+ usage();
+ if(argc > 1) {
+ u = 1;
+ while(u < (unsigned)argc) {
+ if(argv[u][0] == '-') {
+ switch(argv[u][1]) {
+ /* # of reads between reopens */
+ case 'n':
+ reopen_count = atoi(argv[u + 1]);
+ if(reopen_count < 0)
+ usage();
+ u += 2;
+ break;
+
+ /* Be quiet */
+ case 'q':
+ verbose = 0;
+ u++;
+ break;
+
+ /* # of seconds between polling */
+ case 's':
+ poll_time = atoi(argv[u + 1]);
+ if(poll_time < 0)
+ usage();
+ u += 2;
+ break;
+
+ default:
+ usage();
+ break;
+ } /* end switch */
+ } /* end if */
+ else {
+ /* Get the number of records to read */
+ nrecords = atol(argv[u]);
+ if(nrecords <= 0)
+ usage();
+
+ u++;
+ } /* end else */
+ } /* end while */
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose) {
+ 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)
+ fprintf(stderr, "Generating symbol names\n");
+
+ /* Generate dataset names */
+ if(generate_symbols() < 0) {
+ 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;
+
+ /* Reading records from datasets */
+ if(read_records(FILENAME, verbose, (unsigned long) nrecords, (unsigned)poll_time, (unsigned)reopen_count) < 0) {
+ fprintf(stderr, "Error reading records from datasets!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Releasing symbols\n");
+
+ /* Clean up the symbols */
+ if(shutdown_symbols() < 0) {
+ fprintf(stderr, "Error releasing symbols!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Closing objects\n");
+
+ /* Close objects created */
+ if(H5Tclose(symbol_tid) < 0) {
+ fprintf(stderr, "Error closing symbol datatype!\n");
+ exit(1);
+ } /* end if */
+
+ return 0;
+}
diff --git a/test/swmr_sparse_writer.c b/test/swmr_sparse_writer.c
index abcaea2..3c20c9c 100644
--- a/test/swmr_sparse_writer.c
+++ b/test/swmr_sparse_writer.c
@@ -1,454 +1,454 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * 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. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- /*-------------------------------------------------------------------------
- *
- * Created: swmr_sparse_writer.c
- *
- * Purpose: Writes data to a randomly selected subset of the datasets
- * in the SWMR test file.
- *
- * This program is intended to run concurrently with the
- * swmr_sparse_reader program.
- *
- *-------------------------------------------------------------------------
- */
-
-/***********/
-/* Headers */
-/***********/
-
-#include <assert.h>
-
-#include "swmr_common.h"
-
-/****************/
-/* Local Macros */
-/****************/
-
-#define BUSY_WAIT 100000
-
-/********************/
-/* Local Prototypes */
-/********************/
-
-static hid_t open_skeleton(const char *filename, unsigned verbose);
-static int add_records(hid_t fid, unsigned verbose, unsigned long nrecords,
- unsigned long flush_count);
-static void usage(void);
-
-
-
-/*-------------------------------------------------------------------------
- * Function: open_skeleton
- *
- * Purpose: Opens the SWMR HDF5 file and datasets.
- *
- * Parameters: const char *filename
- * The filename of the SWMR HDF5 file to open
- *
- * unsigned verbose
- * Whether or not to emit verbose console messages
- *
- * Return: Success: The file ID of the opened SWMR file
- * The dataset IDs are stored in a global array
- *
- * Failure: -1
- *
- *-------------------------------------------------------------------------
- */
-static hid_t
-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 aid; /* Attribute ID */
- unsigned seed; /* Seed for random number generator */
- unsigned u, v; /* Local index variable */
-
- assert(filename);
-
- /* Create file access property list */
- if((fapl = h5_fileaccess()) < 0)
- return -1;
-
- /* Set to use the latest library format */
- if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
- 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);
- 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
- H5Pset_fapl_log(fapl, "append.log", H5FD_LOG_ALL, (size_t)(512 * 1024 * 1024));
-#endif /* QAK */
-
- /* Open the file */
- if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0)
- return -1;
-
- /* Close file access property list */
- if(H5Pclose(fapl) < 0)
- return -1;
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Opening datasets\n");
-
- /* Seed the random number generator with the attribute in the file */
- if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0)
- return -1;
- if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0)
- return -1;
- if(H5Aclose(aid) < 0)
- return -1;
- srandom(seed);
-
- /* 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);
- symbol_info[u][v].nrecords = 0;
- } /* end for */
-
- return fid;
-}
-
-
-/*-------------------------------------------------------------------------
- * 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 */
-
- assert(fid >= 0);
-
- /* Reset the record */
- /* (record's 'info' field might need to change for each record written, also) */
- memset(&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;
- 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 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)random() % 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 */
- dummy = 0;
- for(v=0; v<BUSY_WAIT; v++)
- dummy++;
- if((unsigned long)dummy != v)
- return -1;
-#endif
- } /* 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;
-}
-
-static void
-usage(void)
-{
- printf("\n");
- printf("Usage error!\n");
- printf("\n");
- printf("Usage: swmr_sparse_writer [-q] [-f <# of records to write between\n");
- printf(" flushing file contents>] <# of records>\n");
- printf("\n");
- printf("<# of records to write between flushing file contents> should be 0\n");
- printf("(for no flushing) or between 1 and (<# of records> - 1)\n");
- printf("\n");
- printf("Defaults to verbose (no '-q' given) and flushing every 1000 records\n");
- printf("('-f 1000')\n");
- printf("\n");
- exit(1);
-}
-
-int main(int argc, const char *argv[])
-{
- hid_t fid; /* File ID for file opened */
- long nrecords = 0; /* # of records to append */
- 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 */
-
- /* Parse command line options */
- if(argc < 2)
- usage();
- if(argc > 1) {
- u = 1;
- while(u < (unsigned)argc) {
- if(argv[u][0] == '-') {
- switch(argv[u][1]) {
- /* # of records to write between flushing file */
- case 'f':
- flush_count = atol(argv[u + 1]);
- if(flush_count < 0)
- usage();
- u += 2;
- break;
-
- /* Be quiet */
- case 'q':
- verbose = 0;
- u++;
- break;
-
- default:
- usage();
- break;
- } /* end switch */
- } /* end if */
- else {
- /* Get the number of records to append */
- nrecords = atol(argv[u]);
- if(nrecords <= 0)
- usage();
-
- u++;
- } /* end else */
- } /* end while */
- } /* end if */
- if(nrecords <= 0)
- usage();
- if(flush_count >= nrecords)
- usage();
-
- /* Emit informational message */
- if(verbose) {
- 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 */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Generating symbol names\n");
-
- /* Generate dataset names */
- if(generate_symbols() < 0)
- return -1;
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Opening skeleton file: %s\n", FILENAME);
-
- /* Open file skeleton */
- if((fid = open_skeleton(FILENAME, verbose)) < 0) {
- fprintf(stderr, "Error opening skeleton file!\n");
- exit(1);
- } /* end if */
-
- /* Send a message to indicate "H5Fopen" is complete--releasing the file lock */
- h5_send_message(WRITER_MESSAGE);
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Adding records\n");
-
- /* Append records to datasets */
- if(add_records(fid, verbose, (unsigned long)nrecords, (unsigned long)flush_count) < 0) {
- fprintf(stderr, "Error appending records to datasets!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Releasing symbols\n");
-
- /* Clean up the symbols */
- if(shutdown_symbols() < 0) {
- fprintf(stderr, "Error releasing symbols!\n");
- exit(1);
- } /* end if */
-
- /* Emit informational message */
- if(verbose)
- fprintf(stderr, "Closing objects\n");
-
- /* Close objects opened */
- if(H5Fclose(fid) < 0) {
- fprintf(stderr, "Error closing file!\n");
- exit(1);
- } /* end if */
-
- return 0;
-}
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+ /*-------------------------------------------------------------------------
+ *
+ * Created: swmr_sparse_writer.c
+ *
+ * Purpose: Writes data to a randomly selected subset of the datasets
+ * in the SWMR test file.
+ *
+ * This program is intended to run concurrently with the
+ * swmr_sparse_reader program.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/***********/
+/* Headers */
+/***********/
+
+#include <assert.h>
+
+#include "swmr_common.h"
+
+/****************/
+/* Local Macros */
+/****************/
+
+#define BUSY_WAIT 100000
+
+/********************/
+/* Local Prototypes */
+/********************/
+
+static hid_t open_skeleton(const char *filename, unsigned verbose);
+static int add_records(hid_t fid, unsigned verbose, unsigned long nrecords,
+ unsigned long flush_count);
+static void usage(void);
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: open_skeleton
+ *
+ * Purpose: Opens the SWMR HDF5 file and datasets.
+ *
+ * Parameters: const char *filename
+ * The filename of the SWMR HDF5 file to open
+ *
+ * unsigned verbose
+ * Whether or not to emit verbose console messages
+ *
+ * Return: Success: The file ID of the opened SWMR file
+ * The dataset IDs are stored in a global array
+ *
+ * Failure: -1
+ *
+ *-------------------------------------------------------------------------
+ */
+static hid_t
+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 aid; /* Attribute ID */
+ unsigned seed; /* Seed for random number generator */
+ unsigned u, v; /* Local index variable */
+
+ assert(filename);
+
+ /* Create file access property list */
+ if((fapl = h5_fileaccess()) < 0)
+ return -1;
+
+ /* Set to use the latest library format */
+ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
+ 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);
+ 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
+ H5Pset_fapl_log(fapl, "append.log", H5FD_LOG_ALL, (size_t)(512 * 1024 * 1024));
+#endif /* QAK */
+
+ /* Open the file */
+ if((fid = H5Fopen(filename, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0)
+ return -1;
+
+ /* Close file access property list */
+ if(H5Pclose(fapl) < 0)
+ return -1;
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Opening datasets\n");
+
+ /* Seed the random number generator with the attribute in the file */
+ if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0)
+ return -1;
+ if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0)
+ return -1;
+ if(H5Aclose(aid) < 0)
+ return -1;
+ srandom(seed);
+
+ /* 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);
+ symbol_info[u][v].nrecords = 0;
+ } /* end for */
+
+ return fid;
+}
+
+
+/*-------------------------------------------------------------------------
+ * 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 */
+
+ assert(fid >= 0);
+
+ /* Reset the record */
+ /* (record's 'info' field might need to change for each record written, also) */
+ memset(&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;
+ 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 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)random() % 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 */
+ dummy = 0;
+ for(v=0; v<BUSY_WAIT; v++)
+ dummy++;
+ if((unsigned long)dummy != v)
+ return -1;
+#endif
+ } /* 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;
+}
+
+static void
+usage(void)
+{
+ printf("\n");
+ printf("Usage error!\n");
+ printf("\n");
+ printf("Usage: swmr_sparse_writer [-q] [-f <# of records to write between\n");
+ printf(" flushing file contents>] <# of records>\n");
+ printf("\n");
+ printf("<# of records to write between flushing file contents> should be 0\n");
+ printf("(for no flushing) or between 1 and (<# of records> - 1)\n");
+ printf("\n");
+ printf("Defaults to verbose (no '-q' given) and flushing every 1000 records\n");
+ printf("('-f 1000')\n");
+ printf("\n");
+ exit(1);
+}
+
+int main(int argc, const char *argv[])
+{
+ hid_t fid; /* File ID for file opened */
+ long nrecords = 0; /* # of records to append */
+ 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 */
+
+ /* Parse command line options */
+ if(argc < 2)
+ usage();
+ if(argc > 1) {
+ u = 1;
+ while(u < (unsigned)argc) {
+ if(argv[u][0] == '-') {
+ switch(argv[u][1]) {
+ /* # of records to write between flushing file */
+ case 'f':
+ flush_count = atol(argv[u + 1]);
+ if(flush_count < 0)
+ usage();
+ u += 2;
+ break;
+
+ /* Be quiet */
+ case 'q':
+ verbose = 0;
+ u++;
+ break;
+
+ default:
+ usage();
+ break;
+ } /* end switch */
+ } /* end if */
+ else {
+ /* Get the number of records to append */
+ nrecords = atol(argv[u]);
+ if(nrecords <= 0)
+ usage();
+
+ u++;
+ } /* end else */
+ } /* end while */
+ } /* end if */
+ if(nrecords <= 0)
+ usage();
+ if(flush_count >= nrecords)
+ usage();
+
+ /* Emit informational message */
+ if(verbose) {
+ 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 */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Generating symbol names\n");
+
+ /* Generate dataset names */
+ if(generate_symbols() < 0)
+ return -1;
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Opening skeleton file: %s\n", FILENAME);
+
+ /* Open file skeleton */
+ if((fid = open_skeleton(FILENAME, verbose)) < 0) {
+ fprintf(stderr, "Error opening skeleton file!\n");
+ exit(1);
+ } /* end if */
+
+ /* Send a message to indicate "H5Fopen" is complete--releasing the file lock */
+ h5_send_message(WRITER_MESSAGE);
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Adding records\n");
+
+ /* Append records to datasets */
+ if(add_records(fid, verbose, (unsigned long)nrecords, (unsigned long)flush_count) < 0) {
+ fprintf(stderr, "Error appending records to datasets!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Releasing symbols\n");
+
+ /* Clean up the symbols */
+ if(shutdown_symbols() < 0) {
+ fprintf(stderr, "Error releasing symbols!\n");
+ exit(1);
+ } /* end if */
+
+ /* Emit informational message */
+ if(verbose)
+ fprintf(stderr, "Closing objects\n");
+
+ /* Close objects opened */
+ if(H5Fclose(fid) < 0) {
+ fprintf(stderr, "Error closing file!\n");
+ exit(1);
+ } /* end if */
+
+ return 0;
+}