1
1

Change attribute hashes to only be non-NULL on MPI objects that

actually have attributes cached on them.  If there are no attributes
cached on the object, the keyhash will be NULL.

This commit was SVN r2968.
Этот коммит содержится в:
Jeff Squyres 2004-10-07 01:26:40 +00:00
родитель d710ed9a49
Коммит 101a83ab5f
9 изменённых файлов: 80 добавлений и 28 удалений

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

@ -263,6 +263,12 @@ ompi_attr_delete(ompi_attribute_type_t type, void *object,
return OMPI_ERR_BAD_PARAM;
}
/* Ensure that we don't have an empty keyhash */
if (NULL == keyhash) {
return OMPI_ERR_BAD_PARAM;
}
/* Check if the key is valid for the communicator/window/dtype. If
yes, then delete the attribute and key entry from the CWD hash */
@ -302,7 +308,7 @@ ompi_attr_delete(ompi_attribute_type_t type, void *object,
int
ompi_attr_set(ompi_attribute_type_t type, void *object,
ompi_hash_table_t *keyhash, int key, void *attribute,
ompi_hash_table_t **keyhash, int key, void *attribute,
int predefined)
{
ompi_attrkey_item_t *key_item;
@ -315,6 +321,9 @@ ompi_attr_set(ompi_attribute_type_t type, void *object,
if (NULL == keyval_hash) {
return MPI_ERR_INTERN;
}
if (NULL == keyhash) {
return MPI_ERR_INTERN;
}
key_item = (ompi_attrkey_item_t *)
ompi_hash_table_get_value_uint32(keyval_hash, key);
@ -326,9 +335,15 @@ ompi_attr_set(ompi_attribute_type_t type, void *object,
return OMPI_ERR_BAD_PARAM;
}
/* Do we need to make a new keyhash? */
if (NULL == *keyhash) {
ompi_attr_hash_init(keyhash);
}
/* Now see if the key is present in the CWD object. If so, delete
the old attribute in the key */
oldattr = ompi_hash_table_get_value_uint32(keyhash, key);
oldattr = ompi_hash_table_get_value_uint32(*keyhash, key);
if (oldattr != NULL) {
switch(type) {
@ -351,7 +366,7 @@ ompi_attr_set(ompi_attribute_type_t type, void *object,
had_old = 1;
}
ret = ompi_hash_table_set_value_uint32(keyhash, key, attribute);
ret = ompi_hash_table_set_value_uint32(*keyhash, key, attribute);
if (OMPI_SUCCESS != ret) {
return ret;
}
@ -386,8 +401,14 @@ ompi_attr_get(ompi_hash_table_t *keyhash, int key, void *attribute,
return MPI_KEYVAL_INVALID;
}
attr = ompi_hash_table_get_value_uint32(keyhash, key);
/* If we have a null keyhash table, that means that nothing has
been cached on this object yet. So just return *flag = 0. */
if (NULL == keyhash) {
return MPI_SUCCESS;
}
attr = ompi_hash_table_get_value_uint32(keyhash, key);
if (NULL != attr) {
*((void **) attribute) = attr;
*flag = 1;
@ -416,6 +437,12 @@ ompi_attr_copy_all(ompi_attribute_type_t type, void *old_object,
return MPI_ERR_INTERN;
}
/* If there's nothing to do, just return */
if (NULL == oldkeyhash) {
return MPI_SUCCESS;
}
/* Get the first key-attr in the CWD hash */
ret = ompi_hash_table_get_first_key_uint32(oldkeyhash, &key, &old_attr,
&node);
@ -460,7 +487,7 @@ ompi_attr_copy_all(ompi_attribute_type_t type, void *old_object,
the copy fn, but since its a pointer in that MPI specs, we
need to pass *new_attr here */
if (flag == 1) {
ompi_attr_set(type, new_object, newkeyhash, key,
ompi_attr_set(type, new_object, &newkeyhash, key,
new_attr, 1);
}
@ -485,6 +512,12 @@ ompi_attr_delete_all(ompi_attribute_type_t type, void *object,
if (NULL == keyval_hash) {
return MPI_ERR_INTERN;
}
/* Ensure that the table is not empty */
if (NULL != keyhash) {
return MPI_SUCCESS;
}
/* Get the first key in local CWD hash */
ret = ompi_hash_table_get_first_key_uint32(keyhash,

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

@ -177,17 +177,20 @@ int ompi_attr_free_keyval(ompi_attribute_type_t type, int *key, int predefined);
* Set an attribute on the comm/win/datatype
* @param type Type of attribute (COMM/WIN/DTYPE) (IN)
* @param object The actual Comm/Win/Datatype object (IN)
* @param keyhash The attribute hash table hanging on the object(IN)
* @param keyhash The attribute hash table hanging on the object(IN/OUT)
* @param key Key val for the attribute (IN)
* @param attribute The actual attribute pointer (IN)
* @param predefined Whether the key is predefined or not 0/1 (IN)
* @return OMPI error code
*
* If (*keyhash) == NULL, a new keyhash will be created and
* initialized.
*
*/
int ompi_attr_set(ompi_attribute_type_t type, void *object,
ompi_hash_table_t *keyhash,
int key, void *attribute, int predefined);
ompi_hash_table_t **keyhash,
int key, void *attribute, int predefined);
/**
* Get an attribute on the comm/win/datatype

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

@ -167,7 +167,7 @@ static int set(int target_keyval, void *value)
return err;
}
err = ompi_attr_set(COMM_ATTR, MPI_COMM_WORLD,
MPI_COMM_WORLD->c_keyhash, keyval, value, 1);
&MPI_COMM_WORLD->c_keyhash, keyval, value, 1);
if (OMPI_SUCCESS != err) {
return err;
}

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

@ -159,11 +159,15 @@ int ompi_comm_set ( ompi_communicator_t *newcomm,
}
}
/* Copy attributes and call according copy functions,
if required */
ompi_attr_hash_init(&newcomm->c_keyhash);
if ( NULL != attr ) {
ompi_attr_copy_all (COMM_ATTR, oldcomm, newcomm, attr, newcomm->c_keyhash);
/* Copy attributes and call according copy functions, if
required */
if (NULL != oldcomm->c_keyhash) {
if (NULL != attr) {
ompi_attr_hash_init(&newcomm->c_keyhash);
ompi_attr_copy_all (COMM_ATTR, oldcomm, newcomm, attr,
newcomm->c_keyhash);
}
}
/* Initialize the PML stuff in the newcomm */
@ -674,8 +678,10 @@ int ompi_comm_free ( ompi_communicator_t **comm )
{
/* Release attributes */
ompi_attr_delete_all ( COMM_ATTR, (*comm), (*comm)->c_keyhash );
OBJ_RELEASE((*comm)->c_keyhash);
if (NULL != (*comm)->c_keyhash) {
ompi_attr_delete_all ( COMM_ATTR, (*comm), (*comm)->c_keyhash );
OBJ_RELEASE((*comm)->c_keyhash);
}
/* Release the communicator */
OBJ_RELEASE ( (*comm) );
@ -1221,9 +1227,6 @@ static int ompi_comm_fill_rest (ompi_communicator_t *comm,
/* determine the cube dimensions */
comm->c_cube_dim = ompi_cube_dim(comm->c_local_group->grp_proc_count);
/* copy attributes and call according copy functions */
ompi_attr_hash_init(&comm->c_keyhash);
/* initialize PML stuff on the communicator */
if (OMPI_SUCCESS != (ret = mca_pml.pml_add_comm(comm))) {
/* some error has happened */

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

@ -75,6 +75,11 @@ int ompi_comm_init(void)
strlen("MPI_COMM_WORLD")+1 );
ompi_mpi_comm_world.c_flags |= OMPI_COMM_NAMEISSET;
ompi_mpi_comm_world.c_flags |= OMPI_COMM_INTRINSIC;
/* We have to create a hash (although it is legal to leave this
filed NULL -- the attribute accessor functions will intepret
this as "there are no attributes cached on this object")
because MPI_COMM_WORLD has some predefined attributes. */
ompi_attr_hash_init(&ompi_mpi_comm_world.c_keyhash);
/* Setup MPI_COMM_SELF */
@ -99,7 +104,11 @@ int ompi_comm_init(void)
strncpy(ompi_mpi_comm_self.c_name,"MPI_COMM_SELF",strlen("MPI_COMM_SELF")+1);
ompi_mpi_comm_self.c_flags |= OMPI_COMM_NAMEISSET;
ompi_mpi_comm_self.c_flags |= OMPI_COMM_INTRINSIC;
ompi_attr_hash_init(&ompi_mpi_comm_self.c_keyhash);
/* We can set MPI_COMM_SELF's keyhash to NULL because it has no
predefined attributes. If a user defines an attribute on
MPI_COMM_SELF, the keyhash will automatically be created. */
ompi_mpi_comm_self.c_keyhash = NULL;
/* Setup MPI_COMM_NULL */
OBJ_CONSTRUCT(&ompi_mpi_comm_null, ompi_communicator_t);
@ -248,6 +257,10 @@ static void ompi_comm_construct(ompi_communicator_t* comm)
comm->c_topo_comm = NULL;
comm->c_topo_module = NULL;
/* A keyhash will be created if/when an attribute is cached on
this communiucator */
comm->c_keyhash = NULL;
#if OMPI_ENABLE_DEBUG
memset (&(comm->c_coll), 0, sizeof(mca_coll_base_module_1_0_0_t));
#endif

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

@ -31,8 +31,8 @@ int MPI_Attr_put(MPI_Comm comm, int keyval, void *attribute_val)
}
}
ret = ompi_attr_set(COMM_ATTR, comm, comm->c_keyhash,
keyval, attribute_val, 0);
ret = ompi_attr_set(COMM_ATTR, comm, &comm->c_keyhash,
keyval, attribute_val, 0);
OMPI_ERRHANDLER_RETURN(ret, comm, MPI_ERR_OTHER, FUNC_NAME);
}

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

@ -31,7 +31,7 @@ int MPI_Comm_set_attr(MPI_Comm comm, int comm_keyval, void *attribute_val)
}
}
ret = ompi_attr_set(COMM_ATTR, comm, comm->c_keyhash,
comm_keyval, attribute_val, 0);
ret = ompi_attr_set(COMM_ATTR, comm, &comm->c_keyhash,
comm_keyval, attribute_val, 0);
OMPI_ERRHANDLER_RETURN(ret, comm, MPI_ERR_OTHER, FUNC_NAME);
}

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

@ -34,8 +34,8 @@ int MPI_Type_set_attr (MPI_Datatype type,
}
}
ret = ompi_attr_set(TYPE_ATTR, type, type->d_keyhash,
type_keyval, attribute_val, 0);
ret = ompi_attr_set(TYPE_ATTR, type, &type->d_keyhash,
type_keyval, attribute_val, 0);
OMPI_ERRHANDLER_RETURN(ret, MPI_COMM_WORLD,
MPI_ERR_OTHER, FUNC_NAME);

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

@ -33,7 +33,7 @@ int MPI_Win_set_attr(MPI_Win win, int win_keyval, void *attribute_val)
}
}
ret = ompi_attr_set(WIN_ATTR, win, win->w_keyhash,
win_keyval, attribute_val, 0);
ret = ompi_attr_set(WIN_ATTR, win, &win->w_keyhash,
win_keyval, attribute_val, 0);
OMPI_ERRHANDLER_RETURN(ret, win, MPI_ERR_OTHER, FUNC_NAME);
}