From 664c013fc76b9a440944db320e9025b4a9a62beb Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Fri, 14 Oct 2011 17:44:11 -0500 Subject: [svn-r21586] Description: Added a funtion to reset dataset & hyperslab buffer size for h5repack from an environment variable. This is performance debugging purpose for now. Tested: jam (linux32-LE), koala (linux64-LE), heiwa (linuxppc64-BE), tejeda (mac32-LE), Windows (32-LE), cmake --- tools/h5diff/h5diffgentest.c | 1 + tools/h5repack/h5repack_filters.c | 1 + tools/h5repack/h5repack_main.c | 4 +++ tools/h5repack/h5repacktst.c | 1 + tools/lib/h5tools.h | 17 ------------- tools/lib/h5tools_utils.c | 52 +++++++++++++++++++++++++++++++++++++++ tools/lib/h5tools_utils.h | 6 ++++- 7 files changed, 64 insertions(+), 18 deletions(-) diff --git a/tools/h5diff/h5diffgentest.c b/tools/h5diff/h5diffgentest.c index 206dca0..4fd6d54 100644 --- a/tools/h5diff/h5diffgentest.c +++ b/tools/h5diff/h5diffgentest.c @@ -18,6 +18,7 @@ #include "hdf5.h" #include "H5private.h" #include "h5tools.h" +#include "h5tools_utils.h" /* Name of tool */ diff --git a/tools/h5repack/h5repack_filters.c b/tools/h5repack/h5repack_filters.c index 213ff65..7072d2d 100644 --- a/tools/h5repack/h5repack_filters.c +++ b/tools/h5repack/h5repack_filters.c @@ -15,6 +15,7 @@ #include "h5repack.h" #include "h5tools.h" +#include "h5tools_utils.h" /* number of members in an array */ #ifndef NELMTS diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c index 99d700d..010d9f2 100644 --- a/tools/h5repack/h5repack_main.c +++ b/tools/h5repack/h5repack_main.c @@ -106,6 +106,10 @@ int main(int argc, const char **argv) h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); + /* update hyperslab buffer size from H5TOOLS_BUFSIZE env if exist */ + if ( h5tools_getenv_update_hyperslab_bufsize() < 0) + exit(EXIT_FAILURE); + /* initialize options */ h5repack_init(&options, 0, 0, (hsize_t)0); diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c index 7be7b32..d0974b6 100644 --- a/tools/h5repack/h5repacktst.c +++ b/tools/h5repack/h5repacktst.c @@ -17,6 +17,7 @@ #include "h5test.h" #include "h5diff.h" #include "h5tools.h" +#include "h5tools_utils.h" #define GOERROR {H5_FAILED(); goto error;} diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 1b2014a..3470b20 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -31,23 +31,6 @@ #define START_OF_DATA 0x0001 #define END_OF_DATA 0x0002 -/* - * The output functions need a temporary buffer to hold a piece of the - * dataset while it's being printed. This constant sets the limit on the - * size of that temporary buffer in bytes. For efficiency's sake, choose the - * largest value suitable for your machine (for testing use a small value). - */ -#if 1 -#define H5TOOLS_BUFSIZE (1024 * 1024) -#else -#define H5TOOLS_BUFSIZE (1024) -#endif - -/* - * Maximum size used in a call to malloc - */ -#define H5TOOLS_MALLOCSIZE (128 * 1024 * 1024) - /* format for hsize_t */ #define HSIZE_T_FORMAT "%"H5_PRINTF_LL_WIDTH"u" diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index ab8536f..3f89572 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -42,6 +42,18 @@ const char *opt_arg; /*flag argument (or value) */ static int h5tools_d_status = 0; static const char *h5tools_progname = "h5tools"; +/* + * The output functions need a temporary buffer to hold a piece of the + * dataset while it's being printed. This constant sets the limit on the + * size of that temporary buffer in bytes. For efficiency's sake, choose the + * largest value suitable for your machine (for testing use a small value). + */ +/* Maximum size used in a call to malloc for a dataset */ +hsize_t H5TOOLS_MALLOCSIZE = (128 * 1024 * 1024); +/* size of hyperslab buffer when a dataset is bigger than H5TOOLS_MALLOCSIZE */ +hsize_t H5TOOLS_BUFSIZE = (1024 * 1024); + + /* ``parallel_print'' variables */ unsigned char g_Parallel = 0; /*0 for serial, 1 for parallel */ char outBuff[OUTBUFF_SIZE]; @@ -889,3 +901,43 @@ int h5tools_getstatus(void) { return h5tools_d_status; } + +/*----------------------------------------------------------- + * PURPOSE : + * if environment variable H5TOOLS_BUFSIZE is set, + * update H5TOOLS_BUFSIZE and H5TOOLS_MALLOCSIZE from the env + * This can be called from each tools main() as part of initial act. + * Note: this is more of debugging purpose for now. + */ +int h5tools_getenv_update_hyperslab_bufsize(void) +{ + const char *env_str = NULL; + long hyperslab_bufsize_mb; + + /* check if environment variable is set for the hyperslab buffer size */ + if (NULL != (env_str = HDgetenv ("H5TOOLS_BUFSIZE"))) + { + errno = 0; + hyperslab_bufsize_mb = HDstrtol(env_str, (char**)NULL, 10); + if (errno != 0 || hyperslab_bufsize_mb <= 0) + { + + /* TODO: later when pubilshed + printf("Error: Invalid environment variable \"H5TOOLS_BUFSIZE\" : %s\n", env_str); + */ + + goto error; + } + + + /* convert MB to byte */ + H5TOOLS_BUFSIZE = hyperslab_bufsize_mb * 1024 * 1024; + + H5TOOLS_MALLOCSIZE = MAX(H5TOOLS_BUFSIZE, H5TOOLS_MALLOCSIZE); + } + + + return (1); +error: + return (-1); +} diff --git a/tools/lib/h5tools_utils.h b/tools/lib/h5tools_utils.h index be32d07..0f3acd1 100644 --- a/tools/lib/h5tools_utils.h +++ b/tools/lib/h5tools_utils.h @@ -32,6 +32,10 @@ extern "C" { #define PRINT_DATA_MAX_SIZE 512 #define OUTBUFF_SIZE (PRINT_DATA_MAX_SIZE*4) +/* Maximum size used in a call to malloc for a dataset */ +H5TOOLS_DLLVAR hsize_t H5TOOLS_MALLOCSIZE; +/* size of hyperslab buffer when a dataset is bigger than H5TOOLS_MALLOCSIZE */ +H5TOOLS_DLLVAR hsize_t H5TOOLS_BUFSIZE; H5TOOLS_DLLVAR int g_nTasks; H5TOOLS_DLLVAR unsigned char g_Parallel; H5TOOLS_DLLVAR char outBuff[]; @@ -169,7 +173,7 @@ H5TOOLS_DLL const char *h5tools_getprogname(void); H5TOOLS_DLL void h5tools_setprogname(const char*progname); H5TOOLS_DLL int h5tools_getstatus(void); H5TOOLS_DLL void h5tools_setstatus(int d_status); - +H5TOOLS_DLL int h5tools_getenv_update_hyperslab_bufsize(void); #ifdef __cplusplus } #endif -- cgit v0.12