1
1

Adding functionality in info.h and info.c so that other modules can call the functions here instead of having to go to the MPI layer

This commit was SVN r731.
Этот коммит содержится в:
Prabhanjan Kambadur 2004-02-11 15:30:51 +00:00
родитель f6cd55432b
Коммит 1410be0370
2 изменённых файлов: 280 добавлений и 3 удалений

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

@ -46,8 +46,233 @@ void lam_info_entry_construct(lam_info_entry_t *entry) {
}
void lam_info_entry_destruct(lam_info_entry_t *entry) {
OBJ_DESTRUCT_SUPER(entry, lam_object_t);
if (NULL != entry->ie_value) {
free(entry->ie_value);
}
OBJ_DESTRUCT_SUPER(entry, lam_object_t);
}
/**
* MPI_Info_dup - Duplicate an 'MPI_Info' object
*
* @param info source info object (handle)
* @param newinfo pointer to the new info object (handle)
*
* @retval MPI_SUCCESS
* @retval MPI_ERR_SYSRESOURCE
*
* Not only will the (key, value) pairs be duplicated, the order of keys
* will be the same in 'newinfo' as it is in 'info'.
* When an info object is no longer being used, it should be freed with
* 'MPI_Info_free'.
*/
int lam_info_dup (lam_info_t *info, lam_info_t **newinfo) {
int err;
int nkeys;
lam_info_entry_t *iterator;
err = lam_info_get_nkeys (info, &nkeys);
for (iterator = (lam_info_entry_t *)lam_list_get_first(&(info->super));
nkeys > 0;
nkeys--) {
err = lam_info_set(*newinfo, iterator->ie_key, iterator->ie_value);
if (MPI_SUCCESS != err) {
return err;
}
iterator = (lam_info_entry_t *)iterator->super.lam_list_next;
}
return MPI_SUCCESS;
}
/*
* Set a new key,value pair on info
*
* @param info pointer to lam_info_t object
* @param key pointer to the new key object
* @param value pointer to the new value object
*
* @retval MPI_SUCCESS
* @retval MPI_ERR_SYSRESOURCE
*/
int lam_info_set (lam_info_t *info, char *key, char *value) {
char *new_value;
lam_info_entry_t *new_info;
lam_info_entry_t *old_info;
int value_length;
value_length = strlen(value);
new_value = malloc(value_length * sizeof(char));
if (NULL == new_value) {
return MPI_ERR_SYSRESOURCE;
}
strcpy (new_value, value);
old_info = lam_info_find_key (info, key);
if (NULL != old_info) {
/*
* key already exists. remove the value associated with it
*/
free(old_info->ie_value);
old_info->ie_value = new_value;
} else {
new_info = OBJ_NEW(lam_info_entry_t);
if (NULL == new_info) {
return MPI_ERR_SYSRESOURCE;
}
strcpy (new_info->ie_key, key);
new_info->ie_value = new_value;
lam_list_append (&(info->super), (lam_list_item_t *) new_info);
}
return MPI_SUCCESS;
}
/**
* lam_info_free - Free an 'MPI_Info' object.
*
* @param info pointer to info (lam_info_t *) object to be freed (handle)
*
* @retval MPI_SUCCESS
* @retval MPI_ERR_ARG
*
* Upon successful completion, 'info' will be set to 'MPI_INFO_NULL'.
*/
int lam_info_free (lam_info_t **info) {
lam_info_entry_t *iterator;
int nkeys;
int err;
err = lam_info_get_nkeys(*info, &nkeys);
/*
* We could just get each element from the list and then call
* MPI_Info_delete. But this causes unnecessary delay because
* MPI_Info_delete has extra logic to it. So, do the simple
* remove operation to save time.
*/
for (iterator = (lam_info_entry_t *)lam_list_get_first(&((*info)->super));
nkeys > 0;
nkeys--) {
iterator = (lam_info_entry_t *)iterator->super.lam_list_next;
OBJ_RELEASE(iterator->super.lam_list_prev);
}
/*
* Anju:
* Add things to remove the fortran handle from the mapping table
*/
OBJ_RELEASE(*info);
*info = MPI_INFO_NULL;
return MPI_SUCCESS;
}
/**
* lam_info_get- Get a (key, value) pair from an 'MPI_Info' object
*
* @param info Pointer to lam_info_t object
* @param key null-terminated character string of the index key
* @param valuelen maximum length of 'value' (integer)
* @param value null-terminated character string of the value
* @param flag true (1) if 'key' defined on 'info', false (0) if not
* (logical)
*
* @retval MPI_SUCCESS
*
* In C and C++, 'valuelen' should be one less than the allocated space
* to allow for for the null terminator.
*/
int lam_info_get (lam_info_t *info, char *key, int valuelen,
char *value, int *flag) {
lam_info_entry_t *search;
int value_length;
search = lam_info_find_key (info, key);
if (NULL == search){
*flag = 0;
} else {
/*
* We have found the element, so we can return the value
* Set the flag, value_length and value
*/
*flag = 1;
value_length = strlen(search->ie_value);
/*
* If the stored value is shorter than valuelen, then
* we can copy the entire value out. Else, we have to
* copy ONLY valuelen bytes out
*/
if (value_length < valuelen ) {
strcpy(value, search->ie_value);
} else {
lam_strncpy(value, search->ie_value, valuelen);
value[valuelen] = 0;
}
}
return MPI_SUCCESS;
}
/**
* Delete a (key,value) pair from "info"
*
* @param info lam_info_t pointer on which we need to operate
* @param key The key portion of the (key,value) pair that
* needs to be deleted
*
* @retval MPI_SUCCESS
* @retval MPI_ERR_NOKEY
*/
int lam_info_delete (lam_info_t *info, char *key) {
lam_info_entry_t *search;
lam_info_entry_t *found;
search = lam_info_find_key (info, key);
if (NULL == search){
return MPI_ERR_INFO_NOKEY;
} else {
/*
* An entry with this key value was found. Remove the item
* and free the memory allocated to it
*/
found = (lam_info_entry_t *)
lam_list_remove_item (&(info->super),
(lam_list_item_t *)search);
OBJ_RELEASE(search);
}
return MPI_SUCCESS;
}
/**
* @param info - lam_info_t pointer object (handle)
* @param key - null-terminated character string of the index key
* @param valuelen - length of the value associated with 'key' (integer)
* @param flag - true (1) if 'key' defined on 'info', false (0) if not
* (logical)
*
* @retval MPI_SUCCESS
* @retval MPI_ERR_ARG
* @retval MPI_ERR_INFO_KEY
*
* The length returned in C and C++ does not include the end-of-string
* character. If the 'key' is not found on 'info', 'valuelen' is left
* alone.
*/
int lam_info_get_valuelen (lam_info_t *info, char *key, int *valuelen,
int *flag) {
lam_info_entry_t *search;
search = lam_info_find_key (info, key);
if (NULL == search){
*flag = 0;
} else {
/*
* We have found the element, so we can return the value
* Set the flag, value_length and value
*/
*flag = 1;
*valuelen = strlen(search->ie_value);
}
return MPI_SUCCESS;
}

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

