root/ompi/mca/vprotocol/base/vprotocol_base_select.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_vprotocol_base_select

   1 /*
   2  * Copyright (c) 2004-2007 The Trustees of the University of Tennessee.
   3  *                         All rights reserved.
   4  * Copyright (c) 2012-2013 Los Alamos National Security, Inc.  All rights reserved.
   5  * Copyright (c) 2015      Research Organization for Information Science
   6  *                         and Technology (RIST). All rights reserved.
   7  * $COPYRIGHT$
   8  *
   9  * Additional copyrights may follow
  10  *
  11  * $HEADER$
  12  */
  13 
  14 #include "ompi_config.h"
  15 
  16 #include <string.h>
  17 
  18 #include "base.h"
  19 #include "ompi/mca/mca.h"
  20 #include "opal/mca/base/base.h"
  21 #include "ompi/mca/pml/v/pml_v_output.h"
  22 
  23 mca_vprotocol_base_module_t mca_vprotocol = {0};
  24 mca_vprotocol_base_component_t mca_vprotocol_component = {
  25     {MCA_VPROTOCOL_BASE_VERSION_0_0_0} /* Initialized with invalid version */
  26 };
  27 
  28 typedef struct opened_component_t {
  29     opal_list_item_t super;
  30     mca_vprotocol_base_component_t *om_component;
  31 } opened_component_t;
  32 
  33 
  34 /*
  35  * Function for selecting one component from all those that are
  36  * available.
  37  *
  38  * Call the init function on all available components and get their
  39  * priorities.  Select the component with the highest priority.  All
  40  * other components will be closed and unloaded.  The selected component
  41  * will have all of its function pointers saved and returned to the
  42  * caller.
  43  */
  44 int mca_vprotocol_base_select(bool enable_progress_threads,
  45                               bool enable_mpi_threads)
  46 {
  47     int priority = 0, best_priority = -1;
  48     opal_list_item_t *item = NULL;
  49     mca_base_component_list_item_t *cli = NULL;
  50     mca_vprotocol_base_component_t *component = NULL, *best_component = NULL;
  51     mca_vprotocol_base_module_t *module = NULL, *best_module = NULL;
  52     opal_list_t opened;
  53     opened_component_t *om = NULL;
  54 
  55     /* Traverse the list of available components; call their init
  56         functions. */
  57     OBJ_CONSTRUCT(&opened, opal_list_t);
  58     OPAL_LIST_FOREACH(cli, &ompi_vprotocol_base_framework.framework_components, mca_base_component_list_item_t)
  59     {
  60         component = (mca_vprotocol_base_component_t *) cli->cli_component;
  61 
  62         if (NULL == mca_vprotocol_base_include_list) {
  63             continue;
  64         }
  65 
  66         V_OUTPUT_VERBOSE(500, "vprotocol select: initializing %s component %s", component->pmlm_version.mca_type_name, component->pmlm_version.mca_component_name);
  67         if(strcmp(component->pmlm_version.mca_component_name,
  68                   mca_vprotocol_base_include_list)) {
  69             V_OUTPUT_VERBOSE(500, "This component is not in the include list: skipping %s", component->pmlm_version.mca_component_name);
  70             continue;
  71         }
  72         if(NULL == component->pmlm_init) {
  73             V_OUTPUT_VERBOSE(2, "vprotocol select: no init function; ignoring component %s", component->pmlm_version.mca_component_name);
  74             continue;
  75         }
  76         module = component->pmlm_init(&priority, enable_progress_threads, enable_mpi_threads);
  77         if (NULL == module) {
  78             V_OUTPUT_VERBOSE(2, "vprotocol select: init returned failure for component %s", component->pmlm_version.mca_component_name);
  79             continue;
  80         }
  81         V_OUTPUT_VERBOSE(500, "vprotocol select: component %s init returned priority %d", component->pmlm_version.mca_component_name, priority);
  82         if (priority > best_priority)
  83         {
  84             best_priority = priority;
  85             best_component = component;
  86             best_module = module;
  87         }
  88 
  89         om = (opened_component_t *) malloc(sizeof(opened_component_t));
  90         if (NULL == om) return OMPI_ERR_OUT_OF_RESOURCE;
  91         OBJ_CONSTRUCT(om, opal_list_item_t);
  92         om->om_component = component;
  93         opal_list_append(&opened, (opal_list_item_t*) om);
  94     }
  95 
  96     /* Finished querying all components.  Check for the bozo case. */
  97     if (NULL == best_component) {
  98         V_OUTPUT_VERBOSE(2, "vprotocol select: no protocol has returned a positive priority, fault tolerance is OFF");
  99     }
 100     else
 101     {
 102         /* Save the winner */
 103         mca_vprotocol_component = *best_component;
 104         mca_vprotocol = *best_module;
 105     }
 106 
 107     /* Finalize all non-selected components */
 108     for (item = opal_list_remove_first(&opened);
 109          NULL != item;
 110          item = opal_list_remove_first(&opened))
 111     {
 112         om = (opened_component_t *) item;
 113         if (om->om_component != best_component) {
 114             /* Finalize */
 115             V_OUTPUT_VERBOSE(500, "vprotocol select: component %s not selected / finalized", om->om_component->pmlm_version.mca_component_name);
 116             if (NULL != om->om_component->pmlm_finalize) {
 117                 /* Blatently ignore the return code (what would we do to
 118                 recover, anyway?  This component is going away, so errors
 119                 don't matter anymore) */
 120                 om->om_component->pmlm_finalize();
 121             }
 122         }
 123         OBJ_DESTRUCT(om);
 124         free(om);
 125     }
 126 
 127     mca_base_components_close(mca_pml_v.output,
 128                               &ompi_vprotocol_base_framework.framework_components,
 129                               (mca_base_component_t *) best_component);
 130 
 131     /* All done */
 132     if(best_component != NULL)
 133     {
 134         V_OUTPUT_VERBOSE(500, "vprotocol select: component %s selected", mca_vprotocol_component.pmlm_version.mca_component_name);
 135         return OMPI_SUCCESS;
 136     }
 137     else
 138         return OMPI_ERR_NOT_FOUND;
 139 }

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