2004-08-02 04:24:22 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-08-02 04:24:22 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "class/ompi_list.h"
|
|
|
|
#include "util/strncpy.h"
|
|
|
|
#include "util/argv.h"
|
|
|
|
#include "util/output.h"
|
|
|
|
#include "mca/mca.h"
|
|
|
|
#include "mca/base/base.h"
|
2004-11-05 10:52:30 +03:00
|
|
|
#include "include/constants.h"
|
2004-08-02 04:24:22 +04:00
|
|
|
|
|
|
|
struct component_name_t {
|
|
|
|
ompi_list_item_t super;
|
|
|
|
|
|
|
|
char mn_name[MCA_BASE_MAX_COMPONENT_NAME_LEN];
|
|
|
|
};
|
|
|
|
typedef struct component_name_t component_name_t;
|
|
|
|
|
|
|
|
|
2004-10-15 14:54:39 +04:00
|
|
|
/*
|
|
|
|
* Local variables
|
|
|
|
*/
|
|
|
|
static bool show_errors = false;
|
|
|
|
|
|
|
|
|
2004-08-02 04:24:22 +04:00
|
|
|
/*
|
|
|
|
* Local functions
|
|
|
|
*/
|
|
|
|
static int open_components(const char *type_name, int output_id,
|
|
|
|
ompi_list_t *components_found,
|
|
|
|
ompi_list_t *components_available,
|
|
|
|
char **requested_component_names);
|
|
|
|
static int parse_requested(int mca_param, char ***requested_component_names);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function for finding and opening either all MCA components, or the
|
|
|
|
* one that was specifically requested via a MCA parameter.
|
|
|
|
*/
|
|
|
|
int mca_base_components_open(const char *type_name, int output_id,
|
|
|
|
const mca_base_component_t **static_components,
|
|
|
|
ompi_list_t *components_available)
|
|
|
|
{
|
2004-10-15 14:54:39 +04:00
|
|
|
int ret, param;
|
2004-08-02 04:24:22 +04:00
|
|
|
ompi_list_item_t *item;
|
|
|
|
ompi_list_t components_found;
|
|
|
|
char **requested_component_names;
|
|
|
|
int param_verbose = -1;
|
|
|
|
int param_type = -1;
|
|
|
|
int verbose_level;
|
|
|
|
|
|
|
|
/* Register MCA parameters */
|
|
|
|
|
|
|
|
param_verbose = mca_base_param_register_int(type_name, "base",
|
|
|
|
"verbose", NULL, 0);
|
|
|
|
param_type = mca_base_param_register_string(type_name, "base", NULL,
|
|
|
|
type_name, NULL);
|
|
|
|
|
2004-10-15 14:54:39 +04:00
|
|
|
param = mca_base_param_find("base", NULL, "component_show_load_errors");
|
|
|
|
mca_base_param_lookup_int(param, &ret);
|
|
|
|
show_errors = (0 != ret) ? true : false;
|
|
|
|
|
2004-08-02 04:24:22 +04:00
|
|
|
/* Setup verbosity for this MCA type */
|
|
|
|
|
|
|
|
mca_base_param_lookup_int(param_verbose, &verbose_level);
|
|
|
|
if (output_id != 0) {
|
|
|
|
ompi_output_set_verbosity(output_id, verbose_level);
|
|
|
|
}
|
2004-10-15 14:54:39 +04:00
|
|
|
ompi_output_verbose(10, output_id,
|
|
|
|
"mca: base: components_open: Looking for components");
|
2004-08-02 04:24:22 +04:00
|
|
|
|
|
|
|
/* Find and load all available components */
|
|
|
|
|
|
|
|
if (OMPI_SUCCESS !=
|
|
|
|
mca_base_component_find(NULL, type_name, static_components,
|
|
|
|
&components_found)) {
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if one or more specific components were requested */
|
|
|
|
|
|
|
|
ret = parse_requested(param_type, &requested_component_names);
|
|
|
|
if (OMPI_SUCCESS == ret) {
|
|
|
|
ret = open_components(type_name, output_id, &components_found,
|
|
|
|
components_available,
|
|
|
|
requested_component_names);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free resources */
|
|
|
|
|
|
|
|
for (item = ompi_list_remove_first(&components_found); NULL != item;
|
|
|
|
item = ompi_list_remove_first(&components_found)) {
|
|
|
|
OBJ_RELEASE(item);
|
|
|
|
}
|
|
|
|
if (NULL != requested_component_names) {
|
|
|
|
ompi_argv_free(requested_component_names);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All done */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int parse_requested(int mca_param, char ***requested_component_names)
|
|
|
|
{
|
|
|
|
char *requested;
|
|
|
|
|
|
|
|
*requested_component_names = NULL;
|
|
|
|
|
|
|
|
/* See if the user requested anything */
|
|
|
|
|
|
|
|
if (OMPI_ERROR == mca_base_param_lookup_string(mca_param, &requested)) {
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
if (NULL == requested) {
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
2004-08-31 13:34:12 +04:00
|
|
|
*requested_component_names = ompi_argv_split(requested, ',');
|
2004-08-02 04:24:22 +04:00
|
|
|
|
|
|
|
/* All done */
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Traverse the entire list of found components (a list of
|
|
|
|
* mca_base_component_t instances). If the requested_component_names
|
|
|
|
* array is empty, or the name of each component in the list of found
|
|
|
|
* components is in the requested_components_array, try to open it.
|
|
|
|
* If it opens, add it to the components_available list.
|
|
|
|
*/
|
|
|
|
static int open_components(const char *type_name, int output_id,
|
|
|
|
ompi_list_t *components_found,
|
|
|
|
ompi_list_t *components_available,
|
|
|
|
char **requested_component_names)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ompi_list_item_t *item;
|
|
|
|
const mca_base_component_t *component;
|
|
|
|
mca_base_component_list_item_t *cli;
|
|
|
|
bool acceptable;
|
|
|
|
bool called_open;
|
|
|
|
bool opened;
|
|
|
|
|
|
|
|
/* Announce */
|
|
|
|
|
|
|
|
if (NULL == requested_component_names) {
|
|
|
|
ompi_output_verbose(10, output_id,
|
2004-10-15 14:54:39 +04:00
|
|
|
"mca: base: components_open: "
|
2004-08-20 05:12:50 +04:00
|
|
|
"looking for any %s components", type_name);
|
2004-08-02 04:24:22 +04:00
|
|
|
} else {
|
|
|
|
ompi_output_verbose(10, output_id,
|
2004-10-15 14:54:39 +04:00
|
|
|
"mca: base: components_open: looking for specific %s components:",
|
2004-08-02 04:24:22 +04:00
|
|
|
type_name);
|
|
|
|
for (i = 0; NULL != requested_component_names[i]; ++i) {
|
2004-10-15 14:54:39 +04:00
|
|
|
ompi_output_verbose(10, output_id, "mca: base: components_open: %s",
|
2004-08-02 04:24:22 +04:00
|
|
|
requested_component_names[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Traverse the list of found components */
|
|
|
|
|
|
|
|
OBJ_CONSTRUCT(components_available, ompi_list_t);
|
|
|
|
for (item = ompi_list_get_first(components_found);
|
|
|
|
ompi_list_get_end(components_found) != item;
|
|
|
|
item = ompi_list_get_next(item)) {
|
|
|
|
cli = (mca_base_component_list_item_t *) item;
|
|
|
|
component = cli->cli_component;
|
|
|
|
|
|
|
|
/* Do we need to check for specific components? */
|
|
|
|
|
|
|
|
if (NULL != requested_component_names) {
|
|
|
|
acceptable = false;
|
|
|
|
for (i = 0; NULL != requested_component_names[i]; ++i) {
|
|
|
|
if (0 == strcmp(requested_component_names[i],
|
|
|
|
component->mca_component_name)) {
|
|
|
|
acceptable = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
acceptable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this is an acceptable component, try to open it */
|
|
|
|
|
|
|
|
if (acceptable) {
|
|
|
|
opened = called_open = false;
|
2004-08-20 05:12:50 +04:00
|
|
|
ompi_output_verbose(10, output_id,
|
2004-10-15 14:54:39 +04:00
|
|
|
"mca: base: components_open: found loaded component %s",
|
2004-08-02 04:24:22 +04:00
|
|
|
component->mca_component_name);
|
|
|
|
|
|
|
|
if (NULL == component->mca_open_component) {
|
|
|
|
opened = true;
|
|
|
|
ompi_output_verbose(10, output_id,
|
2004-10-15 14:54:39 +04:00
|
|
|
"mca: base: components_open: "
|
2004-08-20 05:12:50 +04:00
|
|
|
"component %s has no open function",
|
2004-08-02 04:24:22 +04:00
|
|
|
component->mca_component_name);
|
|
|
|
} else {
|
|
|
|
called_open = true;
|
|
|
|
if (MCA_SUCCESS == component->mca_open_component()) {
|
|
|
|
opened = true;
|
|
|
|
ompi_output_verbose(10, output_id,
|
2004-10-15 14:54:39 +04:00
|
|
|
"mca: base: components_open: "
|
2004-08-20 05:12:50 +04:00
|
|
|
"component %s open function successful",
|
2004-08-02 04:24:22 +04:00
|
|
|
component->mca_component_name);
|
|
|
|
} else {
|
2004-10-15 14:54:39 +04:00
|
|
|
/* We may end up displaying this twice, but it may go to
|
|
|
|
separate streams. So better to be redundant than to
|
|
|
|
not display the error in the stream where it was
|
|
|
|
expected. */
|
|
|
|
|
|
|
|
if (show_errors) {
|
|
|
|
ompi_output(0, "mca: base: components_open: "
|
|
|
|
"component %s open function failed",
|
|
|
|
component->mca_component_name);
|
|
|
|
}
|
|
|
|
ompi_output_verbose(10, output_id,
|
|
|
|
"mca: base: components_open: "
|
|
|
|
"component %s open function failed",
|
|
|
|
component->mca_component_name);
|
2004-08-02 04:24:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it didn't open, close it out and get rid of it */
|
|
|
|
|
|
|
|
if (!opened) {
|
|
|
|
if (called_open) {
|
|
|
|
if (NULL != component->mca_close_component) {
|
|
|
|
component->mca_close_component();
|
|
|
|
}
|
|
|
|
ompi_output_verbose(10, output_id,
|
2004-10-15 14:54:39 +04:00
|
|
|
"mca: base: components_open: component %s closed",
|
2004-08-02 04:24:22 +04:00
|
|
|
component->mca_component_name);
|
|
|
|
called_open = false;
|
|
|
|
}
|
|
|
|
mca_base_component_repository_release(component);
|
|
|
|
ompi_output_verbose(10, output_id,
|
2004-10-15 14:54:39 +04:00
|
|
|
"mca: base: components_open: component %s unloaded",
|
2004-08-02 04:24:22 +04:00
|
|
|
component->mca_component_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it did open, register its "priority" MCA parameter (if it
|
|
|
|
doesn't already have one) and save it in the opened_components
|
|
|
|
list */
|
|
|
|
|
|
|
|
else {
|
|
|
|
if (OMPI_ERROR == mca_base_param_find(type_name,
|
|
|
|
component->mca_component_name,
|
|
|
|
"priority")) {
|
|
|
|
mca_base_param_register_int(type_name,
|
|
|
|
component->mca_component_name,
|
|
|
|
"priority", NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
cli = OBJ_NEW(mca_base_component_list_item_t);
|
|
|
|
if (NULL == cli) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
cli->cli_component = component;
|
|
|
|
ompi_list_append(components_available, (ompi_list_item_t *) cli);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All done */
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|