/* * Function: main * Purpose: Run the program * Return: EXIT_SUCCESS or EXIT_FAILURE * Programmer: Bill Wendling, 05. June 2002 * Modifications: */ int main(int argc, char **argv) { unsigned long min_buf_size = 128 * ONE_KB, max_buf_size = ONE_MB; unsigned long file_size = 64 * ONE_MB; int opt; prog = argv[0]; /* Initialize h5tools lib */ h5tools_init(); while ((opt = get_option(argc, (const char **)argv, s_opts, l_opts)) > 0) { switch ((char)opt) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': compress_level = opt - '0'; break; case 'B': max_buf_size = parse_size_directive(opt_arg); break; case 'b': min_buf_size = parse_size_directive(opt_arg); break; case 'c': compress_percent = (int)HDstrtol(opt_arg, NULL, 10); if (compress_percent < 0) compress_percent = 0; else if (compress_percent > 100) compress_percent = 100; break; case 'p': option_prefix = opt_arg; break; case 'r': random_test = TRUE; break; case 's': file_size = parse_size_directive(opt_arg); break; case '?': usage(); exit(EXIT_FAILURE); break; case 'h': default: usage(); exit(EXIT_SUCCESS); break; } } if (min_buf_size > max_buf_size) error("minmum buffer size (%d) exceeds maximum buffer size (%d)", min_buf_size, max_buf_size); HDfprintf(stdout, "Filesize: %ld\n", file_size); if (compress_level == Z_DEFAULT_COMPRESSION) HDfprintf(stdout, "Compression Level: 6\n"); else HDfprintf(stdout, "Compression Level: %d\n", compress_level); get_unique_name(); do_write_test(file_size, min_buf_size, max_buf_size); cleanup(); return EXIT_SUCCESS; }
/* * Function: parse_command_line * Purpose: Parse the command line options and return a STRUCT OPTIONS * structure which will need to be freed by the calling function. * Return: Pointer to an OPTIONS structure * Programmer: Bill Wendling, 31. October 2001 * Modifications: * Added multidimensional testing (Christian Chilan, April, 2008) */ static struct options * parse_command_line(int argc, char *argv[]) { int opt; struct options *cl_opts; int i, default_rank, actual_rank, ranks[4]; cl_opts = (struct options *)HDmalloc(sizeof(struct options)); cl_opts->page_buffer_size = 0; cl_opts->page_size = 0; cl_opts->output_file = NULL; cl_opts->io_types = 0; /* will set default after parsing options */ cl_opts->num_iters = 1; default_rank = 2; cl_opts->dset_rank = 0; cl_opts->buf_rank = 0; cl_opts->chk_rank = 0; cl_opts->order_rank = 0; for(i = 0; i < MAX_DIMS; i++) { cl_opts->buf_size[i] = (size_t)((i + 1) * 10); cl_opts->dset_size[i] = (hsize_t)((i + 1) * 100); cl_opts->chk_size[i] = (size_t)((i + 1) * 10); cl_opts->order[i] = i + 1; } cl_opts->vfd = sec2; cl_opts->print_times = FALSE; /* Printing times is off by default */ cl_opts->print_raw = FALSE; /* Printing raw data throughput is off by default */ cl_opts->h5_alignment = 1; /* No alignment for HDF5 objects by default */ cl_opts->h5_threshold = 1; /* No threshold for aligning HDF5 objects by default */ cl_opts->h5_use_chunks = FALSE; /* Don't chunk the HDF5 dataset by default */ cl_opts->h5_write_only = FALSE; /* Do both read and write by default */ cl_opts->h5_extendable = FALSE; /* Use extendable dataset */ cl_opts->verify = FALSE; /* No Verify data correctness by default */ while ((opt = get_option(argc, (const char **)argv, s_opts, l_opts)) != EOF) { switch ((char)opt) { case 'a': cl_opts->h5_alignment = parse_size_directive(opt_arg); break; case 'G': cl_opts->page_size = parse_size_directive(opt_arg); break; case 'b': cl_opts->page_buffer_size = parse_size_directive(opt_arg); break; case 'A': { const char *end = opt_arg; while (end && *end != '\0') { char buf[10]; HDmemset(buf, '\0', sizeof(buf)); for (i = 0; *end != '\0' && *end != ','; ++end) if (isalnum(*end) && i < 10) buf[i++] = *end; if (!HDstrcasecmp(buf, "hdf5")) { cl_opts->io_types |= SIO_HDF5; } else if (!HDstrcasecmp(buf, "posix")) { cl_opts->io_types |= SIO_POSIX; } else { fprintf(stderr, "sio_perf: invalid --api option %s\n", buf); exit(EXIT_FAILURE); } if (*end == '\0') break; end++; } } break; #if 0 case 'b': /* the future "binary" option */ break; #endif /* 0 */ case 'c': /* Turn on chunked HDF5 dataset creation */ cl_opts->h5_use_chunks = 1; { const char *end = opt_arg; int j = 0; while (end && *end != '\0') { char buf[10]; HDmemset(buf, '\0', sizeof(buf)); for (i = 0; *end != '\0' && *end != ','; ++end) if (isalnum(*end) && i < 10) buf[i++] = *end; cl_opts->chk_size[j] = parse_size_directive(buf); j++; if (*end == '\0') break; end++; } cl_opts->chk_rank = j; } break; case 'D': { const char *end = opt_arg; while (end && *end != '\0') { char buf[10]; HDmemset(buf, '\0', sizeof(buf)); for (i = 0; *end != '\0' && *end != ','; ++end) if (isalnum(*end) && i < 10) buf[i++] = *end; if (strlen(buf) > 1 || isdigit(buf[0])) { size_t j; for (j = 0; j < 10 && buf[j] != '\0'; ++j) if (!isdigit(buf[j])) { fprintf(stderr, "sio_perf: invalid --debug option %s\n", buf); exit(EXIT_FAILURE); } sio_debug_level = atoi(buf); if (sio_debug_level > 4) sio_debug_level = 4; else if (sio_debug_level < 0) sio_debug_level = 0; } else { switch (*buf) { case 'r': /* Turn on raw data throughput info */ cl_opts->print_raw = TRUE; break; case 't': /* Turn on time printing */ cl_opts->print_times = TRUE; break; case 'v': /* Turn on verify data correctness*/ cl_opts->verify = TRUE; break; default: fprintf(stderr, "sio_perf: invalid --debug option %s\n", buf); exit(EXIT_FAILURE); } } if (*end == '\0') break; end++; } } break; case 'e': { const char *end = opt_arg; int j = 0; while (end && *end != '\0') { char buf[10]; HDmemset(buf, '\0', sizeof(buf)); for (i = 0; *end != '\0' && *end != ','; ++end) if (isalnum(*end) && i < 10) buf[i++] = *end; cl_opts->dset_size[j] = parse_size_directive(buf); j++; if (*end == '\0') break; end++; } cl_opts->dset_rank = j; } break; case 'i': cl_opts->num_iters = atoi(opt_arg); break; case 'o': cl_opts->output_file = opt_arg; break; case 'T': cl_opts->h5_threshold = parse_size_directive(opt_arg); break; case 'v': if (!HDstrcasecmp(opt_arg, "sec2")) { cl_opts->vfd=sec2; } else if (!HDstrcasecmp(opt_arg, "stdio")) { cl_opts->vfd=stdio; } else if (!HDstrcasecmp(opt_arg, "core")) { cl_opts->vfd=core; } else if (!HDstrcasecmp(opt_arg, "split")) { cl_opts->vfd=split; } else if (!HDstrcasecmp(opt_arg, "multi")) { cl_opts->vfd=multi; } else if (!HDstrcasecmp(opt_arg, "family")) { cl_opts->vfd=family; } else if (!HDstrcasecmp(opt_arg, "direct")) { cl_opts->vfd=direct; } else { fprintf(stderr, "sio_perf: invalid --api option %s\n", opt_arg); exit(EXIT_FAILURE); } break; case 'w': cl_opts->h5_write_only = TRUE; break; case 't': cl_opts->h5_extendable = TRUE; break; case 'x': { const char *end = opt_arg; int j = 0; while (end && *end != '\0') { char buf[10]; HDmemset(buf, '\0', sizeof(buf)); for (i = 0; *end != '\0' && *end != ','; ++end) if (isalnum(*end) && i < 10) buf[i++] = *end; cl_opts->buf_size[j] = parse_size_directive(buf); j++; if (*end == '\0') break; end++; } cl_opts->buf_rank = j; } break; case 'r': { const char *end = opt_arg; int j = 0; while (end && *end != '\0') { char buf[10]; HDmemset(buf, '\0', sizeof(buf)); for (i = 0; *end != '\0' && *end != ','; ++end) if (isalnum(*end) && i < 10) buf[i++] = *end; cl_opts->order[j] = (int)parse_size_directive(buf); j++; if (*end == '\0') break; end++; } cl_opts->order_rank = j; } break; case 'h': case '?': default: usage(progname); free(cl_opts); return NULL; } } /* perform rank consistency analysis */ actual_rank = 0; ranks[0] = cl_opts->dset_rank; ranks[1] = cl_opts->buf_rank; ranks[2] = cl_opts->order_rank; ranks[3] = cl_opts->chk_rank; for (i=0; i<4; i++) { if (ranks[i]>0) { if (!actual_rank) { actual_rank = ranks[i]; } else { if (actual_rank != ranks[i]) exit(EXIT_FAILURE); } } } if (!actual_rank) actual_rank = default_rank; cl_opts->dset_rank = actual_rank; cl_opts->buf_rank = actual_rank; cl_opts->order_rank = actual_rank; cl_opts->chk_rank = actual_rank; for (i=0; i<actual_rank; i++) { if (cl_opts->order[i] > actual_rank) { exit(EXIT_FAILURE); } } /* set default if none specified yet */ if (!cl_opts->io_types) cl_opts->io_types = SIO_HDF5 | SIO_POSIX; /* run all API */ /* verify parameters sanity. Adjust if needed. */ /* cap xfer_size with bytes per process */ if (cl_opts->num_iters <= 0) cl_opts->num_iters = 1; return cl_opts; }