root/opal/mca/base/mca_base_components_select.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_base_select

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
   7  *                         reserved.
   8  * Copyright (c) 2015      Intel, Inc. All rights reserved.
   9  * $COPYRIGHT$
  10  *
  11  * Additional copyrights may follow
  12  *
  13  * $HEADER$
  14  */
  15 
  16 #include "opal_config.h"
  17 
  18 #include <stdio.h>
  19 #include <string.h>
  20 #include <stdlib.h>
  21 #ifdef HAVE_SYS_TYPES_H
  22 #include <sys/types.h>
  23 #endif
  24 
  25 #include "opal/runtime/opal.h"
  26 #include "opal/class/opal_list.h"
  27 #include "opal/util/output.h"
  28 #include "opal/mca/mca.h"
  29 #include "opal/mca/base/base.h"
  30 #include "opal/mca/base/mca_base_component_repository.h"
  31 #include "opal/constants.h"
  32 
  33 
  34 int mca_base_select(const char *type_name, int output_id,
  35                     opal_list_t *components_available,
  36                     mca_base_module_t **best_module,
  37                     mca_base_component_t **best_component,
  38                     int *priority_out)
  39 {
  40     mca_base_component_list_item_t *cli = NULL;
  41     mca_base_component_t *component = NULL;
  42     mca_base_module_t *module = NULL;
  43     int priority = 0, best_priority = INT32_MIN;
  44     int rc;
  45 
  46     *best_module = NULL;
  47     *best_component = NULL;
  48 
  49     opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
  50                          "mca:base:select: Auto-selecting %s components",
  51                          type_name);
  52 
  53     /*
  54      * Traverse the list of available components.
  55      * For each call their 'query' functions to determine relative priority.
  56      */
  57     OPAL_LIST_FOREACH(cli, components_available, mca_base_component_list_item_t) {
  58         component = (mca_base_component_t *) cli->cli_component;
  59 
  60         /*
  61          * If there is a query function then use it.
  62          */
  63         if (NULL == component->mca_query_component) {
  64             opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
  65                                  "mca:base:select:(%5s) Skipping component [%s]. It does not implement a query function",
  66                                  type_name, component->mca_component_name );
  67             continue;
  68         }
  69 
  70         /*
  71          * Query this component for the module and priority
  72          */
  73         opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
  74                              "mca:base:select:(%5s) Querying component [%s]",
  75                              type_name, component->mca_component_name);
  76 
  77         rc = component->mca_query_component(&module, &priority);
  78         if (OPAL_ERR_FATAL == rc) {
  79             /* a fatal error was detected by this component - e.g., the
  80              * user specified a required element and the component could
  81              * not find it. In this case, we must not continue as we might
  82              * find some other component that could run, causing us to do
  83              * something the user didn't want */
  84              return rc;
  85         } else if (OPAL_SUCCESS != rc) {
  86             /* silently skip this component */
  87             continue;
  88         }
  89 
  90         /*
  91          * If no module was returned, then skip component
  92          */
  93         if (NULL == module) {
  94             opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
  95                                  "mca:base:select:(%5s) Skipping component [%s]. Query failed to return a module",
  96                                  type_name, component->mca_component_name );
  97             continue;
  98         }
  99 
 100         /*
 101          * Determine if this is the best module we have seen by looking the priority
 102          */
 103         opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
 104                              "mca:base:select:(%5s) Query of component [%s] set priority to %d",
 105                              type_name, component->mca_component_name, priority);
 106         if (priority > best_priority) {
 107             best_priority  = priority;
 108             *best_component = component;
 109             *best_module    = module;
 110         }
 111     }
 112 
 113     if (priority_out) {
 114         *priority_out = best_priority;
 115     }
 116 
 117     /*
 118      * Finished querying all components.
 119      * Make sure we found something in the process.
 120      */
 121     if (NULL == *best_component) {
 122         opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
 123                             "mca:base:select:(%5s) No component selected!",
 124                             type_name);
 125         /*
 126          * Still close the non-selected components
 127          */
 128         mca_base_components_close(0, /* Pass 0 to keep this from closing the output handle */
 129                                   components_available,
 130                                   NULL);
 131         return OPAL_ERR_NOT_FOUND;
 132     }
 133 
 134     opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
 135                          "mca:base:select:(%5s) Selected component [%s]",
 136                          type_name, (*best_component)->mca_component_name);
 137 
 138     /*
 139      * Close the non-selected components
 140      */
 141     mca_base_components_close(output_id,
 142                               components_available,
 143                               (mca_base_component_t *) (*best_component));
 144 
 145 
 146     return OPAL_SUCCESS;
 147 }

/* [<][>][^][v][top][bottom][index][help] */