root/opal/mca/pmix/pmix4x/pmix/src/runtime/pmix_init.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. _notification_eviction_cbfunc
  2. pmix_rte_init

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2007-2012 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2007      Sun Microsystems, Inc.  All rights reserved.
  15  * Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
  16  * Copyright (c) 2010-2015 Los Alamos National Security, LLC.
  17  *                         All rights reserved.
  18  * Copyright (c) 2013-2019 Intel, Inc.  All rights reserved.
  19  * Copyright (c) 2015      Research Organization for Information Science
  20  *                         and Technology (RIST). All rights reserved.
  21  * $COPYRIGHT$
  22  *
  23  * Additional copyrights may follow
  24  *
  25  * $HEADER$
  26  */
  27 
  28 /** @file **/
  29 
  30 #include <src/include/pmix_config.h>
  31 
  32 #ifdef HAVE_UNISTD_H
  33 #include <unistd.h>
  34 #endif
  35 
  36 #include <pmix_rename.h>
  37 
  38 #include "src/include/pmix_globals.h"
  39 #include "src/util/output.h"
  40 #include "src/util/show_help.h"
  41 #include "src/mca/base/base.h"
  42 #include "src/mca/base/pmix_mca_base_var.h"
  43 #include "src/mca/bfrops/base/base.h"
  44 #include "src/mca/pcompress/base/base.h"
  45 #include "src/mca/gds/base/base.h"
  46 #include "src/mca/pif/base/base.h"
  47 #include "src/mca/pinstalldirs/base/base.h"
  48 #include "src/mca/plog/base/base.h"
  49 #include "src/mca/pnet/base/base.h"
  50 #include "src/mca/psec/base/base.h"
  51 #include "src/mca/preg/base/base.h"
  52 #include "src/mca/ptl/base/base.h"
  53 
  54 #include "src/client/pmix_client_ops.h"
  55 #include "src/common/pmix_attributes.h"
  56 #include "src/event/pmix_event.h"
  57 #include "src/include/types.h"
  58 #include "src/util/error.h"
  59 #include "src/util/keyval_parse.h"
  60 
  61 #include "src/runtime/pmix_rte.h"
  62 #include "src/runtime/pmix_progress_threads.h"
  63 
  64 const char pmix_version_string[] = PMIX_IDENT_STRING;
  65 
  66 PMIX_EXPORT int pmix_initialized = 0;
  67 PMIX_EXPORT bool pmix_init_called = false;
  68 /* we have to export the pmix_globals object so
  69  * all plugins can access it. However, it is included
  70  * in the pmix_rename.h file for external protection.
  71  * Initialize only those entries that are not covered
  72  * by MCA params or are complex structures initialized
  73  * below */
  74 PMIX_EXPORT pmix_globals_t pmix_globals = {
  75     .init_cntr = 0,
  76     .mypeer = NULL,
  77     .hostname = NULL,
  78     .nodeid = UINT32_MAX,
  79     .pindex = 0,
  80     .evbase = NULL,
  81     .external_evbase = false,
  82     .debug_output = -1,
  83     .connected = false,
  84     .commits_pending = false,
  85     .mygds = NULL,
  86     .pushstdin = false
  87 };
  88 
  89 
  90 static void _notification_eviction_cbfunc(struct pmix_hotel_t *hotel,
  91                                           int room_num,
  92                                           void *occupant)
  93 {
  94     pmix_notify_caddy_t *cache = (pmix_notify_caddy_t*)occupant;
  95     PMIX_RELEASE(cache);
  96 }
  97 
  98 
  99 int pmix_rte_init(pmix_proc_type_t type,
 100                   pmix_info_t info[], size_t ninfo,
 101                   pmix_ptl_cbfunc_t cbfunc)
 102 {
 103     int ret, debug_level;
 104     char *error = NULL, *evar;
 105     size_t n;
 106     char hostname[PMIX_MAXHOSTNAMELEN];
 107 
 108     if( ++pmix_initialized != 1 ) {
 109         if( pmix_initialized < 1 ) {
 110             return PMIX_ERROR;
 111         }
 112         return PMIX_SUCCESS;
 113     }
 114 
 115     #if PMIX_NO_LIB_DESTRUCTOR
 116         if (pmix_init_called) {
 117             /* can't use show_help here */
 118             fprintf (stderr, "pmix_init: attempted to initialize after finalize without compiler "
 119                      "support for either __attribute__(destructor) or linker support for -fini -- process "
 120                      "will likely abort\n");
 121             return PMIX_ERR_NOT_SUPPORTED;
 122         }
 123     #endif
 124 
 125     pmix_init_called = true;
 126 
 127     /* initialize the output system */
 128     if (!pmix_output_init()) {
 129         return PMIX_ERROR;
 130     }
 131 
 132     /* initialize install dirs code */
 133     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_pinstalldirs_base_framework, 0))) {
 134         fprintf(stderr, "pmix_pinstalldirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of PMIX_SUCCESS)\n",
 135                 __FILE__, __LINE__, ret);
 136         return ret;
 137     }
 138 
 139     /* initialize the help system */
 140     pmix_show_help_init();
 141 
 142     /* keyval lex-based parser */
 143     if (PMIX_SUCCESS != (ret = pmix_util_keyval_parse_init())) {
 144         error = "pmix_util_keyval_parse_init";
 145         goto return_error;
 146     }
 147 
 148     /* Setup the parameter system */
 149     if (PMIX_SUCCESS != (ret = pmix_mca_base_var_init())) {
 150         error = "mca_base_var_init";
 151         goto return_error;
 152     }
 153 
 154     /* register params for pmix */
 155     if (PMIX_SUCCESS != (ret = pmix_register_params())) {
 156         error = "pmix_register_params";
 157         goto return_error;
 158     }
 159 
 160     /* initialize the mca */
 161     if (PMIX_SUCCESS != (ret = pmix_mca_base_open())) {
 162         error = "mca_base_open";
 163         goto return_error;
 164     }
 165 
 166     /* setup the globals structure */
 167     gethostname(hostname, PMIX_MAXHOSTNAMELEN);
 168     pmix_globals.hostname = strdup(hostname);
 169     memset(&pmix_globals.myid.nspace, 0, PMIX_MAX_NSLEN+1);
 170     pmix_globals.myid.rank = PMIX_RANK_INVALID;
 171     PMIX_CONSTRUCT(&pmix_globals.events, pmix_events_t);
 172     pmix_globals.event_window.tv_sec = pmix_event_caching_window;
 173     pmix_globals.event_window.tv_usec = 0;
 174     PMIX_CONSTRUCT(&pmix_globals.cached_events, pmix_list_t);
 175     /* construct the global notification ring buffer */
 176     PMIX_CONSTRUCT(&pmix_globals.notifications, pmix_hotel_t);
 177     ret = pmix_hotel_init(&pmix_globals.notifications, pmix_globals.max_events,
 178                           pmix_globals.evbase, pmix_globals.event_eviction_time,
 179                           _notification_eviction_cbfunc);
 180     if (PMIX_SUCCESS != ret) {
 181         error = "notification hotel init";
 182         goto return_error;
 183     }
 184     /* and setup the iof request tracking list */
 185     PMIX_CONSTRUCT(&pmix_globals.iof_requests, pmix_list_t);
 186     /* setup the stdin forwarding target list */
 187     PMIX_CONSTRUCT(&pmix_globals.stdin_targets, pmix_list_t);
 188 
 189     /* Setup client verbosities as all procs are allowed to
 190      * access client APIs */
 191     if (0 < pmix_client_globals.get_verbose) {
 192         /* set default output */
 193         pmix_client_globals.get_output = pmix_output_open(NULL);
 194         pmix_output_set_verbosity(pmix_client_globals.get_output,
 195                                   pmix_client_globals.get_verbose);
 196     }
 197     if (0 < pmix_client_globals.connect_verbose) {
 198         /* set default output */
 199         pmix_client_globals.connect_output = pmix_output_open(NULL);
 200         pmix_output_set_verbosity(pmix_client_globals.connect_output,
 201                                   pmix_client_globals.connect_verbose);
 202     }
 203     if (0 < pmix_client_globals.fence_verbose) {
 204         /* set default output */
 205         pmix_client_globals.fence_output = pmix_output_open(NULL);
 206         pmix_output_set_verbosity(pmix_client_globals.fence_output,
 207                                   pmix_client_globals.fence_verbose);
 208     }
 209     if (0 < pmix_client_globals.pub_verbose) {
 210         /* set default output */
 211         pmix_client_globals.pub_output = pmix_output_open(NULL);
 212         pmix_output_set_verbosity(pmix_client_globals.pub_output,
 213                                   pmix_client_globals.pub_verbose);
 214     }
 215     if (0 < pmix_client_globals.spawn_verbose) {
 216         /* set default output */
 217         pmix_client_globals.spawn_output = pmix_output_open(NULL);
 218         pmix_output_set_verbosity(pmix_client_globals.spawn_output,
 219                                   pmix_client_globals.spawn_verbose);
 220     }
 221     if (0 < pmix_client_globals.event_verbose) {
 222         /* set default output */
 223         pmix_client_globals.event_output = pmix_output_open(NULL);
 224         pmix_output_set_verbosity(pmix_client_globals.event_output,
 225                                   pmix_client_globals.event_verbose);
 226     }
 227     if (0 < pmix_client_globals.iof_verbose) {
 228         /* set default output */
 229         pmix_client_globals.iof_output = pmix_output_open(NULL);
 230         pmix_output_set_verbosity(pmix_client_globals.iof_output,
 231                                   pmix_client_globals.iof_verbose);
 232     }
 233 
 234     /* get our effective id's */
 235     pmix_globals.uid = geteuid();
 236     pmix_globals.gid = getegid();
 237     /* see if debug is requested */
 238     if (NULL != (evar = getenv("PMIX_DEBUG"))) {
 239         debug_level = strtol(evar, NULL, 10);
 240         pmix_globals.debug_output = pmix_output_open(NULL);
 241         pmix_output_set_verbosity(pmix_globals.debug_output, debug_level);
 242     }
 243     /* create our peer object */
 244     pmix_globals.mypeer = PMIX_NEW(pmix_peer_t);
 245     if (NULL == pmix_globals.mypeer) {
 246         ret = PMIX_ERR_NOMEM;
 247         goto return_error;
 248     }
 249     /* whatever our declared proc type, we are definitely v3.0 */
 250     pmix_globals.mypeer->proc_type = type | PMIX_PROC_V3;
 251     /* create an nspace object for ourselves - we will
 252      * fill in the nspace name later */
 253     pmix_globals.mypeer->nptr = PMIX_NEW(pmix_namespace_t);
 254     if (NULL == pmix_globals.mypeer->nptr) {
 255         PMIX_RELEASE(pmix_globals.mypeer);
 256         ret = PMIX_ERR_NOMEM;
 257         goto return_error;
 258     }
 259 
 260     /* scan incoming info for directives */
 261     if (NULL != info) {
 262         for (n=0; n < ninfo; n++) {
 263             if (PMIX_CHECK_KEY(&info[n], PMIX_EVENT_BASE)) {
 264                 pmix_globals.evbase = (pmix_event_base_t*)info[n].value.data.ptr;
 265                 pmix_globals.external_evbase = true;
 266             } else if (PMIX_CHECK_KEY(&info[n], PMIX_HOSTNAME)) {
 267                 if (NULL != pmix_globals.hostname) {
 268                     free(pmix_globals.hostname);
 269                 }
 270                 pmix_globals.hostname = strdup(info[n].value.data.string);
 271             } else if (PMIX_CHECK_KEY(&info[n], PMIX_NODEID)) {
 272                 PMIX_VALUE_GET_NUMBER(ret, &info[n].value, pmix_globals.nodeid, uint32_t);
 273                 if (PMIX_SUCCESS != ret) {
 274                     goto return_error;
 275                 }
 276             }
 277         }
 278     }
 279 
 280     /* the choice of modules to use when communicating with a peer
 281      * will be done by the individual init functions and at the
 282      * time of connection to that peer */
 283 
 284     /* open the bfrops and select the active plugins */
 285     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_bfrops_base_framework, 0)) ) {
 286         error = "pmix_bfrops_base_open";
 287         goto return_error;
 288     }
 289     if (PMIX_SUCCESS != (ret = pmix_bfrop_base_select()) ) {
 290         error = "pmix_bfrops_base_select";
 291         goto return_error;
 292     }
 293 
 294     /* open and select the compress framework */
 295     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_pcompress_base_framework, 0)) ) {
 296         error = "pmix_pcompress_base_open";
 297         goto return_error;
 298     }
 299     if (PMIX_SUCCESS != (ret = pmix_compress_base_select()) ) {
 300         error = "pmix_pcompress_base_select";
 301         goto return_error;
 302     }
 303 
 304     /* open the ptl and select the active plugins */
 305     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_ptl_base_framework, 0)) ) {
 306         error = "pmix_ptl_base_open";
 307         goto return_error;
 308     }
 309     if (PMIX_SUCCESS != (ret = pmix_ptl_base_select()) ) {
 310         error = "pmix_ptl_base_select";
 311         goto return_error;
 312     }
 313     /* set the notification callback function */
 314     if (PMIX_SUCCESS != (ret = pmix_ptl_base_set_notification_cbfunc(cbfunc))) {
 315         error = "pmix_ptl_set_notification_cbfunc";
 316         goto return_error;
 317     }
 318 
 319     /* open the psec and select the active plugins */
 320     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_psec_base_framework, 0))) {
 321         error = "pmix_psec_base_open";
 322         goto return_error;
 323     }
 324     if (PMIX_SUCCESS != (ret = pmix_psec_base_select())) {
 325         error = "pmix_psec_base_select";
 326         goto return_error;
 327     }
 328 
 329     /* open the gds and select the active plugins */
 330     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_gds_base_framework, 0)) ) {
 331         error = "pmix_gds_base_open";
 332         goto return_error;
 333     }
 334     if (PMIX_SUCCESS != (ret = pmix_gds_base_select(info, ninfo)) ) {
 335         error = "pmix_gds_base_select";
 336         goto return_error;
 337     }
 338 
 339     /* initialize pif framework */
 340     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_pif_base_framework, 0))) {
 341         error = "pmix_pif_base_open";
 342         return ret;
 343     }
 344 
 345     /* open the preg and select the active plugins */
 346     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_preg_base_framework, 0)) ) {
 347         error = "pmix_preg_base_open";
 348         goto return_error;
 349     }
 350     if (PMIX_SUCCESS != (ret = pmix_preg_base_select()) ) {
 351         error = "pmix_preg_base_select";
 352         goto return_error;
 353     }
 354 
 355     /* open the plog and select the active plugins */
 356     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_plog_base_framework, 0)) ) {
 357         error = "pmix_plog_base_open";
 358         goto return_error;
 359     }
 360     if (PMIX_SUCCESS != (ret = pmix_plog_base_select()) ) {
 361         error = "pmix_plog_base_select";
 362         goto return_error;
 363     }
 364 
 365     /* initialize the attribute support system */
 366     pmix_init_registered_attrs();
 367 
 368     /* if an external event base wasn't provide, create one */
 369     if (!pmix_globals.external_evbase) {
 370         /* tell libevent that we need thread support */
 371         pmix_event_use_threads();
 372 
 373         /* create an event base and progress thread for us */
 374         if (NULL == (pmix_globals.evbase = pmix_progress_thread_init(NULL))) {
 375             error = "progress thread";
 376             ret = PMIX_ERROR;
 377             goto return_error;
 378         }
 379     }
 380 
 381     return PMIX_SUCCESS;
 382 
 383   return_error:
 384     if (PMIX_ERR_SILENT != ret) {
 385         pmix_show_help( "help-pmix-runtime.txt",
 386                         "pmix_init:startup:internal-failure", true,
 387                         error, ret );
 388     }
 389     return ret;
 390 }

/* [<][>][^][v][top][bottom][index][help] */