/*------------------------------------------------------------------------- * Function: warn_msg * * Purpose: Print a nicely formatted warning message to stderr flushing * the stdout stream first. * * Return: Nothing * * Programmer: Bill Wendling * Tuesday, 20. February 2001 * * Modifications: * *------------------------------------------------------------------------- */ void warn_msg(const char *fmt, ...) { va_list ap; HDva_start(ap, fmt); HDfflush(rawdatastream); HDfflush(rawoutstream); HDfprintf(rawerrorstream, "%s warning: ", h5tools_getprogname()); HDvfprintf(rawerrorstream, fmt, ap); HDva_end(ap); }
/*------------------------------------------------------------------------- * Function: send_signal * * Purpose: Sends the specified signal. * * In terms of this test framework, a signal consists of a file * on disk. Since there are multiple processes that need to * communicate with each other, they do so by writing and * reading signal files on disk, the names and contents of * which are used to inform a process about when it can * proceed and what it should do next. * * This function writes a signal file. The first argument is * the name of the signal file, and the second and third * arguments are the contents of the first two lines of the * signal file. The last two arguments may be NULL. * * Return: void * * Programmer: Mike McGreevy * August 18, 2010 * * Modifications: * *------------------------------------------------------------------------- */ void send_signal(const char * send, const char * arg1, const char * arg2) { FILE *signalfile = NULL; /* Create signal file (which will send signal to some other process) */ signalfile = fopen(send, "w+"); /* Write messages to signal file, if provided */ if (arg2 != NULL) { HDassert(arg1); HDfprintf(signalfile, "%s\n%s\n", arg1, arg2); } /* end if */ else if (arg1 != NULL) { HDassert(arg2 == NULL); HDfprintf(signalfile, "%s\n", arg1); } /* end if */ else { HDassert(arg1 == NULL); HDassert(arg2 == NULL); }/* end else */ HDfflush(signalfile); HDfclose(signalfile); } /* send_signal */
/* * Function: usage * Purpose: Print a usage message and then exit. * Return: Nothing * Programmer: Bill Wendling, 05. June 2002 * Modifications: */ static void usage(void) { HDfprintf(stdout, "usage: %s [OPTIONS]\n", prog); HDfprintf(stdout, " OPTIONS\n"); HDfprintf(stdout, " -h, --help Print this usage message and exit\n"); HDfprintf(stdout, " -1...-9 Level of compression, from 1 to 9\n"); HDfprintf(stdout, " -c P, --compressability=P Percentage of compressability of the random\n"); HDfprintf(stdout, " data you want [default: 0]"); HDfprintf(stdout, " -s S, --file-size=S Maximum size of uncompressed file [default: 64M]\n"); HDfprintf(stdout, " -B S, --max-buffer_size=S Maximum size of buffer [default: 1M]\n"); HDfprintf(stdout, " -b S, --min-buffer_size=S Minumum size of buffer [default: 128K]\n"); HDfprintf(stdout, " -p D, --prefix=D The directory prefix to place the file\n"); HDfprintf(stdout, " -r, --random-test Use random data to write to the file\n"); HDfprintf(stdout, " [default: no]\n"); HDfprintf(stdout, "\n"); HDfprintf(stdout, " D - a directory which exists\n"); HDfprintf(stdout, " P - a number between 0 and 100\n"); HDfprintf(stdout, " S - is a size specifier, an integer >=0 followed by a size indicator:\n"); HDfprintf(stdout, "\n"); HDfprintf(stdout, " K - Kilobyte (%d)\n", ONE_KB); HDfprintf(stdout, " M - Megabyte (%d)\n", ONE_MB); HDfprintf(stdout, " G - Gigabyte (%d)\n", ONE_GB); HDfprintf(stdout, "\n"); HDfprintf(stdout, " Example: 37M = 37 Megabytes = %d bytes\n", 37 * ONE_MB); HDfprintf(stdout, "\n"); HDfflush(stdout); }
/*------------------------------------------------------------------------- * Function: usage * * Purpose: Print the usage message * * Return: void * * Programmer: * * Modifications: * *------------------------------------------------------------------------- */ static void usage(const char *prog) { HDfflush(stdout); HDfprintf(stdout, "usage: %s -i <in_file.h5> [-o <out_file.h5> ] [-u <out_user_file> | --delete]\n", prog); HDfprintf(stdout, "\n"); HDfprintf(stdout, "Splits user file and HDF5 file into two files: user block data and HDF5 data.\n"); HDfprintf(stdout, "\n"); HDfprintf(stdout, "OPTIONS\n"); HDfprintf(stdout, " -i in_file.h5 Specifies the HDF5 as input. If the input HDF5 file\n"); HDfprintf(stdout, " contains no user block, exit with an error message.\n"); HDfprintf(stdout, " -o out_file.h5 Specifies output HDF5 file without a user block.\n"); HDfprintf(stdout, " If not specified, the user block will be removed from the\n"); HDfprintf(stdout, " input HDF5 file.\n"); HDfprintf(stdout, " -u out_user_file\n"); HDfprintf(stdout, " Specifies the output file containing the data from the\n"); HDfprintf(stdout, " user block.\n"); HDfprintf(stdout, " Cannot be used with --delete option.\n"); HDfprintf(stdout, " --delete Remove the user block from the input HDF5 file. The content\n"); HDfprintf(stdout, " of the user block is discarded.\n"); HDfprintf(stdout, " Cannot be used with the -u option.\n"); HDfprintf(stdout, "\n"); HDfprintf(stdout, " -h Prints a usage message and exits.\n"); HDfprintf(stdout, " -V Prints the HDF5 library version and exits.\n"); HDfprintf(stdout, "\n"); HDfprintf(stdout, " If neither --delete nor -u is specified, the user block from the input file\n"); HDfprintf(stdout, " will be displayed to stdout.\n"); HDfprintf(stdout, "\n"); HDfprintf(stdout, "Exit Status:\n"); HDfprintf(stdout, " 0 Succeeded.\n"); HDfprintf(stdout, " >0 An error occurred.\n"); }
/*------------------------------------------------------------------------- * Function: h5_reset * * Purpose: Reset the library by closing it. * * Return: void * * Programmer: Robb Matzke * Friday, November 20, 1998 * *------------------------------------------------------------------------- */ void h5_reset(void) { HDfflush(stdout); HDfflush(stderr); H5close(); /* Save current error stack reporting routine and redirect to our local one */ HDassert(err_func == NULL); H5Eget_auto2(H5E_DEFAULT, &err_func, NULL); H5Eset_auto2(H5E_DEFAULT, h5_errors, NULL); /* * I commented this chunk of code out because it's not clear what diagnostics * were being output and under what circumstances, and creating this file * is throwing off debugging some of the tests. I can't see any _direct_ * harm in keeping this section of code, but I can't see any _direct_ * benefit right now either. If we figure out under which circumstances * diagnostics are being output, we should enable this behavior based on * appropriate configure flags/macros. QAK - 2007/12/20 */ #ifdef OLD_WAY { char filename[1024]; /* * Cause the library to emit some diagnostics early so they don't * interfere with other formatted output. */ sprintf(filename, "/tmp/h5emit-%05d.h5", HDgetpid()); H5E_BEGIN_TRY { hid_t file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); hid_t grp = H5Gcreate2(file, "emit", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(grp); H5Fclose(file); HDunlink(filename); } H5E_END_TRY; } #endif /* OLD_WAY */ }
static int test_stdio(hid_t fapl) { char filename[1024]; fsizes_t testsize; testsize = supports_big(); if(testsize == NOFILE) { HDfprintf(stdout, "Test for stdio is skipped because file system does not support big files.\n"); goto quit; } HDputs("\nTesting big file with the STDIO Driver "); h5_fixname(FILENAME[2], fapl, filename, sizeof filename); if(writer(filename, fapl, testsize, WRT_N)) goto error; if(reader(filename, fapl)) goto error; HDputs("Test passed with the STDIO Driver."); /* Flush stdout at the end of this test routine to ensure later * output to stderr will not come out before it. */ quit: /* End with normal return code */ /* Clean up the test file */ if(h5_cleanup(FILENAME, fapl)) HDremove(DNAME); HDfflush(stdout); return 0; error: HDputs("*** TEST FAILED ***"); HDfflush(stdout); return 1; } /* end test_stdio() */
/*------------------------------------------------------------------------- * Function: usage * * Purpose: Print the usage message * * Return: void * * Programmer: * * Modifications: * *------------------------------------------------------------------------- */ static void usage (const char *prog) { HDfflush (stdout); HDfprintf (stdout, "usage: %s -i <in_file.h5> -u <in_user_file> [-o <out_file.h5>] [--clobber]\n", prog); HDfprintf (stdout, "\n"); HDfprintf (stdout, "Adds user block to front of an HDF5 file and creates a new concatenated file.\n"); HDfprintf (stdout, "\n"); HDfprintf (stdout, "OPTIONS\n"); HDfprintf (stdout, " -i in_file.h5 Specifies the input HDF5 file.\n"); HDfprintf (stdout, " -u in_user_file Specifies the file to be inserted into the user block.\n"); HDfprintf (stdout, " Can be any file format except an HDF5 format.\n"); HDfprintf (stdout, " -o out_file.h5 Specifies the output HDF5 file.\n"); HDfprintf (stdout, " If not specified, the user block will be concatenated in\n"); HDfprintf (stdout, " place to the input HDF5 file.\n"); HDfprintf (stdout, " --clobber Wipes out any existing user block before concatenating\n"); HDfprintf (stdout, " the given user block.\n"); HDfprintf (stdout, " The size of the new user block will be the larger of;\n"); HDfprintf (stdout, " - the size of existing user block in the input HDF5 file\n"); HDfprintf (stdout, " - the size of user block required by new input user file\n"); HDfprintf (stdout, " (size = 512 x 2N, N is positive integer.)\n"); HDfprintf (stdout, "\n"); HDfprintf (stdout, " -h Prints a usage message and exits.\n"); HDfprintf (stdout, " -V Prints the HDF5 library version and exits.\n"); HDfprintf (stdout, "\n"); HDfprintf (stdout, "Exit Status:\n"); HDfprintf (stdout, " 0 Succeeded.\n"); HDfprintf (stdout, " >0 An error occurred.\n"); }
static void usage(const char *prog) { HDfflush(stdout); HDfprintf(stdout, "Usage: %s [OPTIONS] file\n", prog); HDfprintf(stdout, "\n"); HDfprintf(stdout, " OPTIONS\n"); HDfprintf(stdout, " -h, --help Print a usage message and exit\n"); HDfprintf(stdout, " -V, --version Print version number and exit\n"); HDfprintf(stdout, " -f, --file Print file information\n"); HDfprintf(stdout, " -F, --filemetadata Print file space information for file's metadata\n"); HDfprintf(stdout, " -g, --group Print group information\n"); HDfprintf(stdout, " -G, --groupmetadata Print file space information for groups' metadata\n"); HDfprintf(stdout, " -d, --dset Print dataset information\n"); HDfprintf(stdout, " -D, --dsetmetadata Print file space information for datasets' metadata\n"); HDfprintf(stdout, " -T, --dtypemetadata Print datasets' datatype information\n"); HDfprintf(stdout, " -A, --attribute Print attribute information\n"); HDfprintf(stdout, " -S, --summary Print summary of file space information\n"); }
/*------------------------------------------------------------------------- * Function: usage * * Purpose: Print the usage message about h5watch (only long options) * * Return: void * * Programmer: Vailin Choi; August 2010 * * Modifications: *------------------------------------------------------------------------- */ static void usage(const char *prog) { HDfflush(stdout); HDfprintf(stdout, "Usage: %s [OPTIONS] [OBJECT]\n", prog); HDfprintf(stdout, "\n"); HDfprintf(stdout, " OPTIONS\n"); HDfprintf(stdout, " --help Print a usage message and exit.\n"); HDfprintf(stdout, " --version Print version number and exit.\n"); HDfprintf(stdout, " --label Label members of compound typed dataset.\n"); HDfprintf(stdout, " --simple Use a machine-readable output format.\n"); HDfprintf(stdout, " --dim Monitor changes in size of dataset dimensions only.\n"); HDfprintf(stdout, " --width=N Set the number of columns to N for output.\n"); HDfprintf(stdout, " A value of 0 sets the number of columns to the\n"); HDfprintf(stdout, " maximum (65535). The default width is 80 columns.\n"); HDfprintf(stdout, " --polling=N Set the polling interval to N (in seconds) when the\n"); HDfprintf(stdout, " dataset will be checked for appended data. The default\n"); HDfprintf(stdout, " polling interval is 1.\n"); HDfprintf(stdout, " --fields=<list_of_fields>\n"); HDfprintf(stdout, " Display data for the fields specified in <list_of_fields>\n"); HDfprintf(stdout, " for a compound data type. <list_of_fields> can be\n"); HDfprintf(stdout, " specified as follows:\n"); HDfprintf(stdout, " 1) A comma-separated list of field names in a\n"); HDfprintf(stdout, " compound data type. \",\" is the separator\n"); HDfprintf(stdout, " for field names while \".\" is the separator\n"); HDfprintf(stdout, " for a nested field.\n"); HDfprintf(stdout, " 2) A single field name in a compound data type.\n"); HDfprintf(stdout, " Can use this option multiple times.\n"); HDfprintf(stdout, " Note that backslash is the escape character to avoid\n"); HDfprintf(stdout, " characters in field names that conflict with the tool's\n"); HDfprintf(stdout, " separators.\n"); HDfprintf(stdout, "\n"); HDfprintf(stdout, " OBJECT is specified as [<filename>/<path_to_dataset>/<dsetname>]\n"); HDfprintf(stdout, " <filename> Name of the HDF5 file. It may be preceded by path\n"); HDfprintf(stdout, " separated by slashes to the specified HDF5 file.\n"); HDfprintf(stdout, " <path_to_dataset> Path separated by slashes to the specified dataset\n"); HDfprintf(stdout, " <dsetname> Name of the dataset\n"); HDfprintf(stdout, "\n"); } /* usage() */
/*------------------------------------------------------------------------- * Function: monitor_dataset * * Purpose: To poll a dataset periodically for changes in dimension sizes. * For dataset with unchanged and/or decreased dimension sizes: * it just prints the dimension size changes * For dataset with increase in at least one of its dimension sizes: * it will print the new appended data to the dataset * * Return: Non-negative on success: dataset can be monitored * Negative on failure: dataset cannot be monitored * * Programmer: Vailin Choi; August 2010 * *------------------------------------------------------------------------- */ static herr_t monitor_dataset(hid_t fid, char *dsetname) { hid_t did; /* dataset id */ hid_t sid; /* dataspace id */ int ndims; /* # of dimensions in the dataspace */ int i, u; /* local index variable */ hsize_t prev_dims[H5S_MAX_RANK]; /* current dataspace dimensions */ hsize_t cur_dims[H5S_MAX_RANK]; /* previous dataspace dimensions */ herr_t ret_value = SUCCEED; /* return value */ HDfprintf(stdout, "Monitoring dataset %s...\n", dsetname); /* Open the dataset for minitoring */ if((did = H5Dopen2(fid, dsetname, H5P_DEFAULT)) < 0) { error_msg("error in opening dataset \"%s\"\n", dsetname); ret_value = FAIL; goto done; } if((sid = H5Dget_space(did)) < 0) { error_msg("error in getting dataspace id for dataset \"%s\"\n", dsetname); ret_value = FAIL; goto done; } /* Get the dataset's dimension sizes */ if((ndims = H5Sget_simple_extent_dims(sid, prev_dims, NULL)) < 0) { error_msg("unable to get dimensions sizes for \"%s\"\n", dsetname); ret_value = FAIL; goto done; } while(1) { /* Refreshes the dataset */ if(H5Drefresh(did) < 0) { ret_value = FAIL; goto done; } /* Get the dataset's current dimension sizes */ if(H5LDget_dset_dims(did, cur_dims) < 0) { error_msg("unable to get dimension sizes for \"%s\"\n", dsetname); ret_value = FAIL; goto done; } /* Check the dimension sizes */ for(i = 0; i < ndims; i++) if(cur_dims[i] != prev_dims[i]) break; /* at least one dimension has changed */ if(i != ndims) { /* Printing changes in dimension sizes */ for(u = 0; u < ndims; u++) { HDfprintf(stdout, "dimension %u: %Hu->%Hu", (unsigned)u, prev_dims[u], cur_dims[u]); if(cur_dims[u] > prev_dims[u]) HDfprintf(stdout, " (increases)\n"); else if(cur_dims[u] < prev_dims[u]) HDfprintf(stdout, " (decreases)\n"); else HDfprintf(stdout, " (unchanged)\n"); } /* Printing elements appended to the dataset if there is */ if(!g_monitor_size_only) { /* See if at least one dimension size has increased */ for(u = 0; u < ndims; u++) { int j; hsize_t start[H5S_MAX_RANK]; hsize_t block[H5S_MAX_RANK]; /* Print the new appended data to the dataset */ if(cur_dims[u] > prev_dims[u]) { HDfprintf(stdout, " Data:\n"); for(j = 0; j < ndims; j++) { start[j] = 0; block[j] = 1; } if((ret_value = slicendump(did, prev_dims, cur_dims, start, block, ndims, ndims)) < 0) goto done; break; } } /* end for */ } HDfflush(stdout); } /* Save the current dimension sizes */ HDmemcpy(prev_dims, cur_dims, (size_t)ndims * sizeof(hsize_t)); /* Sleep before next monitor */ HDsleep(g_polling_interval); } /* end while */ done: /* Closing */ H5E_BEGIN_TRY H5Dclose(did); H5E_END_TRY return(ret_value); } /* monitor_dataset() */
/*------------------------------------------------------------------------- * Function: reader * * Purpose: Reads some data from random locations in the dataset. * * Return: Success: 0 * * Failure: >0 * * Programmer: Robb Matzke * Friday, April 10, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int reader(char *filename, hid_t fapl) { FILE *script = NULL; hid_t file = -1, mspace = -1, fspace = -1, d2 = -1; char ln[128], *s; hsize_t hs_offset[1]; hsize_t hs_size[1] = {WRT_SIZE}; int *buf = (int *)HDmalloc(sizeof(int) * WRT_SIZE); int i, j, zero, wrong, nerrors = 0; /* Open script file */ script = HDfopen(DNAME, "r"); /* Open HDF5 file */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) FAIL_STACK_ERROR /* Open the dataset */ if((d2 = H5Dopen2(file, "d2", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR if((fspace = H5Dget_space(d2)) < 0) FAIL_STACK_ERROR /* Describe `buf' */ if((mspace = H5Screate_simple(1, hs_size, hs_size)) < 0) FAIL_STACK_ERROR /* Read each region */ while(HDfgets(ln, (int)sizeof(ln), script)) { if('#' != ln[0]) break; i = (int)HDstrtol(ln + 1, &s, 10); hs_offset[0] = HDstrtoll(s, NULL, 0); HDfprintf(stdout, "#%03d 0x%016Hx%47s", i, hs_offset[0], ""); HDfflush(stdout); if(H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0) FAIL_STACK_ERROR if(H5Dread(d2, H5T_NATIVE_INT, mspace, fspace, H5P_DEFAULT, buf) < 0) FAIL_STACK_ERROR /* Check */ for(j = zero = wrong = 0; j < WRT_SIZE; j++) { if(0 == buf[j]) zero++; else if(buf[j] != i + 1) wrong++; } if(zero) { H5_FAILED(); printf(" %d zero%s\n", zero, 1 == zero ? "" : "s"); } else if(wrong) { SKIPPED(); HDputs(" Possible overlap with another region."); nerrors++; } else { PASSED(); } } if(H5Dclose(d2) < 0) FAIL_STACK_ERROR if(H5Sclose(mspace) < 0) FAIL_STACK_ERROR if(H5Sclose(fspace) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR HDfree(buf); HDfclose(script); return nerrors; error: H5E_BEGIN_TRY { H5Dclose(d2); H5Sclose(mspace); H5Sclose(fspace); H5Fclose(file); } H5E_END_TRY; if(buf) HDfree(buf); if(script) HDfclose(script); return 1; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: * * Return: Success: * * Failure: * * Programmer: Robb Matzke * Thursday, March 12, 1998 * * Modifications: * *------------------------------------------------------------------------- */ int main (void) { static hsize_t size[2] = {REQUEST_SIZE_X, REQUEST_SIZE_Y}; static unsigned nread = NREAD_REQUESTS, nwrite = NWRITE_REQUESTS; unsigned char *the_data = NULL; hid_t file, dset, file_space = -1; herr_t status; #ifdef H5_HAVE_GETRUSAGE struct rusage r_start, r_stop; #else struct timeval r_start, r_stop; #endif struct timeval t_start, t_stop; int fd; unsigned u; hssize_t n; off_t offset; hsize_t start[2]; hsize_t count[2]; #ifdef H5_HAVE_SYS_TIMEB struct _timeb *tbstart = malloc(sizeof(struct _timeb)); struct _timeb *tbstop = malloc(sizeof(struct _timeb)); #endif /* * The extra cast in the following statement is a bug workaround for the * Win32 version 5.0 compiler. * 1998-11-06 ptl */ printf ("I/O request size is %1.1fMB\n", (double)(hssize_t)(size[0]*size[1])/1024.0F*1024); /* Open the files */ file = H5Fcreate (HDF5_FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); assert (file>=0); fd = HDopen (RAW_FILE_NAME, O_RDWR|O_CREAT|O_TRUNC, 0666); assert (fd>=0); /* Create the dataset */ file_space = H5Screate_simple (2, size, size); assert(file_space >= 0); dset = H5Dcreate2(file, "dset", H5T_NATIVE_UCHAR, file_space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); assert(dset >= 0); the_data = (unsigned char *)malloc((size_t)(size[0] * size[1])); /* initial fill for lazy malloc */ HDmemset(the_data, 0xAA, (size_t)(size[0] * size[1])); /* Fill raw */ synchronize (); #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "fill raw"); for(u = 0; u < nwrite; u++) { putc (PROGRESS, stderr); HDfflush(stderr); HDmemset(the_data, 0xAA, (size_t)(size[0]*size[1])); } #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); t_start.tv_sec = tbstart->time; t_start.tv_usec = tbstart->millitm; t_stop.tv_sec = tbstop->time; t_stop.tv_usec = tbstop->millitm; #endif #endif putc ('\n', stderr); print_stats ("fill raw", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*size[0]*size[1])); /* Fill hdf5 */ synchronize (); #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "fill hdf5"); for(u = 0; u < nread; u++) { putc (PROGRESS, stderr); HDfflush(stderr); status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space, H5P_DEFAULT, the_data); assert (status>=0); } #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); t_start.tv_sec = tbstart->time; t_start.tv_usec = tbstart->millitm; t_stop.tv_sec = tbstop->time; t_stop.tv_usec = tbstop->millitm; #endif #endif putc ('\n', stderr); print_stats ("fill hdf5", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*size[0]*size[1])); /* Write the raw dataset */ synchronize (); #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "out raw"); for(u = 0; u < nwrite; u++) { putc (PROGRESS, stderr); HDfflush(stderr); offset = HDlseek (fd, (off_t)0, SEEK_SET); assert (0==offset); n = HDwrite (fd, the_data, (size_t)(size[0]*size[1])); assert (n>=0 && (size_t)n==size[0]*size[1]); } #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); t_start.tv_sec = tbstart->time; t_start.tv_usec = tbstart->millitm; t_stop.tv_sec = tbstop->time; t_stop.tv_usec = tbstop->millitm; #endif #endif putc ('\n', stderr); print_stats ("out raw", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*size[0]*size[1])); /* Write the hdf5 dataset */ synchronize (); #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "out hdf5"); for(u = 0; u < nwrite; u++) { putc (PROGRESS, stderr); HDfflush(stderr); status = H5Dwrite (dset, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, the_data); assert (status>=0); } #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); t_start.tv_sec = tbstart->time; t_start.tv_usec = tbstart->millitm; t_stop.tv_sec = tbstop->time; t_stop.tv_usec = tbstop->millitm; #endif #endif putc ('\n', stderr); print_stats ("out hdf5", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*size[0]*size[1])); /* Read the raw dataset */ synchronize (); #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "in raw"); for(u = 0; u < nread; u++) { putc (PROGRESS, stderr); HDfflush(stderr); offset = HDlseek (fd, (off_t)0, SEEK_SET); assert (0==offset); n = HDread (fd, the_data, (size_t)(size[0]*size[1])); assert (n>=0 && (size_t)n==size[0]*size[1]); } #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); t_start.tv_sec = tbstart->time; t_start.tv_usec = tbstart->millitm; t_stop.tv_sec = tbstop->time; t_stop.tv_usec = tbstop->millitm; #endif #endif putc ('\n', stderr); print_stats ("in raw", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*size[0]*size[1])); /* Read the hdf5 dataset */ synchronize (); #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "in hdf5"); for(u = 0; u < nread; u++) { putc (PROGRESS, stderr); HDfflush(stderr); status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space, H5P_DEFAULT, the_data); assert (status>=0); } #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); t_start.tv_sec = tbstart->time; t_start.tv_usec = tbstart->millitm; t_stop.tv_sec = tbstop->time; t_stop.tv_usec = tbstop->millitm; #endif #endif putc ('\n', stderr); print_stats ("in hdf5", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*size[0]*size[1])); /* Read hyperslab */ assert (size[0]>20 && size[1]>20); start[0] = start[1] = 10; count[0] = count[1] = size[0]-20; status = H5Sselect_hyperslab (file_space, H5S_SELECT_SET, start, NULL, count, NULL); assert (status>=0); synchronize (); #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "in hdf5 partial"); for(u = 0; u < nread; u++) { putc (PROGRESS, stderr); HDfflush(stderr); status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space, H5P_DEFAULT, the_data); assert (status>=0); } #ifdef H5_HAVE_GETRUSAGE HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); t_start.tv_sec = tbstart->time; t_start.tv_usec = tbstart->millitm; t_stop.tv_sec = tbstop->time; t_stop.tv_usec = tbstop->millitm; #endif #endif putc('\n', stderr); print_stats("in hdf5 partial", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*count[0]*count[1])); /* Close everything */ HDclose(fd); H5Dclose(dset); H5Sclose(file_space); H5Fclose(file); free(the_data); return 0; }
/* Overall Algorithm: * Parse options from user; * Generate/pre-created the test file needed and close it; * fork: child processes become the reader processes; * while parent process continues as the writer process; * both run till ending conditions are met. */ int main(int argc, char *argv[]) { /*pid_t childpid[READERS_MAX]; int child_ret_value[READERS_MAX];*/ pid_t childpid=0; int child_ret_value; pid_t mypid, tmppid; int child_status; int child_wait_option=0; int ret_value = 0; /* initialization */ if (setup_parameters(argc, argv) < 0){ Hgoto_error(1); } /* ==============================================================*/ /* UC_READWRITE: create datafile, launch both reader and writer. */ /* UC_WRITER: create datafile, skip reader, launch writer. */ /* UC_READER: skip create, launch reader, exit. */ /* ==============================================================*/ /* ============*/ /* Create file */ /* ============*/ if (launch_g != UC_READER){ printf("Creating skeleton data file for test...\n"); if (create_wo_file() < 0){ fprintf(stderr, "***encounter error\n"); Hgoto_error(1); }else printf("File created.\n"); } /* flush output before possible fork */ HDfflush(stdout); if (launch_g==UC_READWRITE){ /* fork process */ if((childpid = fork()) < 0) { perror("fork"); Hgoto_error(1); }; }; mypid = getpid(); /* ============= */ /* launch reader */ /* ============= */ if (launch_g != UC_WRITER){ /* child process launch the reader */ if(0 == childpid) { printf("%d: launch reader process\n", mypid); if (read_wo_file() < 0){ fprintf(stderr, "read_wo_file encountered error\n"); exit(1); } /* Reader is done. Clean up by removing the data file */ HDremove(DATAFILE); exit(0); } } /* ============= */ /* launch writer */ /* ============= */ /* this process continues to launch the writer */ printf("%d: continue as the writer process\n", mypid); if (write_wo_file() < 0){ fprintf(stderr, "write_wo_file encountered error\n"); Hgoto_error(1); } /* ================================================ */ /* If readwrite, collect exit code of child process */ /* ================================================ */ if (launch_g == UC_READWRITE){ if ((tmppid = waitpid(childpid, &child_status, child_wait_option)) < 0){ perror("waitpid"); Hgoto_error(1); } if (WIFEXITED(child_status)){ if ((child_ret_value=WEXITSTATUS(child_status)) != 0){ printf("%d: child process exited with non-zero code (%d)\n", mypid, child_ret_value); Hgoto_error(2); } } else { printf("%d: child process terminated abnormally\n", mypid); Hgoto_error(2); } } done: /* Print result and exit */ if (ret_value != 0){ printf("Error(s) encountered\n"); }else{ printf("All passed\n"); } return(ret_value); }