From 15a0a8e53736e1e7b7f1f9f02b4f7ae765f3d73c Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Fri, 30 Jan 2004 03:54:52 +0000 Subject: [PATCH] - Remove kruft from pml.h, move some into pml/base/base.h (pml/pml.h is strictly public-only) - Add selection routine for pml base This commit was SVN r605. --- src/mca/mpi/pml/base/Makefile.am | 3 +- src/mca/mpi/pml/base/base.h | 20 ++-- src/mca/mpi/pml/base/pml_base_close.c | 2 +- src/mca/mpi/pml/base/pml_base_open.c | 3 +- src/mca/mpi/pml/base/pml_base_select.c | 136 +++++++++++++++++++++++++ src/mca/mpi/pml/pml.h | 23 ----- 6 files changed, 147 insertions(+), 40 deletions(-) create mode 100644 src/mca/mpi/pml/base/pml_base_select.c diff --git a/src/mca/mpi/pml/base/Makefile.am b/src/mca/mpi/pml/base/Makefile.am index cf87c53142..ad9b5f0d3d 100644 --- a/src/mca/mpi/pml/base/Makefile.am +++ b/src/mca/mpi/pml/base/Makefile.am @@ -16,7 +16,8 @@ libmca_mpi_pml_base_la_SOURCES = \ $(headers) \ pml_base_close.c \ pml_base_request.c \ - pml_base_open.c + pml_base_open.c \ + pml_base_select.c # Conditionally install the header files diff --git a/src/mca/mpi/pml/base/base.h b/src/mca/mpi/pml/base/base.h index d9a320d2d6..0727fc6648 100644 --- a/src/mca/mpi/pml/base/base.h +++ b/src/mca/mpi/pml/base/base.h @@ -18,26 +18,20 @@ #if defined(c_plusplus) || defined(__cplusplus) extern "C" { #endif + int mca_pml_base_open(void); + int mca_pml_base_select(mca_pml_t *selected); int mca_pml_base_close(void); - int mca_pml_base_open(lam_cmd_line_t *cmd); - int mca_pml_base_query(void); - int mca_pml_base_init(void); #if defined(c_plusplus) || defined(__cplusplus) } #endif -/* - * Public variables - */ - -extern lam_list_t *mca_pml_base_opened; -extern lam_list_t *mca_pml_base_available; /* - * Global instance of array of pointers to mca_base_module_t. Will - * effectively be filled in by configure. + * Globals */ - -extern const mca_base_module_t **mca_pml_base_modules; +extern int mca_pml_base_output; +extern lam_list_t mca_pml_base_modules_available; +extern mca_pml_base_module_t mca_pml_base_selected_module; +extern mca_pml_t mca_pml; #endif /* MCA_PML_BASE_H */ diff --git a/src/mca/mpi/pml/base/pml_base_close.c b/src/mca/mpi/pml/base/pml_base_close.c index c5a0249b3f..c3bde4fad0 100644 --- a/src/mca/mpi/pml/base/pml_base_close.c +++ b/src/mca/mpi/pml/base/pml_base_close.c @@ -5,12 +5,12 @@ #include "lam_config.h" #include -#include #include "lam/constants.h" #include "mca/mca.h" #include "mca/lam/base/base.h" #include "mca/mpi/pml/pml.h" +#include "mca/mpi/pml/base/base.h" int mca_pml_base_close(void) diff --git a/src/mca/mpi/pml/base/pml_base_open.c b/src/mca/mpi/pml/base/pml_base_open.c index 03f96f3b3c..144e93de59 100644 --- a/src/mca/mpi/pml/base/pml_base_open.c +++ b/src/mca/mpi/pml/base/pml_base_open.c @@ -5,12 +5,11 @@ #include "lam_config.h" #include -#include -#include #include "mca/mca.h" #include "mca/lam/base/base.h" #include "mca/mpi/pml/pml.h" +#include "mca/mpi/pml/base/base.h" /* diff --git a/src/mca/mpi/pml/base/pml_base_select.c b/src/mca/mpi/pml/base/pml_base_select.c new file mode 100644 index 0000000000..efb9ab20ad --- /dev/null +++ b/src/mca/mpi/pml/base/pml_base_select.c @@ -0,0 +1,136 @@ +/* + * $HEADER$ + */ + +#include "lam_config.h" + +#include "lam/lfc/list.h" +#include "lam/runtime/runtime.h" +#include "mca/mca.h" +#include "mca/lam/base/base.h" +#include "mca/mpi/pml/pml.h" +#include "mca/mpi/pml/base/base.h" + + +typedef struct opened_module_t { + mca_pml_base_module_t *om_module; + mca_pml_t *om_actions; +} opened_module_t; + +/** + * Function for selecting one module from all those that are + * available. + * + * Call the init function on all available modules and get their + * priorities. Select the module with the highest priority. All + * other modules will be closed and unloaded. The selected module + * will have its initialization function invoked, and all of its + * function pointers saved. + */ +int mca_pml_base_select(mca_pml_t *selected) +{ + int priority, best_priority; + int bogus1, bogus2; + lam_list_item_t *item; + mca_base_module_list_item_t *mli; + mca_pml_base_module_t *module, *best_module; + mca_pml_t *actions; + extern lam_list_t mca_pml_base_modules_available; + lam_list_t opened; + opened_module_t *om; + + /* Traverse the list of available modules; call their init + functions. */ + + best_priority = -1; + best_module = NULL; + lam_list_init(&opened); + for (item = lam_list_get_first(&mca_pml_base_modules_available); + lam_list_get_end(&mca_pml_base_modules_available) != item; + item = lam_list_get_next(item)) { + mli = (mca_base_module_list_item_t *) item; + module = (mca_pml_base_module_t *) mli->mli_module; + + lam_output_verbose(10, mca_pml_base_output, + "select: initializing %s module %s", + module->pmlm_version.mca_type_name, + module->pmlm_version.mca_module_name); + if (NULL == module->pmlm_init) { + lam_output_verbose(10, mca_pml_base_output, + "select: no init function; ignoring module"); + } else { + /* JMS Need to change this to take bools about threads */ + actions = module->pmlm_init(&priority, &bogus1, &bogus2); + if (NULL == actions) { + lam_output_verbose(10, mca_pml_base_output, + "select: init returned failure"); + } else { + lam_output_verbose(10, mca_pml_base_output, + "select: init returned priority %d", priority); + if (priority > best_priority) { + best_priority = priority; + best_module = module; + } + + om = LAM_MALLOC(sizeof(opened_module_t)); + if (NULL == om) { + return LAM_ERR_OUT_OF_RESOURCE; + } + lam_list_item_init((lam_list_item_t *) om); + om->om_module = module; + om->om_actions = actions; + lam_list_append(&opened, (lam_list_item_t*) om); + } + } + } + + /* Finished querying all modules. Check for the bozo case. */ + + if (NULL == best_module) { + /* JMS Replace with show_help */ + lam_abort(1, "No pml module available. This shouldn't happen."); + } + + /* Finalize all non-selected modules */ + + for (item = lam_list_get_first(&opened); + lam_list_get_end(&opened) != item; + item = lam_list_get_next(item)) { + om = (opened_module_t *) item; + if (om->om_module != best_module) { + + /* Finalize */ + + if (NULL != om->om_actions->pml_fini) { + + /* Blatently ignore the return code (what would we do to + recover, anyway? This module is going away, so errors + don't matter anymore) */ + + om->om_actions->pml_fini(); + lam_output_verbose(10, mca_pml_base_output, + "select: module %s not selected / finalized", + module->pmlm_version.mca_module_name); + } + } + } + + /* This base function closes, unloads, and removes from the + available list all unselected modules. The available list will + contain only the selected module. */ + + mca_base_modules_close(mca_pml_base_output, &mca_pml_base_modules_available, + (mca_base_module_t *) best_module); + + /* Save the winner */ + + mca_pml_base_selected_module = *best_module; + *selected = *actions; + lam_output_verbose(10, mca_pml_base_output, + "select: module %s selected", + module->pmlm_version.mca_module_name); + + /* All done */ + + return LAM_SUCCESS; +} diff --git a/src/mca/mpi/pml/pml.h b/src/mca/mpi/pml/pml.h index 3a1873489a..065ab5a1b2 100644 --- a/src/mca/mpi/pml/pml.h +++ b/src/mca/mpi/pml/pml.h @@ -166,27 +166,4 @@ typedef mca_pml_1_0_0_t mca_pml_t; /* pml v1.0 */ \ "pml", 1, 0, 0 - -/* - * Global functions for MCA: overall PML open and close - */ - -#if defined(c_plusplus) || defined(__cplusplus) -extern "C" { -#endif - int mca_pml_base_open(void); - int mca_pml_base_select(void); - int mca_pml_base_close(void); -#if defined(c_plusplus) || defined(__cplusplus) -} -#endif - -/* - * Globals - */ -extern int mca_pml_base_output; -extern lam_list_t mca_pml_base_modules_available; -extern mca_pml_base_module_t mca_pml_base_selected_module; -extern mca_pml_t mca_pml; - #endif /* MCA_PML_H */