1
1

Adding some functionality to MPI_Info functions. Yet to add anything

relevant to Fortran functions. So, nothing has been changed in
MPI_Info_f2c and MPI_Info_c2f functions. Everything else has functioning
code now.

This commit was SVN r645.
Этот коммит содержится в:
Prabhanjan Kambadur 2004-02-03 22:34:01 +00:00
родитель 4cd799d590
Коммит 2df9fad227
9 изменённых файлов: 313 добавлений и 31 удалений

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

@ -20,37 +20,34 @@
*
* @retval MPI_SUCCESS
* @retval MPI_ERR_ARG
* @retval MPI_ERR_EXHAUSTED
* @retval MPI_ERR_SYSRESOURCE
*
* When an MPI_Info object is not being used, it should be freed using
* MPI_Info_free
*/
int MPI_Info_create(MPI_Info *info) {
/**
* Anju:
* These are miscelleneous notes. They will be removed later.
*
* MPI_Info is a pointer to the struct lam_info_t. This structure
* contains a pointer to the lam_list_t structure. lam_list_t
* structure is a generic list management structure which is a
* container that can hold lam_list_item_t objects. Hence any
* object that needs to be stored as a list has to have lam_list_item_t
* as its first element.
*
* Steps to initialize the list item:
* info -> pointer to MPI_Info
* MPI_Info -> pointer to lam_info_t
* lam_info_t -> has pointer to lam_list_t item.
*
* First, we initialize by allocating memory for lam_info_t
* structure. Then, we have to initialize the list itself. Way to
* initialize the list is
*
* (*info) = (lam_info_t) LAM_MALLOC (sizeof(struct laminfo_t))
* (*info)->list_pointer = (lam_list_t) LAM_MALLOC (sizeof(struct
* lam_list_t))
* lam_list_init((*info)->list_pointer)
*
/* list of invalid conditions
* 1. MPI_ERR_ARG - If info is NULL
* 2. MPI_ERR_SYSRESOURCE - If LAM_MALLOC fails
* NOTE:
* Yet to add stuff for fortran handles
*/
if (NULL == info) {
printf ("Info handle passed is invalid\n");
return MPI_ERR_ARG;
}
/*
* Call the object create function. This function not only
* allocates the space for MPI_Info, but also calls all the
* relevant init functions.
*/
(*info) = OBJ_CREATE(lam_info_t, &lam_info_cls);
if (NULL == (*info)) {
printf ("Malloc failed. Ran out of resources\n");
return MPI_ERR_SYSRESOURCE;
}
return MPI_SUCCESS;
}

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

