1
1

Move the initialization of the pls components into the selection --

not during the open.  This commit looks bigger than it really is --
most of this is just moved code, and added 2 bool's to indicate
whether the opened and available lists are valid for whether we
traverse them in the base close function or not. 

This commit was SVN r5120.
Этот коммит содержится в:
Jeff Squyres 2005-03-31 23:25:24 +00:00
родитель fa81e66db8
Коммит ba5dcfcb4a
4 изменённых файлов: 149 добавлений и 108 удалений

Просмотреть файл

@ -39,8 +39,12 @@ extern "C" {
int pls_output;
/** List of opened components */
ompi_list_t pls_opened;
/** Whether the list of opened components is valid */
bool pls_opened_valid;
/** Sorted list of available components (highest priority first) */
ompi_list_t pls_available;
/** Whether the list of available components is valid */
bool pls_available_valid;
} orte_pls_base_t;
/**

Просмотреть файл

@ -31,22 +31,28 @@ int orte_pls_base_close(void)
/* Finalize all available modules */
while (NULL !=
(item = ompi_list_remove_first(&orte_pls_base.pls_available))) {
orte_pls_base_cmp_t* cmp = (orte_pls_base_cmp_t*) item;
ompi_output(orte_pls_base.pls_output,
"orte:base:close: finalizing module %s",
cmp->component->pls_version.mca_component_name);
if (NULL != cmp->module->finalize) {
cmp->module->finalize();
if (orte_pls_base.pls_available_valid) {
while (NULL !=
(item = ompi_list_remove_first(&orte_pls_base.pls_available))) {
orte_pls_base_cmp_t* cmp = (orte_pls_base_cmp_t*) item;
ompi_output(orte_pls_base.pls_output,
"orte:base:close: finalizing module %s",
cmp->component->pls_version.mca_component_name);
if (NULL != cmp->module->finalize) {
cmp->module->finalize();
}
OBJ_RELEASE(cmp);
}
OBJ_RELEASE(cmp);
}
orte_pls_base.pls_available_valid = false;
/* Close all remaining open components */
mca_base_components_close(orte_pls_base.pls_output,
&orte_pls_base.pls_opened, NULL);
if (orte_pls_base.pls_opened_valid) {
mca_base_components_close(orte_pls_base.pls_output,
&orte_pls_base.pls_opened, NULL);
}
orte_pls_base.pls_opened_valid = false;
return ORTE_SUCCESS;
}

Просмотреть файл

@ -32,19 +32,10 @@
#include "mca/pls/base/static-components.h"
/*
* Local functions
*/
static void cmp_constructor(orte_pls_base_cmp_t *cmp);
static void cmp_destructor(orte_pls_base_cmp_t *cmp);
static int compare(ompi_list_item_t **a, ompi_list_item_t **b);
/*
* Global variables
*/
orte_pls_base_t orte_pls_base;
OBJ_CLASS_INSTANCE(orte_pls_base_cmp_t, ompi_list_item_t,
cmp_constructor, cmp_destructor);
/**
@ -53,12 +44,7 @@ OBJ_CLASS_INSTANCE(orte_pls_base_cmp_t, ompi_list_item_t,
*/
int orte_pls_base_open(void)
{
ompi_list_item_t *item;
mca_base_component_list_item_t *cli;
orte_pls_base_component_t *component;
orte_pls_base_module_t *module;
int param, priority, value;
orte_pls_base_cmp_t *cmp;
int param, value;
/* Debugging / verbose output */
@ -70,6 +56,9 @@ int orte_pls_base_open(void)
orte_pls_base.pls_output = -1;
}
orte_pls_base.pls_opened_valid = false;
orte_pls_base.pls_available_valid = false;
/* Open up all the components that we can find */
if (ORTE_SUCCESS !=
@ -77,84 +66,9 @@ int orte_pls_base_open(void)
&orte_pls_base.pls_opened)) {
return ORTE_ERROR;
}
orte_pls_base.pls_opened_valid = true;
/* Query all the opened components and see if they want to run */
OBJ_CONSTRUCT(&orte_pls_base.pls_available, ompi_list_t);
for (item = ompi_list_get_first(&orte_pls_base.pls_opened);
ompi_list_get_end(&orte_pls_base.pls_opened) != item;
item = ompi_list_get_next(item)) {
cli = (mca_base_component_list_item_t *) item;
component = (orte_pls_base_component_t *) cli->cli_component;
ompi_output(orte_pls_base.pls_output,
"orte:base:open: querying component %s",
component->pls_version.mca_component_name);
/* Call the component's init function and see if it wants to be
selected */
module = component->pls_init(&priority);
/* If we got a non-NULL module back, then the component wants
to be considered for selection */
if (NULL != module) {
ompi_output(orte_pls_base.pls_output,
"orte:base:open: component %s returns priority %d",
component->pls_version.mca_component_name,
priority);
cmp = OBJ_NEW(orte_pls_base_cmp_t);
cmp->component = component;
cmp->module = module;
cmp->priority = priority;
ompi_list_append(&orte_pls_base.pls_available, &cmp->super);
} else {
ompi_output(orte_pls_base.pls_output,
"orte:base:open: component %s does NOT want to be considered for selection",
component->pls_version.mca_component_name);
}
}
/* Sort the resulting available list in priority order */
ompi_list_sort(&orte_pls_base.pls_available, compare);
/* All done */
return ORTE_SUCCESS;
}
static void cmp_constructor(orte_pls_base_cmp_t *cmp)
{
cmp->component = NULL;
cmp->module = NULL;
cmp->priority = -1;
}
static void cmp_destructor(orte_pls_base_cmp_t *cmp)
{
cmp_constructor(cmp);
}
/*
* Need to make this an *opposite* compare (this is invoked by qsort)
* so that we get the highest priority first (i.e., so the sort is
* highest->lowest, not lowest->highest)
*/
static int compare(ompi_list_item_t **a, ompi_list_item_t **b)
{
orte_pls_base_cmp_t *aa = *((orte_pls_base_cmp_t **) a);
orte_pls_base_cmp_t *bb = *((orte_pls_base_cmp_t **) b);
if (bb->priority > aa->priority) {
return 1;
} else if (bb->priority == aa->priority) {
return 0;
} else {
return -1;
}
}

