This source file includes following definitions.
- mca_spml_base_select
1
2
3
4
5
6
7
8
9
10
11
12
13 #include "oshmem_config.h"
14
15 #include <string.h>
16
17 #include "opal/util/show_help.h"
18 #include "opal/mca/base/base.h"
19 #include "opal/runtime/opal.h"
20
21 #include "oshmem/util/oshmem_util.h"
22 #include "oshmem/constants.h"
23 #include "oshmem/mca/spml/spml.h"
24 #include "oshmem/mca/spml/base/base.h"
25
26 #include "ompi/mca/bml/base/base.h"
27
28
29 typedef struct opened_component_t {
30 opal_list_item_t super;
31 mca_spml_base_component_t *om_component;
32 } opened_component_t;
33
34
35
36
37
38
39
40
41
42
43
44
45 int mca_spml_base_select(bool enable_progress_threads, bool enable_mpi_threads)
46 {
47 int i, priority = 0, best_priority = 0, num_spml = 0;
48 opal_list_item_t *item = NULL;
49 mca_base_component_list_item_t *cli = NULL;
50 mca_spml_base_component_t *component = NULL, *best_component = NULL;
51 mca_spml_base_module_t *module = NULL, *best_module = NULL;
52 opal_list_t opened;
53 opened_component_t *om = NULL;
54 bool found_spml;
55
56
57
58
59 best_priority = -1;
60 best_component = NULL;
61 module = NULL;
62 OBJ_CONSTRUCT(&opened, opal_list_t);
63 OPAL_LIST_FOREACH(cli, &oshmem_spml_base_framework.framework_components, mca_base_component_list_item_t) {
64 component = (mca_spml_base_component_t *) cli->cli_component;
65
66
67 found_spml = false;
68 for( i = 0; i < opal_pointer_array_get_size(&mca_spml_base_spml); i++) {
69 char * tmp_val = NULL;
70 tmp_val = (char *) opal_pointer_array_get_item(&mca_spml_base_spml, i);
71 if( NULL == tmp_val) {
72 continue;
73 }
74
75 if(0 == strncmp(component->spmlm_version.mca_component_name,
76 tmp_val, strlen(component->spmlm_version.mca_component_name)) ) {
77 found_spml = true;
78 break;
79 }
80 }
81
82 if (!found_spml
83 && opal_pointer_array_get_size(&mca_spml_base_spml)) {
84 SPML_VERBOSE( 10,
85 "select: component %s not in the include list",
86 component->spmlm_version.mca_component_name);
87
88 continue;
89 }
90
91
92 if (NULL == component->spmlm_init) {
93 SPML_VERBOSE( 10,
94 "select: no init function; ignoring component %s",
95 component->spmlm_version.mca_component_name);
96 continue;
97 }
98
99
100 num_spml++;
101
102
103 SPML_VERBOSE( 10,
104 "select: initializing %s component %s",
105 component->spmlm_version.mca_type_name, component->spmlm_version.mca_component_name);
106 priority = best_priority;
107 module = component->spmlm_init(&priority,
108 enable_progress_threads,
109 enable_mpi_threads);
110 if (NULL == module) {
111 SPML_VERBOSE( 10,
112 "select: init returned failure for component %s",
113 component->spmlm_version.mca_component_name);
114 continue;
115 }
116
117 SPML_VERBOSE( 10, "select: init returned priority %d", priority);
118
119 if (priority > best_priority) {
120 best_priority = priority;
121 best_component = component;
122 best_module = module;
123 }
124
125 om = (opened_component_t*) malloc(sizeof(opened_component_t));
126 if (NULL == om) {
127 return OSHMEM_ERR_OUT_OF_RESOURCE;
128 }
129 OBJ_CONSTRUCT(om, opal_list_item_t);
130 om->om_component = component;
131 opal_list_append(&opened, (opal_list_item_t*) om);
132 }
133
134
135
136 if (NULL == best_component) {
137 opal_show_help("help-oshmem-memheap.txt",
138 "find-available:none-found",
139 true,
140 "spml");
141 for (i = 0; i < opal_pointer_array_get_size(&mca_spml_base_spml); i++) {
142 char * tmp_val = NULL;
143 tmp_val = (char *) opal_pointer_array_get_item(&mca_spml_base_spml,
144 i);
145 if (NULL == tmp_val) {
146 continue;
147 }
148 ompi_rte_abort(1, "SPML %s cannot be selected", tmp_val);
149 }
150 if (0 == i) {
151 ompi_rte_abort(2,
152 "No spml component available. This shouldn't happen.");
153 }
154 }
155
156 SPML_VERBOSE( 10,
157 "selected %s best priority %d\n",
158 best_component->spmlm_version.mca_component_name, best_priority);
159
160
161 for (item = opal_list_remove_first(&opened);
162 NULL != item;
163 item = opal_list_remove_first(&opened)) {
164 om = (opened_component_t *) item;
165
166 if (om->om_component != best_component) {
167
168
169 if (NULL != om->om_component->spmlm_finalize) {
170
171
172
173
174
175 om->om_component->spmlm_finalize();
176 SPML_VERBOSE(10,
177 "select: component %s not selected / finalized",
178 om->om_component->spmlm_version.mca_component_name);
179 }
180 }
181 OBJ_DESTRUCT( om);
182 free(om);
183 }
184 OBJ_DESTRUCT( &opened);
185
186
187
188 mca_spml_base_selected_component = *best_component;
189 mca_spml = *best_module;
190 SPML_VERBOSE( 10,
191 "select: component %s selected",
192 mca_spml_base_selected_component.spmlm_version.mca_component_name);
193
194
195
196
197
198 mca_base_components_close(oshmem_spml_base_framework.framework_output,
199 &oshmem_spml_base_framework.framework_components,
200 (mca_base_component_t *) best_component);
201
202
203
204 return OSHMEM_SUCCESS;
205 }