topo_base_comm_select.c

来自「MPI stands for the Message Passing Inter」· C语言 代码 · 共 414 行 · 第 1/2 页

C
414
字号
/* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana *                         University Research and Technology *                         Corporation.  All rights reserved. * Copyright (c) 2004-2005 The University of Tennessee and The University *                         of Tennessee Research Foundation.  All rights *                         reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,  *                         University of Stuttgart.  All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. *                         All rights reserved. * $COPYRIGHT$ *  * Additional copyrights may follow *  * $HEADER$ */#include "ompi_config.h"#include <string.h>#include "opal/class/opal_list.h"#include "opal/util/argv.h"#include "opal/mca/mca.h"#include "opal/mca/base/base.h"#include "ompi/mca/topo/topo.h"#include "ompi/mca/topo/base/base.h"#include "opal/util/output.h"#include "ompi/communicator/communicator.h"/* * Local functions */static void fill_null_pointers(mca_topo_base_module_t *module);/* * This structure is needed so that we can close the modules  * which are not selected but were opened. mca_base_modules_close * which does this job for us requires a opal_list_t which contains * these modules */struct queried_module_t {    opal_list_item_t super;    mca_topo_base_component_t *om_component;    mca_topo_base_module_t *om_module;};typedef struct queried_module_t queried_module_t;static OBJ_CLASS_INSTANCE(queried_module_t, opal_list_item_t, NULL, NULL);/* * Only one topo module can be attached to each communicator. * * This module calls the query funtion on all the components that were * detected by topo_base_open. This function is called on a * per-communicator basis. This function has the following function. * * 1. Iterate over the list of available_components * 2. Call the query function on each of these components. * 3. query function returns the structure containing pointers *    to its module and its priority * 4. Select the module with the highest priority * 5. Call the init function on the selected module so that it does the *    right setup for the communicator * 6. Call finalize on all the other modules which returned  *    their module but were unfortunate to not get selected */  int mca_topo_base_comm_select (struct ompi_communicator_t *comm,                               struct mca_base_component_t *preferred) {    int priority;     int best_priority;     char name[MPI_MAX_OBJECT_NAME+32];    opal_list_item_t *item;     opal_list_item_t *next_item;     mca_base_component_priority_list_item_t *selectable_item;    char *names, **name_array;    int num_names;    mca_base_component_priority_list_item_t *cpli;    mca_topo_base_component_t *component;     mca_topo_base_component_t *best_component;    mca_topo_base_module_t *module;     opal_list_t queried;    queried_module_t *om;    opal_list_t *selectable;    char *str;    int err = MPI_SUCCESS;    int i;    bool was_selectable_constructed = false;    /* Announce */    /* ANJU:     * check for names array .... mca_base_param_ */      snprintf(name, sizeof(name), "%s (cid %d)", comm->c_name,               comm->c_contextid);    name[sizeof(name) - 1] = '\0';    opal_output_verbose(10, mca_topo_base_output,                        "topo:base:comm_select: new communicator: %s",                        name);    /* Check and see if a preferred component was provided. If it was     provided then it should be used (if possible) */    if (NULL != preferred) {                 /* We have a preferred component. Check if it is available           and if so, whether it wants to run */                  str = &(preferred->mca_component_name[0]);                  opal_output_verbose(10, mca_topo_base_output,                             "topo:base:comm_select: Checking preferred component: %s",                             str);         /* query the component for its priority and get its module             structure. This is necessary to proceed */        component = (mca_topo_base_component_t *)preferred;         module = component->topom_comm_query (&priority);         if (NULL != module &&              NULL != module->topo_module_init &&             NULL != module->topo_graph_map &&             NULL != module->topo_cart_map) {             /* this query seems to have returned something legitimate              * and we can now go ahead and initialize the              * communicator with it * but first, the functions which              * are null need to be filled in */             fill_null_pointers (module);             comm->c_topo = module;             comm->c_topo_component = preferred;             return module->topo_module_init(comm);         }             /* His preferred component is present, but is unable to             * run. This is not a good sign. We should try selecting             * some other component We let it fall through and select             * from the list of available components             */     } /*end of selection for preferred component */    /*     * We fall till here if one of the two things happened:     * 1. The preferred component was provided but for some reason was     * not able to be selected     * 2. No preferred component was provided     *     * All we need to do is to go through the list of available     * components and find the one which has the highest priority and     * use that for this communicator     */     /* Check if anything was requested by means on the name parameters */    names = NULL;    mca_base_param_lookup_string (mca_topo_base_param, &names);    if (NULL != names && 0 < strlen(names)) {        name_array = opal_argv_split (names, ',');        num_names = opal_argv_count (name_array);        opal_output_verbose(10, mca_topo_base_output,                            "topo:base:comm_Select: Checking all available module");        /* since there are somethings which the mca requested through the            if the intersection is NULL, then we barf saying that the requested           modules are not being available */        selectable = OBJ_NEW(opal_list_t);        was_selectable_constructed = true;                /* go through the compoents_available list and check against the names         * to see whether this can be added or not */        for (item = opal_list_get_first(&mca_topo_base_components_available);            item != opal_list_get_end(&mca_topo_base_components_available);            item = opal_list_get_next(item)) {            /* convert the opal_list_item_t returned into the proper type */            cpli = (mca_base_component_priority_list_item_t *) item;            component = (mca_topo_base_component_t *) cpli->super.cli_component;            opal_output_verbose(10, mca_topo_base_output,                                "select: initialising %s component %s",                                component->topom_version.mca_type_name,                                component->topom_version.mca_component_name);            /* check if this name is present in the mca_base_params */            for (i=0; i < num_names; i++) {                if (0 == strcmp(name_array[i], component->topom_version.mca_component_name)) {                    /* this is present, and should be added o the selectable list */                    /* We need to create a seperate object to initialise this list with                     * since we cannot have the same item in 2 lists */                    selectable_item = OBJ_NEW (mca_base_component_priority_list_item_t);                    *selectable_item = *cpli;                    opal_list_append (selectable, (opal_list_item_t *)selectable_item);                    break;                }            }        }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?