1
1

changed segment dictionary to hash table to improve

search time for reverse lookup

This commit was SVN r7893.
Этот коммит содержится в:
Tim Woodall 2005-10-27 17:00:47 +00:00
родитель 13409ec53b
Коммит c0124fecdd
5 изменённых файлов: 126 добавлений и 118 удалений

Просмотреть файл

@ -35,6 +35,20 @@
#include "orte/mca/gpr/replica/communications/gpr_replica_comm.h" #include "orte/mca/gpr/replica/communications/gpr_replica_comm.h"
static void orte_gpr_replica_send_cb(
int status,
orte_process_name_t* peer,
orte_buffer_t* buffer,
orte_rml_tag_t tag,
void *cbdata)
{
if(0 > status) {
ORTE_ERROR_LOG(ORTE_ERR_COMM_FAILURE);
}
OBJ_RELEASE(buffer);
}
/* /*
* handle message from proxies * handle message from proxies
*/ */
@ -55,12 +69,11 @@ void orte_gpr_replica_recv(int status, orte_process_name_t* sender,
OPAL_THREAD_LOCK(&orte_gpr_replica_globals.mutex); OPAL_THREAD_LOCK(&orte_gpr_replica_globals.mutex);
if (ORTE_SUCCESS == orte_gpr_replica_process_command_buffer(buffer, sender, &answer)) { if (ORTE_SUCCESS == orte_gpr_replica_process_command_buffer(buffer, sender, &answer)) {
if (0 > orte_rml.send_buffer(sender, answer, tag, 0)) { if (0 > orte_rml.send_buffer_nb(sender, answer, tag, 0, orte_gpr_replica_send_cb, NULL)) {
ORTE_ERROR_LOG(ORTE_ERR_COMM_FAILURE); ORTE_ERROR_LOG(ORTE_ERR_COMM_FAILURE);
} }
} }
OBJ_RELEASE(answer);
if (orte_gpr_replica_globals.debug) { if (orte_gpr_replica_globals.debug) {
opal_output(0, "gpr replica: msg processing complete - processing callbacks"); opal_output(0, "gpr replica: msg processing complete - processing callbacks");
} }

Просмотреть файл

@ -157,7 +157,6 @@ int orte_gpr_replica_index_fn(orte_gpr_replica_segment_t *seg,
{ {
char **ptr; char **ptr;
orte_gpr_replica_segment_t **segs; orte_gpr_replica_segment_t **segs;
orte_gpr_replica_dict_t **dict;
size_t i, j; size_t i, j;
@ -192,28 +191,29 @@ int orte_gpr_replica_index_fn(orte_gpr_replica_segment_t *seg,
} }
/* must have requested index of a specific segment */ /* must have requested index of a specific segment */
if (0 < seg->num_dict_entries) { if (0 < opal_list_get_size(&seg->dict_entries)) {
opal_list_item_t* item;
*index = (char**)malloc(orte_gpr_replica.num_segs * sizeof(char*)); *index = (char**)malloc(orte_gpr_replica.num_segs * sizeof(char*));
if (NULL == *index) { if (NULL == *index) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE; return ORTE_ERR_OUT_OF_RESOURCE;
} }
ptr = *index; ptr = *index;
dict = (orte_gpr_replica_dict_t**)(seg->dict)->addr;
for(item = opal_list_get_first(&seg->dict_entries);
for (i=0, j=0; j < seg->num_dict_entries && item != opal_list_get_end(&seg->dict_entries);
i < (seg->dict)->size; i++) { item = opal_list_get_next(item)) {
if (NULL != dict[i]) { orte_gpr_replica_dict_entry_t* value = (orte_gpr_replica_dict_entry_t*)item;
ptr[j] = strdup(dict[i]->entry); ptr[j] = strdup(value->entry);
if (NULL == ptr[j]) { if (NULL == ptr[j]) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
*cnt = j; *cnt = j;
return ORTE_ERR_OUT_OF_RESOURCE; return ORTE_ERR_OUT_OF_RESOURCE;
}
j++;
} }
j++;
} }
*cnt = seg->num_dict_entries; *cnt = opal_list_get_size(&seg->dict_entries);
return ORTE_SUCCESS; return ORTE_SUCCESS;
} }

Просмотреть файл

@ -30,9 +30,9 @@
#include "class/orte_pointer_array.h" #include "class/orte_pointer_array.h"
#include "class/orte_value_array.h" #include "class/orte_value_array.h"
#include "opal/class/opal_hash_table.h"
#include "opal/threads/mutex.h" #include "opal/threads/mutex.h"
#include "opal/threads/condition.h" #include "opal/threads/condition.h"
#include "mca/ns/ns_types.h" #include "mca/ns/ns_types.h"
#include "mca/gpr/base/base.h" #include "mca/gpr/base/base.h"
@ -129,12 +129,15 @@ typedef struct {
* structure is used to translate those strings into an integer itag value, thus allowing * structure is used to translate those strings into an integer itag value, thus allowing
* for faster searches of the registry. * for faster searches of the registry.
*/ */
struct orte_gpr_replica_dict_t { struct orte_gpr_replica_dict_entry_t {
size_t index; /**< location in dictionary array */ opal_list_item_t super;
char *entry; /**< Char string that defines the itag */ char *entry; /**< Char string that defines the itag */
size_t len; /**< String length */
orte_gpr_replica_itag_t itag; /**< Numerical value assigned by registry to represent string */ orte_gpr_replica_itag_t itag; /**< Numerical value assigned by registry to represent string */
}; };
typedef struct orte_gpr_replica_dict_t orte_gpr_replica_dict_t; typedef struct orte_gpr_replica_dict_entry_t orte_gpr_replica_dict_entry_t;
OBJ_CLASS_DECLARATION(orte_gpr_replica_dict_entry_t);
/* /*
* Registry "head" * Registry "head"
@ -173,8 +176,9 @@ struct orte_gpr_replica_segment_t {
opal_object_t super; /**< Make this an object */ opal_object_t super; /**< Make this an object */
char *name; /**< Name of the segment */ char *name; /**< Name of the segment */
orte_gpr_replica_itag_t itag; /**< itag of this segment */ orte_gpr_replica_itag_t itag; /**< itag of this segment */
orte_gpr_replica_itag_t num_dict_entries; opal_hash_table_t dict_hash;
orte_pointer_array_t *dict; /**< Managed array of dict structs */ opal_list_t dict_entries;
size_t dict_next_itag;
size_t num_containers; size_t num_containers;
orte_pointer_array_t *containers; /**< Managed array of pointers to containers on this segment */ orte_pointer_array_t *containers; /**< Managed array of pointers to containers on this segment */
}; };

