root/oshmem/mca/sshmem/base/sshmem_base_select.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_sshmem_base_runtime_query
  2. mca_sshmem_base_select

   1 /*
   2  * Copyright (c) 2014      Mellanox Technologies, Inc.
   3  *                         All rights reserved.
   4  * $COPYRIGHT$
   5  *
   6  * Additional copyrights may follow
   7  *
   8  * $HEADER$
   9  */
  10 
  11 #include "oshmem_config.h"
  12 
  13 #include <string.h>
  14 
  15 #include "opal/constants.h"
  16 #include "opal/util/output.h"
  17 #include "oshmem/mca/mca.h"
  18 #include "opal/mca/base/base.h"
  19 
  20 #include "oshmem/mca/sshmem/sshmem.h"
  21 #include "oshmem/mca/sshmem/base/base.h"
  22 
  23 /*
  24  * globals
  25  */
  26 bool mca_sshmem_base_selected = false;
  27 const mca_sshmem_base_component_2_0_0_t *mca_sshmem_base_component = NULL;
  28 const mca_sshmem_base_module_2_0_0_t *mca_sshmem_base_module = NULL;
  29 
  30 /* ////////////////////////////////////////////////////////////////////////// */
  31 static int
  32 mca_sshmem_base_runtime_query(mca_base_module_t **best_module,
  33                               mca_base_component_t **best_component)
  34 {
  35     mca_base_component_list_item_t *cli = NULL;
  36     mca_base_component_t *component = NULL;
  37     mca_base_module_t *module = NULL;
  38     int priority = 0, best_priority = INT32_MIN;
  39 
  40     *best_module = NULL;
  41     *best_component = NULL;
  42 
  43     opal_output_verbose(10, oshmem_sshmem_base_framework.framework_output,
  44                         "sshmem: base: runtime_query: "
  45                         "Auto-selecting sshmem components");
  46 
  47     /* traverse the list of available components.
  48      * for each call their 'run-time query' functions to determine relative
  49      * priority.
  50      */
  51     OPAL_LIST_FOREACH(cli, &oshmem_sshmem_base_framework.framework_components, mca_base_component_list_item_t) {
  52         component = (mca_base_component_t *)cli->cli_component;
  53 
  54         /* if there is a run-time query function then use it. otherwise, skip
  55          * the component.
  56          */
  57         if (NULL == ((mca_sshmem_base_component_2_0_0_t *)
  58                      component)->runtime_query) {
  59             opal_output_verbose(5, oshmem_sshmem_base_framework.framework_output,
  60                                 "sshmem: base: runtime_query: "
  61                                 "(sshmem) Skipping component [%s]. It does not "
  62                                 "implement a run-time query function",
  63                                 component->mca_component_name);
  64             continue;
  65         }
  66 
  67         /* query this component for the module and priority */
  68         opal_output_verbose(5, oshmem_sshmem_base_framework.framework_output,
  69                             "sshmem: base: runtime_query: "
  70                             "(shmem) Querying component (run-time) [%s]",
  71                             component->mca_component_name);
  72 
  73         ((mca_sshmem_base_component_2_0_0_t *)
  74          component)->runtime_query(&module, &priority, NULL);
  75 
  76         /* if no module was returned, then skip component.
  77          * this probably means that the run-time test deemed the shared memory
  78          * backing facility unusable or unsafe.
  79          */
  80         if (NULL == module) {
  81             opal_output_verbose(5, oshmem_sshmem_base_framework.framework_output,
  82                                 "sshmem: base: runtime_query: "
  83                                 "(sshmem) Skipping component [%s]. Run-time "
  84                                 "Query failed to return a module",
  85                                 component->mca_component_name);
  86             continue;
  87         }
  88 
  89         /* determine if this is the best module we have seen by looking the
  90          * priority
  91          */
  92         opal_output_verbose(5, oshmem_sshmem_base_framework.framework_output,
  93                             "sshmem: base: runtime_query: "
  94                             "(%5s) Query of component [%s] set priority to %d",
  95                             "shmem", component->mca_component_name, priority);
  96         if (priority > best_priority) {
  97             best_priority = priority;
  98             *best_module = module;
  99             *best_component = component;
 100         }
 101     }
 102 
 103     /* finished querying all components.
 104      * make sure we found something in the process.
 105      */
 106     if (NULL == *best_component) {
 107         opal_output_verbose(5, oshmem_sshmem_base_framework.framework_output,
 108                             "sshmem: base: runtime_query: "
 109                             "(%5s) No component selected!", "shmem");
 110         return OSHMEM_ERR_NOT_FOUND;
 111     }
 112 
 113     opal_output_verbose(5, oshmem_sshmem_base_framework.framework_output,
 114                         "sshmem: base: runtime_query: "
 115                         "(%5s) Selected component [%s]", "shmem",
 116                         (*best_component)->mca_component_name);
 117 
 118     /* close the non-selected components */
 119     (void) mca_base_framework_components_close (&oshmem_sshmem_base_framework,
 120                                                 (mca_base_component_t *)(*best_component));
 121 
 122     return OSHMEM_SUCCESS;
 123 }
 124 
 125 /* ////////////////////////////////////////////////////////////////////////// */
 126 int
 127 mca_sshmem_base_select(void)
 128 {
 129     mca_sshmem_base_component_2_0_0_t *best_component = NULL;
 130     mca_sshmem_base_module_2_0_0_t *best_module = NULL;
 131     /* select the best component */
 132     if (OSHMEM_SUCCESS != mca_sshmem_base_runtime_query(
 133                                 (mca_base_module_t **)&best_module,
 134                                 (mca_base_component_t **)&best_component)) {
 135         /* it is NOT okay if we don't find a module because we need at
 136          * least one shared memory backing facility component instance.
 137          */
 138         return OSHMEM_ERROR;
 139     }
 140 
 141     /* save the winner */
 142     mca_sshmem_base_component = best_component;
 143     mca_sshmem_base_module    = best_module;
 144     mca_sshmem_base_selected  = true;
 145 
 146     /* initialize the winner */
 147     if (NULL != mca_sshmem_base_module) {
 148         return mca_sshmem_base_module->module_init();
 149     }
 150     else {
 151         return OSHMEM_ERROR;
 152     }
 153 }
 154 

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