📄 mca_base_param.c
字号:
MCA_BASE_PARAM_TYPE_STRING == param.mbp_type) { if (NULL != default_value && NULL != param.mbp_default_value.stringval) { array[i].mbp_default_value.stringval = strdup(param.mbp_default_value.stringval); } if (NULL != file_value && NULL != param.mbp_file_value.stringval) { array[i].mbp_file_value.stringval = strdup(param.mbp_file_value.stringval); array[i].mbp_file_value_set = true; } if (NULL != override_value && NULL != param.mbp_override_value.stringval) { array[i].mbp_override_value.stringval = strdup(param.mbp_override_value.stringval); array[i].mbp_override_value_set = true; } array[i].mbp_type = param.mbp_type; } /* Original is STRING, new is INT */ else if (MCA_BASE_PARAM_TYPE_STRING == array[i].mbp_type && MCA_BASE_PARAM_TYPE_INT == param.mbp_type) { if (NULL != default_value) { if (NULL != array[i].mbp_default_value.stringval) { free(array[i].mbp_default_value.stringval); } array[i].mbp_default_value.intval = param.mbp_default_value.intval; } if (NULL != file_value) { if (NULL != array[i].mbp_file_value.stringval) { free(array[i].mbp_file_value.stringval); } array[i].mbp_file_value.intval = param.mbp_file_value.intval; array[i].mbp_file_value_set = true; } if (NULL != override_value) { if (NULL != array[i].mbp_override_value.stringval) { free(array[i].mbp_override_value.stringval); } array[i].mbp_override_value.intval = param.mbp_override_value.intval; array[i].mbp_override_value_set = true; } 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); /* Finally, if we have a lookup value, look it up */ if (NULL != current_value) { if (!param_lookup(i, current_value, NULL)) { return OPAL_ERR_NOT_FOUND; } } /* Return the new index */ return (int)i; } } /* Add it to the array */ if (OPAL_SUCCESS != (ret = opal_value_array_append_item(&mca_base_params, ¶m))) { return ret; } ret = (int)opal_value_array_get_size(&mca_base_params) - 1; /* Finally, if we have a lookup value, look it up */ if (NULL != current_value) { if (!param_lookup(ret, current_value, NULL)) { return OPAL_ERR_NOT_FOUND; } } /* All done */ return ret;}/* * Set an override */static bool param_set_override(size_t index, mca_base_param_storage_t *storage, mca_base_param_type_t type){ size_t size; mca_base_param_t *array; /* Lookup the index and see if it's valid */ if (!initialized) { return false; } size = opal_value_array_get_size(&mca_base_params); if (index > size) { return false; } array = OPAL_VALUE_ARRAY_GET_BASE(&mca_base_params, mca_base_param_t); if (MCA_BASE_PARAM_TYPE_INT == type) { array[index].mbp_override_value.intval = storage->intval; } else if (MCA_BASE_PARAM_TYPE_STRING == type) { if (NULL != storage->stringval) { array[index].mbp_override_value.stringval = strdup(storage->stringval); } else { array[index].mbp_override_value.stringval = NULL; } } array[index].mbp_override_value_set = true; return true;}/* * Lookup a parameter in multiple places */static bool param_lookup(size_t index, mca_base_param_storage_t *storage, opal_hash_table_t *attrs){ size_t size; mca_base_param_t *array; char *p, *q; bool found; /* Lookup the index and see if it's valid */ if (!initialized) { return false; } size = opal_value_array_get_size(&mca_base_params); if (index > size) { return false; } array = OPAL_VALUE_ARRAY_GET_BASE(&mca_base_params, mca_base_param_t); /* 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; } /* Check all the places that the param may be hiding, in priority order -- but if read_only is true, then only look at the default location. */ if (array[index].mbp_read_only) { if (lookup_override(&array[index], storage) || lookup_keyvals(&array[index], storage, attrs) || lookup_env(&array[index], storage) || lookup_file(&array[index], storage)) { opal_show_help("help-mca-param.txt", "read-only-param-set", true, array[index].mbp_full_name); } found = lookup_default(&array[index], storage); } else { found = (lookup_override(&array[index], storage) || lookup_keyvals(&array[index], storage, attrs) || lookup_env(&array[index], storage) || lookup_file(&array[index], storage) || lookup_default(&array[index], storage)); } if (found) { /* If we're returning a string, replace all instances of "~/" with the user's home directory */ if (MCA_BASE_PARAM_TYPE_STRING == array[index].mbp_type && NULL != storage->stringval) { if (0 == strncmp(storage->stringval, "~/", 2)) { if( NULL == home ) { asprintf(&p, "%s", storage->stringval + 2); } else { p = opal_os_path( false, home, storage->stringval + 2, NULL ); } free(storage->stringval); storage->stringval = p; } p = strstr(storage->stringval, ":~/"); while (NULL != p) { *p = '\0'; if( NULL == home ) { asprintf(&q, "%s:%s", storage->stringval, p + 2); } else { asprintf(&q, "%s:%s%s", storage->stringval, home, p + 2); } free(storage->stringval); storage->stringval = q; p = strstr(storage->stringval, ":~/"); } } return true; } /* Didn't find it. Doh! */ return false;}/* * Lookup a param in the overrides section */static bool lookup_override(mca_base_param_t *param, mca_base_param_storage_t *storage){ if (param->mbp_override_value_set) { if (MCA_BASE_PARAM_TYPE_INT == param->mbp_type) { storage->intval = param->mbp_override_value.intval; } else if (MCA_BASE_PARAM_TYPE_STRING == param->mbp_type) { storage->stringval = strdup(param->mbp_override_value.stringval); } return true; } /* Don't have an override */ return false;}/* * Lookup a param in the set of attributes/keyvals */static bool lookup_keyvals(mca_base_param_t *param, mca_base_param_storage_t *storage, opal_hash_table_t *attrs){#if 1 /* JMS: Comment this out for now, because it drags in all of libmpi. This is undesirable for programs like mpirun, etc. Need a better solution for this -- perhaps a registration kind of thing...? */ return false;#else int err, flag; /* 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 != param->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, param->mbp_keyval, &storage->stringval, &flag); if (OPAL_SUCCESS == err && 1 == flag) { /* 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*). */ if (MCA_BASE_PARAM_TYPE_INT == param->mbp_type) { storage->intval = *((int *) (storage->stringval + sizeof(void *) - sizeof(int))); } /* Nothing to do for string -- we already have the value loaded in the right place */ return true; } } /* Either this param has not keyval or we didn't find the keyval */ return false;#endif}/* * Lookup a param in the environment */static bool lookup_env(mca_base_param_t *param, mca_base_param_storage_t *storage){ char *env; if (NULL != param->mbp_env_var_name && NULL != (env = getenv(param->mbp_env_var_name))) { if (MCA_BASE_PARAM_TYPE_INT == param->mbp_type) { storage->intval = atoi(env); } else if (MCA_BASE_PARAM_TYPE_STRING == param->mbp_type) { storage->stringval = strdup(env); } return true; } /* Didn't find it */ return false;}/* * Lookup a param in the files */static bool lookup_file(mca_base_param_t *param, mca_base_param_storage_t *storage){ opal_list_item_t *item; mca_base_param_file_value_t *fv; /* See if we previously found a match from a file. If so, just return that */ if (param->mbp_file_value_set) { return set(param->mbp_type, storage, ¶m->mbp_file_value); } /* Scan through the list of values read in from files and try to find a match. If we do, cache it on the param (for future lookups) and save it in the storage. */ for (item = opal_list_get_first(&mca_base_param_file_values); opal_list_get_end(&mca_base_param_file_values) != item; item = opal_list_get_next(item)) { fv = (mca_base_param_file_value_t *) item; if (0 == strcmp(fv->mbpfv_param, param->mbp_full_name)) { if (MCA_BASE_PARAM_TYPE_INT == param->mbp_type) { if (NULL != fv->mbpfv_value) { param->mbp_file_value.intval = atoi(fv->mbpfv_value); } else { param->mbp_file_value.intval = 0; } } else { param->mbp_file_value.stringval = fv->mbpfv_value; fv->mbpfv_value = NULL; } param->mbp_file_value_set = true; /* Since this is now cached on the param, we might as well remove it from the list and make future file lookups faster */ opal_list_remove_item(&mca_base_param_file_values, (opal_list_item_t *) fv); OBJ_RELEASE(fv); return set(param->mbp_type, storage, ¶m->mbp_file_value); } } return false;}/* * Return the default value for a param */static bool lookup_default(mca_base_param_t *param, mca_base_param_storage_t *storage){ return set(param->mbp_type, storage, ¶m->mbp_default_value);}static bool set(mca_base_param_type_t type, mca_base_param_storage_t *dest, mca_base_param_storage_t *src){ switch (type) { case MCA_BASE_PARAM_TYPE_INT: dest->intval = src->intval; break; case MCA_BASE_PARAM_TYPE_STRING: if (NULL != src->stringval) { dest->stringval = strdup(src->stringval); } else { dest->stringval = NULL; } break; default: return false; break; } return true;}/* * Create an empty param container */static void param_constructor(mca_base_param_t *p){ p->mbp_type = MCA_BASE_PARAM_TYPE_MAX; p->mbp_internal = false; p->mbp_read_only = false; p->mbp_type_name = NULL; p->mbp_component_name = NULL; p->mbp_param_name = NULL; p->mbp_full_name = NULL; p->mbp_help_msg = NULL; p->mbp_keyval = -1; p->mbp_env_var_name = NULL; p->mbp_default_value.stringval = NULL; p->mbp_file_value_set = false; p->mbp_file_value.stringval = NULL; p->mbp_override_value_set = false; p->mbp_override_value.stringval = NULL;}/* * Free all the contents of a param container */static void param_destructor(mca_base_param_t *p){ if (NULL != p->mbp_type_name) { free(p->mbp_type_name); } if (NULL != p->mbp_component_name) { free(p->mbp_component_name); } if (NULL != p->mbp_param_name) { free(p->mbp_param_name); } if (NULL != p->mbp_env_var_name) { free(p->mbp_env_var_name); } if (NULL != p->mbp_full_name) { free(p->mbp_full_name); } if (NULL != p->mbp_help_msg) { free(p->mbp_help_msg); } if (MCA_BASE_PARAM_TYPE_STRING == p->mbp_type) { if (NULL != p->mbp_default_value.stringval) { free(p->mbp_default_value.stringval); } if (p->mbp_file_value_set && NULL != p->mbp_file_value.stringval) { free(p->mbp_file_value.stringval); } if (p->mbp_override_value_set && NULL != p->mbp_override_value.stringval) { free(p->mbp_override_value.stringval); } } param_constructor(p);}static void fv_constructor(mca_base_param_file_value_t *f){ f->mbpfv_param = NULL; f->mbpfv_value = NULL;}static void fv_destructor(mca_base_param_file_value_t *f){ if (NULL != f->mbpfv_param) { free(f->mbpfv_param); } if (NULL != f->mbpfv_value) { free(f->mbpfv_value); } fv_constructor(f);}static void info_constructor(mca_base_param_info_t *p){ p->mbpp_index = -1; p->mbpp_type = MCA_BASE_PARAM_TYPE_MAX; p->mbpp_type_name = NULL; p->mbpp_component_name = NULL; p->mbpp_param_name = NULL; p->mbpp_full_name = NULL; p->mbpp_read_only = false; p->mbpp_help_msg = NULL;}static void info_destructor(mca_base_param_info_t *p){ /* No need to free any of the strings -- the pointers were copied by value from their corresponding parameter registration */ info_constructor(p);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -