This source file includes following definitions.
- mca_topo_base_comm_select
- fill_null_pointers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "ompi_config.h"
22
23 #include <string.h>
24
25 #include "opal/class/opal_list.h"
26 #include "opal/util/argv.h"
27 #include "opal/util/output.h"
28 #include "ompi/mca/mca.h"
29 #include "opal/mca/base/base.h"
30
31 #include "ompi/mca/topo/topo.h"
32 #include "ompi/mca/topo/base/base.h"
33 #include "ompi/communicator/communicator.h"
34
35
36
37
38 static void fill_null_pointers(int type, mca_topo_base_module_t *module);
39
40
41
42
43
44
45
46
47 struct queried_module_t {
48 opal_list_item_t super;
49 mca_topo_base_component_t *om_component;
50 mca_topo_base_module_t *om_module;
51 };
52 typedef struct queried_module_t queried_module_t;
53 static OBJ_CLASS_INSTANCE(queried_module_t, opal_list_item_t, NULL, NULL);
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 int mca_topo_base_comm_select(const ompi_communicator_t* comm,
71 mca_topo_base_module_t* preferred_module,
72 mca_topo_base_module_t** selected_module,
73 uint32_t type)
74 {
75 int priority;
76 int best_priority;
77 opal_list_item_t *item;
78 mca_base_component_list_item_t *cli;
79 mca_topo_base_component_t *component;
80 mca_topo_base_component_t *best_component;
81 mca_topo_base_module_t *module;
82 opal_list_t queried;
83 queried_module_t *om;
84 int err = MPI_SUCCESS;
85
86
87 if (OMPI_SUCCESS != (err = mca_topo_base_lazy_init())) {
88 return err;
89 }
90 opal_output_verbose(10, ompi_topo_base_framework.framework_output,
91 "topo:base:comm_select: new communicator: %s (cid %d)",
92 comm->c_name, comm->c_contextid);
93
94
95
96 if (NULL != preferred_module) {
97
98
99
100
101 opal_output_verbose(10, ompi_topo_base_framework.framework_output,
102 "topo:base:comm_select: Checking preferred component: %s",
103 preferred_module->topo_component->topoc_version.mca_component_name);
104
105
106
107 component = (mca_topo_base_component_t *)preferred_module->topo_component;
108 module = component->topoc_comm_query(comm, &priority, type);
109 if (NULL != module) {
110
111
112
113
114
115 fill_null_pointers(type, module);
116 *selected_module = module;
117 module->topo_component = component;
118 return OMPI_SUCCESS;
119 }
120
121
122
123
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137 best_component = NULL;
138 best_priority = -1;
139 OBJ_CONSTRUCT(&queried, opal_list_t);
140
141 OPAL_LIST_FOREACH(cli, &ompi_topo_base_framework.framework_components, mca_base_component_list_item_t) {
142 component = (mca_topo_base_component_t *) cli->cli_component;
143 opal_output_verbose(10, ompi_topo_base_framework.framework_output,
144 "select: initialising %s component %s",
145 component->topoc_version.mca_type_name,
146 component->topoc_version.mca_component_name);
147
148
149
150
151 if (NULL == component->topoc_comm_query) {
152 opal_output_verbose(10, ompi_topo_base_framework.framework_output,
153 "select: no query, ignoring the component");
154 } else {
155
156
157
158 module = component->topoc_comm_query(comm, &priority, type);
159
160 if (NULL == module) {
161
162
163
164 opal_output_verbose(10, ompi_topo_base_framework.framework_output,
165 "select: query returned failure");
166 } else {
167 opal_output_verbose(10, ompi_topo_base_framework.framework_output,
168 "select: query returned priority %d",
169 priority);
170
171
172
173 if (priority > best_priority) {
174 best_priority = priority;
175 best_component = component;
176 }
177
178 om = OBJ_NEW(queried_module_t);
179
180
181
182 if (NULL == om) {
183 OBJ_DESTRUCT(&queried);
184 return OMPI_ERR_OUT_OF_RESOURCE;
185 }
186 om->om_component = component;
187 om->om_module = module;
188 opal_list_append(&queried, (opal_list_item_t *)om);
189 }
190 }
191 }
192
193
194
195
196
197
198
199
200 if (NULL == best_component) {
201 return OMPI_ERR_NOT_FOUND;
202 }
203
204
205
206
207
208
209
210 for (item = opal_list_remove_first(&queried);
211 NULL != item;
212 item = opal_list_remove_first(&queried)) {
213 om = (queried_module_t *) item;
214 if (om->om_component == best_component) {
215
216
217
218
219
220
221
222
223
224 fill_null_pointers(type, om->om_module);
225 om->om_module->topo_component = best_component;
226 *selected_module = om->om_module;
227 } else {
228
229 opal_output_verbose(10, ompi_topo_base_framework.framework_output,
230 "select: component %s is not selected",
231 om->om_component->topoc_version.mca_component_name);
232 OBJ_RELEASE(om->om_module);
233 }
234 OBJ_RELEASE(om);
235 }
236
237 opal_output_verbose(10, ompi_topo_base_framework.framework_output,
238 "select: component %s selected",
239 best_component->topoc_version.mca_component_name);
240 return OMPI_SUCCESS;
241 }
242
243
244
245
246
247
248
249
250
251 static void fill_null_pointers(int type, mca_topo_base_module_t *module)
252 {
253 if( OMPI_COMM_CART == type ) {
254 if (NULL == module->topo.cart.cart_coords) {
255 module->topo.cart.cart_coords = mca_topo_base_cart_coords;
256 }
257 if (NULL == module->topo.cart.cart_create) {
258 module->topo.cart.cart_create = mca_topo_base_cart_create;
259 }
260 if (NULL == module->topo.cart.cart_get) {
261 module->topo.cart.cart_get = mca_topo_base_cart_get;
262 }
263 if (NULL == module->topo.cart.cartdim_get) {
264 module->topo.cart.cartdim_get = mca_topo_base_cartdim_get;
265 }
266 if (NULL == module->topo.cart.cart_map) {
267 module->topo.cart.cart_map = mca_topo_base_cart_map;
268 }
269 if (NULL == module->topo.cart.cart_rank) {
270 module->topo.cart.cart_rank = mca_topo_base_cart_rank;
271 }
272 if (NULL == module->topo.cart.cart_shift) {
273 module->topo.cart.cart_shift = mca_topo_base_cart_shift;
274 }
275 if (NULL == module->topo.cart.cart_sub) {
276 module->topo.cart.cart_sub = mca_topo_base_cart_sub;
277 }
278 } else if( OMPI_COMM_GRAPH == type ) {
279 if (NULL == module->topo.graph.graph_create) {
280 module->topo.graph.graph_create = mca_topo_base_graph_create;
281 }
282 if (NULL == module->topo.graph.graph_get) {
283 module->topo.graph.graph_get = mca_topo_base_graph_get;
284 }
285 if (NULL == module->topo.graph.graph_map) {
286 module->topo.graph.graph_map = mca_topo_base_graph_map;
287 }
288 if (NULL == module->topo.graph.graphdims_get) {
289 module->topo.graph.graphdims_get = mca_topo_base_graphdims_get;
290 }
291 if (NULL == module->topo.graph.graph_neighbors) {
292 module->topo.graph.graph_neighbors = mca_topo_base_graph_neighbors;
293 }
294 if (NULL == module->topo.graph.graph_neighbors_count) {
295 module->topo.graph.graph_neighbors_count = mca_topo_base_graph_neighbors_count;
296 }
297 } else if( OMPI_COMM_DIST_GRAPH == type ) {
298 if (NULL == module->topo.dist_graph.dist_graph_create) {
299 module->topo.dist_graph.dist_graph_create = mca_topo_base_dist_graph_create;
300 }
301 if (NULL == module->topo.dist_graph.dist_graph_create_adjacent) {
302 module->topo.dist_graph.dist_graph_create_adjacent = mca_topo_base_dist_graph_create_adjacent;
303 }
304 if (NULL == module->topo.dist_graph.dist_graph_neighbors) {
305 module->topo.dist_graph.dist_graph_neighbors = mca_topo_base_dist_graph_neighbors;
306 }
307 if (NULL == module->topo.dist_graph.dist_graph_neighbors_count) {
308 module->topo.dist_graph.dist_graph_neighbors_count = mca_topo_base_dist_graph_neighbors_count;
309 }
310 }
311 }