Просмотреть файл

@ -74,17 +74,37 @@ OBJ_CLASS_INSTANCE(
orte_gpr_replica_local_trigger_destructor); /* destructor */ orte_gpr_replica_local_trigger_destructor); /* destructor */
/* DICT ENTRY */
static void orte_gpr_replica_dict_entry_construct(orte_gpr_replica_dict_entry_t* dict_entry)
{
dict_entry->entry = NULL;
}
static void orte_gpr_replica_dict_entry_destruct(orte_gpr_replica_dict_entry_t* dict_entry)
{
if(NULL != dict_entry->entry) {
free(dict_entry->entry);
}
}
/* define instance of orte_gpr_replica_segment_t */
OBJ_CLASS_INSTANCE(
orte_gpr_replica_dict_entry_t, /* type name */
opal_list_item_t, /* parent "class" name */
orte_gpr_replica_dict_entry_construct, /* constructor */
orte_gpr_replica_dict_entry_destruct); /* destructor */
/* SEGMENT */ /* SEGMENT */
/* constructor - used to initialize state of segment instance */ /* constructor - used to initialize state of segment instance */
static void orte_gpr_replica_segment_construct(orte_gpr_replica_segment_t* seg) static void orte_gpr_replica_segment_construct(orte_gpr_replica_segment_t* seg)
{ {
seg->name = NULL; seg->name = NULL;
seg->itag = ORTE_GPR_REPLICA_ITAG_MAX; seg->itag = ORTE_GPR_REPLICA_ITAG_MAX;
seg->num_dict_entries = 0; seg->dict_next_itag = 0;
orte_pointer_array_init(&(seg->dict), orte_gpr_array_block_size, OBJ_CONSTRUCT(&seg->dict_hash, opal_hash_table_t);
orte_gpr_array_max_size, OBJ_CONSTRUCT(&seg->dict_entries, opal_list_t);
orte_gpr_array_block_size); opal_hash_table_init(&seg->dict_hash, 512);
seg->num_containers = 0; seg->num_containers = 0;
orte_pointer_array_init(&(seg->containers), orte_gpr_array_block_size, orte_pointer_array_init(&(seg->containers), orte_gpr_array_block_size,
@ -97,27 +117,18 @@ static void orte_gpr_replica_segment_construct(orte_gpr_replica_segment_t* seg)
static void orte_gpr_replica_segment_destructor(orte_gpr_replica_segment_t* seg) static void orte_gpr_replica_segment_destructor(orte_gpr_replica_segment_t* seg)
{ {
size_t i, k; size_t i, k;
orte_gpr_replica_dict_t **dptr; opal_list_item_t* item;
orte_gpr_replica_container_t **cptr; orte_gpr_replica_container_t **cptr;
if (NULL != seg->name) { if (NULL != seg->name) {
free(seg->name); free(seg->name);
} }
if (NULL != seg->dict) { while(NULL != (item = opal_list_remove_first(&seg->dict_entries))) {
dptr = (orte_gpr_replica_dict_t**)((seg->dict)->addr); OBJ_RELEASE(item);
for (i=0, k=0; k < seg->num_dict_entries &&
i < (seg->dict)->size; i++) {
if (NULL != dptr[i]) {
k++;
if (NULL != dptr[i]->entry) {
free(dptr[i]->entry);
}
free(dptr[i]);
}
}
OBJ_RELEASE(seg->dict);
} }
OBJ_DESTRUCT(&seg->dict_entries);
OBJ_DESTRUCT(&seg->dict_hash);
if (NULL != seg->containers) { if (NULL != seg->containers) {
cptr = (orte_gpr_replica_container_t**)((seg->containers)->addr); cptr = (orte_gpr_replica_container_t**)((seg->containers)->addr);

Просмотреть файл

@ -26,22 +26,22 @@
#include "orte_config.h" #include "orte_config.h"
#include "orte/class/orte_pointer_array.h" #include "orte/class/orte_pointer_array.h"
#include "opal/class/opal_hash_table.h"
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/util/trace.h" #include "opal/util/trace.h"
#include "orte/mca/errmgr/errmgr.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/functional_layer/gpr_replica_fn.h"
#include "orte/mca/gpr/replica/transition_layer/gpr_replica_tl.h" #include "orte/mca/gpr/replica/transition_layer/gpr_replica_tl.h"
int int
orte_gpr_replica_create_itag(orte_gpr_replica_itag_t *itag, orte_gpr_replica_create_itag(orte_gpr_replica_itag_t *itag,
orte_gpr_replica_segment_t *seg, char *name) orte_gpr_replica_segment_t *seg, char *name)
{ {
orte_gpr_replica_dict_t **ptr, *new_dict; orte_gpr_replica_dict_entry_t *new_dict;
orte_gpr_replica_itag_t j; size_t len;
size_t i, len, len2;
OPAL_TRACE(3); OPAL_TRACE(3);
@ -57,15 +57,15 @@ orte_gpr_replica_create_itag(orte_gpr_replica_itag_t *itag,
len = strlen(name); len = strlen(name);
/* check seg's dictionary to ensure uniqueness */ /* check seg's dictionary to ensure uniqueness */
ptr = (orte_gpr_replica_dict_t**)(seg->dict)->addr; if(opal_list_get_size(&seg->dict_entries)) {
for (i=0, j=0; j < seg->num_dict_entries && opal_list_item_t* item;
i < (seg->dict)->size; i++) { for(item = opal_list_get_first(&seg->dict_entries);
if (NULL != ptr[i]) { item != opal_list_get_end(&seg->dict_entries);
j++; item = opal_list_get_next(item)) {
len2 = strlen(ptr[i]->entry); orte_gpr_replica_dict_entry_t* value = (orte_gpr_replica_dict_entry_t*)item;
if ((len == len2 && 0 == strncmp(ptr[i]->entry, name, len))) { if ((len == value->len && 0 == strncmp(value->entry, name, len))) {
/* already present */ /* already present */
*itag = ptr[i]->itag; *itag = value->itag;
return ORTE_SUCCESS; return ORTE_SUCCESS;
} }
} }
@ -74,38 +74,37 @@ orte_gpr_replica_create_itag(orte_gpr_replica_itag_t *itag,
/* okay, name is unique - create dictionary entry */ /* okay, name is unique - create dictionary entry */
/* first check to see if one is available */ /* first check to see if one is available */
if (ORTE_GPR_REPLICA_ITAG_MAX-1 < seg->num_dict_entries) { if (ORTE_GPR_REPLICA_ITAG_MAX-1 < opal_list_get_size(&seg->dict_entries)) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE; return ORTE_ERR_OUT_OF_RESOURCE;
} }
new_dict = (orte_gpr_replica_dict_t*)malloc(sizeof(orte_gpr_replica_dict_t)); new_dict = OBJ_NEW(orte_gpr_replica_dict_entry_t);
if (NULL == new_dict) { if (NULL == new_dict) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE; return ORTE_ERR_OUT_OF_RESOURCE;
} }
new_dict->itag = seg->dict_next_itag++;
new_dict->entry = strdup(name); new_dict->entry = strdup(name);
if (0 > orte_pointer_array_add(&(new_dict->index), seg->dict, (void*)new_dict)) { new_dict->len = strlen(name);
if (OMPI_SUCCESS != opal_hash_table_set_value_uint32(&seg->dict_hash, new_dict->itag, new_dict)) {
*itag = ORTE_GPR_REPLICA_ITAG_MAX; *itag = ORTE_GPR_REPLICA_ITAG_MAX;
free(new_dict->entry); OBJ_RELEASE(new_dict);
free(new_dict);
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE; return ORTE_ERR_OUT_OF_RESOURCE;
} }
opal_list_append(&seg->dict_entries, &new_dict->super);
*itag = seg->num_dict_entries; *itag = new_dict->itag;
new_dict->itag = *itag;
(seg->num_dict_entries)++;
return ORTE_SUCCESS; return ORTE_SUCCESS;
} }
int orte_gpr_replica_delete_itag(orte_gpr_replica_segment_t *seg, char *name) int orte_gpr_replica_delete_itag(orte_gpr_replica_segment_t *seg, char *name)
{ {
orte_gpr_replica_dict_t **ptr; opal_list_item_t* item;
orte_gpr_replica_itag_t itag; orte_gpr_replica_dict_entry_t *value = NULL;
size_t index; size_t len;
int rc; int rc;
OPAL_TRACE(3); OPAL_TRACE(3);
@ -116,37 +115,33 @@ int orte_gpr_replica_delete_itag(orte_gpr_replica_segment_t *seg, char *name)
return ORTE_ERR_BAD_PARAM; return ORTE_ERR_BAD_PARAM;
} }
/* find dictionary element to delete */ /* find dictionary element to delete */
if (ORTE_SUCCESS != (rc = orte_gpr_replica_dict_lookup(&itag, seg, name))) { len = strlen(name);
ORTE_ERROR_LOG(rc); for(item = opal_list_get_first(&seg->dict_entries);
return rc; item != opal_list_get_end(&seg->dict_entries);
item = opal_list_get_next(item)) {
value = (orte_gpr_replica_dict_entry_t*)item;
if ((len == value->len && 0 == strncmp(value->entry, name, len))) {
break;
}
}
if(NULL == value) {
return ORTE_SUCCESS;
} }
/* found name in dictionary */ /* found name in dictionary */
/* need to search this segment's registry to find all instances /* need to search this segment's registry to find all instances
* that name & delete them * 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, value->itag))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
return rc; return rc;
} }
/* free the dictionary element data */ /* free the dictionary element data */
ptr = (orte_gpr_replica_dict_t**)((seg->dict)->addr); opal_hash_table_remove_value_uint32(&seg->dict_hash, value->itag);
if (NULL == ptr[itag]) { /* dict element no longer valid */ opal_list_remove_item(&seg->dict_entries, &value->super);
return ORTE_ERR_NOT_FOUND; OBJ_RELEASE(value);
}
index = ptr[itag]->index;
if (NULL != ptr[itag]->entry) {
free(ptr[itag]->entry);
}
free(ptr[itag]);
/* remove itag from segment dictionary */
orte_pointer_array_set_item(seg->dict, index, NULL);
/* decrease the dict counter */
(seg->num_dict_entries)--;
return ORTE_SUCCESS; return ORTE_SUCCESS;
} }
@ -156,10 +151,8 @@ int
orte_gpr_replica_dict_lookup(orte_gpr_replica_itag_t *itag, orte_gpr_replica_dict_lookup(orte_gpr_replica_itag_t *itag,
orte_gpr_replica_segment_t *seg, char *name) orte_gpr_replica_segment_t *seg, char *name)
{ {
orte_gpr_replica_dict_t **ptr; opal_list_item_t* item;
size_t i; size_t len;
orte_gpr_replica_itag_t j;
size_t len, len2;
OPAL_TRACE(3); OPAL_TRACE(3);
@ -180,16 +173,13 @@ orte_gpr_replica_dict_lookup(orte_gpr_replica_itag_t *itag,
len = strlen(name); len = strlen(name);
/* want specified token-itag pair in that segment's dictionary */ /* want specified token-itag pair in that segment's dictionary */
ptr = (orte_gpr_replica_dict_t**)((seg->dict)->addr); for(item = opal_list_get_first(&seg->dict_entries);
for (i=0, j=0; j < seg->num_dict_entries && item != opal_list_get_next(&seg->dict_entries);
i < (seg->dict)->size; i++) { item = opal_list_get_next(item)) {
if (NULL != ptr[i]) { orte_gpr_replica_dict_entry_t* value = (orte_gpr_replica_dict_entry_t*)item;
j++; if (len == value->len && 0 == strncmp(value->entry, name, len)) {
len2 = strlen(ptr[i]->entry); *itag = value->itag;
if (len == len2 && 0 == strncmp(ptr[i]->entry, name, len)) { return ORTE_SUCCESS;
*itag = ptr[i]->itag;
return ORTE_SUCCESS;
}
} }
} }
@ -200,11 +190,8 @@ orte_gpr_replica_dict_lookup(orte_gpr_replica_itag_t *itag,
int orte_gpr_replica_dict_reverse_lookup(char **name, int orte_gpr_replica_dict_reverse_lookup(char **name,
orte_gpr_replica_segment_t *seg, orte_gpr_replica_itag_t itag) orte_gpr_replica_segment_t *seg, orte_gpr_replica_itag_t itag)
{ {
orte_gpr_replica_dict_t **ptr; orte_gpr_replica_dict_entry_t *value;
orte_gpr_replica_segment_t **segptr; orte_gpr_replica_segment_t **segptr;
size_t i;
orte_gpr_replica_itag_t j;
OPAL_TRACE(3); OPAL_TRACE(3);
@ -233,19 +220,12 @@ int orte_gpr_replica_dict_reverse_lookup(char **name,
* note again that itag is the index into this segment's * note again that itag is the index into this segment's
* dictionary array * dictionary array
*/ */
ptr = (orte_gpr_replica_dict_t**)((seg->dict)->addr);
for (i=0, j=0; j < seg->num_dict_entries && if(ORTE_SUCCESS == opal_hash_table_get_value_uint32(&seg->dict_hash, itag, (void**)&value)) {
i < (seg->dict)->size; i++) { *name = strdup(value->entry);
if (NULL != ptr[i]) { return ORTE_SUCCESS;
j++;
if (itag == ptr[i]->itag) { /* entry found! */
*name = strdup(ptr[i]->entry);
return ORTE_SUCCESS;
}
}
} }
/* get here if entry not found */ /* get here if entry not found */
return ORTE_ERR_NOT_FOUND; return ORTE_ERR_NOT_FOUND;
} }