This source file includes following definitions.
- ompi_op_base_op_select
- avail_op_compare
- check_components
- check_one_component
- query
- query_1_0_0
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  23 
  24 #include "ompi_config.h"
  25 
  26 #include <stdio.h>
  27 #include <string.h>
  28 #include <stdlib.h>
  29 
  30 #include "mpi.h"
  31 #include "ompi/constants.h"
  32 
  33 #include "opal/util/output.h"
  34 #include "opal/class/opal_list.h"
  35 #include "opal/class/opal_object.h"
  36 #include "ompi/mca/mca.h"
  37 #include "opal/mca/base/base.h"
  38 
  39 
  40 #include "ompi/op/op.h"
  41 #include "ompi/mca/op/op.h"
  42 #include "ompi/mca/op/base/base.h"
  43 #include "ompi/mca/op/base/functions.h"
  44 
  45 
  46 
  47 
  48 
  49 typedef struct avail_op_t {
  50     opal_list_item_t super;
  51 
  52     int ao_priority;
  53     ompi_op_base_module_1_0_0_t *ao_module;
  54 } avail_op_t;
  55 
  56 
  57 
  58 
  59 
  60 static opal_list_t *check_components(opal_list_t *components,
  61                                      ompi_op_t *op);
  62 static int check_one_component(ompi_op_t *op,
  63                                const mca_base_component_t *component,
  64                                ompi_op_base_module_1_0_0_t **module);
  65 
  66 static int query(const mca_base_component_t *component,
  67                  ompi_op_t *op, int *priority,
  68                  ompi_op_base_module_1_0_0_t **module);
  69 
  70 static int query_1_0_0(const ompi_op_base_component_1_0_0_t *op_component,
  71                        ompi_op_t *op, int *priority,
  72                        ompi_op_base_module_1_0_0_t **module);
  73 
  74 
  75 
  76 
  77 static OBJ_CLASS_INSTANCE(avail_op_t, opal_list_item_t, NULL, NULL);
  78 
  79 
  80 
  81 
  82 
  83 
  84 
  85 
  86 
  87 
  88 int ompi_op_base_op_select(ompi_op_t *op)
  89 {
  90     int i, ret;
  91     opal_list_t *selectable;
  92     opal_list_item_t *item;
  93     ompi_op_base_module_t *module;
  94 
  95     
  96     opal_output_verbose(10, ompi_op_base_framework.framework_output,
  97                         "op:base:op_select: new op: %s",
  98                         op->o_name);
  99 
 100     
 101 
 102 
 103 
 104     module = OBJ_NEW(ompi_op_base_module_t);
 105 
 106     
 107 
 108 
 109 
 110     memset(&op->o_func, 0, sizeof(op->o_func));
 111     memset(&op->o_3buff_intrinsic, 0, sizeof(op->o_3buff_intrinsic));
 112     for (i = 0; i < OMPI_OP_BASE_TYPE_MAX; ++i) {
 113         op->o_func.intrinsic.fns[i] =
 114             ompi_op_base_functions[op->o_f_to_c_index][i];
 115         op->o_func.intrinsic.modules[i] = module;
 116         OBJ_RETAIN(module);
 117         op->o_3buff_intrinsic.fns[i] =
 118             ompi_op_base_3buff_functions[op->o_f_to_c_index][i];
 119         op->o_3buff_intrinsic.modules[i] = module;
 120         OBJ_RETAIN(module);
 121     }
 122 
 123     
 124     OBJ_RELEASE(module);
 125 
 126     
 127 
 128 
 129     opal_output_verbose(10, ompi_op_base_framework.framework_output,
 130                         "op:base:op_select: Checking all available components");
 131     selectable = check_components(&ompi_op_base_framework.framework_components, op);
 132 
 133     
 134 
 135     for (item = opal_list_remove_first(selectable);
 136          NULL != item;
 137          item = opal_list_remove_first(selectable)) {
 138         avail_op_t *avail = (avail_op_t*) item;
 139 
 140         
 141         if (NULL != avail->ao_module->opm_enable) {
 142             ret = avail->ao_module->opm_enable(avail->ao_module, op);
 143             if (OMPI_SUCCESS != ret) {
 144                 
 145 
 146                 OBJ_RELEASE(avail->ao_module);
 147                 OBJ_RELEASE(avail);
 148                 continue;
 149             }
 150         }
 151 
 152         
 153         for (i = 0; i < OMPI_OP_BASE_TYPE_MAX; ++i) {
 154             
 155             if (NULL != avail->ao_module->opm_fns[i]) {
 156                 OBJ_RELEASE(op->o_func.intrinsic.modules[i]);
 157                 op->o_func.intrinsic.fns[i] = avail->ao_module->opm_fns[i];
 158                 op->o_func.intrinsic.modules[i] = avail->ao_module;
 159                 OBJ_RETAIN(avail->ao_module);
 160             }
 161 
 162             
 163             if (NULL != avail->ao_module->opm_3buff_fns[i]) {
 164                 OBJ_RELEASE(op->o_func.intrinsic.modules[i]);
 165                 op->o_3buff_intrinsic.fns[i] =
 166                     avail->ao_module->opm_3buff_fns[i];
 167                 op->o_3buff_intrinsic.modules[i] = avail->ao_module;
 168                 OBJ_RETAIN(avail->ao_module);
 169             }
 170         }
 171 
 172         
 173         OBJ_RELEASE(avail->ao_module);
 174         OBJ_RELEASE(avail);
 175     }
 176 
 177     
 178     OBJ_RELEASE(selectable);
 179 
 180     
 181 
 182 
 183 
 184 
 185     for (i = 0; i < OMPI_OP_BASE_TYPE_MAX; ++i) {
 186         if ((NULL == ompi_op_base_functions[op->o_f_to_c_index][i] &&
 187              NULL != op->o_func.intrinsic.fns[i]) ||
 188             (NULL != ompi_op_base_functions[op->o_f_to_c_index][i] &&
 189              NULL == op->o_func.intrinsic.fns[i])) {
 190             
 191 
 192 
 193 
 194             for (i = 0; i < OMPI_OP_BASE_TYPE_MAX; ++i) {
 195                 OBJ_RELEASE(op->o_func.intrinsic.modules[i]);
 196                 op->o_func.intrinsic.modules[i] = NULL;
 197                 op->o_func.intrinsic.fns[i] = NULL;
 198             }
 199             return OMPI_ERR_NOT_FOUND;
 200         }
 201     }
 202 
 203     return OMPI_SUCCESS;
 204 }
 205 
 206 static int avail_op_compare(opal_list_item_t **itema,
 207                             opal_list_item_t **itemb)
 208 {
 209     avail_op_t *availa = (avail_op_t *) itema;
 210     avail_op_t *availb = (avail_op_t *) itemb;
 211 
 212     if (availa->ao_priority > availb->ao_priority) {
 213         return 1;
 214     } else if (availa->ao_priority < availb->ao_priority) {
 215         return -1;
 216     } else {
 217         return 0;
 218     }
 219 }
 220 
 221 
 222 
 223 
 224 
 225 
 226 
 227 static opal_list_t *check_components(opal_list_t *components,
 228                                      ompi_op_t *op)
 229 {
 230     int priority;
 231     mca_base_component_list_item_t *cli;
 232     const mca_base_component_t *component;
 233     ompi_op_base_module_1_0_0_t *module;
 234     opal_list_t *selectable;
 235     avail_op_t *avail;
 236 
 237     
 238     selectable = OBJ_NEW(opal_list_t);
 239 
 240     
 241 
 242 
 243 
 244     OPAL_LIST_FOREACH(cli, components, mca_base_component_list_item_t) {
 245         component = cli->cli_component;
 246 
 247         priority = check_one_component(op, component, &module);
 248         if (priority >= 0) {
 249             
 250 
 251             avail = OBJ_NEW(avail_op_t);
 252             avail->ao_priority = priority;
 253             avail->ao_module = module;
 254 
 255             opal_list_append(selectable, (opal_list_item_t*)avail);
 256         }
 257     }
 258 
 259     opal_list_sort(selectable, avail_op_compare);
 260 
 261     
 262     return selectable;
 263 }
 264 
 265 
 266 
 267 
 268 
 269 static int check_one_component(ompi_op_t *op,
 270                                const mca_base_component_t *component,
 271                                ompi_op_base_module_1_0_0_t **module)
 272 {
 273     int err;
 274     int priority = -1;
 275 
 276     err = query(component, op, &priority, module);
 277 
 278     if (OMPI_SUCCESS == err) {
 279         priority = (priority < 100) ? priority : 100;
 280         opal_output_verbose(10, ompi_op_base_framework.framework_output,
 281                             "op:base:op_select: component available: %s, priority: %d",
 282                             component->mca_component_name, priority);
 283 
 284     } else {
 285         priority = -1;
 286         opal_output_verbose(10, ompi_op_base_framework.framework_output,
 287                             "op:base:op_select: component not available: %s",
 288                             component->mca_component_name);
 289     }
 290 
 291     return priority;
 292 }
 293 
 294 
 295 
 296 
 297 
 298 
 299 
 300 
 301 
 302 
 303 static int query(const mca_base_component_t *component,
 304                  ompi_op_t *op,
 305                  int *priority, ompi_op_base_module_1_0_0_t **module)
 306 {
 307     *module = NULL;
 308     if (1 == component->mca_type_major_version &&
 309         0 == component->mca_type_minor_version &&
 310         0 == component->mca_type_release_version) {
 311         const ompi_op_base_component_1_0_0_t *op100 =
 312             (ompi_op_base_component_1_0_0_t *) component;
 313 
 314         return query_1_0_0(op100, op, priority, module);
 315     }
 316 
 317     
 318 
 319     return OMPI_ERROR;
 320 }
 321 
 322 
 323 static int query_1_0_0(const ompi_op_base_component_1_0_0_t *component,
 324                        ompi_op_t *op, int *priority,
 325                        ompi_op_base_module_1_0_0_t **module)
 326 {
 327     ompi_op_base_module_1_0_0_t *ret;
 328 
 329     
 330 
 331     ret = component->opc_op_query(op, priority);
 332     if (NULL != ret) {
 333         *module = ret;
 334         return OMPI_SUCCESS;
 335     }
 336 
 337     return OMPI_ERROR;
 338 }