Просмотреть файл

@ -27,9 +27,22 @@
/*
* Local functions
*/
static orte_pls_base_module_t *select_preferred(char *name);
static orte_pls_base_module_t *select_any(void);
static int compare(ompi_list_item_t **a, ompi_list_item_t **b);
static void cmp_constructor(orte_pls_base_cmp_t *cmp);
static void cmp_destructor(orte_pls_base_cmp_t *cmp);
/*
* Global variables
*/
OBJ_CLASS_INSTANCE(orte_pls_base_cmp_t, ompi_list_item_t,
cmp_constructor, cmp_destructor);
/*
* Function for selecting one component from all those that are
@ -37,6 +50,13 @@ static orte_pls_base_module_t *select_any(void);
*/
orte_pls_base_module_t* orte_pls_base_select(char *preferred)
{
/* Construct the empty list */
OBJ_CONSTRUCT(&orte_pls_base.pls_available, ompi_list_t);
orte_pls_base.pls_available_valid = true;
/* Now - did we want a specific one? */
if (NULL != preferred) {
return select_preferred(preferred);
} else {
@ -48,22 +68,40 @@ orte_pls_base_module_t* orte_pls_base_select(char *preferred)
static orte_pls_base_module_t *select_preferred(char *name)
{
ompi_list_item_t *item;
orte_pls_base_cmp_t *cmp;
mca_base_component_list_item_t *cli;
orte_pls_base_component_t *component;
orte_pls_base_module_t *module;
int priority;
/* Look for a matching selected name */
ompi_output(orte_pls_base.pls_output,
"orte:base:select: looking for component %s", name);
for (item = ompi_list_get_first(&orte_pls_base.pls_available);
item != ompi_list_get_end(&orte_pls_base.pls_available);
for (item = ompi_list_get_first(&orte_pls_base.pls_opened);
item != ompi_list_get_end(&orte_pls_base.pls_opened);
item = ompi_list_get_next(item)) {
cmp = (orte_pls_base_cmp_t *) item;
cli = (mca_base_component_list_item_t *) item;
component = (orte_pls_base_component_t *) cli->cli_component;
/* If we found it, call the component's init function to see
if we get a module back */
if (0 == strcmp(name,
cmp->component->pls_version.mca_component_name)) {
component->pls_version.mca_component_name)) {
ompi_output(orte_pls_base.pls_output,
"orte:base:select: found module for compoent %s", name);
return cmp->module;
module = component->pls_init(&priority);
/* If we got a non-NULL module back, then the component wants
to be considered for selection */
if (NULL != module) {
ompi_output(orte_pls_base.pls_output,
"orte:base:open: component %s returns priority %d",
component->pls_version.mca_component_name,
priority);
return module;
}
}
}
@ -78,8 +116,50 @@ static orte_pls_base_module_t *select_preferred(char *name)
static orte_pls_base_module_t *select_any(void)
{
ompi_list_item_t *item;
mca_base_component_list_item_t *cli;
orte_pls_base_component_t *component;
orte_pls_base_module_t *module;
int priority;
orte_pls_base_cmp_t *cmp;
/* Query all the opened components and see if they want to run */
for (item = ompi_list_get_first(&orte_pls_base.pls_opened);
ompi_list_get_end(&orte_pls_base.pls_opened) != item;
item = ompi_list_get_next(item)) {
cli = (mca_base_component_list_item_t *) item;
component = (orte_pls_base_component_t *) cli->cli_component;
ompi_output(orte_pls_base.pls_output,
"orte:base:open: querying component %s",
component->pls_version.mca_component_name);
/* Call the component's init function and see if it wants to be
selected */
module = component->pls_init(&priority);
/* If we got a non-NULL module back, then the component wants
to be considered for selection */
if (NULL != module) {
ompi_output(orte_pls_base.pls_output,
"orte:base:open: component %s returns priority %d",
component->pls_version.mca_component_name,
priority);
cmp = OBJ_NEW(orte_pls_base_cmp_t);
cmp->component = component;
cmp->module = module;
cmp->priority = priority;
ompi_list_append(&orte_pls_base.pls_available, &cmp->super);
} else {
ompi_output(orte_pls_base.pls_output,
"orte:base:open: component %s does NOT want to be considered for selection",
component->pls_version.mca_component_name);
}
}
/* If the list is empty, return NULL */
if (ompi_list_is_empty(&orte_pls_base.pls_available)) {
@ -88,6 +168,10 @@ static orte_pls_base_module_t *select_any(void)
return NULL;
}
/* Sort the resulting available list in priority order */
ompi_list_sort(&orte_pls_base.pls_available, compare);
/* Otherwise, return the first item (it's already sorted in
priority order) */
@ -98,3 +182,36 @@ static orte_pls_base_module_t *select_any(void)
cmp->component->pls_version.mca_component_name);
return cmp->module;
}
/*
* Need to make this an *opposite* compare (this is invoked by qsort)
* so that we get the highest priority first (i.e., so the sort is
* highest->lowest, not lowest->highest)
*/
static int compare(ompi_list_item_t **a, ompi_list_item_t **b)
{
orte_pls_base_cmp_t *aa = *((orte_pls_base_cmp_t **) a);
orte_pls_base_cmp_t *bb = *((orte_pls_base_cmp_t **) b);
if (bb->priority > aa->priority) {
return 1;
} else if (bb->priority == aa->priority) {
return 0;
} else {
return -1;
}
}
static void cmp_constructor(orte_pls_base_cmp_t *cmp)
{
cmp->component = NULL;
cmp->module = NULL;
cmp->priority = -1;
}
static void cmp_destructor(orte_pls_base_cmp_t *cmp)
{
cmp_constructor(cmp);
}