From 2a1cf2ae817ca37563302458c88a4716dc6ae693 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Wed, 15 Jul 2009 04:54:53 +0000 Subject: [PATCH] Create two new modex functions for send/recv of specific OPAL data types - basically, ensure that the values are packed and unpacked appropriately. Provides a convenience function as otherwise anyone wanting to send a value had to do this themselves. Use it to send the arch. This commit was SVN r21677. --- ompi/proc/proc.c | 9 +---- ompi/runtime/ompi_module_exchange.c | 57 +++++++++++++++++++++++++++++ ompi/runtime/ompi_module_exchange.h | 41 +++++++++++++++++++++ 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/ompi/proc/proc.c b/ompi/proc/proc.c index 6b7ed2e68c..b9d17aa168 100644 --- a/ompi/proc/proc.c +++ b/ompi/proc/proc.c @@ -113,7 +113,7 @@ int ompi_proc_init(void) proc->proc_hostname = orte_process_info.nodename; proc->proc_arch = opal_local_arch; /* add our arch to the modex */ - if (OMPI_SUCCESS != (ret = ompi_modex_send_string("OMPI_ARCH", &proc->proc_arch, sizeof(proc->proc_arch)))) { + if (OMPI_SUCCESS != (ret = ompi_modex_send_key_value("OMPI_ARCH", &proc->proc_arch, OPAL_UINT32))) { return ret; } } else { @@ -141,8 +141,6 @@ int ompi_proc_set_arch(void) { ompi_proc_t *proc = NULL; opal_list_item_t *item = NULL; - uint32_t *arch; - size_t sizearch; int ret; OPAL_THREAD_LOCK(&ompi_proc_lock); @@ -153,12 +151,10 @@ int ompi_proc_set_arch(void) proc = (ompi_proc_t*)item; if (proc->proc_name.vpid != ORTE_PROC_MY_NAME->vpid) { - if (OMPI_SUCCESS != (ret = ompi_modex_recv_string("OMPI_ARCH", proc, (void**)&arch, &sizearch))) { + if (OMPI_SUCCESS != (ret = ompi_modex_recv_key_value("OMPI_ARCH", proc, (void*)&(proc->proc_arch), OPAL_UINT32))) { OPAL_THREAD_UNLOCK(&ompi_proc_lock); return ret; } - proc->proc_arch = *arch; - free(arch); /* if arch is different than mine, create a new convertor for this proc */ if (proc->proc_arch != opal_local_arch) { #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT @@ -543,7 +539,6 @@ ompi_proc_unpack(opal_buffer_t* buf, /* update all the values */ plist[i]->proc_arch = new_arch; - /* if arch is different than mine, create a new convertor for this proc */ if (plist[i]->proc_arch != opal_local_arch) { #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT diff --git a/ompi/runtime/ompi_module_exchange.c b/ompi/runtime/ompi_module_exchange.c index b83e9271db..b64e6522ff 100644 --- a/ompi/runtime/ompi_module_exchange.c +++ b/ompi/runtime/ompi_module_exchange.c @@ -23,9 +23,13 @@ #include "opal/mca/mca.h" #include "opal/mca/base/base.h" +#include "opal/dss/dss.h" #include "orte/mca/grpcomm/grpcomm.h" +#include "orte/util/name_fns.h" +#include "orte/runtime/orte_globals.h" + #include "ompi/proc/proc.h" #include "ompi/runtime/ompi_module_exchange.h" @@ -80,3 +84,56 @@ ompi_modex_recv_string(const char* key, { return orte_grpcomm.get_proc_attr(source_proc->proc_name, key, buffer, size); } + +int +ompi_modex_send_key_value(const char* key, + const void *value, + opal_data_type_t dtype) +{ + int rc; + opal_buffer_t buf; + opal_byte_object_t bo; + + OBJ_CONSTRUCT(&buf, opal_buffer_t); + if (OPAL_SUCCESS != (rc = opal_dss.pack(&buf, value, 1, dtype))) { + OBJ_DESTRUCT(&buf); + return rc; + } + if (OPAL_SUCCESS != (rc = opal_dss.unload(&buf, (void**)&bo.bytes, &bo.size))) { + OBJ_DESTRUCT(&buf); + return rc; + } + OBJ_DESTRUCT(&buf); + + return orte_grpcomm.set_proc_attr(key, bo.bytes, bo.size); +} + + +int +ompi_modex_recv_key_value(const char* key, + struct ompi_proc_t *source_proc, + void *value, opal_data_type_t dtype) +{ + int rc; + opal_buffer_t buf; + opal_byte_object_t bo; + int32_t n; + size_t bsize; + + bo.bytes = NULL; + bo.size = 0; + if (OMPI_SUCCESS != (rc = orte_grpcomm.get_proc_attr(source_proc->proc_name, key, + (void**)&bo.bytes, &bsize))) { + return rc; + } + bo.size = bsize; + OBJ_CONSTRUCT(&buf, opal_buffer_t); + if (OMPI_SUCCESS != (rc = opal_dss.load(&buf, bo.bytes, bo.size))) { + OBJ_DESTRUCT(&buf); + return rc; + } + n = 1; + rc = opal_dss.unpack(&buf, value, &n, dtype); + OBJ_DESTRUCT(&buf); + return rc; +} diff --git a/ompi/runtime/ompi_module_exchange.h b/ompi/runtime/ompi_module_exchange.h index c0c3b8262e..8c1ce937d8 100644 --- a/ompi/runtime/ompi_module_exchange.h +++ b/ompi/runtime/ompi_module_exchange.h @@ -130,6 +130,24 @@ OMPI_DECLSPEC int ompi_modex_send(mca_base_component_t *source_component, OMPI_DECLSPEC int ompi_modex_send_string(const char* key, const void *buffer, size_t size); +/** + * Send a value to all other corresponding peer process + * + * Similar to ompi_modex_send(), but uses a char* key instead of a + * component name for indexing, and performs all required conditioning + * to deal with heterogeneity. + * + * @param[in] key A unique key for data storage / lookup + * @param[in] value A pointer to data value + * @param[in] dtype Data type of the value + * + * @retval OMPI_SUCCESS On success + * @retval OMPI_ERROR An unspecified error occurred + */ +OMPI_DECLSPEC int ompi_modex_send_key_value(const char* key, + const void *value, + opal_data_type_t dtype); + /** * Receive a module-specific buffer from a corresponding MCA module @@ -205,6 +223,29 @@ OMPI_DECLSPEC int ompi_modex_recv_string(const char* key, struct ompi_proc_t *source_proc, void **buffer, size_t *size); +/** + * Recv a value from a given peer + * + * Similar to ompi_modex_recv(), but uses a char* key instead of a + * component name for indexing, and performs all required conditioning + * to deal with heterogeneity. + * + * @param[in] key A unique key for data storage / lookup + * @param[in] source_proc Peer process to receive from + * @param[in] value A pointer to the address where the data + * value will be stored + * @param[in] dtype Data type of the value + * + * @retval OMPI_SUCCESS If a corresponding module value is found and + * successfully returned to the caller. + * @retval OMPI_ERR_NOT_IMPLEMENTED Modex support is not available in + * this build of Open MPI (systems like the Cray XT) + */ +OMPI_DECLSPEC int ompi_modex_recv_key_value(const char* key, + struct ompi_proc_t *source_proc, + void *value, + opal_data_type_t dtype); + END_C_DECLS