1
1

Add functionality to copy/delete all attributes at once, to be used by functions like MPI_*_DUP, MPI_*_FREE

This commit was SVN r953.
Этот коммит содержится в:
Vishal Sahay 2004-03-23 23:44:53 +00:00
родитель c6f6c52f5b
Коммит 7bb2e7e3ba
2 изменённых файлов: 229 добавлений и 3 удалений

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

@ -19,10 +19,19 @@
#define lam_c_t lam_communicator_t *
#define lam_d_t lam_datatype_t *
#define lam_w_t lam_win_t *
#define MPI_c_delete_attr_function MPI_Comm_delete_attr_function
#define MPI_d_delete_attr_function MPI_Type_delete_attr_function
#define MPI_w_delete_attr_function MPI_Win_delete_attr_function
#define MPI_c_copy_attr_function MPI_Comm_copy_attr_function
#define MPI_d_copy_attr_function MPI_Type_copy_attr_function
#define MPI_w_copy_attr_function MPI_Win_copy_attr_function
#define CAST_HANDLE(object, type) (lam_##type##_t) object
#define KEYHASH(type) ((lam_##type##_t)object)->type##_keyhash
#define CREATE_KEY() lam_bitmap_find_and_set_first_unset_bit(key_bitmap)
@ -30,8 +39,8 @@
#define DELETE_ATTR_OBJECT(type, caps_type, attr) \
if ((MPI_##caps_type##_NULL_DELETE_FN == \
(MPI_##type##_delete_attr_function *) (key_item->delete_attr_fn)) || \
if ((MPI_##caps_type##_NULL_DELETE_FN != \
(MPI_##type##_delete_attr_function *) (key_item->delete_attr_fn)) && \
((*((MPI_##type##_delete_attr_function *) \
(key_item->delete_attr_fn)))((lam_##type##_t)object, \
key, attr, \
@ -39,6 +48,14 @@
return LAM_ERROR;\
}
#define COPY_ATTR_OBJECT(type, old_object, hash_value) \
if ((*(MPI_##type##_copy_attr_function *) (hash_value->copy_attr_fn)) \
((lam_##type##_t)old_object, key, hash_value->extra_state, \
old_attr, new_attr, &flag) != MPI_SUCCESS) { \
return LAM_ERROR; \
}
#define GET_ATTR(type) \
lam_hash_table_get_value_uint32(((lam_##type##_t)object)->type##_keyhash, key);
@ -311,7 +328,7 @@ lam_attr_set(lam_attribute_type_t type, void *object, int key, void *attribute,
/* If key not found */
if ((NULL == key_item) || (key_item->attr_type != type) ||
((predefined) && (key_item->attr_flag & LAM_PREDEFINED))) {
((!predefined) && (key_item->attr_flag & LAM_PREDEFINED))) {
fprintf(stderr, "lam_attribute: lam_attr_set: key not found \n");
return MPI_INVALID_ATTR_KEYVAL;
}
@ -404,3 +421,174 @@ lam_attr_get(lam_attribute_type_t type, void *object, int key, void *attribute,
*flag = 1;
return MPI_SUCCESS;
}
/* There is too much of code copy/paste in here, see if some other
logic could work here */
int
lam_attr_copy_all(lam_attribute_type_t type, void *old_object,
void *new_object)
{
int ret = LAM_SUCCESS;
int key, flag;
void *node, *in_node, *old_attr, *new_attr;
lam_attrkey_item_t *hash_value;
void *object = old_object; /* For consistent interface to
KEYHASH. I know whis is a bad way,
but was being lazy to change all
calls to KEYHASH with an ardditional
argument */
switch (type) {
case COMM_ATTR:
/* Get the first key-attr in the CWD hash */
ret = lam_hash_table_get_first_key_uint32(KEYHASH(c), &key, old_attr,
node);
/* While we still have some key-attr pair in the CWD hash */
while (ret != LAM_ERROR) {
in_node = node;
/* Get the attr_item in the main hash - so that we know
what the copy_attr_fn is */
hash_value = (lam_attrkey_item_t *)
lam_hash_table_get_value_uint32(&(attr_hash->super), key);
assert (hash_value != NULL);
/* Now call the copy_attr_fn */
COPY_ATTR_OBJECT(c, CAST_HANDLE(old_object, c),
hash_value);
/* Hang this off the new CWD object */
lam_attr_set(COMM_ATTR, new_object, key, new_attr, 1);
ret = lam_hash_table_get_next_key_uint32(KEYHASH(c), &key,
old_attr, in_node, node);
}
break;
case TYPE_ATTR:
ret = lam_hash_table_get_first_key_uint32(KEYHASH(d), &key, old_attr,
node);
while (ret != LAM_ERROR) {
in_node = node;
hash_value = (lam_attrkey_item_t *)
lam_hash_table_get_value_uint32(&(attr_hash->super), key);
assert (hash_value != NULL);
/* Now call the copy_attr_fn */
COPY_ATTR_OBJECT(d, CAST_HANDLE(old_object, d), hash_value);
/* Hang this off the new CWD object */
lam_attr_set(TYPE_ATTR, new_object, key, new_attr, 1);
ret = lam_hash_table_get_next_key_uint32(KEYHASH(d), &key,
old_attr, in_node, node);
}
break;
case WIN_ATTR:
ret = lam_hash_table_get_first_key_uint32(KEYHASH(w), &key, old_attr,
node);
while (ret != LAM_ERROR) {
in_node = node;
hash_value = (lam_attrkey_item_t *)
lam_hash_table_get_value_uint32(&(attr_hash->super), key);
assert (hash_value != NULL);
/* Now call the copy_attr_fn */
COPY_ATTR_OBJECT(w, CAST_HANDLE(old_object, w), hash_value);
/* Hang this off the new CWD object */
lam_attr_set(WIN_ATTR, new_object, key, new_attr, 1);
ret = lam_hash_table_get_next_key_uint32(KEYHASH(w), &key,
old_attr, in_node, node);
}
break;
}
return MPI_SUCCESS;
}
int
lam_attr_delete_all(lam_attribute_type_t type, void *object)
{
int ret;
int key;
void *node, *in_node, *old_attr;
lam_attrkey_item_t *hash_value;
switch (type) {
case COMM_ATTR:
/* Get the first key in local CWD hash */
ret = lam_hash_table_get_first_key_uint32(KEYHASH(c), &key, old_attr,
node);
while (ret != LAM_ERROR) {
in_node = node;
hash_value = (lam_attrkey_item_t *)
lam_hash_table_get_value_uint32(&(attr_hash->super), key);
assert (hash_value != NULL);
/* Now delete this attribute */
lam_attr_delete(type, object, key, 1);
ret = lam_hash_table_get_next_key_uint32(KEYHASH(c), &key,
old_attr, in_node, node);
}
break;
case TYPE_ATTR:
/* Get the first key in local CWD hash */
ret = lam_hash_table_get_first_key_uint32(KEYHASH(d), &key, old_attr,
node);
while (ret != LAM_ERROR) {
in_node = node;
hash_value = (lam_attrkey_item_t *)
lam_hash_table_get_value_uint32(&(attr_hash->super), key);
assert (hash_value != NULL);
/* Now delete this attribute */
lam_attr_delete(type, object, key, 1);
ret = lam_hash_table_get_next_key_uint32(KEYHASH(d), &key,
old_attr, in_node, node);
}
break;
case WIN_ATTR:
/* Get the first key in local CWD hash */
ret = lam_hash_table_get_first_key_uint32(KEYHASH(w), &key, old_attr,
node);
while (ret != LAM_ERROR) {
in_node = node;
hash_value = (lam_attrkey_item_t *)
lam_hash_table_get_value_uint32(&(attr_hash->super), key);
assert (hash_value != NULL);
/* Now delete this attribute */
lam_attr_delete(type, object, key, 1);
ret = lam_hash_table_get_next_key_uint32(KEYHASH(w), &key,
old_attr, in_node, node);
}
break;
}
return MPI_SUCCESS;
}

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

@ -107,7 +107,17 @@ void lam_attr_destroy(void);
* @param extra_state Extra state to hang off/do some special things (IN)
* @param predefined Whether this key is should be treated as
* predefined (IN)
* NOTE: I have taken the assumption that user cannot modify/delete
* any predefined keys or the attributes attached. To accomplish this,
* all MPI* calls will have predefined argument set as 0. MPI
* implementors who will need to play with the predefined keys and
* attributes would call the lam* functions here and not the MPI*
* functions, with predefined argument set to 1.
* END OF NOTE
*
* @return LAM return code
*
*/
@ -166,6 +176,34 @@ int lam_attr_get(lam_attribute_type_t type, void *object, int key,
int lam_attr_delete(lam_attribute_type_t type, void *object, int key,
int predefined);
/**
* This to be used from functions like MPI_*_DUP inorder to copy all
* the attributes from the old Comm/Win/Dtype object to a new
* object.
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param old_object The old COMM/WIN/DTYPE object (IN)
* @param new_object The new COMM/WIN/DTYPE object (IN)
* @return LAM error code
*
*/
int lam_attr_copy_all(lam_attribute_type_t type, void *old_object,
void *new_object);
/**
* This to be used to delete all the attributes from the Comm/Win/Dtype
* object in one shot
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param object The COMM/WIN/DTYPE object (IN)
* @return LAM error code
*
*/
int lam_attr_delete_all(lam_attribute_type_t type, void *object);
#if defined(c_plusplus) || defined(__cplusplus)
}
#endif