diff --git a/src/mpi/Makefile.am b/src/mpi/Makefile.am index 4769aaf9bf..08c0a3af27 100644 --- a/src/mpi/Makefile.am +++ b/src/mpi/Makefile.am @@ -12,6 +12,7 @@ noinst_LTLIBRARIES = libmpi_convenience.la sources = \ communicator/libmpi_communicator.la \ datatype/libmpi_datatype.la \ + info/libmpi_info.la \ interface/libmpi_interface.la \ proc/libmpi_proc.la \ request/libmpi_request.la \ diff --git a/src/mpi/info/Makefile.am b/src/mpi/info/Makefile.am index b8194ab5be..419d07d310 100644 --- a/src/mpi/info/Makefile.am +++ b/src/mpi/info/Makefile.am @@ -5,11 +5,17 @@ include $(top_srcdir)/config/Makefile.options +# libraries +noinst_LTLIBRARIES = libmpi_info.la # Source code files headers = \ info.h +libmpi_info_la_SOURCES = \ + $(headers) \ + info.c + # Conditionally install the header files if WANT_INSTALL_HEADERS diff --git a/src/mpi/info/info.c b/src/mpi/info/info.c new file mode 100644 index 0000000000..b6d4e5814c --- /dev/null +++ b/src/mpi/info/info.c @@ -0,0 +1,50 @@ +/** + * $HEADER$ + */ + +#include "mpi/info/info.h" + +/* + * lam_info_t classes + */ +lam_class_info_t lam_info_cls = { "lam_info_t", + &lam_list_cls, + (class_init_t)lam_info_init, + (class_destroy_t)lam_info_destroy}; + +/* + * lam_info_entry_t classes + */ +lam_class_info_t lam_info_entry_cls = { + "lam_info_entry_t", + &lam_list_item_cls, + (class_init_t)lam_info_entry_init, + (class_destroy_t)lam_info_entry_destroy}; + +/* + * lam_info_t interface functions + */ +void lam_info_init(lam_info_t *info) { + SUPER_INIT(info, lam_info_cls.cls_parent); + info->i_fhandle = -1; +} + +void lam_info_destroy(lam_info_t *info) { + SUPER_DESTROY(info, lam_info_cls.cls_parent); +} + +/* + * lam_info_entry_t interface functions + */ +void lam_info_entry_init(lam_info_entry_t *entry) { + SUPER_INIT(entry, lam_list_item_cls.cls_parent); + LAM_MEM_ZERO (entry->ie_key); + entry->ie_key[MPI_MAX_INFO_KEY] = 0; +} + +void lam_info_entry_destroy(lam_info_entry_t *entry) { + SUPER_DESTROY(entry, lam_list_item_cls.cls_parent); + if (NULL != entry->ie_value) { + LAM_FREE(entry->ie_value); + } +} diff --git a/src/mpi/info/info.h b/src/mpi/info/info.h index bb184e882d..1ed186713d 100644 --- a/src/mpi/info/info.h +++ b/src/mpi/info/info.h @@ -7,20 +7,18 @@ #include "mpi.h" #include "lam/lfc/list.h" +#include "lam/lam.h" +#include + /** * lam_info_t structure. MPI_Info is a pointer to this structure */ struct lam_info_t { - char i_name[MPI_MAX_OBJECT_NAME]; /**< name of the info object - * being instantiated */ - lam_list_t *lam_info_list; /**< generic list pointer which is - * the container for (key,value) - * pairs */ - /* Anju: - * Should add appropriate member/s to support - * fortran translation. - */ + lam_list_t super; /**< generic list pointer which is + * the container for (key,value) pairs */ + int i_fhandle; /**< fortran handle for info. This is needed + * for translation from fortran to C and vice versa */ }; typedef struct lam_info_t lam_info_t; @@ -30,11 +28,67 @@ typedef struct lam_info_t lam_info_t; */ struct lam_info_entry_t { lam_list_item_t super; /**< required for lam_list_t type */ - char *value; /**< value part of the (key, value) pair. + char *ie_value; /**< value part of the (key, value) pair. * Maximum length is MPI_MAX_INFO_VAL */ - char key[MPI_MAX_INFO_KEY + 1]; /**< "key" part of the (key, value) + char ie_key[MPI_MAX_INFO_KEY + 1]; /**< "key" part of the (key, value) * pair */ }; typedef struct lam_info_entry_t lam_info_entry_t; +/** + * Some declarations needed to use OBJ_CREATE and OBJ_DESTROY macros + */ +extern lam_class_info_t lam_info_cls; +extern lam_class_info_t lam_info_entry_cls; + +#if defined(c_plusplus) || defined(__cplusplus) +extern "C" { +#endif +void lam_info_init(lam_info_t *info); +void lam_info_destroy(lam_info_t *info); + +void lam_info_entry_init(lam_info_entry_t *entry); +void lam_info_entry_destroy(lam_info_entry_t *entry); +#if defined(c_plusplus) || defined(__cplusplus) +} +#endif + +/** + * Iterate through the list and search for "key" + * + * @param info MPI_Info handle + * @param key Key value to search for + * + * @retval (lam_info_entry_t *) to the object having the same key + * NULL if no matching item is found + * + * We need a function to go through the entries and find whether + * a given key is already present in the list. If so, this function + * returns the item which matches this key. It was required + * often enough to make it into a function. No error checking on + * info is performed. + * Assumptions: + * "info" is a valid key + */ +static inline lam_info_entry_t *lam_info_find_key (MPI_Info info, + char *key) { + lam_info_entry_t *iterator; + int nkeys; + + /* Iterate over all the entries. If the key is found, then + * return immediately. Else, the loop will fall of the edge + * and NULL is returned + */ + nkeys = lam_list_get_size(&(info->super)); + for (iterator = (lam_info_entry_t *)lam_list_get_first(&(info->super)); + nkeys > 0; + nkeys--) { + if (0 == strcmp(key, iterator->ie_key)) { + return iterator; + } + iterator = (lam_info_entry_t *)iterator->super.lam_list_next; + } + return (lam_info_entry_t *)0; +} + #endif /* LAM_INFO_H */