root/ompi/mca/pml/v/pml_v_component.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_pml_v_component_register
  2. mca_pml_v_component_open
  3. mca_pml_v_component_close
  4. mca_pml_v_component_parasite_finalize
  5. mca_pml_v_component_parasite_close
  6. mca_pml_v_component_init
  7. mca_pml_v_component_finalize
  8. mca_pml_v_enable

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2015 The Trustees of the University of Tennessee.
   4  *                         All rights reserved.
   5  * Copyright (c) 2010-2018 Cisco Systems, Inc.  All rights reserved
   6  * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
   7  *                         reserved.
   8  * Copyright (c) 2016      Research Organization for Information Science
   9  *                         and Technology (RIST). All rights reserved.
  10  * Copyright (c) 2017      IBM Corporation. All rights reserved.
  11  * Copyright (c) 2018      Amazon.com, Inc. or its affiliates.  All Rights reserved.
  12  * $COPYRIGHT$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 
  19 #include "ompi_config.h"
  20 
  21 #include "opal/mca/base/base.h"
  22 #include "opal/mca/base/mca_base_component_repository.h"
  23 #include "opal/util/printf.h"
  24 #include "opal/util/string_copy.h"
  25 #include "ompi/constants.h"
  26 #include "ompi/mca/pml/base/base.h"
  27 #include "ompi/mca/vprotocol/vprotocol.h"
  28 #include "ompi/mca/vprotocol/base/base.h"
  29 #include "pml_v_output.h"
  30 #include "pml_v.h"
  31 
  32 static int mca_pml_v_component_register(void);
  33 static int mca_pml_v_component_open(void);
  34 static int mca_pml_v_component_close(void);
  35 static int mca_pml_v_component_parasite_close(void);
  36 
  37 static mca_pml_base_module_t *mca_pml_v_component_init(int* priority, bool enable_progress_threads, bool enable_mpi_thread_multiple);
  38 static int mca_pml_v_component_finalize(void);
  39 static int mca_pml_v_component_parasite_finalize(void);
  40 
  41 static int mca_pml_v_enable(bool enable);
  42 
  43 mca_pml_base_component_2_0_0_t mca_pml_v_component =
  44 {
  45     /* First, the mca_base_component_t struct containing meta
  46      * information about the component itself */
  47     .pmlm_version = {
  48         MCA_PML_BASE_VERSION_2_0_0,
  49         .mca_component_name = "v",
  50         MCA_BASE_MAKE_VERSION(component, OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION,
  51                               OMPI_RELEASE_VERSION),
  52         .mca_open_component = mca_pml_v_component_open,
  53         .mca_close_component = mca_pml_v_component_close,
  54         .mca_register_component_params = mca_pml_v_component_register,
  55     },
  56     .pmlm_data = {
  57         MCA_BASE_METADATA_PARAM_NONE /* Component is not checkpointable */
  58     },
  59 
  60     .pmlm_init = mca_pml_v_component_init,
  61     .pmlm_finalize = mca_pml_v_component_finalize,
  62 };
  63 
  64 static bool pml_v_enable_progress_treads = OPAL_ENABLE_PROGRESS_THREADS;
  65 static bool pml_v_enable_mpi_thread_multiple = 1;
  66 
  67 static char *ompi_pml_vprotocol_include_list;
  68 static char *ompi_pml_v_output;
  69 static int ompi_pml_v_verbose;
  70 
  71 /*******************************************************************************
  72  * MCA level functions - parasite setup
  73  */
  74 static int mca_pml_v_component_register(void)
  75 {
  76     int var_id;
  77 
  78     ompi_pml_v_output = "stderr";
  79     (void) mca_base_component_var_register(&mca_pml_v_component.pmlm_version,
  80                                            "output", NULL, MCA_BASE_VAR_TYPE_STRING,
  81                                            NULL, 0, 0, OPAL_INFO_LVL_9,
  82                                            MCA_BASE_VAR_SCOPE_READONLY,
  83                                            &ompi_pml_v_output);
  84 
  85     ompi_pml_v_verbose = 0;
  86     (void) mca_base_component_var_register(&mca_pml_v_component.pmlm_version,
  87                                            "verbose", "Verbosity of the pml v component",
  88                                            MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
  89                                            OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY,
  90                                            &ompi_pml_v_verbose);
  91 
  92     ompi_pml_vprotocol_include_list = "";
  93     /* This parameter needs to go away if pml/v is unloaded so register it with a pml/v name */
  94     var_id = mca_base_component_var_register(&mca_pml_v_component.pmlm_version,
  95                                              "vprotocol", "Specify a specific vprotocol to use",
  96                                              MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
  97                                              OPAL_INFO_LVL_9, MCA_BASE_VAR_SCOPE_READONLY,
  98                                              &ompi_pml_vprotocol_include_list);
  99     (void) mca_base_var_register_synonym(var_id, "ompi", "vprotocol", NULL, NULL, 0);
 100 
 101     return OMPI_SUCCESS;
 102 }
 103 
 104 static int mca_pml_v_component_open(void)
 105 {
 106     int rc;
 107     ompi_pml_v_output_open(ompi_pml_v_output, ompi_pml_v_verbose);
 108 
 109     V_OUTPUT_VERBOSE(500, "loaded");
 110 
 111     mca_vprotocol_base_set_include_list(ompi_pml_vprotocol_include_list);
 112 
 113     if (OMPI_SUCCESS != (rc = mca_base_framework_open(&ompi_vprotocol_base_framework, 0))) {
 114         return rc;
 115     }
 116 
 117     if( NULL == mca_vprotocol_base_include_list ) {
 118         ompi_pml_v_output_close();
 119         return mca_base_framework_close(&ompi_vprotocol_base_framework);
 120     }
 121 
 122     return rc;
 123 }
 124 
 125 static int mca_pml_v_component_close(void)
 126 {
 127     if( NULL == mca_vprotocol_base_include_list ) {
 128         /* Nothing to do, let's just close and move away */
 129         return OMPI_SUCCESS;
 130     }
 131 
 132     /* Save original PML before making any changes  */
 133     mca_pml_v.host_pml_component = mca_pml_base_selected_component;
 134     mca_pml_v.host_pml = mca_pml;
 135     mca_pml_v.host_request_fns = ompi_request_functions;
 136 
 137     /* Do not load anything if no FT protocol is selected */
 138     if (NULL != mca_vprotocol_base_include_list && !mca_vprotocol_base_include_list[0]) {
 139         return mca_pml_v_component_parasite_close();
 140     }
 141 
 142     /* Make sure to close out output even if vprotocol isn't in use */
 143     ompi_pml_v_output_close ();
 144 
 145     /* Mark that we have changed something */
 146     char *new_name;
 147     opal_asprintf(&new_name, "%s]v%s",
 148              mca_pml_v.host_pml_component.pmlm_version.mca_component_name,
 149              mca_vprotocol_component.pmlm_version.mca_component_name);
 150     opal_string_copy(mca_pml_base_selected_component.pmlm_version.mca_component_name,
 151                      new_name,
 152                      sizeof(mca_pml_base_selected_component.pmlm_version.mca_component_name));
 153     free(new_name);
 154 
 155     /* Replace finalize */
 156     mca_pml_base_selected_component.pmlm_finalize =
 157         mca_pml_v_component_parasite_finalize;
 158 
 159     /* Make sure we get initialized if some Vprotocol is enabled */
 160     mca_pml.pml_enable = mca_pml_v_enable;
 161 
 162     return OMPI_SUCCESS;
 163 }
 164 
 165 /*******************************************************************************
 166  * Parasite cleanup
 167  */
 168 static int mca_pml_v_component_parasite_finalize(void)
 169 {
 170     mca_base_component_list_item_t *cli = NULL;
 171 
 172     V_OUTPUT_VERBOSE(500, "parasite_finalize");
 173 
 174     /* Make sure we'll get closed again with the true close function */
 175     mca_pml_v_component.pmlm_version.mca_close_component =
 176         mca_pml_v_component_parasite_close;
 177     cli = OBJ_NEW(mca_base_component_list_item_t);
 178     cli->cli_component = (mca_base_component_t *) &mca_pml_v_component;
 179     opal_list_prepend(&ompi_pml_base_framework.framework_components,
 180                       (opal_list_item_t *) cli);
 181 
 182     /* finalize vprotocol component */
 183     if(mca_vprotocol_base_selected())
 184         mca_vprotocol_component.pmlm_finalize();
 185 
 186     if(mca_pml_v.host_pml_component.pmlm_finalize != NULL)
 187         return mca_pml_v.host_pml_component.pmlm_finalize();
 188     else
 189         return OMPI_SUCCESS;
 190 }
 191 
 192 static int mca_pml_v_component_parasite_close(void)
 193 {
 194     V_OUTPUT_VERBOSE(500, "parasite_close: Ok, I accept to die and let %s component finish",
 195                           mca_pml_v.host_pml_component.pmlm_version.mca_component_name);
 196     mca_pml_base_selected_component = mca_pml_v.host_pml_component;
 197 
 198     (void) mca_base_framework_close(&ompi_vprotocol_base_framework);
 199     ompi_pml_v_output_close();
 200 
 201     mca_pml.pml_enable = mca_pml_v.host_pml.pml_enable;
 202     /* don't need to call the host component's close: pml_base will do it */
 203     return OMPI_SUCCESS; /* ignore any errors as we are leaving anyway */
 204 }
 205 
 206 
 207 /*******************************************************************************
 208  * Init/finalize for MCA PML components
 209  */
 210 static mca_pml_base_module_t *mca_pml_v_component_init(int *priority,
 211                                                       bool enable_progress_threads,
 212                                                       bool enable_mpi_thread_multiple)
 213 {
 214     V_OUTPUT_VERBOSE(1, "init: I'm not supposed to be here until BTL loading stuff gets fixed!? That's strange...");
 215 
 216     pml_v_enable_progress_treads = enable_progress_threads;
 217     pml_v_enable_mpi_thread_multiple = enable_mpi_thread_multiple;
 218 
 219     /* I NEVER want to be the selected PML, so I report less than possible
 220      * priority and a NULL module
 221      */
 222     *priority = -1;
 223     return NULL;
 224 }
 225 
 226 static int mca_pml_v_component_finalize(void)
 227 {
 228     V_OUTPUT_VERBOSE(1, "finalize: I'm not supposed to be here until BTL loading stuff gets fixed!? That's strange...");
 229     /* Nothing to do here. We are not sure we need to be unloaded or not at
 230      * this stage
 231      */
 232     return OMPI_SUCCESS;
 233 }
 234 
 235 
 236 /*******************************************************************************
 237  * Enable the PML V (and initialize the Vprotocol)
 238  */
 239 static int mca_pml_v_enable(bool enable)
 240 {
 241     int ret;
 242 
 243     /* Enable the real PML (no threading issues there as threads are started
 244      * later)
 245      */
 246     ret = mca_pml_v.host_pml.pml_enable(enable);
 247     if(OMPI_SUCCESS != ret) return ret;
 248 
 249     if(enable) {
 250         /* Check if a protocol have been selected during init */
 251         if(! mca_vprotocol_base_selected())
 252             mca_vprotocol_base_select(pml_v_enable_progress_treads,
 253                                       pml_v_enable_mpi_thread_multiple);
 254 
 255         /* Check if we succeeded selecting a protocol */
 256         if(mca_vprotocol_base_selected()) {
 257             V_OUTPUT_VERBOSE(1, "I don't want to die: I will parasite %s host component %s with %s %s",
 258                              mca_pml_base_selected_component.pmlm_version.mca_type_name,
 259                              mca_pml_base_selected_component.pmlm_version.mca_component_name,
 260                              mca_vprotocol_component.pmlm_version.mca_type_name,
 261                              mca_vprotocol_component.pmlm_version.mca_component_name);
 262 
 263             ret = mca_vprotocol_base_parasite();
 264             if(OMPI_SUCCESS != ret) return ret;
 265             if(mca_vprotocol.enable)
 266                 return mca_vprotocol.enable(enable);
 267             else
 268                 return OMPI_SUCCESS;
 269         }
 270         V_OUTPUT_VERBOSE(1, "No fault tolerant protocol selected. All are unloaded");
 271     }
 272     /* Disable */
 273     mca_pml = mca_pml_v.host_pml;
 274     mca_pml.pml_enable = mca_pml_v_enable;
 275     /* /!\ This is incorrect if another component also changed the requests */
 276     ompi_request_functions = mca_pml_v.host_request_fns;
 277     return OMPI_SUCCESS;
 278 }

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