File: shmem_base_select.c

package info (click to toggle)
openmpi 1.6.5-9.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 91,628 kB
  • ctags: 44,305
  • sloc: ansic: 408,966; cpp: 44,454; sh: 27,828; makefile: 10,486; asm: 3,882; python: 1,239; lex: 805; perl: 549; csh: 253; fortran: 232; f90: 126; tcl: 12
file content (220 lines) | stat: -rw-r--r-- 8,693 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2006 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-2013 Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2010-2011 Los Alamos National Security, LLC.
 *                         All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */

#include "opal/constants.h"
#include "opal/util/output.h"
#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_param.h"
#include "opal/mca/shmem/shmem.h"
#include "opal/mca/shmem/base/base.h"

/*
 * globals
 */
bool opal_shmem_base_selected = false;
const opal_shmem_base_component_2_0_0_t *opal_shmem_base_component = NULL;
const opal_shmem_base_module_2_0_0_t *opal_shmem_base_module = NULL;

/* ////////////////////////////////////////////////////////////////////////// */
char *
opal_shmem_base_best_runnable_component_name(void)
{
    mca_base_component_t *best_component = NULL;
    mca_base_module_t *best_module = NULL;

    opal_output_verbose(10, opal_shmem_base_output,
                        "shmem: base: best_runnable_component_name: "
                        "Searching for best runnable component.");
    /* select the best component so we can get its name. */
    if (OPAL_SUCCESS != opal_shmem_base_runtime_query(&best_module,
                                                      &best_component)) {
        /* fail! */
        return NULL;
    }
    else {
        if (NULL != best_component) {
            opal_output_verbose(10, opal_shmem_base_output,
                                "shmem: base: best_runnable_component_name: "
                                "Found best runnable component: (%s).",
                                best_component->mca_component_name);
            return strdup(best_component->mca_component_name);
        }
        else {
            opal_output_verbose(10, opal_shmem_base_output,
                                "shmem: base: best_runnable_component_name: "
                                "Could not find runnable component.");
            /* no component returned, so return NULL */
            return NULL;
        }
    }
}

/* ////////////////////////////////////////////////////////////////////////// */
int
opal_shmem_base_runtime_query(mca_base_module_t **best_module,
                              mca_base_component_t **best_component)
{
    mca_base_component_list_item_t *cli = NULL;
    mca_base_component_t *component = NULL;
    mca_base_module_t *module = NULL;
    opal_list_item_t *item = NULL;
    int priority = 0, best_priority = INT32_MIN;
    char *env_hint_name = NULL, *env_hint_val = NULL;

    *best_module = NULL;
    *best_component = NULL;

    opal_output_verbose(10, opal_shmem_base_output,
                        "shmem: base: runtime_query: "
                        "Auto-selecting shmem components");
    /* we are using a nonstandard name here because shmem_RUNTIME_QUERY_hint
     * is for internal use only!
     * see odls_base_default_fns.c for more details.
     */
    env_hint_name = mca_base_param_environ_variable("shmem_RUNTIME_QUERY_hint",
                                                    NULL, NULL);
    env_hint_val = getenv(env_hint_name);
    free(env_hint_name);

    /* traverse the list of available components.
     * for each call their 'run-time query' functions to determine relative
     * priority.
     */
    for (item  = opal_list_get_first(&opal_shmem_base_components_opened);
         item != opal_list_get_end(&opal_shmem_base_components_opened);
         item  = opal_list_get_next(item) ) {
        cli = (mca_base_component_list_item_t *)item;
        component = (mca_base_component_t *)cli->cli_component;

        /* if there is a run-time query function then use it. otherwise, skip
         * the component.
         */
        if (NULL == ((opal_shmem_base_component_2_0_0_t *)
                     component)->runtime_query) {
            opal_output_verbose(5, opal_shmem_base_output,
                                "shmem: base: runtime_query: "
                                "(shmem) Skipping component [%s]. It does not "
                                "implement a run-time query function",
                                component->mca_component_name);
            continue;
        }

        /* query this component for the module and priority */
        opal_output_verbose(5, opal_shmem_base_output,
                            "shmem: base: runtime_query: "
                            "(shmem) Querying component (run-time) [%s]",
                            component->mca_component_name);

        ((opal_shmem_base_component_2_0_0_t *)
         component)->runtime_query(&module, &priority, env_hint_val);

        /* if no module was returned, then skip component.
         * this probably means that the run-time test deemed the shared memory
         * backing facility unusable or unsafe.
         */
        if (NULL == module) {
            opal_output_verbose(5, opal_shmem_base_output,
                                "shmem: base: runtime_query: "
                                "(shmem) Skipping component [%s]. Run-time "
                                "Query failed to return a module",
                                component->mca_component_name);
            continue;
        }

        /* determine if this is the best module we have seen by looking the
         * priority
         */
        opal_output_verbose(5, opal_shmem_base_output,
                            "shmem: base: runtime_query: "
                            "(%5s) Query of component [%s] set priority to %d",
                            "shmem", component->mca_component_name, priority);
        if (priority > best_priority) {
            best_priority = priority;
            *best_module = module;
            *best_component = component;
        }
    }

    /* finished querying all components.
     * make sure we found something in the process.
     */
    if (NULL == *best_component) {
        opal_output_verbose(5, opal_shmem_base_output,
                            "shmem: base: runtime_query: "
                            "(%5s) No component selected!", "shmem");
        /* still close the non-selected components.
         */
        mca_base_components_close(opal_shmem_base_output,
                                  &opal_shmem_base_components_opened, 
                                  NULL, false);
        return OPAL_ERR_NOT_FOUND;
    }

    opal_output_verbose(5, opal_shmem_base_output,
                        "shmem: base: runtime_query: "
                        "(%5s) Selected component [%s]", "shmem",
                        (*best_component)->mca_component_name);
    /* close the non-selected components */
    mca_base_components_close(opal_shmem_base_output,
                              &opal_shmem_base_components_opened,
                              (mca_base_component_t *)(*best_component),
                              false);

    return OPAL_SUCCESS;
}

/* ////////////////////////////////////////////////////////////////////////// */
int
opal_shmem_base_select(void)
{
    opal_shmem_base_component_2_0_0_t *best_component = NULL;
    opal_shmem_base_module_2_0_0_t *best_module = NULL;
    /* select the best component */
    if (OPAL_SUCCESS != opal_shmem_base_runtime_query(
                                (mca_base_module_t **)&best_module,
                                (mca_base_component_t **)&best_component)) {
        /* it is NOT okay if we don't find a module because we need at
         * least one shared memory backing facility component instance.
         */
        return OPAL_ERROR;
    }

    /* save the winner */
    opal_shmem_base_component = best_component;
    opal_shmem_base_module    = best_module;
    opal_shmem_base_selected  = true;

    /* initialize the winner */
    if (NULL != opal_shmem_base_module) {
        return opal_shmem_base_module->module_init();
    }
    else {
        return OPAL_ERROR;
    }
}