1
1

Restore the pointer arrays to the registry dictionaries. Revise the system so that the itag is equivalent to the index into the pointer array. It already was, but it wasn't obvious before (several functions relied upon it, but others "hid" the relationship) - now, make it explicitly clear. Set things up so lookups occur at max speed by just indexing into the dictionary array.

This commit was SVN r7912.
Этот коммит содержится в:
Ralph Castain 2005-10-28 04:56:06 +00:00
родитель d916e0c5b4
Коммит ad9de4ca3b
4 изменённых файлов: 112 добавлений и 137 удалений

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

@ -157,6 +157,7 @@ int orte_gpr_replica_index_fn(orte_gpr_replica_segment_t *seg,
{
char **ptr;
orte_gpr_replica_segment_t **segs;
char **dict;
size_t i, j;
@ -191,29 +192,28 @@ int orte_gpr_replica_index_fn(orte_gpr_replica_segment_t *seg,
}
/* must have requested index of a specific segment */
if (0 < opal_list_get_size(&seg->dict_entries)) {
opal_list_item_t* item;
if (0 < seg->num_dict_entries) {
*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 = (char**)(seg->dict)->addr;
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;
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++;
}
j++;
}
*cnt = opal_list_get_size(&seg->dict_entries);
*cnt = seg->num_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"
@ -123,32 +123,16 @@ typedef struct {
} orte_gpr_replica_globals_t;
/** Dictionary of string-itag pairs.
* This structure is used to create a linked list of string-itag pairs. All calls to
* registry functions pass character strings for programming clarity - the replica_dict
* 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_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_entry_t orte_gpr_replica_dict_entry_t;
OBJ_CLASS_DECLARATION(orte_gpr_replica_dict_entry_t);
/*
* Registry "head"
* The registry "head" contains:
*
* (2) the next available itag for the segment dictionary.
*
* (3) a managed array of pointers to segment objects.
*
* (4) a managed array of pointers to triggers acting on the entire registry
*
* (4) a managed array of pointers to subscriptions acting on the entire registry
*
*/
struct orte_gpr_replica_t {
orte_pointer_array_t *segments; /**< Managed array of pointers to segment objects */
@ -176,9 +160,8 @@ 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 */
opal_hash_table_t dict_hash;
opal_list_t dict_entries;
size_t dict_next_itag;
orte_gpr_replica_itag_t num_dict_entries;
orte_pointer_array_t *dict; /**< Managed array of dict structs */
size_t num_containers;
orte_pointer_array_t *containers; /**< Managed array of pointers to containers on this segment */
};

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

@ -74,26 +74,6 @@ 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)
@ -101,10 +81,10 @@ static void orte_gpr_replica_segment_construct(orte_gpr_replica_segment_t* seg)
seg->name = NULL;
seg->itag = ORTE_GPR_REPLICA_ITAG_MAX;
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_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->num_containers = 0;
orte_pointer_array_init(&(seg->containers), orte_gpr_array_block_size,
@ -117,18 +97,25 @@ 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;
opal_list_item_t* item;
char **dptr;
orte_gpr_replica_itag_t j;
orte_gpr_replica_container_t **cptr;
if (NULL != seg->name) {
free(seg->name);
}
while(NULL != (item = opal_list_remove_first(&seg->dict_entries))) {
OBJ_RELEASE(item);
if (NULL != seg->dict) {
dptr = (char**)(seg->dict)->addr;
for (i=0, j=0; j < seg->num_dict_entries &&
i < (seg->dict)->size; i++) {
if (NULL != dptr[i]) {
j++;
free(dptr[i]);
}
}
OBJ_RELEASE(seg->dict);
}
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_entry_t *new_dict;
size_t len;
char **ptr, *new_dict;
orte_gpr_replica_itag_t j;
size_t i, len, len2, index;
OPAL_TRACE(3);
@ -57,54 +57,50 @@ orte_gpr_replica_create_itag(orte_gpr_replica_itag_t *itag,
len = strlen(name);
/* check seg's dictionary to ensure uniqueness */
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))) {
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 = strlen(ptr[i]);
if ((len == len2 && 0 == strncmp(ptr[i], name, len))) {
/* already present */
*itag = value->itag;
return ORTE_SUCCESS;
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;
}
}
}
/* okay, name is unique - create dictionary entry */
/* first check to see if one is available */
if (ORTE_GPR_REPLICA_ITAG_MAX-1 < opal_list_get_size(&seg->dict_entries)) {
new_dict = strdup(name);
if (0 > orte_pointer_array_add(&index, seg->dict, (void*)new_dict)) {
free(new_dict);
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE;
}
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;
if ((orte_gpr_replica_itag_t)index < ORTE_GPR_REPLICA_ITAG_MAX) {
*itag = (orte_gpr_replica_itag_t)index;
(seg->num_dict_entries)++;
return ORTE_SUCCESS;
}
new_dict->itag = seg->dict_next_itag++;
new_dict->entry = strdup(name);
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;
OBJ_RELEASE(new_dict);
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE;
}
opal_list_append(&seg->dict_entries, &new_dict->super);
*itag = new_dict->itag;
return ORTE_SUCCESS;
/* otherwise, the itag violates the max value */
free(new_dict);
ptr[index] = NULL;
return ORTE_ERR_OUT_OF_RESOURCE;
}
int orte_gpr_replica_delete_itag(orte_gpr_replica_segment_t *seg, char *name)
{
opal_list_item_t* item;
orte_gpr_replica_dict_entry_t *value = NULL;
size_t len;
char **ptr;
orte_gpr_replica_itag_t itag;
int rc;
OPAL_TRACE(3);
@ -116,32 +112,32 @@ int orte_gpr_replica_delete_itag(orte_gpr_replica_segment_t *seg, char *name)
}
/* 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;
if (ORTE_SUCCESS != (rc = orte_gpr_replica_dict_lookup(&itag, seg, name))) {
ORTE_ERROR_LOG(rc);
return rc;
}
/* 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, value->itag))) {
if (ORTE_SUCCESS != (rc = orte_gpr_replica_purge_itag(seg, itag))) {
ORTE_ERROR_LOG(rc);
return rc;
}
}
/* 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);
/* 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]);
/* remove itag from segment dictionary */
orte_pointer_array_set_item(seg->dict, (size_t)itag, NULL);
/* decrease the dict counter */
(seg->num_dict_entries)--;
return ORTE_SUCCESS;
}
@ -151,8 +147,10 @@ int
orte_gpr_replica_dict_lookup(orte_gpr_replica_itag_t *itag,
orte_gpr_replica_segment_t *seg, char *name)
{
opal_list_item_t* item;
size_t len;
char **ptr;
size_t i;
orte_gpr_replica_itag_t j;
size_t len, len2;
OPAL_TRACE(3);
@ -173,13 +171,20 @@ orte_gpr_replica_dict_lookup(orte_gpr_replica_itag_t *itag,
len = strlen(name);
/* want specified token-itag pair in that segment's dictionary */
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;
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 = 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;
}
}
}
@ -190,7 +195,7 @@ 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_entry_t *value;
char **ptr;
orte_gpr_replica_segment_t **segptr;
OPAL_TRACE(3);
@ -220,13 +225,13 @@ int orte_gpr_replica_dict_reverse_lookup(char **name,
* note again that itag is the index into this segment's
* dictionary array
*/
if(ORTE_SUCCESS == opal_hash_table_get_value_uint32(&seg->dict_hash, itag, (void**)&value)) {
*name = strdup(value->entry);
return ORTE_SUCCESS;
ptr = (char**)((seg->dict)->addr);
if (NULL == ptr[itag]) { /* this entry is no longer valid! */
return ORTE_ERR_NOT_FOUND;
}
/* get here if entry not found */
return ORTE_ERR_NOT_FOUND;
*name = strdup(ptr[itag]);
return ORTE_SUCCESS;
}
int