2004-01-18 02:07:40 +03:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2004-03-19 00:35:28 +03:00
|
|
|
#include "include/constants.h"
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "class/ompi_value_array.h"
|
2004-06-29 04:02:25 +04:00
|
|
|
#include "class/ompi_hash_table.h"
|
|
|
|
#include "attribute/attribute.h"
|
2004-01-18 02:07:40 +03:00
|
|
|
#include "mca/mca.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "mca/base/mca_base_param.h"
|
2004-07-14 00:24:26 +04:00
|
|
|
#include "mca/base/mca_base_param_internal.h"
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
|
2004-01-30 01:10:33 +03:00
|
|
|
/*
|
|
|
|
* Public variables
|
|
|
|
*
|
|
|
|
* This variable is public, but not advertised in mca_base_param.h.
|
2004-07-14 00:24:26 +04:00
|
|
|
* It's only public so that ompi_info can see it. The relevant component
|
2004-06-07 19:33:53 +04:00
|
|
|
* in ompi_info will provide an extern to see this variable.
|
2004-01-30 01:10:33 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_value_array_t mca_base_params;
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* local variables
|
|
|
|
*/
|
2004-06-29 04:02:25 +04:00
|
|
|
static char *mca_prefix = "OMPI_MCA_";
|
2004-01-18 02:07:40 +03:00
|
|
|
static bool initialized = false;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* local functions
|
|
|
|
*/
|
2004-07-14 00:24:26 +04:00
|
|
|
static int param_register(const char *type_name, const char *component_name,
|
2004-01-21 02:23:47 +03:00
|
|
|
const char *param_name,
|
2004-01-18 02:07:40 +03:00
|
|
|
const char *mca_param_name,
|
|
|
|
mca_base_param_type_t type,
|
|
|
|
mca_base_param_storage_t *default_value);
|
2004-06-29 04:02:25 +04:00
|
|
|
static bool param_lookup(int index, mca_base_param_storage_t *storage,
|
|
|
|
ompi_hash_table_t *attrs);
|
2004-07-14 00:24:26 +04:00
|
|
|
static void param_constructor(mca_base_param_t *p);
|
|
|
|
static void param_destructor(mca_base_param_t *p);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make the class instance for mca_base_param_t
|
|
|
|
*/
|
|
|
|
OBJ_CLASS_INSTANCE(mca_base_param_t, ompi_object_t,
|
|
|
|
param_constructor, param_destructor);
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
|
2004-04-22 20:59:56 +04:00
|
|
|
/*
|
|
|
|
* Register an integer MCA parameter
|
2004-01-18 02:07:40 +03:00
|
|
|
*/
|
2004-06-29 04:02:25 +04:00
|
|
|
int mca_base_param_register_int(const char *type_name,
|
2004-07-14 00:24:26 +04:00
|
|
|
const char *component_name,
|
2004-01-18 02:07:40 +03:00
|
|
|
const char *param_name,
|
|
|
|
const char *mca_param_name,
|
|
|
|
int default_value)
|
|
|
|
{
|
|
|
|
mca_base_param_storage_t storage;
|
|
|
|
|
|
|
|
storage.intval = default_value;
|
2004-07-14 00:24:26 +04:00
|
|
|
return param_register(type_name, component_name, param_name, mca_param_name,
|
2004-01-18 02:07:40 +03:00
|
|
|
MCA_BASE_PARAM_TYPE_INT, &storage);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-22 20:59:56 +04:00
|
|
|
/*
|
2004-01-18 02:07:40 +03:00
|
|
|
* Register a string MCA parameter.
|
|
|
|
*/
|
|
|
|
int mca_base_param_register_string(const char *type_name,
|
2004-07-14 00:24:26 +04:00
|
|
|
const char *component_name,
|
2004-01-18 02:07:40 +03:00
|
|
|
const char *param_name,
|
|
|
|
const char *mca_param_name,
|
|
|
|
const char *default_value)
|
|
|
|
{
|
|
|
|
mca_base_param_storage_t storage;
|
2004-06-29 04:02:25 +04:00
|
|
|
if (NULL != default_value) {
|
2004-01-22 03:37:58 +03:00
|
|
|
storage.stringval = (char *) default_value;
|
2004-06-29 04:02:25 +04:00
|
|
|
} else {
|
2004-01-21 02:23:47 +03:00
|
|
|
storage.stringval = NULL;
|
2004-06-29 04:02:25 +04:00
|
|
|
}
|
2004-07-14 00:24:26 +04:00
|
|
|
return param_register(type_name, component_name, param_name, mca_param_name,
|
2004-01-18 02:07:40 +03:00
|
|
|
MCA_BASE_PARAM_TYPE_STRING, &storage);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-29 04:02:25 +04:00
|
|
|
/*
|
|
|
|
* Associate a keyval with a parameter index
|
|
|
|
*/
|
|
|
|
int mca_base_param_kv_associate(int index, int keyval)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
mca_base_param_t *array;
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = ompi_value_array_get_size(&mca_base_params);
|
|
|
|
if (0 > index || index > len) {
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have a valid entry (remember that we never delete MCA
|
|
|
|
parameters, so if the index is >0 and <len, it must be good), so
|
|
|
|
save the keyval */
|
|
|
|
|
|
|
|
array = OMPI_VALUE_ARRAY_GET_BASE(&mca_base_params, mca_base_param_t);
|
|
|
|
array[index].mbp_keyval = keyval;
|
|
|
|
|
|
|
|
/* All done */
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-04-22 20:59:56 +04:00
|
|
|
/*
|
2004-01-18 02:07:40 +03:00
|
|
|
* Look up an integer MCA parameter.
|
|
|
|
*/
|
|
|
|
int mca_base_param_lookup_int(int index, int *value)
|
|
|
|
{
|
|
|
|
mca_base_param_storage_t storage;
|
|
|
|
|
2004-06-29 04:02:25 +04:00
|
|
|
if (param_lookup(index, &storage, NULL)) {
|
|
|
|
*value = storage.intval;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up an integer MCA parameter, including in attributes
|
|
|
|
*/
|
|
|
|
int mca_base_param_kv_lookup_int(int index, ompi_hash_table_t *attrs,
|
|
|
|
int *value)
|
|
|
|
{
|
|
|
|
mca_base_param_storage_t storage;
|
|
|
|
|
|
|
|
if (param_lookup(index, &storage, attrs)) {
|
2004-01-18 02:07:40 +03:00
|
|
|
*value = storage.intval;
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERROR;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-22 20:59:56 +04:00
|
|
|
/*
|
2004-01-18 02:07:40 +03:00
|
|
|
* Look up a string MCA parameter.
|
|
|
|
*/
|
|
|
|
int mca_base_param_lookup_string(int index, char **value)
|
|
|
|
{
|
|
|
|
mca_base_param_storage_t storage;
|
|
|
|
|
2004-06-29 04:02:25 +04:00
|
|
|
if (param_lookup(index, &storage, NULL)) {
|
|
|
|
*value = storage.stringval;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up a string MCA parameter, including in attributes.
|
|
|
|
*/
|
|
|
|
int mca_base_param_kv_lookup_string(int index, ompi_hash_table_t *attrs,
|
|
|
|
char **value)
|
|
|
|
{
|
|
|
|
mca_base_param_storage_t storage;
|
|
|
|
|
|
|
|
if (param_lookup(index, &storage, attrs)) {
|
2004-01-18 02:07:40 +03:00
|
|
|
*value = storage.stringval;
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERROR;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-22 20:59:56 +04:00
|
|
|
/*
|
2004-01-18 02:07:40 +03:00
|
|
|
* Find the index for an MCA parameter based on its names.
|
|
|
|
*/
|
2004-07-14 00:24:26 +04:00
|
|
|
int mca_base_param_find(const char *type_name, const char *component_name,
|
2004-01-18 02:07:40 +03:00
|
|
|
const char *param_name)
|
|
|
|
{
|
|
|
|
size_t i, size;
|
2004-02-11 01:12:47 +03:00
|
|
|
mca_base_param_t *array;
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
/* Check for bozo cases */
|
|
|
|
|
2004-06-29 04:02:25 +04:00
|
|
|
if (!initialized) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERROR;
|
2004-06-29 04:02:25 +04:00
|
|
|
}
|
2004-07-14 00:24:26 +04:00
|
|
|
if (NULL == type_name) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERROR;
|
2004-06-29 04:02:25 +04:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
/* Loop through looking for a parameter of a given
|
2004-07-14 00:24:26 +04:00
|
|
|
type/component/param */
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
size = ompi_value_array_get_size(&mca_base_params);
|
|
|
|
array = OMPI_VALUE_ARRAY_GET_BASE(&mca_base_params, mca_base_param_t);
|
2004-01-18 02:07:40 +03:00
|
|
|
for (i = 0; i < size; ++i) {
|
2004-02-11 01:12:47 +03:00
|
|
|
if (0 == strcmp(type_name, array[i].mbp_type_name) &&
|
2004-07-14 00:24:26 +04:00
|
|
|
((NULL == component_name && NULL == array[i].mbp_component_name) ||
|
|
|
|
(NULL != component_name && NULL != array[i].mbp_component_name &&
|
|
|
|
0 == strcmp(component_name, array[i].mbp_component_name))) &&
|
|
|
|
((NULL == param_name && NULL == array[i].mbp_param_name) ||
|
|
|
|
(NULL != param_name && NULL != array[i].mbp_param_name &&
|
|
|
|
0 == strcmp(param_name, array[i].mbp_param_name)))) {
|
2004-01-18 02:07:40 +03:00
|
|
|
return i;
|
2004-06-29 04:02:25 +04:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Didn't find it */
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERROR;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-22 20:59:56 +04:00
|
|
|
/*
|
2004-01-18 02:07:40 +03:00
|
|
|
* Shut down the MCA parameter system (normally only invoked by the
|
|
|
|
* MCA framework itself).
|
|
|
|
*/
|
|
|
|
int mca_base_param_finalize(void)
|
|
|
|
{
|
2004-02-11 01:12:47 +03:00
|
|
|
mca_base_param_t *array;
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
if (initialized) {
|
2004-07-14 00:24:26 +04:00
|
|
|
|
|
|
|
/* This is slow, but effective :-) */
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
array = OMPI_VALUE_ARRAY_GET_BASE(&mca_base_params, mca_base_param_t);
|
|
|
|
while (0 < ompi_value_array_get_size(&mca_base_params)) {
|
2004-07-14 00:24:26 +04:00
|
|
|
OBJ_DESTRUCT(&array[0]);
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_value_array_remove_item(&mca_base_params, 0);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-02-11 01:12:47 +03:00
|
|
|
OBJ_DESTRUCT(&mca_base_params);
|
2004-01-18 02:07:40 +03:00
|
|
|
initialized = false;
|
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
static int param_register(const char *type_name, const char *component_name,
|
2004-01-18 02:07:40 +03:00
|
|
|
const char *param_name, const char *mca_param_name,
|
|
|
|
mca_base_param_type_t type,
|
|
|
|
mca_base_param_storage_t *default_value)
|
|
|
|
{
|
2004-07-14 00:24:26 +04:00
|
|
|
int ret;
|
2004-01-18 02:07:40 +03:00
|
|
|
size_t i, len;
|
2004-02-11 01:12:47 +03:00
|
|
|
mca_base_param_t param, *array;
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
/* Initialize the array if it has never been initialized */
|
|
|
|
|
|
|
|
if (!initialized) {
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_CONSTRUCT(&mca_base_params, ompi_value_array_t);
|
|
|
|
ompi_value_array_init(&mca_base_params, sizeof(mca_base_param_t));
|
2004-01-18 02:07:40 +03:00
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
/* Error check */
|
|
|
|
|
|
|
|
if (NULL == type_name) {
|
|
|
|
return OMPI_ERR_BAD_PARAM;
|
|
|
|
}
|
|
|
|
|
2004-01-18 02:07:40 +03:00
|
|
|
/* Create a parameter entry. If a keyval is to be used, it will be
|
|
|
|
registered elsewhere. We simply assign -1 here. */
|
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
OBJ_CONSTRUCT(¶m, mca_base_param_t);
|
2004-02-11 01:12:47 +03:00
|
|
|
param.mbp_type = type;
|
2004-07-14 00:24:26 +04:00
|
|
|
param.mbp_keyval = MPI_KEYVAL_INVALID;
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-02-11 01:12:47 +03:00
|
|
|
param.mbp_type_name = strdup(type_name);
|
|
|
|
if (NULL == param.mbp_type_name) {
|
2004-07-14 00:24:26 +04:00
|
|
|
OBJ_DESTRUCT(¶m);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
if (NULL != component_name) {
|
|
|
|
param.mbp_component_name = strdup(component_name);
|
|
|
|
if (NULL == param.mbp_component_name) {
|
|
|
|
OBJ_DESTRUCT(¶m);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
2004-01-21 07:13:53 +03:00
|
|
|
} else {
|
2004-07-14 00:24:26 +04:00
|
|
|
param.mbp_param_name = NULL;
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-07-14 00:24:26 +04:00
|
|
|
if (NULL != param_name) {
|
2004-02-11 01:12:47 +03:00
|
|
|
param.mbp_param_name = strdup(param_name);
|
|
|
|
if (NULL == param.mbp_param_name) {
|
2004-07-14 00:24:26 +04:00
|
|
|
OBJ_DESTRUCT(¶m);
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
2004-01-21 07:13:53 +03:00
|
|
|
} else {
|
2004-02-11 01:12:47 +03:00
|
|
|
param.mbp_param_name = NULL;
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
/* The full parameter name may have been specified by the caller.
|
|
|
|
If it was, use that (only for backwards compatability).
|
2004-07-14 00:24:26 +04:00
|
|
|
Otherwise, derive it from the type, component, and parameter
|
2004-01-18 02:07:40 +03:00
|
|
|
name. */
|
|
|
|
|
2004-02-11 01:12:47 +03:00
|
|
|
param.mbp_env_var_name = NULL;
|
2004-07-14 00:24:26 +04:00
|
|
|
if (NULL != mca_param_name) {
|
2004-02-11 01:12:47 +03:00
|
|
|
param.mbp_full_name = strdup(mca_param_name);
|
2004-07-14 00:24:26 +04:00
|
|
|
if (NULL == param.mbp_full_name) {
|
|
|
|
OBJ_DESTRUCT(¶m);
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
} else {
|
|
|
|
len = 16 + strlen(type_name);
|
2004-07-14 00:24:26 +04:00
|
|
|
if (NULL != component_name) {
|
|
|
|
len += strlen(component_name);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
|
|
|
if (NULL != param_name) {
|
2004-01-18 02:07:40 +03:00
|
|
|
len += strlen(param_name);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-02-11 01:12:47 +03:00
|
|
|
param.mbp_full_name = malloc(len);
|
|
|
|
if (NULL == param.mbp_full_name) {
|
2004-07-14 00:24:26 +04:00
|
|
|
OBJ_DESTRUCT(¶m);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERROR;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
/* Copy the name over in parts */
|
|
|
|
|
|
|
|
strncpy(param.mbp_full_name, type_name, len);
|
|
|
|
if (NULL != component_name) {
|
2004-02-11 01:12:47 +03:00
|
|
|
strcat(param.mbp_full_name, "_");
|
2004-07-14 00:24:26 +04:00
|
|
|
strcat(param.mbp_full_name, component_name);
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
|
|
|
if (NULL != param_name) {
|
2004-02-11 01:12:47 +03:00
|
|
|
strcat(param.mbp_full_name, "_");
|
|
|
|
strcat(param.mbp_full_name, param_name);
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
/* Create the environment name */
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
len = strlen(param.mbp_full_name) + strlen(mca_prefix) + 16;
|
|
|
|
param.mbp_env_var_name = malloc(len);
|
|
|
|
if (NULL == param.mbp_env_var_name) {
|
|
|
|
OBJ_DESTRUCT(¶m);
|
|
|
|
return OMPI_ERROR;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
2004-07-14 00:24:26 +04:00
|
|
|
snprintf(param.mbp_env_var_name, len, "%s%s", mca_prefix,
|
|
|
|
param.mbp_full_name);
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
/* Figure out the default value; zero it out if a default is not
|
|
|
|
provided */
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
if (NULL != default_value) {
|
2004-02-11 01:12:47 +03:00
|
|
|
if (MCA_BASE_PARAM_TYPE_STRING == param.mbp_type &&
|
2004-01-21 07:13:53 +03:00
|
|
|
NULL != default_value->stringval) {
|
2004-02-11 01:12:47 +03:00
|
|
|
param.mbp_default_value.stringval = strdup(default_value->stringval);
|
2004-01-21 07:13:53 +03:00
|
|
|
} else {
|
2004-02-11 01:12:47 +03:00
|
|
|
param.mbp_default_value = *default_value;
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
|
|
|
} else {
|
2004-02-11 01:12:47 +03:00
|
|
|
memset(¶m.mbp_default_value, 0, sizeof(param.mbp_default_value));
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
/* See if this entry is already in the array */
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
len = ompi_value_array_get_size(&mca_base_params);
|
|
|
|
array = OMPI_VALUE_ARRAY_GET_BASE(&mca_base_params, mca_base_param_t);
|
2004-01-21 07:13:53 +03:00
|
|
|
for (i = 0; i < len; ++i) {
|
2004-02-11 01:12:47 +03:00
|
|
|
if (0 == strcmp(param.mbp_full_name, array[i].mbp_full_name)) {
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
/* We found an entry with the same param name. Free the old
|
|
|
|
value (if it was a string */
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-02-11 01:12:47 +03:00
|
|
|
if (MCA_BASE_PARAM_TYPE_STRING == array[i].mbp_type &&
|
|
|
|
NULL != array[i].mbp_default_value.stringval) {
|
|
|
|
free(array[i].mbp_default_value.stringval);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-07-14 00:24:26 +04:00
|
|
|
|
|
|
|
/* Now put in the new value */
|
|
|
|
|
|
|
|
if (MCA_BASE_PARAM_TYPE_STRING == param.mbp_type) {
|
|
|
|
if (NULL != param.mbp_default_value.stringval) {
|
|
|
|
array[i].mbp_default_value.stringval =
|
|
|
|
strdup(param.mbp_default_value.stringval);
|
|
|
|
} else {
|
|
|
|
array[i].mbp_default_value.stringval = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
array[i].mbp_default_value.intval =
|
|
|
|
param.mbp_default_value.intval;
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
/* Just in case we changed type */
|
|
|
|
|
|
|
|
array[i].mbp_type = param.mbp_type;
|
|
|
|
|
|
|
|
/* Now delete the newly-created entry (since we just saved the
|
|
|
|
value in the old entry) */
|
|
|
|
|
|
|
|
OBJ_DESTRUCT(¶m);
|
2004-01-18 02:07:40 +03:00
|
|
|
return i;
|
|
|
|
}
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
/* Add it to the array */
|
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
if (OMPI_SUCCESS !=
|
|
|
|
(ret = ompi_value_array_append_item(&mca_base_params, ¶m))) {
|
|
|
|
return ret;
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-06-07 19:33:53 +04:00
|
|
|
return ompi_value_array_get_size(&mca_base_params) - 1;
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-07-14 00:24:26 +04:00
|
|
|
* Lookup a parameter
|
2004-01-18 02:07:40 +03:00
|
|
|
*/
|
2004-06-29 04:02:25 +04:00
|
|
|
static bool param_lookup(int index, mca_base_param_storage_t *storage,
|
|
|
|
ompi_hash_table_t *attrs)
|
2004-01-18 02:07:40 +03:00
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
char *env;
|
2004-06-29 04:02:25 +04:00
|
|
|
int err, flag;
|
2004-02-11 01:12:47 +03:00
|
|
|
mca_base_param_t *array;
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
/* Lookup the index and see if it's valid */
|
|
|
|
|
2004-01-21 07:13:53 +03:00
|
|
|
if (!initialized) {
|
2004-01-18 02:07:40 +03:00
|
|
|
return false;
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-06-07 19:33:53 +04:00
|
|
|
if (ompi_value_array_get_size(&mca_base_params) < index) {
|
2004-01-18 02:07:40 +03:00
|
|
|
return false;
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-06-07 19:33:53 +04:00
|
|
|
size = ompi_value_array_get_size(&mca_base_params);
|
|
|
|
array = OMPI_VALUE_ARRAY_GET_BASE(&mca_base_params, mca_base_param_t);
|
2004-01-18 02:07:40 +03:00
|
|
|
|
2004-06-29 04:02:25 +04:00
|
|
|
/* Ensure that MCA param has a good type */
|
|
|
|
|
|
|
|
if (MCA_BASE_PARAM_TYPE_INT != array[index].mbp_type &&
|
|
|
|
MCA_BASE_PARAM_TYPE_STRING != array[index].mbp_type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this param has a keyval and we were provided with a hash
|
|
|
|
table, look it up and see if we can find a value */
|
|
|
|
|
|
|
|
if (-1 != array[index].mbp_keyval) {
|
|
|
|
|
|
|
|
/* Use the stringval member of the union because it's definitely
|
|
|
|
big enough to handle both (int) and (char*) */
|
|
|
|
|
|
|
|
err = ompi_attr_get(attrs, array[index].mbp_keyval,
|
|
|
|
&storage->stringval, &flag);
|
|
|
|
if (OMPI_SUCCESS == err && 1 == flag) {
|
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
/* Because of alignment weirdness between (void*) and int, we
|
|
|
|
must grab the lower sizeof(int) bytes from the (char*) in
|
|
|
|
stringval, in case sizeof(int) != sizeof(char*). */
|
2004-06-29 04:02:25 +04:00
|
|
|
|
|
|
|
if (MCA_BASE_PARAM_TYPE_INT == array[index].mbp_type) {
|
2004-07-14 00:24:26 +04:00
|
|
|
storage->intval = *((int *) (storage->stringval +
|
|
|
|
sizeof(void *) - sizeof(int)));
|
2004-06-29 04:02:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Nothing to do for string -- we already have the value loaded
|
|
|
|
in the right place */
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-18 02:07:40 +03:00
|
|
|
/* We either don't have a keyval or didn't find it. So look in the
|
|
|
|
environment. */
|
|
|
|
|
2004-02-11 01:12:47 +03:00
|
|
|
if (NULL != array[index].mbp_env_var_name &&
|
|
|
|
NULL != (env = getenv(array[index].mbp_env_var_name))) {
|
|
|
|
if (MCA_BASE_PARAM_TYPE_INT == array[index].mbp_type) {
|
2004-01-18 02:07:40 +03:00
|
|
|
storage->intval = atoi(env);
|
2004-02-11 01:12:47 +03:00
|
|
|
} else if (MCA_BASE_PARAM_TYPE_STRING == array[index].mbp_type) {
|
2004-01-18 02:07:40 +03:00
|
|
|
storage->stringval = strdup(env);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Didn't find it; use the default value. */
|
|
|
|
|
2004-02-11 01:12:47 +03:00
|
|
|
switch (array[index].mbp_type) {
|
2004-01-18 02:07:40 +03:00
|
|
|
case MCA_BASE_PARAM_TYPE_INT:
|
2004-02-11 01:12:47 +03:00
|
|
|
storage->intval = array[index].mbp_default_value.intval;
|
2004-01-18 02:07:40 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MCA_BASE_PARAM_TYPE_STRING:
|
2004-02-11 01:12:47 +03:00
|
|
|
if (NULL != array[index].mbp_default_value.stringval) {
|
|
|
|
storage->stringval = strdup(array[index].mbp_default_value.stringval);
|
2004-01-22 03:37:58 +03:00
|
|
|
} else {
|
|
|
|
storage->stringval = NULL;
|
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All done */
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-14 00:24:26 +04:00
|
|
|
/*
|
|
|
|
* Create an empty param container
|
|
|
|
*/
|
|
|
|
static void param_constructor(mca_base_param_t *p)
|
|
|
|
{
|
|
|
|
p->mbp_type = MCA_BASE_PARAM_TYPE_MAX;
|
|
|
|
|
|
|
|
p->mbp_type_name = NULL;
|
|
|
|
p->mbp_component_name = NULL;
|
|
|
|
p->mbp_param_name = NULL;
|
|
|
|
p->mbp_full_name = NULL;
|
|
|
|
|
|
|
|
p->mbp_keyval = -1;
|
|
|
|
p->mbp_env_var_name = NULL;
|
|
|
|
p->mbp_default_value.stringval = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free all the contents of a param container
|
|
|
|
*/
|
|
|
|
static void param_destructor(mca_base_param_t *p)
|
2004-01-18 02:07:40 +03:00
|
|
|
{
|
2004-01-21 07:13:53 +03:00
|
|
|
if (NULL != p->mbp_type_name) {
|
2004-02-10 03:09:36 +03:00
|
|
|
free(p->mbp_type_name);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-07-14 00:24:26 +04:00
|
|
|
if (NULL != p->mbp_component_name) {
|
|
|
|
free(p->mbp_component_name);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
|
|
|
if (NULL != p->mbp_param_name) {
|
2004-02-10 03:09:36 +03:00
|
|
|
free(p->mbp_param_name);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
|
|
|
if (NULL != p->mbp_env_var_name) {
|
2004-02-10 03:09:36 +03:00
|
|
|
free(p->mbp_env_var_name);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
|
|
|
if (NULL != p->mbp_full_name) {
|
2004-02-10 03:09:36 +03:00
|
|
|
free(p->mbp_full_name);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
if (MCA_BASE_PARAM_TYPE_STRING == p->mbp_type &&
|
2004-01-21 07:13:53 +03:00
|
|
|
NULL != p->mbp_default_value.stringval) {
|
2004-02-10 03:09:36 +03:00
|
|
|
free(p->mbp_default_value.stringval);
|
2004-01-21 07:13:53 +03:00
|
|
|
}
|
2004-01-18 02:07:40 +03:00
|
|
|
}
|