diff options
author | Robb Matzke <matzke@llnl.gov> | 1998-08-28 15:24:12 (GMT) |
---|---|---|
committer | Robb Matzke <matzke@llnl.gov> | 1998-08-28 15:24:12 (GMT) |
commit | 1b1be9918c1a654225f2040619f0b26ae83028fb (patch) | |
tree | db8bfa193965145aea917d4f06f122238324555d /test/ragged.c | |
parent | 69ed3c270a64d5c60544126b34431d1a7e9a7c8c (diff) | |
download | hdf5-1b1be9918c1a654225f2040619f0b26ae83028fb.zip hdf5-1b1be9918c1a654225f2040619f0b26ae83028fb.tar.gz hdf5-1b1be9918c1a654225f2040619f0b26ae83028fb.tar.bz2 |
[svn-r627] Changes since 19980827
----------------------
./src/H5G.c
Fixed a link count on groups. Groups were always created with
a link count of zero instead of one.
./src/H5Gpublic.h
Added H5G_NTYPES so applications can easily declare arrays
which are indexed by object type.
./src/H5O.c
Calling `H5O_link(&ent,0)' will succeed when the file is open
for read only because it's the only way to get the object's
current link count.
./tools/h5ls.c
Can take non-group object names on the command line (and
multiple objects). Reorganized to be more extendible. The
link count is displayed for `-v'.
./src/H5F.c
Dumping of cache statistics is controlled by only the
HDF5_DEBUG environment variable and not the H5F_ACC_DEBUG flag
for H5Fopen() and H5Fcreate() since this makes it similar to
the other debugging options.
./src/H5R.c
./test/ragged.c
./test/Makefile.in
Tests pass but still a little work left to be done.
Diffstat (limited to 'test/ragged.c')
-rw-r--r-- | test/ragged.c | 518 |
1 files changed, 445 insertions, 73 deletions
diff --git a/test/ragged.c b/test/ragged.c index 43e3ca4..f5ba2f4 100644 --- a/test/ragged.c +++ b/test/ragged.c @@ -16,6 +16,11 @@ #define NOTIFY_INTERVAL 2 /*seconds*/ #define TIME_LIMIT 60 /*seconds*/ #define CH_SIZE 8192*8 /*approx chunk size in bytes*/ +#define MAX_NELMTS 3000000 + +#define C_MTYPE unsigned int /*type in memory */ +#define H_MTYPE H5T_NATIVE_UINT /*type in memory */ +#define H_FTYPE H5T_NATIVE_UINT /*type in file */ typedef struct { double percent; @@ -54,7 +59,7 @@ static quant_t quant_g[] = { #endif static volatile sig_atomic_t alarm_g = 0; -static volatile sig_atomic_t abort_g = 0; +static volatile sig_atomic_t timeout_g = 0; /*------------------------------------------------------------------------- @@ -73,7 +78,7 @@ static volatile sig_atomic_t abort_g = 0; *------------------------------------------------------------------------- */ static void -catch_alarm(int signum) +catch_alarm(int __unused__ signum) { static int ncalls=0; @@ -81,14 +86,37 @@ catch_alarm(int signum) if (0==ncalls % NOTIFY_INTERVAL) { alarm_g++; } - if (ncalls>=TIME_LIMIT) { - abort_g=1; - } + if (timeout_g>0) --timeout_g; alarm(1); } /*------------------------------------------------------------------------- + * Function: display_error_cb + * + * Purpose: Displays the error stack after printing "*FAILED*". + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Robb Matzke + * Wednesday, March 4, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +display_error_cb (void __unused__ *client_data) +{ + putchar('\n'); + H5Eprint (stdout); + return 0; +} + + +/*------------------------------------------------------------------------- * Function: rand_nelmts * * Purpose: Returns a the length of a 1-d array according to the @@ -106,144 +134,488 @@ catch_alarm(int signum) *------------------------------------------------------------------------- */ static size_t -rand_nelmts(void) +rand_nelmts(int reset_counters) { - double p = (rand() % 1000000)/1000000.0; - double total = 0.0; - size_t size, i; - - for (i=0; i<NELMTS(quant_g); i++) { - total += quant_g[i].percent/100.0; - if (p<total) { - size = rand()%(1+(quant_g[i].hi-quant_g[i].lo)) + quant_g[i].lo; - quant_g[i].nhits++; - break; + double p = (rand() % 1000000)/1000000.0; + double total = 0.0; + size_t size, i; + static size_t ncalls=0; + + if (reset_counters) { + printf(" %9s %8s %8s\n", "Length", "Requsted", "Actual"); + printf(" --------------- -------- --------\n"); + for (i=0; i<NELMTS(quant_g); i++) { + printf(" [%6lu,%6lu] %7.3f%% %7.3f%%\n", + (unsigned long)(quant_g[i].lo), + (unsigned long)(quant_g[i].hi), + quant_g[i].percent, + 100.0*(double)(quant_g[i].nhits)/(double)ncalls); + quant_g[i].nhits = 0; + } + printf(" --------------- -------- --------\n"); + ncalls = 0; + size = 0; + } else { + for (i=0; i<NELMTS(quant_g); i++) { + total += quant_g[i].percent/100.0; + if (p<total) { + size = rand()%(1+(quant_g[i].hi-quant_g[i].lo)) + + quant_g[i].lo; + quant_g[i].nhits++; + break; + } } + assert(i<NELMTS(quant_g)); + ncalls++; } - assert(i<NELMTS(quant_g)); + return size; } /*------------------------------------------------------------------------- - * Function: main + * Function: ragged_append * - * Purpose: + * Purpose: Writes rows to the end of ragged array RA. * - * Return: Success: + * Return: Success: 0 * - * Failure: + * Failure: -1 * * Programmer: Robb Matzke - * Friday, August 21, 1998 + * Thursday, August 27, 1998 * * Modifications: * *------------------------------------------------------------------------- */ -int -main(void) +static int +ragged_append(hid_t ra, hsize_t rows_at_once) { - hid_t file, dcpl, ra; - int *dd, max_nelmts=3000000, total_nelmts=0; - int i, rows_at_once=100; + int *dd, total_nelmts=0; hssize_t row; /*current row number */ + hsize_t i; /*counter */ hsize_t max_width = quant_g[NELMTS(quant_g)-1].hi; - hsize_t ch_size[2]; /*chunk size */ hsize_t interval_nelmts; /*elmts/interval timer */ hsize_t *size=NULL; /*size of each row */ void **buf=NULL; /*buffer for each row */ - struct sigaction act; /*alarm signal handler */ H5_timer_t timer, timer_total; /*performance timers */ char s[64]; /*tempory string buffer */ + char testname[80]; - /* Get a SIGALRM every few seconds */ - act.sa_handler = catch_alarm; - sigemptyset(&(act.sa_mask)); - act.sa_flags = 0; - sigaction(SIGALRM, &act, NULL); - alarm(1); - - /* Create the file and ragged array */ - if ((file=H5Fcreate("ragged.h5", H5F_ACC_TRUNC, H5P_DEFAULT, - H5P_DEFAULT))<0) goto error; - if ((dcpl=H5Pcreate(H5P_DATASET_CREATE))<0) goto error; - ch_size[1] = 20; - ch_size[0] = MAX(1, CH_SIZE/(ch_size[1]*sizeof(int))); /*length*/ - printf("Chunk size is %lu by %lu\n", - (unsigned long)(ch_size[0]), (unsigned long)(ch_size[1])); - if (H5Pset_chunk(dcpl, 2, ch_size)<0) goto error; - if ((ra=H5Rcreate(file, "ra", H5T_NATIVE_INT, dcpl))<0) goto error; - if (H5Pclose(dcpl)<0) goto error; + sprintf(testname, "Testing append, units of %lu", + (unsigned long)rows_at_once); + printf("%s...\n", testname); + fflush(stdout); + timeout_g = 60; /* Create the ragged array row in memory */ - if (NULL==(dd = malloc(max_width*sizeof(int)))) goto error; + if (NULL==(dd = malloc(max_width*sizeof(C_MTYPE))) || + NULL==(size = malloc(rows_at_once*sizeof(*size))) || + NULL==(buf = malloc(rows_at_once*sizeof(*buf)))) { + puts("Memory allocation failed"); + goto error; + } for (i=0; i<max_width; i++) dd[i] = i+1; - size = malloc(rows_at_once*sizeof(*size)); - buf = malloc(rows_at_once*sizeof(*buf)); /* * Describe a few rows then add them to the ragged array. Print a status * report every once in a while too. */ - printf("Aggregated to %d row%s\n", rows_at_once, 1==rows_at_once?"":"s"); printf(" %8s %8s %8s %10s\n", "Row", "Nelmts", "Complete", "Bandwidth"); printf(" -------- -------- -------- ----------\n"); H5_timer_reset(&timer_total); H5_timer_begin(&timer); interval_nelmts = 0; - for (row=0; total_nelmts<max_nelmts && !abort_g; row+=i) { - for (i=0; i<rows_at_once && total_nelmts<max_nelmts; i++) { - size[i] = rand_nelmts(); + for (row=0; total_nelmts<MAX_NELMTS && timeout_g>0; row+=i) { + for (i=0; i<rows_at_once && total_nelmts<MAX_NELMTS; i++) { + size[i] = rand_nelmts(0); total_nelmts += size[i]; buf[i] = dd; interval_nelmts += size[i]; } - if (H5Rwrite(ra, row, i, H5T_NATIVE_INT, size, buf)<0) goto error; + if (H5Rwrite(ra, row, i, H_MTYPE, size, buf)<0) goto error; if (0==row || alarm_g) { alarm_g = 0; H5_timer_end(&timer_total, &timer); - H5_bandwidth(s, (double)interval_nelmts*sizeof(int), timer.etime); + H5_bandwidth(s, (double)interval_nelmts*sizeof(C_MTYPE), + timer.etime); printf(" %8lu %8lu %7.3f%% %10s%s\n", (unsigned long)(row+i), (unsigned long)total_nelmts, - 100.0*total_nelmts/max_nelmts, s, abort_g?" (aborting)":""); + 100.0*total_nelmts/MAX_NELMTS, s, + 0==timeout_g?" (aborting)":""); interval_nelmts = 0; H5_timer_begin(&timer); } } /* Conclusions */ - if (!abort_g) { + if (timeout_g) { /*a minor race condition, but who really cares?*/ H5_timer_end(&timer_total, &timer); - H5_bandwidth(s, (double)interval_nelmts*sizeof(int), timer.etime); + H5_bandwidth(s, (double)interval_nelmts*sizeof(C_MTYPE), timer.etime); printf(" %8lu %8lu %7.3f%% %10s\n", (unsigned long)row, (unsigned long)total_nelmts, - 100.0*total_nelmts/max_nelmts, s); + 100.0*total_nelmts/MAX_NELMTS, s); + } + printf(" -------- -------- -------- ----------\n"); + H5_bandwidth(s, (double)total_nelmts*sizeof(C_MTYPE), timer_total.etime); + printf(" %27s%10s\n", "", s); + + /* Cleanup */ + free(dd); + free(size); + free(buf); + printf("%-70s PASSED\n\n", testname); + return 0; + + error: + printf("%-70s*FAILED*\n\n", testname); + return -1; +} + + +/*------------------------------------------------------------------------- + * Function: ragged_readall + * + * Purpose: Reads all rows of a ragged array in row order a few rows at a + * time. + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Robb Matzke + * Thursday, August 27, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +ragged_readall(hid_t ra, hsize_t rows_at_once) +{ + int total_nelmts=0; + hsize_t i, j; /*counters */ + hssize_t row; /*current row number */ + hsize_t interval_nelmts; /*elmts/interval timer */ + hsize_t *size=NULL; /*size of each row */ + C_MTYPE **buf=NULL; /*buffer for each row */ + H5_timer_t timer, timer_total; /*performance timers */ + char s[64]; /*tempory string buffer */ + char testname[80]; + + sprintf(testname, "Testing read all, units of %lu", + (unsigned long)rows_at_once); + printf("%s...\n", testname); + fflush(stdout); + timeout_g = 60; + + /* Create the ragged array row in memory */ + if (NULL==(size = malloc(rows_at_once*sizeof(*size))) || + NULL==(buf = malloc(rows_at_once*sizeof(*buf)))) { + puts("Memory allocation failed"); + goto error; } + + /* + * Read a few rows at a time from the ragged array. Print a status report + * every once in a while too. + */ + printf(" %8s %8s %8s %10s\n", + "Row", "Nelmts", "Complete", "Bandwidth"); printf(" -------- -------- -------- ----------\n"); - H5_bandwidth(s, (double)total_nelmts*sizeof(int), timer_total.etime); - printf(" %27s%10s\n\n", "", s); + H5_timer_reset(&timer_total); + H5_timer_begin(&timer); + interval_nelmts = 0; + for (row=0; total_nelmts<MAX_NELMTS && timeout_g>0; row+=i) { + /* Clear data then read */ + HDmemset(size, 0, rows_at_once*sizeof(*size)); + HDmemset(buf, 0, rows_at_once*sizeof(*buf)); + if (H5Rread(ra, row, rows_at_once, H_MTYPE, size, + (void**)buf)<0) { + goto error; + } - printf(" %9s %8s %8s\n", "Length", "Requsted", "Actual"); - printf(" --------------- -------- --------\n"); - for (i=0; i<NELMTS(quant_g); i++) { - printf(" [%6lu,%6lu] %7.3f%% %7.3f%%\n", - (unsigned long)(quant_g[i].lo), (unsigned long)(quant_g[i].hi), - quant_g[i].percent, - 100.0*(double)(quant_g[i].nhits)/(double)row); + /* Check values read */ + for (i=0; i<rows_at_once && size[i]; i++) { + interval_nelmts += size[i]; + total_nelmts += size[i]; + for (j=0; j<size[i]; j++) { + if (buf[i][j]!=j+1) { + printf("Wrong value(s) read for row %ld.\n", + (long)(row+i)); + for (j=0; j<size[i]; j++) { + printf("%s%d", j?",":"", buf[i][j]); + } + putchar('\n'); + goto error; + } + } + free(buf[i]); + buf[i] = NULL; + } + + /* Print statistics? */ + if (0==row || alarm_g) { + alarm_g = 0; + H5_timer_end(&timer_total, &timer); + H5_bandwidth(s, (double)interval_nelmts*sizeof(C_MTYPE), + timer.etime); + printf(" %8lu %8lu %7.3f%% %10s%s\n", + (unsigned long)(row+i), (unsigned long)total_nelmts, + 100.0*total_nelmts/MAX_NELMTS, s, + 0==timeout_g?" (aborting)":""); + interval_nelmts = 0; + H5_timer_begin(&timer); + } + if (0==size[rows_at_once-1]) { + /* Reached the end of the array */ + assert(total_nelmts>=MAX_NELMTS); + row += i; + break; + } } - printf(" --------------- -------- --------\n"); + + /* Conclusions */ + if (timeout_g) { /*a minor race condition, but who really cares?*/ + H5_timer_end(&timer_total, &timer); + H5_bandwidth(s, (double)interval_nelmts*sizeof(C_MTYPE), timer.etime); + printf(" %8lu %8lu %7.3f%% %10s\n", + (unsigned long)row, (unsigned long)total_nelmts, + 100.0*total_nelmts/MAX_NELMTS, s); + } + printf(" -------- -------- -------- ----------\n"); + H5_bandwidth(s, (double)total_nelmts*sizeof(C_MTYPE), timer_total.etime); + printf(" %27s%10s\n", "", s); /* Cleanup */ - if (H5Rclose(ra)<0) goto error; - if (H5Fclose(file)<0) goto error; - free(dd); free(size); free(buf); + printf("%-70s PASSED\n\n", testname); + return 0; + + error: + printf("%-70s*FAILED*\n\n", testname); + return -1; +} + + +/*------------------------------------------------------------------------- + * Function: ragged_readshort + * + * Purpose: Reads all the data but only the part that is in the `raw' + * dataset. We should see a nice speed increase because we + * don't have to perform the little reads into the overflow + * array. + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Robb Matzke + * Friday, August 28, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +ragged_readshort(hid_t ra, hsize_t rows_at_once, hsize_t width) +{ + int total_nelmts=0; + hsize_t i, j; + hssize_t row; /*current row number */ + hsize_t interval_nelmts; /*elmts/interval timer */ + hsize_t *size=NULL; /*size of each row */ + C_MTYPE **buf=NULL; /*buffer for each row */ + H5_timer_t timer, timer_total; /*performance timers */ + char s[64]; /*tempory string buffer */ + char testname[80]; + + sprintf(testname, "Testing read short, units of %lu", + (unsigned long)rows_at_once); + printf("%s...\n", testname); + fflush(stdout); + timeout_g = 60; + + /* Create the ragged array row in memory */ + if (NULL==(size = malloc(rows_at_once*sizeof(*size))) || + NULL==(buf = malloc(rows_at_once*sizeof(*buf)))) { + puts("Memory allocation failed"); + goto error; + } + for (i=0; i<rows_at_once; i++) { + if (NULL==(buf[i] = malloc(width*sizeof(C_MTYPE)))) { + puts("Memory allocation failed"); + goto error; + } + } + + /* + * Read a few rows at a time from the ragged array. Print a status report + * every once in a while too. + */ + printf(" %8s %8s %8s %10s\n", + "Row", "Nelmts", "Complete", "Bandwidth"); + printf(" -------- -------- -------- ----------\n"); + H5_timer_reset(&timer_total); + H5_timer_begin(&timer); + interval_nelmts = 0; + for (row=0; total_nelmts<MAX_NELMTS && timeout_g>0; row+=i) { + + /* Read data */ + for (i=0; i<rows_at_once; i++) size[i] = width; + if (H5Rread(ra, row, rows_at_once, H_MTYPE, size, + (void**)buf)<0) { + goto error; + } + + /* Check values read */ + for (i=0; i<rows_at_once && size[i]; i++) { + + /* + * Number of useful elements actually read in this timing + * interval. This is used to calculate bandwidth. + */ + interval_nelmts += MIN(width, size[i]); + + /* + * Total number of elements for all the rows read so far. This + * is used to calculate the percent done. + */ + total_nelmts += size[i]; + + /* Check the values */ + for (j=0; j<MIN(width, size[i]); j++) { + if (buf[i][j]!=j+1) { + printf("Wrong value(s) read for row %ld.\n", + (long)(row+i)); + for (j=0; j<MIN(width, size[i]); j++) { + printf("%s%d", j?",":"", buf[i][j]); + } + putchar('\n'); + goto error; + } + } + } + + /* Print statistics? */ + if (0==row || alarm_g) { + alarm_g = 0; + H5_timer_end(&timer_total, &timer); + H5_bandwidth(s, (double)interval_nelmts*sizeof(C_MTYPE), + timer.etime); + printf(" %8lu %8lu %7.3f%% %10s%s\n", + (unsigned long)(row+i), (unsigned long)total_nelmts, + 100.0*total_nelmts/MAX_NELMTS, s, + 0==timeout_g?" (aborting)":""); + interval_nelmts = 0; + H5_timer_begin(&timer); + } + if (0==size[rows_at_once-1]) { + /* Reached the end of the array */ + assert(total_nelmts>=MAX_NELMTS); + row += i; + break; + } + } + + /* Conclusions */ + if (timeout_g) { /*a minor race condition, but who really cares?*/ + H5_timer_end(&timer_total, &timer); + H5_bandwidth(s, (double)interval_nelmts*sizeof(C_MTYPE), timer.etime); + printf(" %8lu %8lu %7.3f%% %10s\n", + (unsigned long)row, (unsigned long)total_nelmts, + 100.0*total_nelmts/MAX_NELMTS, s); + } + printf(" -------- -------- -------- ----------\n"); + H5_bandwidth(s, (double)total_nelmts*sizeof(C_MTYPE), timer_total.etime); + printf(" %27s%10s\n", "", s); + + /* Cleanup */ + for (i=0; i<rows_at_once; i++) free(buf[i]); + free(size); + free(buf); + printf("%-70s PASSED\n\n", testname); + return 0; + + error: + printf("%-70s*FAILED*\n\n", testname); + return -1; +} + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: + * + * Return: Success: + * + * Failure: + * + * Programmer: Robb Matzke + * Friday, August 21, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +main(int argc, char *argv[]) +{ + hid_t file, dcpl, ra; + hsize_t ch_size[2]; /*chunk size */ + struct sigaction act; /*alarm signal handler */ + hsize_t rows_at_once=100; /*row aggregation */ + int argno=1; + + /* Parse command line options */ + if (argno<argc) { + rows_at_once = strtol(argv[argno++], NULL, 0); + } + + /* Display HDF5 API errors in a special way */ + H5Eset_auto(display_error_cb, NULL); + + /* Get a SIGALRM every few seconds */ + act.sa_handler = catch_alarm; + sigemptyset(&(act.sa_mask)); + act.sa_flags = 0; + sigaction(SIGALRM, &act, NULL); + alarm(1); + + /* Create the file and ragged array */ + if ((file=H5Fcreate("ragged.h5", H5F_ACC_TRUNC, H5P_DEFAULT, + H5P_DEFAULT))<0) goto error; + if ((dcpl=H5Pcreate(H5P_DATASET_CREATE))<0) goto error; + ch_size[1] = 20; + ch_size[0] = MAX(1, CH_SIZE/(ch_size[1]*sizeof(C_MTYPE))); /*length*/ + printf("Chunk size is %lu by %lu\n", + (unsigned long)(ch_size[0]), (unsigned long)(ch_size[1])); + if (H5Pset_chunk(dcpl, 2, ch_size)<0) goto error; + if ((ra=H5Rcreate(file, "ra", H_FTYPE, dcpl))<0) goto error; + if (H5Pclose(dcpl)<0) goto error; + + /* The tests */ + if (ragged_append(ra, rows_at_once)<0) goto error; + if (ragged_readall(ra, rows_at_once)<0) goto error; + if (ragged_readshort(ra, rows_at_once, ch_size[1])<0) goto error; + + /* Conclusions */ + printf("\n\nDistribution of row lengths:\n"); + rand_nelmts(1); + + /* Cleanup */ + if (H5Rclose(ra)<0) goto error; + if (H5Fclose(file)<0) goto error; + + puts("All ragged array tests passed."); return 0; error: + puts("*** RAGGED ARRAY TEST(S) FAILED ***"); return -1; } |