File: atomic_base_select.c

package info (click to toggle)
openmpi 5.0.8-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,692 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (247 lines) | stat: -rw-r--r-- 7,372 bytes parent folder | download | duplicates (7)
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
/*
 * Copyright (c) 2013      Mellanox Technologies, Inc.
 *                         All rights reserved.
 * Copyright (c) 2015      Research Organization for Information Science
 *                         and Technology (RIST). All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "oshmem_config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "oshmem/constants.h"

#include "opal/class/opal_list.h"
#include "oshmem/util/oshmem_util.h"
#include "oshmem/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_component_repository.h"

#include "oshmem/mca/atomic/atomic.h"
#include "oshmem/mca/atomic/base/base.h"

/*
 * Global variables; most of which are loaded by back-ends of MCA
 * variables
 */
mca_atomic_base_module_t mca_atomic = {{0}};

/*
 * Local types
 */
struct avail_com_t {
    opal_list_item_t super;

    int ac_priority;
    mca_atomic_base_module_t *ac_module;
};
typedef struct avail_com_t avail_com_t;

/*
 * Local functions
 */
static opal_list_t *check_components(opal_list_t * components);
static int check_one_component(const mca_base_component_t * component,
                               mca_atomic_base_module_1_0_0_t ** module);

static int query(const mca_base_component_t * component,
                 int *priority,
                 mca_atomic_base_module_1_0_0_t ** module);

static int query_1_0_0(const mca_atomic_base_component_1_0_0_t * atomic_component,
                       int *priority,
                       mca_atomic_base_module_1_0_0_t ** module);

/*
 * Stuff for the OBJ interface
 */
static OBJ_CLASS_INSTANCE(avail_com_t, opal_list_item_t, NULL, NULL);

/*
 * This function is called at the initialization.
 * It is used to select which atomic component will be
 * active for a given group.
 */
int mca_atomic_base_select(void)
{
    opal_list_t *selectable;
    opal_list_item_t *item;

    /* Announce */
    ATOMIC_VERBOSE(10,
                   "atomic:base:atomic_select: Checking all available modules");
    selectable = check_components(&oshmem_atomic_base_framework.framework_components);

    /* Upon return from the above, the modules list will contain the
     list of modules that returned (priority >= 0).  If we have no
     atomic modules available, then print error and return. */
    if (NULL == selectable) {
        /* There's no modules available */
        return OSHMEM_ERROR;
    }

    /* do the selection loop */
    for (item = opal_list_remove_first(selectable); NULL != item; item =
            opal_list_remove_first(selectable)) {
        avail_com_t *avail = (avail_com_t *) item;

        /* Set module having the highest priority */
        memcpy(&mca_atomic, avail->ac_module, sizeof(mca_atomic));

        OBJ_RELEASE(avail->ac_module);
        OBJ_RELEASE(avail);
        /* check correctness */
        if (!(mca_atomic.atomic_fadd)  || !(mca_atomic.atomic_add) ||
            !(mca_atomic.atomic_fand)  || !(mca_atomic.atomic_and) ||
            !(mca_atomic.atomic_for)   || !(mca_atomic.atomic_or) ||
            !(mca_atomic.atomic_fxor)  || !(mca_atomic.atomic_xor) ||
            !(mca_atomic.atomic_cswap) || !(mca_atomic.atomic_swap)) {
            return OSHMEM_ERR_NOT_FOUND;
        }
    }

    /* Done with the list from the check_components() call so release it. */
    OBJ_RELEASE(selectable);

    return OSHMEM_SUCCESS;
}

static int avail_com_compare (opal_list_item_t **a,
                               opal_list_item_t **b)
{
    avail_com_t *acom = (avail_com_t *) *a;
    avail_com_t *bcom = (avail_com_t *) *b;

    if (acom->ac_priority > bcom->ac_priority) {
        return 1;
    } else if (acom->ac_priority < bcom->ac_priority) {
        return -1;
    }

    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.
 */
static opal_list_t *check_components(opal_list_t *components)
{
    int priority;
    const mca_base_component_t *component;
    mca_base_component_list_item_t *cli;
    mca_atomic_base_module_1_0_0_t *module;
    opal_list_t *selectable;
    avail_com_t *avail;

    /* Make a list of the components that query successfully */
    selectable = OBJ_NEW(opal_list_t);

    /* Scan through the list of components */
    OPAL_LIST_FOREACH(cli, &oshmem_atomic_base_framework.framework_components, mca_base_component_list_item_t) {
        component = cli->cli_component;

        priority = check_one_component(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_com_t);
            avail->ac_priority = priority;
            avail->ac_module = module;

            opal_list_append(selectable, &avail->super);
        }
    }

    /* If we didn't find any available components, return an error */
    if (0 == opal_list_get_size(selectable)) {
        OBJ_RELEASE(selectable);
        return NULL;
    }

    /* Put this list in priority order */
    opal_list_sort(selectable, avail_com_compare);

    /* All done */
    return selectable;
}

/*
 * Check a single component
 */
static int check_one_component(const mca_base_component_t *component,
                               mca_atomic_base_module_1_0_0_t **module)
{
    int err;
    int priority = -1;

    err = query(component, &priority, module);

    if (OSHMEM_SUCCESS == err) {
        priority = (priority < 100) ? priority : 100;
        ATOMIC_VERBOSE(10,
                       "atomic:base:atomic_select: component available: %s, priority: %d",
                       component->mca_component_name, priority);

    } else {
        priority = -1;
        ATOMIC_VERBOSE(10,
                       "atomic:base:atomic_select: component not available: %s",
                       component->mca_component_name);
    }

    return priority;
}

/**************************************************************************
 * Query functions
 **************************************************************************/

/*
 * Take any version of a atomic module, query it, and return the right
 * module struct
 */
static int query(const mca_base_component_t *component,
                 int *priority,
                 mca_atomic_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 mca_atomic_base_component_1_0_0_t *atomic100 =
                (mca_atomic_base_component_1_0_0_t *) component;

        return query_1_0_0(atomic100, priority, module);
    }

    /* Unknown atomic API version -- return error */

    return OSHMEM_ERROR;
}

static int query_1_0_0(const mca_atomic_base_component_1_0_0_t *component,
                       int *priority,
                       mca_atomic_base_module_1_0_0_t **module)
{
    mca_atomic_base_module_1_0_0_t *ret;

    /* There's currently no need for conversion */

    ret = component->atomic_query(priority);
    if (NULL != ret) {
        *module = ret;
        return OSHMEM_SUCCESS;
    }

    return OSHMEM_ERROR;
}