From 77a2e54459cee60effc94513bdb047dbf2ef847b Mon Sep 17 00:00:00 2001 From: James Laird Date: Mon, 8 Jan 2007 09:54:12 -0500 Subject: [svn-r13119] More code cleanup. Made shared messages zero-indexed instead of one-indexed. Changed the names of some constants to be more consistent. Tested on juniper, smirom, and copper. --- examples/h5_shared_mesg.c | 16 +++--- src/H5Fsuper.c | 6 +-- src/H5Omessage.c | 3 -- src/H5Oprivate.h | 16 ++---- src/H5Opublic.h | 5 +- src/H5Oshared.c | 7 --- src/H5Pfcpl.c | 55 ++++++++++----------- src/H5SM.c | 16 +++--- src/H5SMcache.c | 2 +- test/objcopy.c | 2 +- test/tattr.c | 2 +- test/tsohm.c | 123 ++++++++++++++++++++++------------------------ 12 files changed, 114 insertions(+), 139 deletions(-) diff --git a/examples/h5_shared_mesg.c b/examples/h5_shared_mesg.c index f6e806c..4094b21 100644 --- a/examples/h5_shared_mesg.c +++ b/examples/h5_shared_mesg.c @@ -111,7 +111,7 @@ int main(void) * it holds. For the simple case, we'll put every message that could be * shared in this single index. */ - ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_MESG_ALL_FLAG, 40); + ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_MESG_ALL_FLAG, 40); if(ret < 0) goto error; /* The other property that can be set for shared messages is the @@ -147,7 +147,7 @@ int main(void) * will be about the same size as a normal file (with just a little extra * overhead). */ - ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_MESG_ALL_FLAG, 1000); + ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_MESG_ALL_FLAG, 1000); if(ret < 0) goto error; ret = create_standard_file("only_huge_mesgs_file.h5", fcpl_id); @@ -158,22 +158,22 @@ int main(void) * attributes (which might make sense if we were going to use committed * datatypes). We could change the flags on the index: */ - ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_MESG_SDSPACE_FLAG | H5O_MESG_ATTR_FLAG, 40); + ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_MESG_SDSPACE_FLAG | H5O_MESG_ATTR_FLAG, 40); if(ret < 0) goto error; ret = create_standard_file("only_dspaces_and_attrs_file.h5", fcpl_id); if(ret < 0) goto error; - /* We create a second index and put attributes in it to separate them from - * datatypes and dataspaces (and then run some performance metrics to + /* We could create a second index and put attributes in it to separate them + * from datatypes and dataspaces (and then run some performance metrics to * see whether this improved caching performance). */ ret = H5Pset_shared_mesg_nindexes(fcpl_id, 2); if(ret < 0) goto error; - ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_MESG_DTYPE_FLAG | H5O_MESG_SDSPACE_FLAG, 40); + ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_MESG_DTYPE_FLAG | H5O_MESG_SDSPACE_FLAG, 40); if(ret < 0) goto error; - ret = H5Pset_shared_mesg_index(fcpl_id, 2, H5O_MESG_ATTR_FLAG, 40); + ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_MESG_ATTR_FLAG, 40); if(ret < 0) goto error; ret = create_standard_file("separate_indexes_file.h5", fcpl_id); @@ -186,7 +186,7 @@ int main(void) */ ret = H5Pset_shared_mesg_nindexes(fcpl_id, 1); if(ret < 0) goto error; - ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_MESG_ALL_FLAG, 40); + ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_MESG_ALL_FLAG, 40); if(ret < 0) goto error; ret = H5Pset_shared_mesg_phase_change(fcpl_id, 5, 0); diff --git a/src/H5Fsuper.c b/src/H5Fsuper.c index 821981c..d8c5d0e 100644 --- a/src/H5Fsuper.c +++ b/src/H5Fsuper.c @@ -372,12 +372,12 @@ H5F_read_superblock(H5F_t *f, hid_t dxpl_id, H5G_loc_t *root_loc, haddr_t addr, * fcpl */ if(shared->sohm_addr != HADDR_UNDEF) { - unsigned index_flags[H5SM_MAX_NINDEXES] = {0}; - unsigned minsizes[H5SM_MAX_NINDEXES] = {0}; + unsigned index_flags[H5O_SHMESG_MAX_NINDEXES] = {0}; + unsigned minsizes[H5O_SHMESG_MAX_NINDEXES] = {0}; unsigned sohm_l2b; /* SOHM list-to-btree cutoff */ unsigned sohm_b2l; /* SOHM btree-to-list cutoff */ - HDassert(shared->sohm_nindexes > 0 && shared->sohm_nindexes <= H5SM_MAX_NINDEXES); + HDassert(shared->sohm_nindexes > 0 && shared->sohm_nindexes <= H5O_SHMESG_MAX_NINDEXES); /* Read in the shared OH message information if there is any */ if(H5SM_get_info(f, index_flags, minsizes, &sohm_l2b, &sohm_b2l, dxpl_id) < 0) diff --git a/src/H5Omessage.c b/src/H5Omessage.c index 515e131..c7979d4 100644 --- a/src/H5Omessage.c +++ b/src/H5Omessage.c @@ -307,8 +307,6 @@ done: * *------------------------------------------------------------------------- */ -/* JAMES: this will probably get put through its paces when extending shared - * dataspaces */ herr_t H5O_msg_write(H5O_loc_t *loc, unsigned type_id, unsigned overwrite, unsigned mesg_flags, unsigned update_flags, void *mesg, hid_t dxpl_id) @@ -1362,7 +1360,6 @@ H5O_msg_iterate_real(H5F_t *f, H5O_t *oh, const H5O_msg_class_t *type, } /* end if */ else { /* If the message is shared, get the real message it points to */ - /* JAMES: test */ if(idx_msg->flags & H5O_MSG_FLAG_SHARED) { if(NULL == (native_mesg = H5O_shared_read(f, dxpl_id, idx_msg->native, idx_msg->type, NULL))) diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 9330d4a..392b223 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -46,21 +46,14 @@ typedef struct H5O_msg_class_t H5O_msg_class_t; typedef struct H5O_t H5O_t; /* JAMES: should these be in H5SM_private? or renamed? */ -/* JAMES: causes errors encoding/decoding if this is wrong. Can't be constant. */ +/* Fractal heap ID type for shared message heap IDs. The length of a heap ID + * depends on how the heap is configured; currently they're always stored in + * 8-byte fields, although only seven bytes are used. + */ #define H5SM_FHEAP_ID_LEN 7 - -/* JAMES: not great? */ typedef uint64_t H5SM_fheap_id_t; -/* JAMES for debugging */ -#define PRINT_BUF(buf, size) \ - if(1) { size_t x; \ - for(x=0; x H5SM_MAX_NINDEXES) - HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "number of indexes is greater than H5SM_MAX_NINDEXES"); + if (nindexes > H5O_SHMESG_MAX_NINDEXES) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "number of indexes is greater than H5O_SHMESG_MAX_NINDEXES"); /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id, H5P_FILE_CREATE))) @@ -765,6 +767,9 @@ done: * message that should be stored in this index and the minimum * size of a message in the index. * + * INDEX_NUM is zero-indexed (in a file with three indexes, + * they are numbered 0, 1, and 2). + * * Return: Non-negative on success/Negative on failure * * Programmer: James Laird @@ -777,16 +782,14 @@ H5Pset_shared_mesg_index(hid_t plist_id, unsigned index_num, unsigned mesg_type_ { H5P_genplist_t *plist; /* Property list pointer */ unsigned nindexes; /* Number of SOHM indexes */ - unsigned type_flags[H5SM_MAX_NINDEXES]; /* Array of mesg_type_flags*/ - unsigned minsizes[H5SM_MAX_NINDEXES]; /* Array of min_mesg_sizes*/ + unsigned type_flags[H5O_SHMESG_MAX_NINDEXES]; /* Array of mesg_type_flags*/ + unsigned minsizes[H5O_SHMESG_MAX_NINDEXES]; /* Array of min_mesg_sizes*/ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(H5Pset_shared_mesg_index, FAIL) H5TRACE4("e", "iIuIuIu", plist_id, index_num, mesg_type_flags, min_mesg_size); /* Check arguments */ - if(index_num == 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "index_num must be at least 1"); if(mesg_type_flags > H5O_MESG_ALL_FLAG) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "unrecognized flags in mesg_type_flags"); @@ -799,8 +802,8 @@ H5Pset_shared_mesg_index(hid_t plist_id, unsigned index_num, unsigned mesg_type_ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get number of indexes"); /* Range check */ - if(index_num > nindexes) - HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "index_num is greater than number of indexes in property list"); + if(index_num >= nindexes) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "index_num is too large; no such index"); /* Get arrays of type flags and message sizes */ if(H5P_get(plist, H5F_CRT_SHMSG_INDEX_TYPES_NAME, type_flags) < 0) @@ -809,8 +812,8 @@ H5Pset_shared_mesg_index(hid_t plist_id, unsigned index_num, unsigned mesg_type_ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get current min sizes") /* Set values in arrays */ - type_flags[index_num - 1] = mesg_type_flags; - minsizes[index_num - 1] = min_mesg_size; + type_flags[index_num] = mesg_type_flags; + minsizes[index_num] = min_mesg_size; /* Write arrays back to plist */ if(H5P_set(plist, H5F_CRT_SHMSG_INDEX_TYPES_NAME, type_flags) < 0) @@ -842,18 +845,14 @@ H5Pget_shared_mesg_index(hid_t plist_id, unsigned index_num, unsigned *mesg_type { H5P_genplist_t *plist; /* Property list pointer */ unsigned nindexes; /* Number of SOHM indexes */ - unsigned type_flags[H5SM_MAX_NINDEXES]; /* Array of mesg_type_flags*/ - unsigned minsizes[H5SM_MAX_NINDEXES]; /* Array of min_mesg_sizes*/ + unsigned type_flags[H5O_SHMESG_MAX_NINDEXES]; /* Array of mesg_type_flags*/ + unsigned minsizes[H5O_SHMESG_MAX_NINDEXES]; /* Array of min_mesg_sizes*/ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_API(H5Pget_shared_mesg_index, FAIL); H5TRACE4("e", "iIu*Iu*Iu", plist_id, index_num, mesg_type_flags, min_mesg_size); - /* Check arguments */ - if(index_num == 0) - HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "index_num must be at least 1") - /* Get the plist structure */ if(NULL == (plist = H5P_object_verify(plist_id,H5P_FILE_CREATE))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") @@ -862,7 +861,7 @@ H5Pget_shared_mesg_index(hid_t plist_id, unsigned index_num, unsigned *mesg_type if(H5P_get(plist, H5F_CRT_SHMSG_NINDEXES_NAME, &nindexes) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get number of indexes") - if(index_num > nindexes) + if(index_num >= nindexes) HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "index_num is greater than number of indexes in property list") /* Get arrays of type flags and message sizes */ @@ -873,9 +872,9 @@ H5Pget_shared_mesg_index(hid_t plist_id, unsigned index_num, unsigned *mesg_type /* Get values from arrays */ if(mesg_type_flags) - *mesg_type_flags = type_flags[index_num - 1]; + *mesg_type_flags = type_flags[index_num]; if(min_mesg_size) - *min_mesg_size = minsizes[index_num - 1]; + *min_mesg_size = minsizes[index_num]; done: FUNC_LEAVE_API(ret_value); @@ -917,10 +916,10 @@ H5Pset_shared_mesg_phase_change(hid_t plist_id, unsigned max_list, unsigned min_ */ if(max_list + 1 < min_btree) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "minimum B-tree value is greater than maximum list value") - if(max_list > H5SM_MAX_LIST_ELEMS) - HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "max list value is larger than H5SM_MAX_LIST_ELEMS") - if(min_btree > H5SM_MAX_LIST_ELEMS) - HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "min btree value is larger than H5SM_MAX_LIST_ELEMS") + if(max_list > H5O_SHMESG_MAX_LIST_SIZE) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "max list value is larger than H5O_SHMESG_MAX_LIST_SIZE") + if(min_btree > H5O_SHMESG_MAX_LIST_SIZE) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "min btree value is larger than H5O_SHMESG_MAX_LIST_SIZE") /* Avoid the strange case where max_list == 0 and min_btree == 1, so deleting the * last message in a B-tree makes it become an empty list. diff --git a/src/H5SM.c b/src/H5SM.c index 74315d7..38d1b34 100755 --- a/src/H5SM.c +++ b/src/H5SM.c @@ -73,9 +73,9 @@ static herr_t H5SM_type_to_flag(unsigned type_id, unsigned *type_flag); /*********************/ H5FL_DEFINE(H5SM_master_table_t); -H5FL_ARR_DEFINE(H5SM_index_header_t, H5SM_MAX_NINDEXES); +H5FL_ARR_DEFINE(H5SM_index_header_t, H5O_SHMESG_MAX_NINDEXES); H5FL_DEFINE(H5SM_list_t); -H5FL_ARR_DEFINE(H5SM_sohm_t, H5SM_MAX_LIST_ELEMS); +H5FL_ARR_DEFINE(H5SM_sohm_t, H5O_SHMESG_MAX_LIST_SIZE); /*****************************/ @@ -111,8 +111,8 @@ H5SM_init(H5F_t *f, H5P_genplist_t * fc_plist, hid_t dxpl_id) haddr_t table_addr = HADDR_UNDEF; unsigned num_indexes; unsigned list_max, btree_min; - unsigned index_type_flags[H5SM_MAX_NINDEXES]; - unsigned minsizes[H5SM_MAX_NINDEXES]; + unsigned index_type_flags[H5O_SHMESG_MAX_NINDEXES]; + unsigned minsizes[H5O_SHMESG_MAX_NINDEXES]; unsigned type_flags_used; unsigned x; hsize_t table_size; @@ -141,7 +141,7 @@ H5SM_init(H5F_t *f, H5P_genplist_t * fc_plist, hid_t dxpl_id) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get SOHM message min sizes") /* Verify that values are valid */ - if(num_indexes > H5SM_MAX_NINDEXES) + if(num_indexes > H5O_SHMESG_MAX_NINDEXES) HGOTO_ERROR(H5E_PLIST, H5E_BADRANGE, FAIL, "number of indexes in property list is too large") /* Check that type flags weren't duplicated anywhere */ @@ -168,7 +168,7 @@ H5SM_init(H5F_t *f, H5P_genplist_t * fc_plist, hid_t dxpl_id) * min. */ HDassert(list_max + 1 >= btree_min); - HDassert(table->num_indexes > 0 && table->num_indexes <= H5SM_MAX_NINDEXES); + HDassert(table->num_indexes > 0 && table->num_indexes <= H5O_SHMESG_MAX_NINDEXES); /* Allocate the SOHM indexes as an array. */ if(NULL == (table->indexes = (H5SM_index_header_t *)H5FL_ARR_MALLOC(H5SM_index_header_t, (size_t)table->num_indexes))) @@ -439,7 +439,7 @@ H5SM_create_index(H5F_t *f, H5SM_index_header_t *header, hid_t dxpl_id) { header->index_type = H5SM_LIST; - if((list_addr = H5SM_create_list(f, header, dxpl_id)) == HADDR_UNDEF) /* JAMES: only allocate part of the list? */ + if((list_addr = H5SM_create_list(f, header, dxpl_id)) == HADDR_UNDEF) HGOTO_ERROR(H5E_SOHM, H5E_CANTCREATE, FAIL, "list creation failed for SOHM index") header->index_addr = list_addr; @@ -937,7 +937,7 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5SM_index_header_t *header, if (NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") - /* JAMES: not very effecient (gets hash value twice, searches list twice). Refactor. */ + /* JAMES: not very efficient (gets hash value twice, searches list twice). Refactor. */ /* See if the message is already in the index and get its location */ /* JAMES: should return a pointer to the message */ list_pos = H5SM_find_in_list(list, &key); diff --git a/src/H5SMcache.c b/src/H5SMcache.c index d4323b0..5e8f58f 100644 --- a/src/H5SMcache.c +++ b/src/H5SMcache.c @@ -44,7 +44,7 @@ /* Local Macros */ /****************/ /* JAMES: should this change according to address size? */ -#define H5F_LISTBUF_SIZE H5SM_LIST_SIZEOF_MAGIC + H5SM_MAX_LIST_ELEMS * 16 +#define H5F_LISTBUF_SIZE H5SM_LIST_SIZEOF_MAGIC + H5O_SHMESG_MAX_LIST_SIZE * 16 #define H5SM_LIST_VERSION 0 /* Verion of Shared Object Header Message List Indexes */ diff --git a/test/objcopy.c b/test/objcopy.c index f321a25..8778ad4 100755 --- a/test/objcopy.c +++ b/test/objcopy.c @@ -7115,7 +7115,7 @@ main(void) /* Create an FCPL with sharing enabled */ if((fcpl_shared = H5Pcreate(H5P_FILE_CREATE)) < 0) TEST_ERROR if(H5Pset_shared_mesg_nindexes(fcpl_shared, 1) < 0) TEST_ERROR - if(H5Pset_shared_mesg_index(fcpl_shared, 1, H5O_MESG_ALL_FLAG, (size_t) 10) < 0) TEST_ERROR + if(H5Pset_shared_mesg_index(fcpl_shared, 0, H5O_MESG_ALL_FLAG, (size_t) 10) < 0) TEST_ERROR /* Test in all configurations */ for(configuration = 0; configuration <= MAX_CONFIGURATION; configuration++) { diff --git a/test/tattr.c b/test/tattr.c index cc0200d..99e03ab 100644 --- a/test/tattr.c +++ b/test/tattr.c @@ -2968,7 +2968,7 @@ test_attr(void) /* Make attributes > 1 byte shared (i.e. all of them :-) */ ret = H5Pset_shared_mesg_nindexes(fcpl2, (unsigned)1); CHECK_I(ret, "H5Pset_shared_mesg_nindexes"); - ret = H5Pset_shared_mesg_index(fcpl2, (unsigned)1, H5O_MESG_ATTR_FLAG, (unsigned)1); + ret = H5Pset_shared_mesg_index(fcpl2, (unsigned)0, H5O_MESG_ATTR_FLAG, (unsigned)1); CHECK_I(ret, "H5Pset_shared_mesg_index"); #ifndef QAK diff --git a/test/tsohm.c b/test/tsohm.c index 3bdb340..23a2975 100644 --- a/test/tsohm.c +++ b/test/tsohm.c @@ -24,20 +24,20 @@ /* Default SOHM values */ #define DEF_NUM_INDEXES 0 -const unsigned def_type_flags[H5SM_MAX_NINDEXES] = {0,0,0,0,0,0}; -const unsigned def_minsizes[H5SM_MAX_NINDEXES] = {250,250,250,250,250,250}; +const unsigned def_type_flags[H5O_SHMESG_MAX_NINDEXES] = {0,0,0,0,0,0}; +const unsigned def_minsizes[H5O_SHMESG_MAX_NINDEXES] = {250,250,250,250,250,250}; #define DEF_L2B 50 #define DEF_B2L 40 /* Non-default SOHM values for testing */ #define TEST_NUM_INDEXES 4 -const unsigned test_type_flags[H5SM_MAX_NINDEXES] = +const unsigned test_type_flags[H5O_SHMESG_MAX_NINDEXES] = {H5O_MESG_FILL_FLAG, H5O_MESG_DTYPE_FLAG | H5O_MESG_ATTR_FLAG, H5O_MESG_SDSPACE_FLAG, H5O_MESG_PLINE_FLAG, 0, 0}; -const unsigned test_minsizes[H5SM_MAX_NINDEXES] = {0, 2, 40, 100, 3, 1000}; +const unsigned test_minsizes[H5O_SHMESG_MAX_NINDEXES] = {0, 2, 40, 100, 3, 1000}; #define TEST_L2B 65 #define TEST_B2L 64 @@ -55,7 +55,7 @@ const unsigned test_minsizes[H5SM_MAX_NINDEXES] = {0, 2, 40, 100, 3, 1000}; typedef struct dtype1_struct { int i1; - char str[10]; /* JAMES */ + char str[10]; int i2; int i3; int i4; @@ -176,12 +176,12 @@ static void check_fcpl_values(hid_t fcpl_id, const unsigned nindexes_in, VERIFY(num_indexes, nindexes_in, "H5Pget_shared_mesg_nindexes"); /* Verify index flags and minsizes are set */ - for(x=1; x<=num_indexes; ++x) + for(x=0; x