@ -8,6 +8,7 @@
#include <string.h>
#include "mpi.h"
#include "lam/util/strncpy.h"
#include "lam/lfc/lam_list.h"
#include "lam/lam.h"
@ -50,6 +51,14 @@ void lam_info_destruct(lam_info_t *info);
void lam_info_entry_construct(lam_info_entry_t *entry);
void lam_info_entry_destruct(lam_info_entry_t *entry);
int lam_info_dup (lam_info_t *info, lam_info_t **newinfo);
int lam_info_set (lam_info_t *info, char *key, char *value);
int lam_info_free (lam_info_t **info);
int lam_info_get (lam_info_t *info, char *key, int valuelen,
char *value, int *flag);
int lam_info_delete (lam_info_t *info, char *key);
int lam_info_get_valuelen (lam_info_t *info, char *key, int *valuelen,
int *flag);
#if defined(c_plusplus) || defined(__cplusplus)
}
#endif
@ -57,7 +66,7 @@ void lam_info_entry_destruct(lam_info_entry_t *entry);
/**
* Iterate through the list and search for "key"
*
* @param info MPI_Info handle
* @param info pointer to lam_info_t handle
* @param key Key value to search for
*
* @retval (lam_info_entry_t *) to the object having the same key
@ -71,7 +80,7 @@ void lam_info_entry_destruct(lam_info_entry_t *entry);
* Assumptions:
* "info" is a valid key
*/
static inline lam_info_entry_t *lam_info_find_key (MPI_Info info,
static inline lam_info_entry_t *lam_info_find_key (lam_info_t *info,
char *key) {
lam_info_entry_t *iterator;
int nkeys;
@ -92,4 +101,47 @@ static inline lam_info_entry_t *lam_info_find_key (MPI_Info info,
return (lam_info_entry_t *)0;
}
/**
* Get the number of keys defined on on an MPI_Info object
* @param info Pointer to lam_info_t object.
* @param nkeys Pointer to nkeys, which needs to be filled up.
*
* @retval The number of keys defined on info
*/
static inline int
lam_info_get_nkeys(lam_info_t *info, int *nkeys) {
*nkeys = (int) lam_list_get_size(&(info->super));
return MPI_SUCCESS;
}
/**
* lam_info_get_nthkey - Get a key indexed by integer from an 'MPI_Info' o
*
* @param info Pointer to lam_info_t object
* @param n index of key to retrieve (integer)
* @param key character string of at least 'MPI_MAX_INFO_KEY' characters
*
* @retval MPI_SUCCESS
* @retval MPI_ERR_ARG
*/
static inline int
lam_info_get_nthkey (lam_info_t *info, int n, char *key) {
lam_info_entry_t *iterator;
/*
* Iterate over and over till we get to the nth key
*/
iterator = (lam_info_entry_t *)lam_list_get_first(&(info->super));
for ( ; n > 0; n--) {
iterator = (lam_info_entry_t *)
iterator->super.lam_list_next;
}
/*
* iterator is of the type lam_list_item_t. We have to
* cast it to lam_info_entry_t before we can use it to
* access the value
*/
strcpy(key, iterator->ie_key);
return MPI_SUCCESS;
}
#endif /* LAM_INFO_H */