Source

mpi3-fortran / ompi / tools / ompi_info / components.c

Full commit
  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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/*
 * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2011 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) 2006-2012 Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2010-2012 Los Alamos National Security, LLC.
 *                         All rights reserved.
 * Copyright (c) 2011-2012 University of Houston. All rights reserved.
 * $COPYRIGHT$
 * 
 * Additional copyrights may follow
 * 
 * $HEADER$
 */

#include "ompi_config.h"

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

#include "opal/util/argv.h"
#include "opal/runtime/opal_info_support.h"

#include "orte/runtime/runtime.h"
#include "orte/runtime/orte_info_support.h"

#include "ompi/mca/allocator/base/base.h"
#include "ompi/mca/coll/base/base.h"
#include "ompi/mca/io/io.h"
#include "ompi/mca/io/base/base.h"
#include "ompi/mca/mpool/base/base.h"
#include "ompi/mca/pml/pml.h"
#include "ompi/mca/pml/base/base.h"
#include "ompi/mca/bml/base/base.h"
#include "ompi/mca/rcache/rcache.h"
#include "ompi/mca/rcache/base/base.h"
#include "ompi/mca/btl/base/base.h"
#include "ompi/mca/mtl/mtl.h"
#include "ompi/mca/mtl/base/base.h"
#include "ompi/mca/topo/base/base.h"
#include "ompi/mca/osc/osc.h"
#include "ompi/mca/osc/base/base.h"
#include "ompi/mca/pubsub/base/base.h"
#include "ompi/mca/dpm/base/base.h"
#include "ompi/mca/op/base/base.h"
#include "ompi/mca/vprotocol/base/base.h"
#include "ompi/mca/fbtl/fbtl.h"
#include "ompi/mca/fbtl/base/base.h"
#include "ompi/mca/fs/fs.h"
#include "ompi/mca/fs/base/base.h"
#include "ompi/mca/fcoll/fcoll.h"
#include "ompi/mca/fcoll/base/base.h"
#include "ompi/mca/sharedfp/sharedfp.h"
#include "ompi/mca/sharedfp/base/base.h"
#include "ompi/runtime/params.h"

#if OPAL_ENABLE_FT_CR == 1
#include "ompi/mca/crcp/crcp.h"
#include "ompi/mca/crcp/base/base.h"
#endif


#include "ompi/tools/ompi_info/ompi_info.h"


/*
 * Private variables
 */

static bool opened_components = false;


/*
 * Open all MCA components so that they can register their MCA
 * parameters.  Take a shotgun approach here and indiscriminately open
 * all components -- don't be selective.  To this end, we need to clear
 * out the environment of all OMPI_MCA_<type> variables to ensure
 * that the open algorithms don't try to only open one component.
 */
