From 56a3fd8f36fa733393b883907e8229a6f540465a Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Thu, 19 Aug 2004 16:51:51 +0000 Subject: [PATCH] Changed the GPR interface (per Tim's request) so that a "put" will automatically create the specified segment if it doesn't already exist. You will not need to create it explicitly. Added the gpr test directory to configure.ac, and updated the tests. This commit was SVN r2228. --- configure.ac | 2 +- src/mca/gpr/gpr.h | 19 +++--- src/mca/gpr/proxy/gpr_proxy.c | 46 ------------- src/mca/gpr/proxy/gpr_proxy.h | 5 -- src/mca/gpr/proxy/gpr_proxy_component.c | 1 - src/mca/gpr/replica/gpr_replica.c | 31 +++------ src/mca/gpr/replica/gpr_replica_component.c | 41 ++++-------- src/mca/gpr/replica/gpr_replica_internals.c | 29 +++++++- src/mca/gpr/replica/gpr_replica_internals.h | 2 + src/mca/ns/ns.h | 10 --- test/mca/gpr/Makefile.am | 22 +++---- test/mca/gpr/test_gpr_replica.c | 73 ++++++++++++++++----- 12 files changed, 125 insertions(+), 156 deletions(-) diff --git a/configure.ac b/configure.ac index d0c6edda41..e7fffd9ae9 100644 --- a/configure.ac +++ b/configure.ac @@ -937,6 +937,7 @@ AC_CONFIG_FILES([ test/support/Makefile test/class/Makefile test/mca/Makefile + test/mca/gpr/Makefile test/mca/oob/Makefile test/mca/ns/Makefile test/mca/llm/Makefile @@ -945,6 +946,5 @@ AC_CONFIG_FILES([ test/mca/pcm/base/Makefile test/threads/Makefile test/util/Makefile - test/rte/Makefile ]) AC_OUTPUT diff --git a/src/mca/gpr/gpr.h b/src/mca/gpr/gpr.h index 5bc3c0e6ce..cc80c0e9ff 100644 --- a/src/mca/gpr/gpr.h +++ b/src/mca/gpr/gpr.h @@ -58,15 +58,14 @@ typedef uint16_t ompi_registry_mode_t; /* * Define flag values for remote commands - only used internally */ -#define MCA_GPR_DEFINE_SEGMENT_CMD 0x0001 -#define MCA_GPR_DELETE_SEGMENT_CMD 0x0002 -#define MCA_GPR_PUT_CMD 0x0004 -#define MCA_GPR_DELETE_OBJECT_CMD 0x0008 -#define MCA_GPR_INDEX_CMD 0x0010 -#define MCA_GPR_SUBSCRIBE_CMD 0x0020 -#define MCA_GPR_UNSUBSCRIBE_CMD 0x0040 -#define MCA_GPR_GET_CMD 0x0080 -#define MCA_GPR_TEST_INTERNALS_CMD 0x0100 +#define MCA_GPR_DELETE_SEGMENT_CMD 0x0001 +#define MCA_GPR_PUT_CMD 0x0002 +#define MCA_GPR_DELETE_OBJECT_CMD 0x0004 +#define MCA_GPR_INDEX_CMD 0x0008 +#define MCA_GPR_SUBSCRIBE_CMD 0x0010 +#define MCA_GPR_UNSUBSCRIBE_CMD 0x0020 +#define MCA_GPR_GET_CMD 0x0040 +#define MCA_GPR_TEST_INTERNALS_CMD 0x0080 #define MCA_GPR_ERROR 0xffff typedef uint16_t mca_gpr_cmd_flag_t; @@ -137,7 +136,6 @@ OBJ_CLASS_DECLARATION(ompi_registry_internal_test_results_t); /* * Component functions that MUST be provided */ -typedef int (*mca_gpr_base_module_define_segment_fn_t)(char *segment); typedef int (*mca_gpr_base_module_delete_segment_fn_t)(char *segment); typedef int (*mca_gpr_base_module_put_fn_t)(ompi_registry_mode_t mode, char *segment, char **tokens, ompi_registry_object_t *object, @@ -167,7 +165,6 @@ typedef ompi_list_t* (*mca_gpr_base_module_test_internals_fn_t)(int level); struct mca_gpr_base_module_1_0_0_t { mca_gpr_base_module_get_fn_t get; mca_gpr_base_module_put_fn_t put; - mca_gpr_base_module_define_segment_fn_t define_segment; mca_gpr_base_module_delete_segment_fn_t delete_segment; mca_gpr_base_module_subscribe_fn_t subscribe; mca_gpr_base_module_unsubscribe_fn_t unsubscribe; diff --git a/src/mca/gpr/proxy/gpr_proxy.c b/src/mca/gpr/proxy/gpr_proxy.c index 063d8b7dc1..82989a212c 100644 --- a/src/mca/gpr/proxy/gpr_proxy.c +++ b/src/mca/gpr/proxy/gpr_proxy.c @@ -18,52 +18,6 @@ * Implemented registry functions */ -int gpr_proxy_define_segment(char *segment) -{ - ompi_buffer_t cmd; - ompi_buffer_t answer; - mca_gpr_cmd_flag_t command; - int recv_tag; - int32_t response; - - command = MCA_GPR_DEFINE_SEGMENT_CMD; - recv_tag = MCA_OOB_TAG_GPR; - - if (OMPI_SUCCESS != ompi_buffer_init(&cmd, 0)) { /* got a problem */ - return OMPI_ERROR; - } - - if (OMPI_SUCCESS != ompi_pack(cmd, (void*)&command, 1, MCA_GPR_OOB_PACK_CMD)) { - return OMPI_ERROR; - } - - if (OMPI_SUCCESS != ompi_pack(cmd, (void*)segment, 1, OMPI_STRING)) { - return OMPI_ERROR; - } - - if (0 > mca_oob_send_packed(mca_gpr_my_replica, cmd, MCA_OOB_TAG_GPR, 0)) { - return OMPI_ERROR; - } - - if (0 > mca_oob_recv_packed(mca_gpr_my_replica, &answer, &recv_tag)) { - return OMPI_ERROR; - } - - if ((OMPI_SUCCESS != ompi_unpack(answer, &command, 1, MCA_GPR_OOB_PACK_CMD)) - || (MCA_GPR_DEFINE_SEGMENT_CMD != command)) { - ompi_buffer_free(answer); - return OMPI_ERROR; - } - - if (OMPI_SUCCESS != ompi_unpack(answer, &response, 1, OMPI_INT32)) { - ompi_buffer_free(answer); - return OMPI_ERROR; - } else { - ompi_buffer_free(answer); - return (int)response; - } -} - int gpr_proxy_delete_segment(char *segment) { diff --git a/src/mca/gpr/proxy/gpr_proxy.h b/src/mca/gpr/proxy/gpr_proxy.h index 1508500b83..adafb41c9d 100644 --- a/src/mca/gpr/proxy/gpr_proxy.h +++ b/src/mca/gpr/proxy/gpr_proxy.h @@ -33,11 +33,6 @@ int mca_gpr_proxy_finalize(void); extern ompi_process_name_t *mca_gpr_my_replica; -/* - * Implementation of define_segment(). - */ -int gpr_proxy_define_segment(char *segment); - /* * Implementation of delete_segment(). */ diff --git a/src/mca/gpr/proxy/gpr_proxy_component.c b/src/mca/gpr/proxy/gpr_proxy_component.c index 05f3602b74..06af2bd52c 100644 --- a/src/mca/gpr/proxy/gpr_proxy_component.c +++ b/src/mca/gpr/proxy/gpr_proxy_component.c @@ -48,7 +48,6 @@ mca_gpr_base_component_t mca_gpr_proxy_component = { static mca_gpr_base_module_t mca_gpr_proxy = { gpr_proxy_get, gpr_proxy_put, - gpr_proxy_define_segment, gpr_proxy_delete_segment, gpr_proxy_subscribe, gpr_proxy_unsubscribe, diff --git a/src/mca/gpr/replica/gpr_replica.c b/src/mca/gpr/replica/gpr_replica.c index 0a94138668..50531ccbab 100644 --- a/src/mca/gpr/replica/gpr_replica.c +++ b/src/mca/gpr/replica/gpr_replica.c @@ -25,28 +25,6 @@ #include "gpr_replica.h" #include "gpr_replica_internals.h" -int gpr_replica_define_segment(char *segment) -{ - mca_gpr_registry_segment_t *seg; - mca_gpr_replica_key_t key; - int response; - - response = gpr_replica_define_key(segment, NULL); - if (0 > response) { /* got some kind of error code */ - return response; - } - - /* need to add the segment to the registry */ - key = gpr_replica_get_key(segment, NULL); - if (MCA_GPR_REPLICA_KEY_MAX == key) { /* couldn't retrieve it */ - return OMPI_ERROR; - } - seg = OBJ_NEW(mca_gpr_registry_segment_t); - seg->segment = key; - ompi_list_append(&mca_gpr_replica_head.registry, &seg->item); - - return(OMPI_SUCCESS); -} int gpr_replica_delete_segment(char *segment) { @@ -106,9 +84,16 @@ int gpr_replica_put(ompi_registry_mode_t mode, char *segment, /* find the segment */ seg = gpr_replica_find_seg(segment); - if (NULL == seg) { /* couldn't find segment */ + if (NULL == seg) { /* couldn't find segment - try to create it */ + if (0 > gpr_replica_define_segment(segment)) { /* couldn't create it */ return_code = OMPI_ERROR; goto CLEANUP; + } + seg = gpr_replica_find_seg(segment); + if (NULL == seg) { /* ok, we tried - time to give up */ + return_code = OMPI_ERROR; + goto CLEANUP; + } } /* see if specified entry already exists */ diff --git a/src/mca/gpr/replica/gpr_replica_component.c b/src/mca/gpr/replica/gpr_replica_component.c index 89aa887af3..8eca182ab3 100644 --- a/src/mca/gpr/replica/gpr_replica_component.c +++ b/src/mca/gpr/replica/gpr_replica_component.c @@ -52,7 +52,6 @@ mca_gpr_base_component_t mca_gpr_replica_component = { static mca_gpr_base_module_t mca_gpr_replica = { gpr_replica_get, gpr_replica_put, - gpr_replica_define_segment, gpr_replica_delete_segment, gpr_replica_subscribe, gpr_replica_unsubscribe, @@ -236,14 +235,14 @@ int mca_gpr_replica_close(void) mca_gpr_base_module_t *mca_gpr_replica_init(bool *allow_multi_user_threads, bool *have_hidden_threads, int *priority) { - mca_gpr_registry_segment_t *seg; - mca_gpr_replica_key_t key; + int response; /* If we're the seed, then we want to be selected, so do all the setup and return the module */ if (ompi_process_info.seed) { + ompi_output(mca_gpr_base_output, "entered replica_init"); /* Return a module (choose an arbitrary, positive priority -- it's only relevant compared to other ns components). If @@ -265,19 +264,17 @@ mca_gpr_base_module_t *mca_gpr_replica_init(bool *allow_multi_user_threads, bool OBJ_CONSTRUCT(&mca_gpr_replica_head.freekeys, ompi_list_t); mca_gpr_replica_head.lastkey = 0; - /* define the "universe" segment key */ - key = gpr_replica_define_key("universe", NULL); - if (MCA_GPR_REPLICA_KEY_MAX == key) { - ompi_output(mca_gpr_base_output, "registry_init(error): could not create universe dictionary entry\n"); - exit(OMPI_ERROR); + /* define the "universe" segment */ + response = gpr_replica_define_segment("universe"); + if (0 > response) { /* got error code */ + ompi_output(mca_gpr_base_output, "registry_init(error): could not create universe segment\n"); + exit(response); } - /* initialize the "universe" segment */ - seg = OBJ_NEW(mca_gpr_registry_segment_t); - seg->segment = gpr_replica_get_key("universe", NULL); - ompi_list_append(&mca_gpr_replica_head.registry, &seg->item); + + ompi_output(mca_gpr_base_output, "issuing receive"); /* issue the non-blocking receive */ - mca_oob_recv_packed_nb(MCA_OOB_NAME_ANY, MCA_OOB_TAG_GPR, 0, mca_gpr_replica_recv, NULL); +/* mca_oob_recv_packed_nb(MCA_OOB_NAME_ANY, MCA_OOB_TAG_GPR, 0, mca_gpr_replica_recv, NULL); */ /* Return the module */ @@ -334,23 +331,7 @@ void mca_gpr_replica_recv(int status, ompi_process_name_t* sender, goto RETURN_ERROR; } - if (MCA_GPR_DEFINE_SEGMENT_CMD == command) { /* got a command to create a new segment */ - if (OMPI_SUCCESS != ompi_unpack_string(buffer, &segment)) { - goto RETURN_ERROR; - } - - response = (int32_t)ompi_registry.define_segment(segment); - - if (OMPI_SUCCESS != ompi_pack(answer, &command, 1, MCA_GPR_OOB_PACK_CMD)) { - goto RETURN_ERROR; - } - if (OMPI_SUCCESS != ompi_pack(answer, &response, 1, OMPI_INT16)) { - goto RETURN_ERROR; - } - if (0 > mca_oob_send_packed(sender, answer, tag, 0)) { - /* RHC -- not sure what to do if the return send fails */ - } - } else if (MCA_GPR_DELETE_SEGMENT_CMD == command) { /* got command to delete a segment */ + if (MCA_GPR_DELETE_SEGMENT_CMD == command) { /* got command to delete a segment */ if (OMPI_SUCCESS != ompi_unpack_string(buffer, &segment)) { goto RETURN_ERROR; } diff --git a/src/mca/gpr/replica/gpr_replica_internals.c b/src/mca/gpr/replica/gpr_replica_internals.c index a2a05a6c9b..a90d9ce486 100644 --- a/src/mca/gpr/replica/gpr_replica_internals.c +++ b/src/mca/gpr/replica/gpr_replica_internals.c @@ -30,6 +30,31 @@ /* * */ + +int gpr_replica_define_segment(char *segment) +{ + mca_gpr_registry_segment_t *seg; + mca_gpr_replica_key_t key; + int response; + + response = gpr_replica_define_key(segment, NULL); + if (0 > response) { /* got some kind of error code */ + return response; + } + + /* need to add the segment to the registry */ + key = gpr_replica_get_key(segment, NULL); + if (MCA_GPR_REPLICA_KEY_MAX == key) { /* couldn't retrieve it */ + return OMPI_ERROR; + } + seg = OBJ_NEW(mca_gpr_registry_segment_t); + seg->segment = key; + ompi_list_append(&mca_gpr_replica_head.registry, &seg->item); + + return OMPI_SUCCESS; +} + + mca_gpr_registry_segment_t *gpr_replica_find_seg(char *segment) { mca_gpr_keytable_t *ptr_seg; @@ -49,8 +74,10 @@ mca_gpr_registry_segment_t *gpr_replica_find_seg(char *segment) } } } + return NULL; /* segment in dictionary, but can't locate it */ } - return(NULL); /* couldn't find the specified segment */ + /* didn't find the dictionary entry */ + return NULL; } mca_gpr_keytable_t *gpr_replica_find_dict_entry(char *segment, char *token) diff --git a/src/mca/gpr/replica/gpr_replica_internals.h b/src/mca/gpr/replica/gpr_replica_internals.h index 929f9d6e1f..7f3d9b2fb3 100644 --- a/src/mca/gpr/replica/gpr_replica_internals.h +++ b/src/mca/gpr/replica/gpr_replica_internals.h @@ -72,3 +72,5 @@ int gpr_replica_empty_segment(mca_gpr_registry_segment_t *seg); ompi_list_t *gpr_replica_get_key_list(char *segment, char **tokens); bool gpr_replica_check_key_list(ompi_registry_mode_t mode, ompi_list_t *key_list, mca_gpr_registry_core_t *entry); + +int gpr_replica_define_segment(char *segment); diff --git a/src/mca/ns/ns.h b/src/mca/ns/ns.h index a640c5b765..77a3c52c7e 100644 --- a/src/mca/ns/ns.h +++ b/src/mca/ns/ns.h @@ -99,16 +99,6 @@ typedef struct ompi_process_name_t ompi_process_name_t; typedef uint8_t ompi_ns_cmd_bitmask_t; -/* - * define the actual name server message buffer - */ - -struct ompi_ns_msg_buffer_t { - ompi_ns_cmd_bitmask_t command; - int buflen; - uint8_t *buf; -}; -typedef struct ompi_ns_msg_buffer_t ompi_ns_msg_buffer_t; /* * Component functions - all MUST be provided! diff --git a/test/mca/gpr/Makefile.am b/test/mca/gpr/Makefile.am index e69445df0a..68be169637 100644 --- a/test/mca/gpr/Makefile.am +++ b/test/mca/gpr/Makefile.am @@ -7,22 +7,18 @@ include $(top_srcdir)/config/Makefile.options AM_CPPFLAGS = -I$(top_srcdir)/test/support -DOMPI_ENABLE_DEBUG_OVERRIDE=1 noinst_PROGRAMS = \ - test_gpr_replica + test_gpr_replica \ + test_gpr_proxy test_gpr_replica_SOURCES = test_gpr_replica.c test_gpr_replica_LDADD = \ - $(top_builddir)/src/class/ompi_object.lo \ - $(top_builddir)/src/util/malloc.lo \ - $(top_builddir)/src/util/output.lo \ - $(top_builddir)/src/util/argv.lo \ - $(top_builddir)/src/util/strncpy.lo \ - $(top_builddir)/src/mca/gpr/base/libmca_gpr_base.la \ - $(top_builddir)/src/mca/gpr/replica/libmca_gpr_replica.la \ - $(top_builddir)/src/mca/gpr/proxy/libmca_gpr_proxy.la \ $(top_builddir)/src/libmpi.la \ - $(top_builddir)/src/threads/mutex.lo \ - $(top_builddir)/src/threads/mutex_pthread.lo \ - $(top_builddir)/src/threads/mutex_spinlock.lo \ - $(top_builddir)/src/threads/mutex_spinwait.lo \ $(top_builddir)/test/support/libsupport.la test_gpr_replica_DEPENDENCIES = $(test_gpr_replica_LDADD) + + +test_gpr_proxy_SOURCES = test_gpr_proxy.c +test_gpr_proxy_LDADD = \ + $(top_builddir)/src/libmpi.la \ + $(top_builddir)/test/support/libsupport.la +test_gpr_proxy_DEPENDENCIES = $(test_gpr_proxy_LDADD) diff --git a/test/mca/gpr/test_gpr_replica.c b/test/mca/gpr/test_gpr_replica.c index 7bb3df5240..4e251b764b 100644 --- a/test/mca/gpr/test_gpr_replica.c +++ b/test/mca/gpr/test_gpr_replica.c @@ -35,15 +35,17 @@ int main(int argc, char **argv) ompi_list_t *test_list, *internal_tests; ompi_registry_index_value_t *ptr; ompi_registry_internal_test_results_t *ptri; - ompi_registry_object_t *test_buffer; + ompi_registry_object_t test_buffer; uint8_t *test_buf; ompi_registry_object_size_t input_size; ompi_registry_mode_t mode; + ompi_list_t *answer; + ompi_registry_value_t *ans; bool multi, hidden; - int i, j; + int i, j, response; bool success; char *tmp; - char name[30], *name2[30]; + char name[30], *name2[30], *name3[30]; int result, put_test; /* result from system call */ test_init("test_gpr_replica"); @@ -65,6 +67,7 @@ int main(int argc, char **argv) exit (1); } + fprintf(stderr, "opening gpr base\n"); /* open the GPR */ if (OMPI_SUCCESS == mca_gpr_base_open()) { fprintf(test_out, "GPR opened\n"); @@ -76,6 +79,7 @@ int main(int argc, char **argv) exit(1); } + fprintf(stderr, "selecting gpr module\n"); /* startup the GPR replica */ if (OMPI_SUCCESS != mca_gpr_base_select(&multi, &hidden)) { fprintf(test_out, "GPR replica could not start\n"); @@ -87,9 +91,10 @@ int main(int argc, char **argv) test_success(); } + fprintf(stderr, "testing define segment\n"); /* try to define a segment */ - if (OMPI_SUCCESS != ompi_registry.define_segment("test-segment")) { - fprintf(test_out, "GPR replica: could not define segment\n"); + if (OMPI_SUCCESS != (response = ompi_registry.define_segment("test-segment"))) { + fprintf(test_out, "GPR replica: could not define segment - error code %d\n", response); test_failure("test_gpr_replica define_segment failed"); test_finalize(); exit(1); @@ -98,6 +103,7 @@ int main(int argc, char **argv) test_success(); } + fprintf(stderr, "testing get index\n"); /* check index */ test_list = ompi_registry.index(NULL); if (0 == ompi_list_get_size(test_list)) { /* should have been something in dictionary */ @@ -115,7 +121,7 @@ int main(int argc, char **argv) test_success(); } - + fprintf(stderr, "testing internals\n"); /* check internals */ internal_tests = ompi_registry.test_internals(1); if (0 == ompi_list_get_size(internal_tests)) { /* should have been something in list */ @@ -134,21 +140,30 @@ int main(int argc, char **argv) test_success(); } + + fprintf(stderr, "testing put\n"); /* test the put function */ success = true; input_size = 10000; - test_buffer = (ompi_registry_object_t*)malloc(input_size); + test_buffer = (ompi_registry_object_t)malloc(input_size); test_buf = (uint8_t*)test_buffer; for (i=0; iobject_size != input_size) { + success = false; + } + } + } else { + mode = OMPI_REGISTRY_XAND; + answer = ompi_registry.get(mode, name, name3); + if (0 < ompi_list_get_size(answer)) { /* should not have gotten a result */ + success = false; + } + } + } + if (success) { + fprintf(test_out, "get test: success\n"); + test_success(); + } else { + fprintf(test_out, "get test failed\n"); + test_failure("test_gpr_replica get_test failed\n"); + test_finalize(); + exit(1); + } + /* check the universe segment - should have a key value of "1" */ fclose( test_out );