1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
|
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2009 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007 Lawrence Livermore National Security, LLC. All
* rights reserved.
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2008-2015 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2020 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mpi.h"
#include "ompi/constants.h"
#include "opal/util/output.h"
#include "opal/class/opal_list.h"
#include "opal/class/opal_object.h"
#include "ompi/mca/mca.h"
#include "opal/mca/base/base.h"
#include "ompi/op/op.h"
#include "ompi/mca/op/op.h"
#include "ompi/mca/op/base/base.h"
#include "ompi/mca/op/base/functions.h"
/*
* Local types
*/
typedef struct avail_op_t {
opal_list_item_t super;
int ao_priority;
ompi_op_base_module_1_0_0_t *ao_module;
} avail_op_t;
/*
* Local functions
*/
static opal_list_t *check_components(opal_list_t *components,
ompi_op_t *op);
static int check_one_component(ompi_op_t *op,
const mca_base_component_t *component,
ompi_op_base_module_1_0_0_t **module);
static int query(const mca_base_component_t *component,
ompi_op_t *op, int *priority,
ompi_op_base_module_1_0_0_t **module);
static int query_1_0_0(const ompi_op_base_component_1_0_0_t *op_component,
ompi_op_t *op, int *priority,
ompi_op_base_module_1_0_0_t **module);
/*
* Stuff for the OBJ interface
*/
static OBJ_CLASS_INSTANCE(avail_op_t, opal_list_item_t, NULL, NULL);
/*
* This function is called at the initialization time of every
* *intrinsic* MPI_Op (it is *not* used for user-defined MPI_Ops!).
* It is used to select which op component(s) will be active for a
* given MPI_Op.
*
* This selection logic is not for the weak.
*/
int ompi_op_base_op_select(ompi_op_t *op)
{
int i, ret;
opal_list_t *selectable;
opal_list_item_t *item;
ompi_op_base_module_t *module;
/* Announce */
opal_output_verbose(10, ompi_op_base_framework.framework_output,
"op:base:op_select: new op: %s",
op->o_name);
/* Make a module for all the base functions so that other modules
can RETAIN it (vs. having NULL for the base function modules,
and forcing all other modules to check for NULL before calling
RETAIN). */
module = OBJ_NEW(ompi_op_base_module_t);
/* Initialize all functions to point to the corresponding base
functions. Set the corresponding module pointers to NULL,
indicating that these are base functions with no corresponding
module. */
memset(&op->o_func, 0, sizeof(op->o_func));
memset(&op->o_3buff_intrinsic, 0, sizeof(op->o_3buff_intrinsic));
for (i = 0; i < OMPI_OP_BASE_TYPE_MAX; ++i) {
op->o_func.intrinsic.fns[i] =
ompi_op_base_functions[op->o_f_to_c_index][i];
op->o_func.intrinsic.modules[i] = module;
OBJ_RETAIN(module);
op->o_3buff_intrinsic.fns[i] =
ompi_op_base_3buff_functions[op->o_f_to_c_index][i];
op->o_3buff_intrinsic.modules[i] = module;
OBJ_RETAIN(module);
}
/* Offset the initial OBJ_NEW */
OBJ_RELEASE(module);
/* Check for any components that want to run. It's not an error
if there are none; we'll just use all the base functions in
this case. */
opal_output_verbose(10, ompi_op_base_framework.framework_output,
"op:base:op_select: Checking all available components");
selectable = check_components(&ompi_op_base_framework.framework_components, op);
/* Do the selection loop. The selectable list is in priority
order; lowest priority first. */
for (item = opal_list_remove_first(selectable);
NULL != item;
item = opal_list_remove_first(selectable)) {
avail_op_t *avail = (avail_op_t*) item;
/* Enable the module */
if (NULL != avail->ao_module->opm_enable) {
ret = avail->ao_module->opm_enable(avail->ao_module, op);
if (OMPI_SUCCESS != ret) {
/* If the module fails to enable, just release it and move
on */
OBJ_RELEASE(avail->ao_module);
OBJ_RELEASE(avail);
continue;
}
}
/* Copy over the non-NULL pointers */
for (i = 0; i < OMPI_OP_BASE_TYPE_MAX; ++i) {
/* 2-buffer variants */
if (NULL != avail->ao_module->opm_fns[i]) {
OBJ_RELEASE(op->o_func.intrinsic.modules[i]);
op->o_func.intrinsic.fns[i] = avail->ao_module->opm_fns[i];
op->o_func.intrinsic.modules[i] = avail->ao_module;
OBJ_RETAIN(avail->ao_module);
}
/* 3-buffer variants */
if (NULL != avail->ao_module->opm_3buff_fns[i]) {
OBJ_RELEASE(op->o_func.intrinsic.modules[i]);
op->o_3buff_intrinsic.fns[i] =
avail->ao_module->opm_3buff_fns[i];
op->o_3buff_intrinsic.modules[i] = avail->ao_module;
OBJ_RETAIN(avail->ao_module);
}
}
/* release the original module reference and the list item */
OBJ_RELEASE(avail->ao_module);
OBJ_RELEASE(avail);
}
/* Done with the list from the check_components() call so release it. */
OBJ_RELEASE(selectable);
/* Sanity check: for intrinsic MPI_Ops, we should have exactly the
same pointers non-NULL as the corresponding initial table row
in ompi_op_base_functions / ompi_op_base_3buff_functions. The
values may be different, of course, but the pattern of
NULL/non-NULL should be exactly the same. */
for (i = 0; i < OMPI_OP_BASE_TYPE_MAX; ++i) {
if ((NULL == ompi_op_base_functions[op->o_f_to_c_index][i] &&
NULL != op->o_func.intrinsic.fns[i]) ||
(NULL != ompi_op_base_functions[op->o_f_to_c_index][i] &&
NULL == op->o_func.intrinsic.fns[i])) {
/* Oops -- we found a mismatch. This shouldn't happen; so
go release everything and return an error (yes, re-use
the "i" index because we're going to return without
completing the outer loop). */
for (i = 0; i < OMPI_OP_BASE_TYPE_MAX; ++i) {
OBJ_RELEASE(op->o_func.intrinsic.modules[i]);
op->o_func.intrinsic.modules[i] = NULL;
op->o_func.intrinsic.fns[i] = NULL;
}
return OMPI_ERR_NOT_FOUND;
}
}
return OMPI_SUCCESS;
}
static int avail_op_compare(opal_list_item_t **itema,
opal_list_item_t **itemb)
{
avail_op_t *availa = (avail_op_t *) *itema;
avail_op_t *availb = (avail_op_t *) *itemb;
if (availa->ao_priority > availb->ao_priority) {
return 1;
} else if (availa->ao_priority < availb->ao_priority) {
return -1;
} else {
return 0;
}
}
/*
* For each module in the list, check and see if it wants to run, and
* do the resulting priority comparison. Make a list of modules to be
* only those who returned that they want to run, and put them in
* priority order (lowest to highest).
*/
static opal_list_t *check_components(opal_list_t *components,
ompi_op_t *op)
{
int priority;
mca_base_component_list_item_t *cli;
const mca_base_component_t *component;
ompi_op_base_module_1_0_0_t *module;
opal_list_t *selectable;
avail_op_t *avail;
/* Make a list of the components that query successfully */
selectable = OBJ_NEW(opal_list_t);
/* Scan through the list of components. This nested loop is O(N^2),
but we should never have too many components and/or names, so this
*hopefully* shouldn't matter... */
OPAL_LIST_FOREACH(cli, components, mca_base_component_list_item_t) {
component = cli->cli_component;
priority = check_one_component(op, component, &module);
if (priority >= 0) {
/* We have a component that indicated that it wants to run by
giving us a module */
avail = OBJ_NEW(avail_op_t);
avail->ao_priority = priority;
avail->ao_module = module;
opal_list_append(selectable, (opal_list_item_t*)avail);
}
}
opal_list_sort(selectable, avail_op_compare);
/* All done (even if the list is empty; that's ok) */
return selectable;
}
/*
* Check a single component
*/
static int check_one_component(ompi_op_t *op,
const mca_base_component_t *component,
ompi_op_base_module_1_0_0_t **module)
{
int err;
int priority = -1;
err = query(component, op, &priority, module);
if (OMPI_SUCCESS == err) {
priority = (priority < 100) ? priority : 100;
opal_output_verbose(10, ompi_op_base_framework.framework_output,
"op:base:op_select: component available: %s, priority: %d",
component->mca_component_name, priority);
} else {
priority = -1;
opal_output_verbose(10, ompi_op_base_framework.framework_output,
"op:base:op_select: component not available: %s",
component->mca_component_name);
}
return priority;
}
/**************************************************************************
* Query functions
**************************************************************************/
/*
* Take any version of a op module, query it, and return the right
* module struct
*/
static int query(const mca_base_component_t *component,
ompi_op_t *op,
int *priority, ompi_op_base_module_1_0_0_t **module)
{
*module = NULL;
if (1 == component->mca_type_major_version &&
0 == component->mca_type_minor_version &&
0 == component->mca_type_release_version) {
const ompi_op_base_component_1_0_0_t *op100 =
(ompi_op_base_component_1_0_0_t *) component;
return query_1_0_0(op100, op, priority, module);
}
/* Unknown op API version -- return error */
return OMPI_ERROR;
}
static int query_1_0_0(const ompi_op_base_component_1_0_0_t *component,
ompi_op_t *op, int *priority,
ompi_op_base_module_1_0_0_t **module)
{
ompi_op_base_module_1_0_0_t *ret;
/* There's currently no need for conversion */
ret = component->opc_op_query(op, priority);
if (NULL != ret) {
*module = ret;
return OMPI_SUCCESS;
}
return OMPI_ERROR;
}
|