@ -8,6 +8,8 @@
#include "mpi/interface/c/bindings.h"
#include "lam/lfc/list.h"
#include "mpi/info/info.h"
#include <stdlib.h>
#include <string.h>
#if LAM_HAVE_WEAK_SYMBOLS && LAM_PROFILING_DEFINES
#pragma weak MPI_Info_delete = PMPI_Info_delete
@ -22,14 +24,41 @@
*
* @retval MPI_SUCCESS If the (key,val) pair was deleted
* @retval MPI_ERR_ARG
* @retval MPI_ERR_KEY
* @retval MPI_ERR_NOKEY
* @retval MPI_ERR_INTERN
*/
int MPI_Info_delete(MPI_Info info, char *key) {
lam_info_entry_t *search;
lam_info_entry_t *found;
int key_length;
/**
* This function merely deletes the (key,val) pair in info
*/
if (NULL == info){
printf ("Invalid MPI_Info handle passed\n");
return MPI_ERR_ARG;
}
key_length = (key) ? strlen (key) : 0;
if ( (0 == key_length) || (MPI_MAX_INFO_KEY <= key_length)) {
printf ("The key passed to MPI_INFO_SET is too long\n");
return MPI_ERR_INFO_KEY;
}
search = lam_info_find_key (info, key);
if (NULL == search){
printf ("Invalid key given\n");
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;
}

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

@ -28,11 +28,44 @@
* 'MPI_Info_free'.
*/
int MPI_Info_dup(MPI_Info info, MPI_Info *newinfo) {
lam_info_entry_t *iterator;
int err;
int nkeys;
/**
* Here we need to do 2 things
* 1. Create a newinfo object using MPI_Info_create
* 2. Fetch all the values from info and copy them to
* newinfo using MPI_Info_set
* The new implementation facilitates traversal in many ways.
* I have chosen to get the number of elements on the list
* and copy them to newinfo one by one
*/
if (NULL == info){
printf ("Invalid MPI_Info handle passed\n");
return MPI_ERR_ARG;
}
err = MPI_Info_create(newinfo);
if (MPI_SUCCESS != err) {
printf ("Creation of newinfo falied\n");
return err;
}
/*
* Now to actually duplicate all the values
*/
err = MPI_Info_get_nkeys (info, &nkeys);
for (iterator = (lam_info_entry_t *)lam_list_get_first(&(info->super));
nkeys > 0;
nkeys--) {
err = MPI_Info_set (*newinfo, iterator->ie_key, iterator->ie_value);
if (MPI_SUCCESS != err) {
printf ("Failed to set a key in newinfo\n");
return err;
}
iterator = (lam_info_entry_t *)iterator->super.lam_list_next;
}
return MPI_SUCCESS;
}

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

@ -24,6 +24,9 @@
* Upon successful completion, 'info' will be set to 'MPI_INFO_NULL'.
*/
int MPI_Info_free(MPI_Info *info) {
lam_info_entry_t *iterator;
int nkeys;
int err;
/*
* Free all the alloced items from MPI_Info info.
* Make sure the items are freed in an orderly
@ -31,5 +34,36 @@ int MPI_Info_free(MPI_Info *info) {
* Also, something needs to be done about the
* fortran handle.
*/
if (NULL == info){
printf ("Invalid MPI_Info handle passed\n");
return MPI_ERR_ARG;
}
/*
* Now to actually free all the values
*/
err = MPI_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;
}

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

@ -8,6 +8,9 @@
#include "mpi/interface/c/bindings.h"
#include "lam/lfc/list.h"
#include "mpi/info/info.h"
#include "lam/util/strncpy.h"
#include <stdlib.h>
#include <string.h>
#if LAM_HAVE_WEAK_SYMBOLS && LAM_PROFILING_DEFINES
#pragma weak MPI_Info_get = PMPI_Info_get
@ -33,11 +36,49 @@
int MPI_Info_get(MPI_Info info, char *key, int valuelen,
char *value, int *flag) {
lam_info_entry_t *search;
int key_length;
int value_length;
/*
* Simple function. All we need to do is search for the value
* having the "key" associated with it and then populate the
* necessary structures.
*/
if (NULL == info){
printf ("Invalid MPI_Info handle passed\n");
return MPI_ERR_ARG;
}
key_length = (key) ? strlen (key) : 0;
if ( (0 == key_length) || (MPI_MAX_INFO_KEY <= key_length)) {
printf ("The key passed to MPI_INFO_SET is too long\n");
return MPI_ERR_INFO_KEY;
}
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;
}

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

@ -27,5 +27,12 @@
* containing the key-value pairs
*/
int MPI_Info_get_nkeys(MPI_Info info, int *nkeys) {
if (NULL == info){
printf ("Invalid MPI_Info handle passed\n");
return MPI_ERR_ARG;
}
*nkeys = (int) lam_list_get_size(&(info->super));
return MPI_SUCCESS;
}

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

@ -8,6 +8,7 @@
#include "mpi/interface/c/bindings.h"
#include "lam/lfc/list.h"
#include "mpi/info/info.h"
#include <string.h>
#if LAM_HAVE_WEAK_SYMBOLS && LAM_PROFILING_DEFINES
#pragma weak MPI_Info_get_nthkey = PMPI_Info_get_nthkey
@ -24,5 +25,39 @@
* @retval MPI_ERR_ARG
*/
int MPI_Info_get_nthkey(MPI_Info info, int n, char *key) {
lam_info_entry_t *iterator;
int nkeys;
/*
* 1. Check if info is a valid handle
* 2. Check if there are atleast "n" elements
* 3. If so, give the nth defined key
*/
if (NULL == info){
printf ("Invalid MPI_Info handle passed\n");
return MPI_ERR_ARG;
}
MPI_Info_get_nkeys(info, &nkeys);
if (nkeys < n) {
printf ("Requested key does not exist\n");
return MPI_ERR_ARG;
} else {
/*
* 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;
}

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

@ -8,6 +8,8 @@
#include "mpi/interface/c/bindings.h"
#include "lam/lfc/list.h"
#include "mpi/info/info.h"
#include <stdlib.h>
#include <string.h>
#if LAM_HAVE_WEAK_SYMBOLS && LAM_PROFILING_DEFINES
#pragma weak MPI_Info_get_valuelen = PMPI_Info_get_valuelen
@ -27,9 +29,41 @@
* @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.
* character. If the 'key' is not found on 'info', 'valuelen' is left
* alone.
*/
int MPI_Info_get_valuelen(MPI_Info info, char *key, int *valuelen,
int *flag) {
lam_info_entry_t *search;
int key_length;
/*
* Simple function. All we need to do is search for the value
* having the "key" associated with it and return the length
*/
if (NULL == info){
printf ("Invalid MPI_Info handle passed\n");
return MPI_ERR_ARG;
}
key_length = (key) ? strlen (key) : 0;
if ( (0 == key_length) || (MPI_MAX_INFO_KEY <= key_length)) {
printf ("The key passed to MPI_INFO_SET is too long\n");
return MPI_ERR_INFO_KEY;
}
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,8 @@
#include "mpi/interface/c/bindings.h"
#include "lam/lfc/list.h"
#include "mpi/info/info.h"
#include <stdlib.h>
#include <string.h>
#if LAM_HAVE_WEAK_SYMBOLS && LAM_PROFILING_DEFINES
#pragma weak MPI_Info_set = PMPI_Info_set
@ -29,11 +31,81 @@
*
* MPI_Info_set adds the (key,value) pair to info, and overrides
* teh value if for the same key a previsou value was set. key and
* value must nen NULL terminated strings in C. In fortan, leading
* value must be NULL terminated strings in C. In fortan, leading
* and trailing spaces in key and value are stripped. If either
* key or value is greater than the allowed maxima, MPI_ERR_INFO_KEY
* and MPI_ERR_INFO_VALUE are raised
*/
int MPI_Info_set(MPI_Info info, char *key, char *value) {
lam_info_entry_t *new_info;
lam_info_entry_t *old_info;
int key_length;
int value_length;
char *new_value;
/*
* Error conditions are
* 1. MPI_ERR_ARG if
* - info is NULL
* 2. MPI_ERR_SYSRESOURCE
* - No storage space available for the new value
* 3. MPI_ERR_INFO_KEY
* - Key length exceeded MPI_MAX_KEY_VAL
* 3. MPI_ERR_INFO_VAL
* - value length exceeded MPI_MAX_KEY_VAL
*/
if (NULL == info){
printf ("Invalid MPI_Info handle passed\n");
return MPI_ERR_ARG;
}
key_length = (key) ? strlen (key) : 0;
if ( (0 == key_length) || (MPI_MAX_INFO_KEY <= key_length)) {
printf ("The key passed to MPI_INFO_SET is too long\n");
return MPI_ERR_INFO_KEY;
}
value_length = (value) ? strlen (value) : 0;
if ( (0 == value_length) || (MPI_MAX_INFO_KEY <= value_length)) {
printf ("The value passed to MPI_INFO_SET is too long\n");
return MPI_ERR_INFO_VALUE;
}
/*
* If all is right with the arguments, then:
* 1. Allocate space for value
* 2. Check if the key was associated with a previous value
* - If so delete that value and store the new value
* 3. Store the (key, value) pair
*/
new_value = (char *) LAM_MALLOC(value_length * sizeof(char));
if (NULL == new_value) {
printf ("Unable to malloc memory for new (key, value) pair\n");
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
*/
LAM_FREE (old_info->ie_value);
old_info->ie_value = new_value;
} else {
new_info = OBJ_CREATE(lam_info_entry_t, &lam_info_entry_cls);
if (NULL == new_info) {
printf ("Unable to malloc memory for new (key, value) pair\n");
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;
}