diff --git a/src/mca/ns/base/base.h b/src/mca/ns/base/base.h index cf46688f5d..47ff2f3614 100644 --- a/src/mca/ns/base/base.h +++ b/src/mca/ns/base/base.h @@ -35,6 +35,8 @@ extern "C" { mca_ns_base_jobid_t job, mca_ns_base_vpid_t vpid); + ompi_process_name_t* ns_base_copy_process_name(ompi_process_name_t* name); + ompi_process_name_t* ns_base_convert_string_to_process_name(const char* name); char* ns_base_get_proc_name_string(const ompi_process_name_t* name); @@ -74,7 +76,7 @@ extern "C" { extern int mca_ns_base_output; extern mca_ns_base_module_t ompi_name_server; /* holds selected module's function pointers */ -extern ompi_process_name_t mca_ns_my_replica; +extern ompi_process_name_t *mca_ns_my_replica; /* the name of the replica for this process */ extern bool mca_ns_base_selected; extern ompi_list_t mca_ns_base_components_available; extern mca_ns_base_component_t mca_ns_base_selected_component; diff --git a/src/mca/ns/base/ns_base_local_fns.c b/src/mca/ns/base/ns_base_local_fns.c index 70eedbd2be..532466c0c1 100644 --- a/src/mca/ns/base/ns_base_local_fns.c +++ b/src/mca/ns/base/ns_base_local_fns.c @@ -34,7 +34,7 @@ ompi_process_name_t* ns_base_create_process_name(mca_ns_base_cellid_t cell, return(NULL); } - newname = OBJ_NEW(ompi_process_name_t); + newname = (ompi_process_name_t*)malloc(sizeof(ompi_process_name_t)); if (NULL == newname) { /* got an error */ return(NULL); } @@ -45,6 +45,24 @@ ompi_process_name_t* ns_base_create_process_name(mca_ns_base_cellid_t cell, return(newname); } +ompi_process_name_t* ns_base_copy_process_name(ompi_process_name_t* name) +{ + mca_ns_base_cellid_t cell; + mca_ns_base_jobid_t job; + mca_ns_base_vpid_t vpid; + ompi_process_name_t *newname; + + if (NULL == name) { + return NULL; + } + + cell = ns_base_get_cellid(name); + job = ns_base_get_jobid(name); + vpid = ns_base_get_vpid(name); + + newname = ns_base_create_process_name(cell, job, vpid); + return newname; +} char* ns_base_get_proc_name_string(const ompi_process_name_t* name) { @@ -254,3 +272,12 @@ int ns_base_compare(ompi_ns_cmp_bitmask_t fields, return(0); } + +int ns_base_free_name(ompi_process_name_t* name) +{ + if (NULL != name) { + free(name); + } + + return OMPI_SUCCESS; +} diff --git a/src/mca/ns/base/ns_base_open.c b/src/mca/ns/base/ns_base_open.c index 0b23fb308f..5389fb816e 100644 --- a/src/mca/ns/base/ns_base_open.c +++ b/src/mca/ns/base/ns_base_open.c @@ -22,32 +22,12 @@ * globals */ -/* constructor - used to initialize state of name instance */ -static void ompi_name_construct(ompi_process_name_t* name) -{ - name->cellid = 0; - name->jobid = 0; - name->vpid = 0; -} - -/* destructor - used to free any resources held by instance */ -static void ompi_name_destructor(ompi_process_name_t* name) -{ -} - -OBJ_CLASS_INSTANCE( - ompi_process_name_t, /* type name */ - ompi_object_t, /* parent "class" name */ - ompi_name_construct, /* constructor */ - ompi_name_destructor); /* destructor */ - - /* * Global variables */ int mca_ns_base_output = -1; mca_ns_base_module_t ompi_name_server; -ompi_process_name_t mca_ns_my_replica; +ompi_process_name_t *mca_ns_my_replica; bool mca_ns_base_selected = false; ompi_list_t mca_ns_base_components_available; mca_ns_base_component_t mca_ns_base_selected_component; diff --git a/src/mca/ns/base/ns_base_remote_fns.c b/src/mca/ns/base/ns_base_remote_fns.c index 8fee8e4cdd..2bd4fddc34 100644 --- a/src/mca/ns/base/ns_base_remote_fns.c +++ b/src/mca/ns/base/ns_base_remote_fns.c @@ -7,6 +7,7 @@ #include "ompi_config.h" #include "mca/mca.h" +#include "util/pack.h" #include "mca/oob/base/base.h" #include "mca/ns/base/base.h" @@ -20,45 +21,118 @@ mca_ns_base_cellid_t ns_base_create_cellid(void) { - ompi_ns_msg_buffer_t cmd, *answer; - struct iovec msg; + ompi_buffer_t cmd; mca_ns_base_cellid_t cell; + ompi_buffer_t *answer; + mca_ns_cmd_flag_t command; + int recv_tag; - cmd.command = OMPI_NS_CREATE_CELLID; - cmd.buflen = 0; - cmd.buf = NULL; + command = MCA_NS_CREATE_CELLID_CMD; + recv_tag = MCA_OOB_TAG_NS; - msg.iov_base = (char*)&cmd; - msg.iov_len = sizeof(cmd); + if (OMPI_SUCCESS != ompi_buffer_init(&cmd, 0)) { /* got a problem */ + return OMPI_ERROR; + } - if (0 > mca_oob_send(&mca_ns_my_replica, &msg, 1, MCA_OOB_TAG_ANY, 0)) { /* error on send */ - return 0; - } + if (OMPI_SUCCESS != ompi_pack(cmd, (void*)&command, 1, MCA_NS_OOB_PACK_CMD)) { + return OMPI_ERROR; + } - if (0 > mca_oob_recv(&mca_ns_my_replica, &msg, 1, MCA_OOB_TAG_ANY, 0)) { /* error on recv */ - return 0; - } + if (0 > mca_oob_send_packed(mca_ns_my_replica, cmd, MCA_OOB_TAG_NS, 0)) { + return MCA_NS_BASE_CELLID_MAX; + } - answer = (ompi_ns_msg_buffer_t*)msg.iov_base; - cell = (mca_ns_base_cellid_t)answer->buf; - return cell; + if (0 > mca_oob_recv_packed(mca_ns_my_replica, answer, &recv_tag)) { + return MCA_NS_BASE_CELLID_MAX; + } + + if (OMPI_SUCCESS != ompi_unpack(*answer, &cell, 1, MCA_NS_OOB_PACK_CELLID)) { + ompi_buffer_free(*answer); + return MCA_NS_BASE_CELLID_MAX; + } else { + ompi_buffer_free(*answer); + return cell; + } } + mca_ns_base_jobid_t ns_base_create_jobid(void) { - /* JMS fill in here */ - return 0; + ompi_buffer_t cmd; + mca_ns_base_jobid_t job; + ompi_buffer_t *answer; + mca_ns_cmd_flag_t command; + int recv_tag; + + command = MCA_NS_CREATE_JOBID_CMD; + recv_tag = MCA_OOB_TAG_NS; + + if (OMPI_SUCCESS != ompi_buffer_init(&cmd, 0)) { /* got a problem */ + return OMPI_ERROR; + } + + if (OMPI_SUCCESS != ompi_pack(cmd, (void*)&command, 1, MCA_NS_OOB_PACK_CMD)) { /* got a problem */ + return OMPI_ERROR; + } + + if (0 > mca_oob_send_packed(mca_ns_my_replica, cmd, MCA_OOB_TAG_NS, 0)) { + return MCA_NS_BASE_JOBID_MAX; + } + + if (0 > mca_oob_recv_packed(mca_ns_my_replica, answer, &recv_tag)) { + return MCA_NS_BASE_JOBID_MAX; + } + + if (OMPI_SUCCESS != ompi_unpack(*answer, &job, 1, MCA_NS_OOB_PACK_JOBID)) { + ompi_buffer_free(*answer); + return MCA_NS_BASE_JOBID_MAX; + } else { + ompi_buffer_free(*answer); + return job; + } } mca_ns_base_vpid_t ns_base_reserve_range(mca_ns_base_jobid_t job, mca_ns_base_vpid_t range) { - /* JMS fill in here */ - return 0; -} + ompi_buffer_t cmd; + mca_ns_base_vpid_t starting_vpid; + ompi_buffer_t *answer; + mca_ns_cmd_flag_t command; + int recv_tag; + command = MCA_NS_RESERVE_RANGE_CMD; + recv_tag = MCA_OOB_TAG_NS; -int ns_base_free_name(ompi_process_name_t* name) -{ - return OMPI_SUCCESS; + if (OMPI_SUCCESS != ompi_buffer_init(&cmd, 0)) { /* got a problem */ + return OMPI_ERROR; + } + + if (OMPI_SUCCESS != ompi_pack(cmd, (void*)&command, 1, MCA_NS_OOB_PACK_CMD)) { /* got a problem */ + return OMPI_ERROR; + } + + if (OMPI_SUCCESS != ompi_pack(cmd, (void*)&job, 1, MCA_NS_OOB_PACK_JOBID)) { /* got a problem */ + return OMPI_ERROR; + } + + if (OMPI_SUCCESS != ompi_pack(cmd, (void*)&range, 1, MCA_NS_OOB_PACK_VPID)) { /* got a problem */ + return OMPI_ERROR; + } + + if (0 > mca_oob_send_packed(mca_ns_my_replica, cmd, MCA_OOB_TAG_NS, 0)) { + return MCA_NS_BASE_VPID_MAX; + } + + if (0 > mca_oob_recv_packed(mca_ns_my_replica, answer, &recv_tag)) { + return MCA_NS_BASE_VPID_MAX; + } + + if (OMPI_SUCCESS != ompi_unpack(*answer, &starting_vpid, 1, MCA_NS_OOB_PACK_VPID)) { + ompi_buffer_free(*answer); + return MCA_NS_BASE_VPID_MAX; + } else { + ompi_buffer_free(*answer); + return starting_vpid; + } } diff --git a/src/mca/ns/ns.h b/src/mca/ns/ns.h index fd15b6f665..f47373645e 100644 --- a/src/mca/ns/ns.h +++ b/src/mca/ns/ns.h @@ -26,6 +26,7 @@ #include "class/ompi_list.h" #include "mca/mca.h" +#include "util/pack.h" /* @@ -43,14 +44,39 @@ #define MCA_NS_BASE_JOBID_MAX UINT32_MAX #define MCA_NS_BASE_VPID_MAX UINT32_MAX +/* + * define flag values for remote commands - only used internally + */ +#define MCA_NS_CREATE_CELLID_CMD 0x01 +#define MCA_NS_CREATE_JOBID_CMD 0x02 +#define MCA_NS_RESERVE_RANGE_CMD 0x04 +#define MCA_NS_FREE_NAME_CMD 0x08 + + /* * general typedefs & structures */ -/**< Set the allowed range for ids in each space */ +/** Set the allowed range for ids in each space */ +/* CAUTION - any changes here must also change corresponding + * OOB_PACK definitions below + */ typedef uint32_t mca_ns_base_jobid_t; typedef uint32_t mca_ns_base_cellid_t; typedef uint32_t mca_ns_base_vpid_t; typedef uint8_t ompi_ns_cmp_bitmask_t; /**< Bit mask for comparing process names */ +typedef uint16_t mca_ns_cmd_flag_t; + +/* + * packing type definitions + */ +/* CAUTION - any changes here must also change corresponding + * typedefs above + */ +#define MCA_NS_OOB_PACK_JOBID OMPI_INT32 +#define MCA_NS_OOB_PACK_CELLID OMPI_INT32 +#define MCA_NS_OOB_PACK_VPID OMPI_INT32 +#define MCA_NS_OOB_PACK_CMD OMPI_INT16 + struct ompi_process_name_t { mca_ns_base_cellid_t cellid; /**< Cell number */ @@ -59,8 +85,6 @@ struct ompi_process_name_t { }; typedef struct ompi_process_name_t ompi_process_name_t; -/* declare the class */ -OBJ_CLASS_DECLARATION(ompi_process_name_t); /* * define the command names/ids for use in OOB buffers. @@ -161,6 +185,18 @@ typedef mca_ns_base_jobid_t (*mca_ns_base_module_create_jobid_fn_t)(void); */ typedef ompi_process_name_t* (*mca_ns_base_module_create_proc_name_fn_t)(mca_ns_base_cellid_t cell, mca_ns_base_jobid_t job, mca_ns_base_vpid_t vpid); +/** + * Make a copy of a process name. + * Given a process name, this function creates a copy of it and returns a pointer + * to the duplicate structure. + * + * @param *name Pointer to an existing process name structure. + * + * @retval *newname Pointer to the duplicate structure, with all fields transferred. + * @retval NULL Indicates an error - most likely due to a NULL process name + * pointer being supplied as input. + */ +typedef ompi_process_name_t* (*mca_ns_base_module_copy_proc_name_fn_t)(ompi_process_name_t* name); /** * Convert a string representation to a process name. @@ -403,6 +439,7 @@ struct mca_ns_base_module_1_0_0_t { mca_ns_base_module_create_cellid_fn_t create_cellid; mca_ns_base_module_create_jobid_fn_t create_jobid; mca_ns_base_module_create_proc_name_fn_t create_process_name; + mca_ns_base_module_copy_proc_name_fn_t copy_process_name; mca_ns_base_module_convert_string_to_process_name_fn_t convert_string_to_process_name; mca_ns_base_module_reserve_range_fn_t reserve_range; mca_ns_base_module_free_name_fn_t free_name; diff --git a/src/mca/ns/proxy/src/ns_proxy.h b/src/mca/ns/proxy/src/ns_proxy.h index 85b0f4f8ad..d012853c9c 100644 --- a/src/mca/ns/proxy/src/ns_proxy.h +++ b/src/mca/ns/proxy/src/ns_proxy.h @@ -30,7 +30,4 @@ int mca_ns_proxy_finalize(void); * globals used within proxy component */ -extern ompi_process_name_t mca_ns_my_replica; - - #endif diff --git a/src/mca/ns/proxy/src/ns_proxy_component.c b/src/mca/ns/proxy/src/ns_proxy_component.c index d6d6ba07b0..3d64c4b65d 100644 --- a/src/mca/ns/proxy/src/ns_proxy_component.c +++ b/src/mca/ns/proxy/src/ns_proxy_component.c @@ -21,6 +21,7 @@ #include "util/proc_info.h" #include "util/output.h" #include "mca/mca.h" +#include "mca/base/mca_base_param.h" #include "mca/ns/base/base.h" #include "ns_proxy.h" @@ -53,6 +54,7 @@ static mca_ns_base_module_t mca_ns_proxy = { ns_base_create_cellid, ns_base_create_jobid, ns_base_create_process_name, + ns_base_copy_process_name, ns_base_convert_string_to_process_name, ns_base_reserve_range, ns_base_free_name, @@ -75,10 +77,10 @@ static bool initialized = false; * globals needed within proxy component */ +ompi_process_name_t *mca_ns_my_replica; /* - * don't really need this function - could just put NULL in the above structure - * Just holding the place in case we decide there is something we need to do + * Open the proxy component and obtain the name of my replica. */ int mca_ns_proxy_open(void) { @@ -95,34 +97,50 @@ int mca_ns_proxy_close(void) mca_ns_base_module_t* mca_ns_proxy_init(bool *allow_multi_user_threads, bool *have_hidden_threads, int *priority) { + int index, error_code; + char *my_replica_string; + /* If we're NOT the seed, then we want to be selected, so do all the setup and return the module */ - ompi_output(mca_ns_base_output, "ns_proxy: entered init\n"); + /* ompi_output(mca_ns_base_output, "ns_proxy: entered init\n"); */ if (!ompi_process_info.seed) { - /* Return a module (choose an arbitrary, positive priority -- - it's only relevant compared to other ns components). If - we're not the seed, then we don't want to be selected, so - return NULL. */ + /* Return a module (choose an arbitrary, positive priority -- + it's only relevant compared to other ns components). If + we're not the seed, then we don't want to be selected, so + return NULL. */ - *priority = 10; + *priority = 10; - /* We allow multi user threads but don't have any hidden threads */ + /* We allow multi user threads but don't have any hidden threads */ - *allow_multi_user_threads = true; - *have_hidden_threads = false; + *allow_multi_user_threads = true; + *have_hidden_threads = false; - /* define the replica for us to use - for now, use only the seed */ - mca_ns_my_replica.cellid = 0; - mca_ns_my_replica.jobid = 0; - mca_ns_my_replica.vpid = 0; + /* define the replica for us to use */ + /* register the mca parameter containing my replica's contact info */ + index = mca_base_param_register_string("NS", "PROXY", "REPLICA", NULL, NULL); - /* Return the module */ + error_code = mca_base_param_lookup_string(index, &my_replica_string); + if (OMPI_ERROR == error_code) { /* can't lookup mca parameter for some reason - can't operate */ + return NULL; + } - initialized = true; - return &mca_ns_proxy; + mca_ns_my_replica = mca_ns_proxy.convert_string_to_process_name(my_replica_string); + if(NULL == mca_ns_my_replica) { + /* couldn't convert string to name - probably parameter not set - use seed as default */ + mca_ns_my_replica = mca_ns_proxy.create_process_name(0,0,0); + if (NULL == mca_ns_my_replica) { /* couldn't create process name - can't operate */ + return NULL; + } + } + + /* Return the module */ + + initialized = true; + return &mca_ns_proxy; } else { - return NULL; + return NULL; } } diff --git a/src/mca/ns/replica/src/ns_replica.c b/src/mca/ns/replica/src/ns_replica.c index 89b1c6832c..cb84016bc2 100644 --- a/src/mca/ns/replica/src/ns_replica.c +++ b/src/mca/ns/replica/src/ns_replica.c @@ -69,5 +69,9 @@ mca_ns_base_vpid_t ns_replica_reserve_range(mca_ns_base_jobid_t job, mca_ns_base int ns_replica_free_name(ompi_process_name_t* name) { + if (NULL != name) { + free(name); + } + return OMPI_SUCCESS; } diff --git a/src/mca/ns/replica/src/ns_replica_component.c b/src/mca/ns/replica/src/ns_replica_component.c index e126925be2..06b338ab86 100644 --- a/src/mca/ns/replica/src/ns_replica_component.c +++ b/src/mca/ns/replica/src/ns_replica_component.c @@ -54,6 +54,7 @@ static mca_ns_base_module_t mca_ns_replica = { ns_replica_create_cellid, ns_replica_create_jobid, ns_base_create_process_name, + ns_base_copy_process_name, ns_base_convert_string_to_process_name, ns_replica_reserve_range, ns_replica_free_name, @@ -118,6 +119,7 @@ int mca_ns_replica_close(void) mca_ns_base_module_t* mca_ns_replica_init(bool *allow_multi_user_threads, bool *have_hidden_threads, int *priority) { + /* If we're the seed, then we want to be selected, so do all the setup and return the module */ @@ -142,6 +144,10 @@ mca_ns_base_module_t* mca_ns_replica_init(bool *allow_multi_user_threads, bool * OBJ_CONSTRUCT(&mca_ns_replica_name_tracker, ompi_list_t); + /* set my_replica to point to myself */ + + mca_ns_my_replica = mca_ns_replica.copy_process_name(&ompi_process_info.name); + /* Return the module */ initialized = true; diff --git a/src/mca/oob/base/base.h b/src/mca/oob/base/base.h index 3bfa0690b7..710be752f3 100644 --- a/src/mca/oob/base/base.h +++ b/src/mca/oob/base/base.h @@ -39,9 +39,15 @@ extern ompi_process_name_t mca_oob_name_self; * Other constants */ /** - * Recieve from any tag. + * Receive from any tag. */ #define MCA_OOB_TAG_ANY 0 +/** + * Service tags + */ +#define MCA_OOB_TAG_NS 1 +#define MCA_OOB_TAG_GPR 2 + /* * OOB API diff --git a/src/mca/oob/base/oob_base_init.c b/src/mca/oob/base/oob_base_init.c index f192f7f85b..00d74f2153 100644 --- a/src/mca/oob/base/oob_base_init.c +++ b/src/mca/oob/base/oob_base_init.c @@ -10,6 +10,7 @@ #include "util/output.h" #include "mca/mca.h" #include "mca/base/base.h" +#include "mca/ns/base/base.h" #include "mca/pcm/pcm.h" #include "mca/oob/oob.h" #include "mca/oob/base/base.h" @@ -49,7 +50,6 @@ int mca_oob_base_init(bool *user_threads, bool *hidden_threads) ompi_process_name_t *self; /* setup local name */ - OBJ_CONSTRUCT(&mca_oob_name_self, ompi_process_name_t); self = mca_pcm.pcm_self(); if(NULL == self) { ompi_output(0, "mca_oob_base_init: could not get PCM self pointer"); @@ -58,13 +58,12 @@ int mca_oob_base_init(bool *user_threads, bool *hidden_threads) mca_oob_name_self = *self; /* setup wildcard name */ - OBJ_CONSTRUCT(&mca_oob_name_any, ompi_process_name_t); - mca_oob_name_any.cellid = -1; - mca_oob_name_any.jobid = -1; - mca_oob_name_any.vpid = -1; + mca_oob_name_any = *ompi_name_server.create_process_name(MCA_NS_BASE_CELLID_MAX, + MCA_NS_BASE_JOBID_MAX, + MCA_NS_BASE_VPID_MAX); /* setup seed daemons name */ - OBJ_CONSTRUCT(&mca_oob_name_seed, ompi_process_name_t); + mca_oob_name_seed = *ompi_name_server.create_process_name(0,0,0); /* Traverse the list of available modules; call their init functions. */ for (item = ompi_list_get_first(&mca_oob_base_components);