root/opal/mca/shmem/base/shmem_base_select.c

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

DEFINITIONS

This source file includes following definitions.
  1. opal_shmem_base_runtime_query
  2. opal_shmem_base_best_runnable_component_name
  3. opal_shmem_base_select

   1 /*
   2  * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2006 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2007-2015 Cisco Systems, Inc.  All rights reserved.
  13  * Copyright (c) 2010-2011 Los Alamos National Security, LLC.
  14  *                         All rights reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 #include "opal_config.h"
  23 
  24 #include <string.h>
  25 
  26 #include "opal/constants.h"
  27 #include "opal/util/output.h"
  28 #include "opal/mca/mca.h"
  29 #include "opal/mca/base/base.h"
  30 #include "opal/mca/shmem/shmem.h"
  31 #include "opal/mca/shmem/base/base.h"
  32 
  33 /*
  34  * globals
  35  */
  36 bool opal_shmem_base_selected = false;
  37 opal_shmem_base_component_t *opal_shmem_base_component = NULL;
  38 opal_shmem_base_module_t *opal_shmem_base_module = NULL;
  39 
  40 /* ////////////////////////////////////////////////////////////////////////// */
  41 
  42 /*
  43  * Performs a run-time query across all available shmem components.
  44  * Similar to mca_base_select, but take into consideration environment
  45  * hints provided by orte.
  46  */
  47 static int
  48 opal_shmem_base_runtime_query(mca_base_module_t **best_module,
  49                               mca_base_component_t **best_component)
  50 {
  51     mca_base_component_list_item_t *cli = NULL;
  52     mca_base_component_t *component = NULL;
  53     mca_base_module_t *module = NULL;
  54     int priority = 0, best_priority = INT32_MIN;
  55 
  56     /* If we've already done this query, then just return the
  57        results */
  58     if (opal_shmem_base_selected) {
  59         *best_component = &(opal_shmem_base_component->base_version);
  60         *best_module = &(opal_shmem_base_module->base);
  61 
  62         return OPAL_SUCCESS;
  63     }
  64 
  65     *best_module = NULL;
  66     *best_component = NULL;
  67 
  68     opal_output_verbose(10, opal_shmem_base_framework.framework_output,
  69                         "shmem: base: runtime_query: "
  70                         "Auto-selecting shmem components");
  71 
  72     /* traverse the list of available components.
  73      * for each call their 'run-time query' functions to determine relative
  74      * priority.
  75      */
  76     OPAL_LIST_FOREACH(cli, &opal_shmem_base_framework.framework_components, mca_base_component_list_item_t) {
  77         component = (mca_base_component_t *)cli->cli_component;
  78 
  79         /* if there is a run-time query function then use it. otherwise, skip
  80          * the component.
  81          */
  82         if (NULL == ((opal_shmem_base_component_2_0_0_t *)
  83                      component)->runtime_query) {
  84             opal_output_verbose(5, opal_shmem_base_framework.framework_output,
  85                                 "shmem: base: runtime_query: "
  86                                 "(shmem) Skipping component [%s]. It does not "
  87                                 "implement a run-time query function",
  88                                 component->mca_component_name);
  89             continue;
  90         }
  91 
  92         /* query this component for the module and priority */
  93         opal_output_verbose(5, opal_shmem_base_framework.framework_output,
  94                             "shmem: base: runtime_query: "
  95                             "(shmem) Querying component (run-time) [%s]",
  96                             component->mca_component_name);
  97 
  98         ((opal_shmem_base_component_2_0_0_t *)
  99          component)->runtime_query(&module, &priority, opal_shmem_base_RUNTIME_QUERY_hint);
 100 
 101         /* if no module was returned, then skip component.
 102          * this probably means that the run-time test deemed the shared memory
 103          * backing facility unusable or unsafe.
 104          */
 105         if (NULL == module) {
 106             opal_output_verbose(5, opal_shmem_base_framework.framework_output,
 107                                 "shmem: base: runtime_query: "
 108                                 "(shmem) Skipping component [%s]. Run-time "
 109                                 "Query failed to return a module",
 110                                 component->mca_component_name);
 111             continue;
 112         }
 113 
 114         /* determine if this is the best module we have seen by looking the
 115          * priority
 116          */
 117         opal_output_verbose(5, opal_shmem_base_framework.framework_output,
 118                             "shmem: base: runtime_query: "
 119                             "(%5s) Query of component [%s] set priority to %d",
 120                             "shmem", component->mca_component_name, priority);
 121         if (priority > best_priority) {
 122             best_priority = priority;
 123             *best_module = module;
 124             *best_component = component;
 125         }
 126     }
 127 
 128     /* finished querying all components.
 129      * make sure we found something in the process.
 130      */
 131     if (NULL == *best_component) {
 132         opal_output_verbose(5, opal_shmem_base_framework.framework_output,
 133                             "shmem: base: runtime_query: "
 134                             "(%5s) No component selected!", "shmem");
 135         return OPAL_ERR_NOT_FOUND;
 136     }
 137 
 138     opal_output_verbose(5, opal_shmem_base_framework.framework_output,
 139                         "shmem: base: runtime_query: "
 140                         "(%5s) Selected component [%s]", "shmem",
 141                         (*best_component)->mca_component_name);
 142 
 143     /* close the non-selected components */
 144     (void) mca_base_framework_components_close (&opal_shmem_base_framework,
 145                                                 (mca_base_component_t *)(*best_component));
 146 
 147     /* save the winner */
 148     opal_shmem_base_component = (opal_shmem_base_component_t*) *best_component;
 149     opal_shmem_base_module = (opal_shmem_base_module_t*) *best_module;
 150     opal_shmem_base_selected = true;
 151 
 152     return OPAL_SUCCESS;
 153 }
 154 
 155 /* ////////////////////////////////////////////////////////////////////////// */
 156 char *
 157 opal_shmem_base_best_runnable_component_name(void)
 158 {
 159     mca_base_component_t *best_component = NULL;
 160     mca_base_module_t *best_module = NULL;
 161 
 162     opal_output_verbose(10, opal_shmem_base_framework.framework_output,
 163                         "shmem: base: best_runnable_component_name: "
 164                         "Searching for best runnable component.");
 165     /* select the best component so we can get its name. */
 166     if (OPAL_SUCCESS != opal_shmem_base_runtime_query(&best_module,
 167                                                       &best_component)) {
 168         /* fail! */
 169         return NULL;
 170     }
 171     else {
 172         if (NULL != best_component) {
 173             opal_output_verbose(10, opal_shmem_base_framework.framework_output,
 174                                 "shmem: base: best_runnable_component_name: "
 175                                 "Found best runnable component: (%s).",
 176                                 best_component->mca_component_name);
 177             return strdup(best_component->mca_component_name);
 178         }
 179         else {
 180             opal_output_verbose(10, opal_shmem_base_framework.framework_output,
 181                                 "shmem: base: best_runnable_component_name: "
 182                                 "Could not find runnable component.");
 183             /* no component returned, so return NULL */
 184             return NULL;
 185         }
 186     }
 187 }
 188 
 189 /* ////////////////////////////////////////////////////////////////////////// */
 190 int
 191 opal_shmem_base_select(void)
 192 {
 193     opal_shmem_base_component_2_0_0_t *best_component = NULL;
 194     opal_shmem_base_module_2_0_0_t *best_module = NULL;
 195     /* select the best component */
 196     if (OPAL_SUCCESS != opal_shmem_base_runtime_query(
 197                                 (mca_base_module_t **)&best_module,
 198                                 (mca_base_component_t **)&best_component)) {
 199         /* it is NOT okay if we don't find a module because we need at
 200          * least one shared memory backing facility component instance.
 201          */
 202         return OPAL_ERROR;
 203     }
 204 
 205     /* initialize the winner */
 206     if (NULL != opal_shmem_base_module) {
 207         return opal_shmem_base_module->module_init();
 208     }
 209     else {
 210         return OPAL_ERROR;
 211     }
 212 }
 213 

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