File: sshmem_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 (154 lines) | stat: -rw-r--r-- 5,769 bytes parent folder | download | duplicates (9)
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
/*
 * Copyright (c) 2014      Mellanox Technologies, Inc.
 *                         All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "oshmem_config.h"

#include <string.h>

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

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

/*
 * globals
 */
bool mca_sshmem_base_selected = false;
const mca_sshmem_base_component_2_0_0_t *mca_sshmem_base_component = NULL;
const mca_sshmem_base_module_2_0_0_t *mca_sshmem_base_module = NULL;

/* ////////////////////////////////////////////////////////////////////////// */
static int
mca_sshmem_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;
    int priority = 0, best_priority = INT32_MIN;

    *best_module = NULL;
    *best_component = NULL;

    opal_output_verbose(10, oshmem_sshmem_base_framework.framework_output,
                        "sshmem: base: runtime_query: "
                        "Auto-selecting sshmem components");

    /* traverse the list of available components.
     * for each call their 'run-time query' functions to determine relative
     * priority.
     */
    OPAL_LIST_FOREACH(cli, &oshmem_sshmem_base_framework.framework_components, mca_base_component_list_item_t) {
        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 == ((mca_sshmem_base_component_2_0_0_t *)
                     component)->runtime_query) {
            opal_output_verbose(5, oshmem_sshmem_base_framework.framework_output,
                                "sshmem: base: runtime_query: "
                                "(sshmem) 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, oshmem_sshmem_base_framework.framework_output,
                            "sshmem: base: runtime_query: "
                            "(shmem) Querying component (run-time) [%s]",
                            component->mca_component_name);

        ((mca_sshmem_base_component_2_0_0_t *)
         component)->runtime_query(&module, &priority, NULL);

        /* 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, oshmem_sshmem_base_framework.framework_output,
                                "sshmem: base: runtime_query: "
                                "(sshmem) 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, oshmem_sshmem_base_framework.framework_output,
                            "sshmem: 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, oshmem_sshmem_base_framework.framework_output,
                            "sshmem: base: runtime_query: "
                            "(%5s) No component selected!", "shmem");
        return OSHMEM_ERR_NOT_FOUND;
    }

    opal_output_verbose(5, oshmem_sshmem_base_framework.framework_output,
                        "sshmem: base: runtime_query: "
                        "(%5s) Selected component [%s]", "shmem",
                        (*best_component)->mca_component_name);

    /* close the non-selected components */
    (void) mca_base_framework_components_close (&oshmem_sshmem_base_framework,
                                                (mca_base_component_t *)(*best_component));

    return OSHMEM_SUCCESS;
}

/* ////////////////////////////////////////////////////////////////////////// */
int
mca_sshmem_base_select(void)
{
    mca_sshmem_base_component_2_0_0_t *best_component = NULL;
    mca_sshmem_base_module_2_0_0_t *best_module = NULL;
    /* select the best component */
    if (OSHMEM_SUCCESS != mca_sshmem_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 OSHMEM_ERROR;
    }

    /* save the winner */
    mca_sshmem_base_component = best_component;
    mca_sshmem_base_module    = best_module;
    mca_sshmem_base_selected  = true;

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