int ompi_info_register_components(opal_pointer_array_t *mca_types,
                                  opal_pointer_array_t *component_map)
{
    int i, rc;
    char *env, *str;
    char *target, *save, *type;
    char **env_save=NULL;
    bool need_close_components = false;
    opal_info_component_map_t *map;
    
    /* Clear out the environment.  Use strdup() to orphan the resulting
     * strings because items are placed in the environment by reference,
     * not by value.
     */
    
    for (i = 0; i < mca_types->size; ++i) {
        if (NULL == (type = (char*)opal_pointer_array_get_item(mca_types, i))) {
            continue;
        }
        (void)asprintf(&env, "OMPI_MCA_%s", type);
        if (NULL != (save = getenv(env))) {
            /* save this param so it can later be restored */
            (void)asprintf(&str, "%s=%s", env, save);
            opal_argv_append_nosize(&env_save, str);
            free(str);
            /* can't manipulate it directly, so make a copy first */
            (void)asprintf(&target, "%s=", env);
            putenv(target);
            free(target);
        }
        free(env);
    }
    
    /* Register the MPI layer's MCA parameters */
    if (OMPI_SUCCESS != (rc = ompi_mpi_register_params())) {
        str = "ompi_mpi_register_params";
        if (OMPI_ERR_BAD_PARAM == rc)  {
            goto breakout;
        }
        goto error;
    }
    
    /* Find / open all components */
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("base");
    opal_pointer_array_add(component_map, map);
    
    /* MPI frameworks */
    if (OMPI_SUCCESS != (rc = mca_allocator_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "allocator open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("allocator");
    map->components = &mca_allocator_base_components;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "allocator";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_btl_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "btl open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("btl");
    map->components = &mca_btl_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "btl";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_coll_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "coll open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("coll");
    map->components = &mca_coll_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "coll";
        goto breakout;
    }

#if OPAL_ENABLE_FT_CR == 1
    if (OMPI_SUCCESS != (rc = ompi_crcp_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "crcp open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("crcp");
    map->components = &ompi_crcp_base_components_available;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "crcp";
        goto breakout;
    }
#endif
    
    if (OMPI_SUCCESS != (rc = ompi_dpm_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "dpm open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("dpm");
    map->components = &ompi_dpm_base_components_available;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "dpm";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_fbtl_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "fbtl open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("fbtl");
    map->components = &mca_fbtl_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "fbtl";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_fcoll_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "fcoll open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("fcoll");
    map->components = &mca_fcoll_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "fcoll";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_fs_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "fs open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("fs");
    map->components = &mca_fs_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "fs";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_io_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "io open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("io");
    map->components = &mca_io_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "io";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_mpool_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "mpool open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("mpool");
    map->components = &mca_mpool_base_components;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "mpool";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = ompi_mtl_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "mtl open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("mtl");
    map->components = &ompi_mtl_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "mtl";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = ompi_op_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "op open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("op");
    map->components = &ompi_op_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "op";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = ompi_osc_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "osc open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("osc");
    map->components = &ompi_osc_base_open_components;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "osc";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_pml_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "pml open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("pml");
    map->components = &mca_pml_base_components_available;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "pml";
        goto breakout;
    }

    /* No need to call the bml_base_open() because the ob1 pml calls it.
     * mca_bml_base_open();
     */
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("bml");
    map->components = &mca_bml_base_components_available;
    opal_pointer_array_add(component_map, map);
    
    if (OMPI_SUCCESS != (rc = ompi_pubsub_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "pubsub open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("pubsub");
    map->components = &ompi_pubsub_base_components_available;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "pubsub";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_rcache_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "rcache open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("rcache");
    map->components = &mca_rcache_base_components;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "rcache";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_sharedfp_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "sharedfp open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("sharedfp");
    map->components = &mca_sharedfp_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "sharedfp";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_topo_base_open()) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "topo open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("topo");
    map->components = &mca_topo_base_components_opened;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "topo";
        goto breakout;
    }

    if (OMPI_SUCCESS != (rc = mca_vprotocol_base_open(NULL)) &&
        OMPI_ERR_BAD_PARAM != rc) {
        str = "vprotocol open";
        goto error;
    }
    map = OBJ_NEW(opal_info_component_map_t);
    map->type = strdup("vprotocol");
    map->components = &mca_vprotocol_base_components_available;
    opal_pointer_array_add(component_map, map);
    if (OMPI_ERR_BAD_PARAM == rc)  {
        str = "vprotocol";
        goto breakout;
    }

    /* flag that we need to close components */
    need_close_components = true;

 breakout:
    /* Restore the environment to what it was before we started so that
     * if users setenv OMPI_MCA_<framework name> to some value, they'll
     * see that value when it is shown via --param output.
     */
    
    if (NULL != env_save) {
        for (i = 0; i < opal_argv_count(env_save); ++i) {
            putenv(env_save[i]);
        }
    }
    
    if (OPAL_ERR_BAD_PARAM == rc) {
        fprintf(stderr, "\nA \"bad parameter\" error was encountered when opening the OMPI %s framework\n", str);
        fprintf(stderr, "The output received from that framework includes the following parameters:\n\n");
    }

    opened_components = true;
    return rc;

 error:
    fprintf(stderr, "ompi_info_register: %s failed\n", str);
    fprintf(stderr, "ompi_info will likely not display all configuration information\n");
    return OMPI_ERROR;
}


void ompi_info_close_components()
{
    /* Note that the order of shutdown here doesn't matter because
     * we aren't *using* any components -- none were selected, so
     * there are no dependencies between the frameworks.  We list
     * them generally "in order", but it doesn't really matter.
         
     * We also explicitly ignore the return values from the
     * close() functions -- what would we do if there was an
     * error?
     */
        
#if OPAL_ENABLE_FT_CR == 1
    (void) ompi_crcp_base_close();
#endif
    (void) ompi_op_base_close();
    (void) ompi_dpm_base_close();
    (void) ompi_pubsub_base_close();
    (void) mca_topo_base_close();
    (void) mca_btl_base_close();
    (void) ompi_mtl_base_close();
    (void) mca_pml_base_close();
    (void) mca_mpool_base_close();
    (void) mca_rcache_base_close();
    (void) mca_io_base_close();
    (void) mca_fbtl_base_close();
    (void) mca_fcoll_base_close();
    (void) mca_fs_base_close();
    (void) mca_sharedfp_base_close();
    (void) mca_coll_base_close();
    (void) mca_allocator_base_close();
    (void) ompi_osc_base_close();

    /* close the ORTE components */
    (void) orte_info_close_components();
}