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"
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
*/
@ -55,12 +69,11 @@ void orte_gpr_replica_recv(int status, orte_process_name_t* sender,
OPAL_THREAD_LOCK(&orte_gpr_replica_globals.mutex);
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);
}
}
OBJ_RELEASE(answer);
if (orte_gpr_replica_globals.debug) {
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;
orte_gpr_replica_segment_t **segs;
orte_gpr_replica_dict_t **dict;
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 */
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*));
if (NULL == *index) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE;
}
ptr = *index;
dict = (orte_gpr_replica_dict_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]->entry);
if (NULL == ptr[j]) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
*cnt = j;
return ORTE_ERR_OUT_OF_RESOURCE;
}
j++;
for(item = opal_list_get_first(&seg->dict_entries);
item != opal_list_get_end(&seg->dict_entries);
item = opal_list_get_next(item)) {
orte_gpr_replica_dict_entry_t* value = (orte_gpr_replica_dict_entry_t*)item;
ptr[j] = strdup(value->entry);
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;
*cnt = opal_list_get_size(&seg->dict_entries);
return ORTE_SUCCESS;
}

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

@ -30,9 +30,9 @@
#include "class/orte_pointer_array.h"
#include "class/orte_value_array.h"
#include "opal/class/opal_hash_table.h"
#include "opal/threads/mutex.h"
#include "opal/threads/condition.h"
#include "mca/ns/ns_types.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
* for faster searches of the registry.
*/
struct orte_gpr_replica_dict_t {
size_t index; /**< location in dictionary array */
struct orte_gpr_replica_dict_entry_t {
opal_list_item_t super;
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 */
};
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"
@ -173,8 +176,9 @@ struct orte_gpr_replica_segment_t {
opal_object_t super; /**< Make this an object */
char *name; /**< Name of the segment */
orte_gpr_replica_itag_t itag; /**< itag of this segment */
orte_gpr_replica_itag_t num_dict_entries;
orte_pointer_array_t *dict; /**< Managed array of dict structs */
opal_hash_table_t dict_hash;
opal_list_t dict_entries;
size_t dict_next_itag;
size_t num_containers;
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 */
/* 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 */
/* constructor - used to initialize state of segment instance */
static void orte_gpr_replica_segment_construct(orte_gpr_replica_segment_t* seg)
{
seg->name = NULL;
seg->itag = ORTE_GPR_REPLICA_ITAG_MAX;
seg->num_dict_entries = 0;
orte_pointer_array_init(&(seg->dict), orte_gpr_array_block_size,
orte_gpr_array_max_size,
orte_gpr_array_block_size);
seg->dict_next_itag = 0;
OBJ_CONSTRUCT(&seg->dict_hash, opal_hash_table_t);
OBJ_CONSTRUCT(&seg->dict_entries, opal_list_t);
opal_hash_table_init(&seg->dict_hash, 512);
seg->num_containers = 0;
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)
{
size_t i, k;
orte_gpr_replica_dict_t **dptr;
opal_list_item_t* item;
orte_gpr_replica_container_t **cptr;
if (NULL != seg->name) {
free(seg->name);
}
if (NULL != seg->dict) {
dptr = (orte_gpr_replica_dict_t**)((seg->dict)->addr);
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);
while(NULL != (item = opal_list_remove_first(&seg->dict_entries))) {
OBJ_RELEASE(item);
}
OBJ_DESTRUCT(&seg->dict_entries);
OBJ_DESTRUCT(&seg->dict_hash);
if (NULL != seg->containers) {
cptr = (orte_gpr_replica_container_t**)((seg->containers)->addr);

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

@ -26,22 +26,22 @@
#include "orte_config.h"
#include "orte/class/orte_pointer_array.h"
#include "opal/class/opal_hash_table.h"
#include "opal/util/output.h"
#include "opal/util/trace.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)
{
orte_gpr_replica_dict_t **ptr, *new_dict;
orte_gpr_replica_itag_t j;
size_t i, len, len2;
orte_gpr_replica_dict_entry_t *new_dict;
size_t len;
OPAL_TRACE(3);
@ -57,15 +57,15 @@ orte_gpr_replica_create_itag(orte_gpr_replica_itag_t *itag,
len = strlen(name);
/* check seg's dictionary to ensure uniqueness */
ptr = (orte_gpr_replica_dict_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 = strlen(ptr[i]->entry);
if ((len == len2 && 0 == strncmp(ptr[i]->entry, name, len))) {
if(opal_list_get_size(&seg->dict_entries)) {
opal_list_item_t* item;
for(item = opal_list_get_first(&seg->dict_entries);
item != opal_list_get_end(&seg->dict_entries);
item = opal_list_get_next(item)) {
orte_gpr_replica_dict_entry_t* value = (orte_gpr_replica_dict_entry_t*)item;
if ((len == value->len && 0 == strncmp(value->entry, name, len))) {
/* already present */
*itag = ptr[i]->itag;
*itag = value->itag;
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 */
/* 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);
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) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE;
}
new_dict->itag = seg->dict_next_itag++;
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;
free(new_dict->entry);
free(new_dict);
OBJ_RELEASE(new_dict);
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE;
}
*itag = seg->num_dict_entries;
new_dict->itag = *itag;
(seg->num_dict_entries)++;
opal_list_append(&seg->dict_entries, &new_dict->super);
*itag = new_dict->itag;
return ORTE_SUCCESS;
}
int orte_gpr_replica_delete_itag(orte_gpr_replica_segment_t *seg, char *name)
{
orte_gpr_replica_dict_t **ptr;
orte_gpr_replica_itag_t itag;
size_t index;
opal_list_item_t* item;
orte_gpr_replica_dict_entry_t *value = NULL;
size_t len;
int rc;
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;
}
/* find dictionary element to delete */
if (ORTE_SUCCESS != (rc = orte_gpr_replica_dict_lookup(&itag, seg, name))) {
ORTE_ERROR_LOG(rc);
return rc;
/* find dictionary element to delete */
len = strlen(name);
for(item = opal_list_get_first(&seg->dict_entries);
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 */
/* 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, value->itag))) {
ORTE_ERROR_LOG(rc);
return rc;
}
}
/* free the dictionary element data */
ptr = (orte_gpr_replica_dict_t**)((seg->dict)->addr);
if (NULL == ptr[itag]) { /* dict element no longer valid */
return ORTE_ERR_NOT_FOUND;
}
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)--;
/* free the dictionary element data */
opal_hash_table_remove_value_uint32(&seg->dict_hash, value->itag);
opal_list_remove_item(&seg->dict_entries, &value->super);
OBJ_RELEASE(value);
return ORTE_SUCCESS;
}
@ -156,10 +151,8 @@ int
orte_gpr_replica_dict_lookup(orte_gpr_replica_itag_t *itag,
orte_gpr_replica_segment_t *seg, char *name)
{
orte_gpr_replica_dict_t **ptr;
size_t i;
orte_gpr_replica_itag_t j;
size_t len, len2;
opal_list_item_t* item;
size_t len;
OPAL_TRACE(3);
@ -180,16 +173,13 @@ orte_gpr_replica_dict_lookup(orte_gpr_replica_itag_t *itag,
len = strlen(name);
/* want specified token-itag pair in that segment's dictionary */
ptr = (orte_gpr_replica_dict_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 = strlen(ptr[i]->entry);
if (len == len2 && 0 == strncmp(ptr[i]->entry, name, len)) {
*itag = ptr[i]->itag;
return ORTE_SUCCESS;
}
for(item = opal_list_get_first(&seg->dict_entries);
item != opal_list_get_next(&seg->dict_entries);
item = opal_list_get_next(item)) {
orte_gpr_replica_dict_entry_t* value = (orte_gpr_replica_dict_entry_t*)item;
if (len == value->len && 0 == strncmp(value->entry, name, len)) {
*itag = value->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,
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;
size_t i;
orte_gpr_replica_itag_t j;
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
* dictionary array
*/
ptr = (orte_gpr_replica_dict_t**)((seg->dict)->addr);
for (i=0, j=0; j < seg->num_dict_entries &&
i < (seg->dict)->size; i++) {
if (NULL != ptr[i]) {
j++;
if (itag == ptr[i]->itag) { /* entry found! */
*name = strdup(ptr[i]->entry);
return ORTE_SUCCESS;
}
}
if(ORTE_SUCCESS == opal_hash_table_get_value_uint32(&seg->dict_hash, itag, (void**)&value)) {
*name = strdup(value->entry);
return ORTE_SUCCESS;
}
/* get here if entry not found */
return ORTE_ERR_NOT_FOUND;
}