Index: transition_layer/gpr_replica_dict_tl.c =================================================================== --- transition_layer/gpr_replica_dict_tl.c (revision 14736) +++ transition_layer/gpr_replica_dict_tl.c (working copy) @@ -2,7 +2,7 @@ * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. - * Copyright (c) 2004-2005 The University of Tennessee and The University + * Copyright (c) 2004-2007 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, @@ -27,23 +27,24 @@ #include "orte_config.h" -#include "orte/class/orte_pointer_array.h" +#include "opal/hash_string.h" #include "opal/util/output.h" #include "opal/util/trace.h" +#include "orte/class/orte_pointer_array.h" #include "orte/mca/errmgr/errmgr.h" - +#include "orte/mca/gpr/replica/gpr_replica.h" #include "orte/mca/gpr/replica/functional_layer/gpr_replica_fn.h" - #include "orte/mca/gpr/replica/transition_layer/gpr_replica_tl.h" int orte_gpr_replica_create_itag(orte_gpr_replica_itag_t *itag, orte_gpr_replica_segment_t *seg, char *name) { - char **ptr, *new_dict; - orte_gpr_replica_itag_t j; - orte_std_cntr_t i, len, len2, index; + orte_gpr_replica_dict_entry_t* new_dict; + orte_std_cntr_t index; + uint32_t len, hash_key; + int rc; OPAL_TRACE(3); @@ -56,29 +57,19 @@ return ORTE_ERR_BAD_PARAM; } - len = (orte_std_cntr_t)strlen(name); - - /* check seg's dictionary to ensure uniqueness */ - ptr = (char**)(seg->dict)->addr; - for (i=0, j=0; j < seg->num_dict_entries && - i < (seg->dict)->size; i++) { - if (NULL != ptr[i]) { - j++; - len2 = (orte_std_cntr_t)strlen(ptr[i]); - if ((len == len2 && 0 == strncmp(ptr[i], name, len))) { - /* already present */ - if (i < ORTE_GPR_REPLICA_ITAG_MAX) { - *itag = (orte_gpr_replica_itag_t)i; - return ORTE_SUCCESS; - } - /* otherwise, the itag violates the max value */ - return ORTE_ERR_BAD_PARAM; - } - } + if( ORTE_ERR_NOT_FOUND != (rc = orte_gpr_replica_dict_lookup(itag, seg, name))) { + return rc; } + OPAL_HASH_STRLEN( name, hash_key, len ); + /* okay, name is unique - create dictionary entry */ - new_dict = strdup(name); + new_dict = (orte_gpr_replica_dict_entry_t*)malloc( sizeof(orte_gpr_replica_dict_entry_t) + len ); + new_dict->hash_key = hash_key; + new_dict->length = len; + strncpy( new_dict->string, name, len ); + new_dict->string[len] = '\0'; + if (0 > orte_pointer_array_add(&index, seg->dict, (void*)new_dict)) { free(new_dict); ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); @@ -93,7 +84,8 @@ /* otherwise, the itag violates the max value */ free(new_dict); - ptr[index] = NULL; + /* remove itag from segment dictionary */ + orte_pointer_array_set_item(seg->dict, (orte_std_cntr_t)index, NULL); return ORTE_ERR_OUT_OF_RESOURCE; } @@ -101,7 +93,7 @@ int orte_gpr_replica_delete_itag(orte_gpr_replica_segment_t *seg, char *name) { - char **ptr; + orte_gpr_replica_dict_entry_t **ptr; orte_gpr_replica_itag_t itag; int rc; @@ -123,19 +115,19 @@ /* need to search this segment's registry to find all instances * that name & delete them */ - if (ORTE_SUCCESS != (rc = orte_gpr_replica_purge_itag(seg, itag))) { + if (ORTE_SUCCESS != (rc = orte_gpr_replica_purge_itag(seg, itag))) { ORTE_ERROR_LOG(rc); return rc; - } + } - /* free the dictionary element data */ - ptr = (char**)((seg->dict)->addr); - if (NULL == ptr[itag]) { /* dict element no longer valid */ - return ORTE_ERR_NOT_FOUND; - } - free(ptr[itag]); + /* free the dictionary element data */ + ptr = (orte_gpr_replica_dict_entry_t**)(seg->dict->addr); + if (NULL == ptr[itag]) { /* dict element no longer valid */ + return ORTE_ERR_NOT_FOUND; + } + free(ptr[itag]); - /* remove itag from segment dictionary */ + /* remove itag from segment dictionary */ orte_pointer_array_set_item(seg->dict, (orte_std_cntr_t)itag, NULL); /* decrease the dict counter */ @@ -149,10 +141,10 @@ orte_gpr_replica_dict_lookup(orte_gpr_replica_itag_t *itag, orte_gpr_replica_segment_t *seg, char *name) { - char **ptr; + orte_gpr_replica_dict_entry_t **ptr; orte_std_cntr_t i; orte_gpr_replica_itag_t j; - orte_std_cntr_t len, len2; + uint32_t hash_key, len; OPAL_TRACE(3); @@ -168,27 +160,26 @@ if (NULL == name) { /* just want segment token-itag pair */ *itag = seg->itag; return ORTE_SUCCESS; - } + } - len = (orte_std_cntr_t)strlen(name); - - /* want specified token-itag pair in that segment's dictionary */ - ptr = (char**)((seg->dict)->addr); + OPAL_HASH_STRLEN( name, hash_key, len ); + + ptr = (orte_gpr_replica_dict_entry_t**)(seg->dict)->addr; for (i=0, j=0; j < seg->num_dict_entries && i < (seg->dict)->size; i++) { - if (NULL != ptr[i]) { - j++; - len2 = (orte_std_cntr_t)strlen(ptr[i]); - if (len == len2 && 0 == strncmp(ptr[i], name, len)) { - if (i < ORTE_GPR_REPLICA_ITAG_MAX) { - *itag = (orte_gpr_replica_itag_t)i; - return ORTE_SUCCESS; - } - /* otherwise, the itag violates the max value */ - return ORTE_ERR_BAD_PARAM; + if (NULL == ptr[i]) continue; + j++; + if( (len == ptr[i]->length) && (hash_key == ptr[i]->hash_key) + && (0 == strncmp(ptr[i]->string, name, len)) ) { + /* already present */ + if (i < ORTE_GPR_REPLICA_ITAG_MAX) { + *itag = (orte_gpr_replica_itag_t)i; + return ORTE_SUCCESS; } + /* otherwise, the itag violates the max value */ + return ORTE_ERR_BAD_PARAM; } - } + } return ORTE_ERR_NOT_FOUND; /* couldn't find the specified entry */ } @@ -197,7 +188,7 @@ int orte_gpr_replica_dict_reverse_lookup(char **name, orte_gpr_replica_segment_t *seg, orte_gpr_replica_itag_t itag) { - char **ptr; + orte_gpr_replica_dict_entry_t **ptr; orte_gpr_replica_segment_t **segptr; OPAL_TRACE(3); @@ -212,34 +203,34 @@ } if (NULL == seg) { - /* return the segment name - * note that itag is the index of the segment in that array - */ + /* return the segment name + * note that itag is the index of the segment in that array + */ segptr = (orte_gpr_replica_segment_t**)(orte_gpr_replica.segments->addr); if (NULL == segptr[itag]) { /* this segment is no longer alive */ return ORTE_ERR_NOT_FOUND; } - *name = strdup(segptr[itag]->name); - return ORTE_SUCCESS; + *name = strdup(segptr[itag]->name); + return ORTE_SUCCESS; } /* seg is provided - find the matching token for this itag * note again that itag is the index into this segment's * dictionary array */ - ptr = (char**)((seg->dict)->addr); + ptr = (orte_gpr_replica_dict_entry_t**)((seg->dict)->addr); if (NULL == ptr[itag]) { /* this entry is no longer valid! */ return ORTE_ERR_NOT_FOUND; } - *name = strdup(ptr[itag]); + *name = strdup(ptr[itag]->string); return ORTE_SUCCESS; } int -orte_gpr_replica_get_itag_list(orte_gpr_replica_itag_t **itaglist, - orte_gpr_replica_segment_t *seg, char **names, - orte_std_cntr_t *num_names) +orte_gpr_replica_get_itag_list( orte_gpr_replica_itag_t **itaglist, + orte_gpr_replica_segment_t *seg, char **names, + orte_std_cntr_t *num_names ) { char **namptr; int rc; @@ -257,15 +248,15 @@ /* check for wild-card case */ if (NULL == names) { - return ORTE_SUCCESS; + return ORTE_SUCCESS; } if (0 >= (*num_names)) { /* NULL-terminated list - count them */ *num_names = 0; namptr = names; while (NULL != *namptr) { - *num_names = (*num_names) + 1; - namptr++; + *num_names = (*num_names) + 1; + namptr++; } } @@ -277,14 +268,13 @@ namptr = names; - for (i=0; i < (*num_names); i++) { /* traverse array of names - ignore any NULL's */ - if (NULL != names[i]) { - if (ORTE_SUCCESS != (rc = orte_gpr_replica_create_itag(&((*itaglist)[i]), seg, names[i]))) { - ORTE_ERROR_LOG(rc); - free(*itaglist); - *itaglist = NULL; - return rc; - } + for( i = 0; i < (*num_names); i++ ) { /* traverse array of names - ignore any NULL's */ + if (NULL == names[i]) continue; + if (ORTE_SUCCESS != (rc = orte_gpr_replica_create_itag(&((*itaglist)[i]), seg, names[i]))) { + ORTE_ERROR_LOG(rc); + free(*itaglist); + *itaglist = NULL; + return rc; } } return ORTE_SUCCESS; Index: gpr_replica_class_instances.h =================================================================== --- gpr_replica_class_instances.h (revision 14736) +++ gpr_replica_class_instances.h (working copy) @@ -99,7 +99,7 @@ static void orte_gpr_replica_segment_destructor(orte_gpr_replica_segment_t* seg) { orte_std_cntr_t i, k; - char **dptr; + orte_gpr_replica_dict_entry_t **dptr; orte_gpr_replica_itag_t j; orte_gpr_replica_container_t **cptr; @@ -108,7 +108,7 @@ } if (NULL != seg->dict) { - dptr = (char**)(seg->dict)->addr; + dptr = (orte_gpr_replica_dict_entry_t**)(seg->dict->addr); for (i=0, j=0; j < seg->num_dict_entries && i < (seg->dict)->size; i++) { if (NULL != dptr[i]) { Index: gpr_replica.h =================================================================== --- gpr_replica.h (revision 14736) +++ gpr_replica.h (working copy) @@ -152,6 +152,18 @@ }; typedef struct orte_gpr_replica_t orte_gpr_replica_t; +/** + * This structure will be used for all dictionary entries. Instead of using strcmp (& co.) + * we will compute a quick hash value for each string and store this value together with + * the string in the orte_pointer_array. The string have to be the last entry in the + * structure, in order to allow us to allocate it only once. + */ +struct orte_gpr_replica_dict_entry_t { + uint32_t hash_key; /**< the associated hash value */ + uint32_t length; /**< the length of the string computed once */ + char string[1]; /**< the real string (i.e. the structure will have a variable size) */ +}; +typedef struct orte_gpr_replica_dict_entry_t orte_gpr_replica_dict_entry_t; /** Registry segment definition. * The registry is subdivided into segments, each defining a unique domain. The "universe" segment Index: functional_layer/gpr_replica_dump_fn.c =================================================================== --- functional_layer/gpr_replica_dump_fn.c (revision 14736) +++ functional_layer/gpr_replica_dump_fn.c (working copy) @@ -2,7 +2,7 @@ * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. - * Copyright (c) 2004-2005 The University of Tennessee and The University + * Copyright (c) 2004-2007 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, @@ -833,7 +833,7 @@ { size_t data_size, isize; orte_std_cntr_t i, j, k, m; - char **dict; + orte_gpr_replica_dict_entry_t **dict; orte_gpr_replica_container_t **cptr; orte_gpr_replica_itagval_t **iptr; int rc; @@ -842,48 +842,48 @@ data_size += 2*sizeof(orte_gpr_replica_itag_t); /* itag, num_dict_entries */ data_size += (seg->dict)->size * sizeof(void*); /* account for size of pointer array */ - dict = (char**)(seg->dict)->addr; + dict = (orte_gpr_replica_dict_entry_t**)(seg->dict)->addr; for (i=0, j=0; j < seg->num_dict_entries && - i < (seg->dict)->size; i++) { - if (NULL != dict[i]) { - j++; - data_size += strlen(dict[i]) + 1; - } - } + i < (seg->dict)->size; i++) { + if (NULL != dict[i]) { + j++; + data_size += dict[i]->length + 1; + } + } - data_size += sizeof(orte_std_cntr_t); /* num_containers */ - cptr = (orte_gpr_replica_container_t**)(seg->containers)->addr; - for (i=0, j=0; j < (seg->num_containers) && - i < (seg->containers)->size; i++) { - if (NULL != cptr[i]) { - j++; - data_size += sizeof(orte_std_cntr_t); /* index */ - data_size += cptr[i]->num_itags * sizeof(orte_gpr_replica_itag_t); /* itags array */ - data_size += sizeof(orte_std_cntr_t); /* num_itags */ - data_size += (cptr[i]->itagvals)->size * sizeof(void*); /* account for size of pointer array */ - data_size += sizeof(orte_std_cntr_t); /* num_itagvals */ - iptr = (orte_gpr_replica_itagval_t**)(cptr[i]->itagvals)->addr; - for (k=0, m=0; m < cptr[i]->num_itagvals && - k < (cptr[i]->itagvals)->size; k++) { - if (NULL != iptr[k]) { - m++; - data_size += sizeof(orte_std_cntr_t); /* index */ - data_size += sizeof(orte_gpr_replica_itag_t); - data_size += sizeof(orte_data_type_t); - if (ORTE_SUCCESS != (rc = orte_dss.size(&isize, iptr[k]->value->data, iptr[k]->value->type))) { - ORTE_ERROR_LOG(rc); - *segsize = 0; - return rc; - } - data_size += isize; - } - } - data_size += 3*sizeof(orte_std_cntr_t); - data_size += (cptr[i]->itaglist).array_size * sizeof(unsigned char*); - } - } + data_size += sizeof(orte_std_cntr_t); /* num_containers */ + cptr = (orte_gpr_replica_container_t**)(seg->containers)->addr; + for (i=0, j=0; j < (seg->num_containers) && + i < (seg->containers)->size; i++) { + if (NULL != cptr[i]) { + j++; + data_size += sizeof(orte_std_cntr_t); /* index */ + data_size += cptr[i]->num_itags * sizeof(orte_gpr_replica_itag_t); /* itags array */ + data_size += sizeof(orte_std_cntr_t); /* num_itags */ + data_size += (cptr[i]->itagvals)->size * sizeof(void*); /* account for size of pointer array */ + data_size += sizeof(orte_std_cntr_t); /* num_itagvals */ + iptr = (orte_gpr_replica_itagval_t**)(cptr[i]->itagvals)->addr; + for (k=0, m=0; m < cptr[i]->num_itagvals && + k < (cptr[i]->itagvals)->size; k++) { + if (NULL != iptr[k]) { + m++; + data_size += sizeof(orte_std_cntr_t); /* index */ + data_size += sizeof(orte_gpr_replica_itag_t); + data_size += sizeof(orte_data_type_t); + if (ORTE_SUCCESS != (rc = orte_dss.size(&isize, iptr[k]->value->data, iptr[k]->value->type))) { + ORTE_ERROR_LOG(rc); + *segsize = 0; + return rc; + } + data_size += isize; + } + } + data_size += 3*sizeof(orte_std_cntr_t); + data_size += (cptr[i]->itaglist).array_size * sizeof(unsigned char*); + } + } - *segsize = data_size; - return ORTE_SUCCESS; + *segsize = data_size; + return ORTE_SUCCESS; } Index: functional_layer/gpr_replica_del_index_fn.c =================================================================== --- functional_layer/gpr_replica_del_index_fn.c (revision 14736) +++ functional_layer/gpr_replica_del_index_fn.c (working copy) @@ -2,7 +2,7 @@ * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. - * Copyright (c) 2004-2005 The University of Tennessee and The University + * Copyright (c) 2004-2007 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, @@ -159,10 +159,9 @@ { char **ptr; orte_gpr_replica_segment_t **segs; - char **dict; + orte_gpr_replica_dict_entry_t **dict; orte_std_cntr_t i, j; - OPAL_TRACE(2); /* set default responses */ @@ -185,7 +184,7 @@ ptr = *index; segs = (orte_gpr_replica_segment_t**) (orte_gpr_replica.segments)->addr; for (i=0, j=0; j < orte_gpr_replica.num_segs && - i < (orte_gpr_replica.segments)->size; i++) { + i < (orte_gpr_replica.segments)->size; i++) { if (NULL != segs[i]) { ptr[j] = strdup(segs[i]->name); if (NULL == ptr[j]) { @@ -208,19 +207,18 @@ return ORTE_ERR_OUT_OF_RESOURCE; } ptr = *index; - dict = (char**)(seg->dict)->addr; + dict = (orte_gpr_replica_dict_entry_t**)(seg->dict)->addr; - for (i=0, j=0; j < seg->num_dict_entries && - i < (seg->dict)->size; i++) { - if (NULL != dict[i]) { - ptr[j] = strdup(dict[i]); - if (NULL == ptr[j]) { - ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); - *cnt = j; - return ORTE_ERR_OUT_OF_RESOURCE; - } - j++; + for( i = 0, j = 0; ((j < seg->num_dict_entries) && + (i < (seg->dict)->size)); i++ ) { + if(NULL == dict[i]) continue; + ptr[j] = strdup(dict[i]->string); + if (NULL == ptr[j]) { + ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); + *cnt = j; + return ORTE_ERR_OUT_OF_RESOURCE; } + j++; } *cnt = seg->num_dict_entries; return ORTE_SUCCESS;