1
1
openmpi/orte/util/proc_info.c
Nathan Hjelm cf377db823 MCA/base: Add new MCA variable system
Features:
 - Support for an override parameter file (openmpi-mca-param-override.conf).
   Variable values in this file can not be overridden by any file or environment
   value.
 - Support for boolean, unsigned, and unsigned long long variables.
 - Support for true/false values.
 - Support for enumerations on integer variables.
 - Support for MPIT scope, verbosity, and binding.
 - Support for command line source.
 - Support for setting variable source via the environment using
   OMPI_MCA_SOURCE_<var name>=source (either command or file:filename)
 - Cleaner API.
 - Support for variable groups (equivalent to MPIT categories).

Notes:
 - Variables must be created with a backing store (char **, int *, or bool *)
   that must live at least as long as the variable.
 - Creating a variable with the MCA_BASE_VAR_FLAG_SETTABLE enables the use of
   mca_base_var_set_value() to change the value.
 - String values are duplicated when the variable is registered. It is up to
   the caller to free the original value if necessary. The new value will be
   freed by the mca_base_var system and must not be freed by the user.
 - Variables with constant scope may not be settable.
 - Variable groups (and all associated variables) are deregistered when the
   component is closed or the component repository item is freed. This
   prevents a segmentation fault from accessing a variable after its component
   is unloaded.
 - After some discussion we decided we should remove the automatic registration
   of component priority variables. Few component actually made use of this
   feature.
 - The enumerator interface was updated to be general enough to handle
   future uses of the interface.
 - The code to generate ompi_info output has been moved into the MCA variable
   system. See mca_base_var_dump().

opal: update core and components to mca_base_var system
orte: update core and components to mca_base_var system
ompi: update core and components to mca_base_var system

This commit also modifies the rmaps framework. The following variables were
moved from ppr and lama: rmaps_base_pernode, rmaps_base_n_pernode,
rmaps_base_n_persocket. Both lama and ppr create synonyms for these variables.

This commit was SVN r28236.
2013-03-27 21:09:41 +00:00

331 строка
13 KiB
C

/*
* Copyright (c) 2004-2005 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) 2009 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, LLC.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "orte_config.h"
#include "orte/constants.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <ctype.h>
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_var.h"
#include "opal/util/net.h"
#include "opal/util/output.h"
#include "orte/util/proc_info.h"
/* provide a connection to a reqd variable */
extern bool orte_keep_fqdn_hostnames;
#define ORTE_NAME_INVALID {ORTE_JOBID_INVALID, ORTE_VPID_INVALID}
ORTE_DECLSPEC orte_proc_info_t orte_process_info = {
/* .my_name = */ ORTE_NAME_INVALID,
/* .my_daemon = */ ORTE_NAME_INVALID,
/* .my_daemon_uri = */ NULL,
/* .my_hnp = */ ORTE_NAME_INVALID,
/* .my_hnp_uri = */ NULL,
/* .my_parent = */ ORTE_NAME_INVALID,
/* .hnp_pid = */ 0,
/* .app_num = */ 0,
/* .num_procs = */ 1,
/* .max_procs = */ 1,
/* .num_daemons = */ 1,
/* .num_nodes = */ 1,
/* .nodename = */ NULL,
/* .pid = */ 0,
/* .proc_type = */ ORTE_PROC_TYPE_NONE,
/* .sync_buf = */ NULL,
/* .my_port = */ 0,
/* .num_restarts = */ 0,
/* .my_node_rank = */ ORTE_NODE_RANK_INVALID,
/* .my_local_rank = */ ORTE_LOCAL_RANK_INVALID,
/* .num_local_peers = */ 0,
/* .tmpdir_base = */ NULL,
/* .top_session_dir = */ NULL,
/* .job_session_dir = */ NULL,
/* .proc_session_dir = */ NULL,
/* .sock_stdin = */ NULL,
/* .sock_stdout = */ NULL,
/* .sock_stderr = */ NULL,
#if OPAL_HAVE_HWLOC
/* .cpuset = */ NULL,
#endif
/* .app_rank = */ -1,
/* .peer_modex = */ -1,
/* .peer_init_barrier = */ -1,
/* .peer_fini_barrier = */ -1,
/* .strip_prefix_from_node_names = */ false
};
static bool init=false;
static int orte_ess_node_rank;
static int orte_peer_modex_id;
static int orte_peer_init_barrier_id;
static int orte_peer_fini_barrier_id;
int orte_proc_info(void)
{
int idx;
char *ptr;
char hostname[ORTE_MAX_HOSTNAME_SIZE];
if (init) {
return ORTE_SUCCESS;
}
init = true;
orte_process_info.my_hnp_uri = NULL;
mca_base_var_register ("orte", "orte", NULL, "hnp_uri",
"HNP contact info",
MCA_BASE_VAR_TYPE_STRING, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&orte_process_info.my_hnp_uri);
if (NULL != orte_process_info.my_hnp_uri) {
ptr = orte_process_info.my_hnp_uri;
/* the uri value passed to us will have quote marks around it to protect
* the value if passed on the command line. We must remove those
* to have a correct uri string
*/
if ('"' == ptr[0]) {
/* if the first char is a quote, then so will the last one be */
ptr[strlen(ptr)-1] = '\0';
memmove (ptr, ptr + 1, strlen (ptr));
}
}
orte_process_info.my_daemon_uri = NULL;
(void) mca_base_var_register ("orte", "orte", NULL, "local_daemon_uri",
"Daemon contact info",
MCA_BASE_VAR_TYPE_STRING, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&orte_process_info.my_daemon_uri);
if (NULL != orte_process_info.my_daemon_uri) {
ptr = orte_process_info.my_daemon_uri;
/* the uri value passed to us may have quote marks around it to protect
* the value if passed on the command line. We must remove those
* to have a correct uri string
*/
if ('"' == ptr[0]) {
/* if the first char is a quote, then so will the last one be */
ptr[strlen(ptr)-1] = '\0';
memmove (ptr, ptr + 1, strlen (ptr) - 1);
}
}
orte_process_info.app_num = 0;
(void) mca_base_var_register ("orte", "orte", NULL, "app_num",
"Index of the app_context that defines this proc",
MCA_BASE_VAR_TYPE_INT, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&orte_process_info.app_num);
/* get the process id */
orte_process_info.pid = getpid();
/* get the nodename */
gethostname(hostname, ORTE_MAX_HOSTNAME_SIZE);
if (!orte_keep_fqdn_hostnames) {
/* if the nodename is an IP address, do not mess with it! */
if (!opal_net_isaddr(hostname)) {
/* not an IP address, so remove any domain info */
if (NULL != (ptr = strchr(hostname, '.'))) {
*ptr = '\0';
}
}
}
orte_process_info.strip_prefix_from_node_names = false;
(void) mca_base_var_register ("orte", "orte", NULL, "strip_prefix_from_node_names",
"Whether to strip leading characters and zeroes from node names returned by daemons",
MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&orte_process_info.strip_prefix_from_node_names);
/* we have to strip node names here, if user directs, to ensure that
* the names exchanged in the modex match the names found locally
*/
if (orte_process_info.strip_prefix_from_node_names) {
/* remove all leading characters and zeroes */
idx = 0;
while (idx < (int)strlen(hostname) &&
(hostname[idx] <= '0' || '9' < hostname[idx])) {
idx++;
}
if ((int)strlen(hostname) <= idx) {
/* there were no non-zero numbers in the name */
orte_process_info.nodename = strdup(hostname);
} else {
orte_process_info.nodename = strdup(&hostname[idx]);
}
} else {
orte_process_info.nodename = strdup(hostname);
}
/* get the number of nodes in the job */
orte_process_info.num_nodes = 1;
(void) mca_base_var_register ("orte", "orte", NULL, "num_nodes",
"Number of nodes in the job",
MCA_BASE_VAR_TYPE_INT, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&orte_process_info.num_nodes);
/* get the number of times this proc has restarted */
orte_process_info.num_restarts = 0;
(void) mca_base_var_register ("orte", "orte", NULL, "num_restarts",
"Number of times this proc has restarted",
MCA_BASE_VAR_TYPE_INT, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&orte_process_info.num_restarts);
orte_process_info.app_rank = 0;
(void) mca_base_var_register ("orte", "orte", NULL, "app_rank",
"Rank of this proc within its app_context",
MCA_BASE_VAR_TYPE_INT, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&orte_process_info.app_rank);
/* get my node rank in case we are using static ports - this won't
* be present for daemons, so don't error out if we don't have it
*/
orte_ess_node_rank = ORTE_NODE_RANK_INVALID;
(void) mca_base_var_register ("orte", "orte", NULL, "ess_node_rank", "Process node rank",
MCA_BASE_VAR_TYPE_INT, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_CONSTANT,
&orte_ess_node_rank);
orte_process_info.my_node_rank = (orte_node_rank_t) orte_ess_node_rank;
/* setup the sync buffer */
orte_process_info.sync_buf = OBJ_NEW(opal_buffer_t);
/* get the collective id info */
orte_peer_modex_id = -1;
(void) mca_base_var_register ("orte", "orte", NULL, "peer_modex_id", "Peer modex collective id",
MCA_BASE_VAR_TYPE_INT, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_CONSTANT,
&orte_peer_modex_id);
orte_process_info.peer_modex = (orte_grpcomm_coll_id_t) orte_peer_modex_id;
orte_peer_init_barrier_id = -1;
(void) mca_base_var_register ("orte", "orte", NULL, "peer_init_barrier_id", "Peer init barrier collective id",
MCA_BASE_VAR_TYPE_INT, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_CONSTANT,
&orte_peer_init_barrier_id);
orte_process_info.peer_init_barrier = (orte_grpcomm_coll_id_t) orte_peer_init_barrier_id;
orte_peer_fini_barrier_id = -1;
(void) mca_base_var_register ("orte", "orte", NULL, "peer_fini_barrier_id", "Peer finalize barrier collective id",
MCA_BASE_VAR_TYPE_INT, NULL, 0,
MCA_BASE_VAR_FLAG_INTERNAL,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_CONSTANT,
&orte_peer_fini_barrier_id);
orte_process_info.peer_fini_barrier = (orte_grpcomm_coll_id_t) orte_peer_fini_barrier_id;
return ORTE_SUCCESS;
}
int orte_proc_info_finalize(void)
{
if (!init) {
return ORTE_SUCCESS;
}
if (NULL != orte_process_info.tmpdir_base) {
free(orte_process_info.tmpdir_base);
orte_process_info.tmpdir_base = NULL;
}
if (NULL != orte_process_info.top_session_dir) {
free(orte_process_info.top_session_dir);
orte_process_info.top_session_dir = NULL;
}
if (NULL != orte_process_info.job_session_dir) {
free(orte_process_info.job_session_dir);
orte_process_info.job_session_dir = NULL;
}
if (NULL != orte_process_info.proc_session_dir) {
free(orte_process_info.proc_session_dir);
orte_process_info.proc_session_dir = NULL;
}
if (NULL != orte_process_info.nodename) {
free(orte_process_info.nodename);
orte_process_info.nodename = NULL;
}
if (NULL != orte_process_info.sock_stdin) {
free(orte_process_info.sock_stdin);
orte_process_info.sock_stdin = NULL;
}
if (NULL != orte_process_info.sock_stdout) {
free(orte_process_info.sock_stdout);
orte_process_info.sock_stdout = NULL;
}
if (NULL != orte_process_info.sock_stderr) {
free(orte_process_info.sock_stderr);
orte_process_info.sock_stderr = NULL;
}
orte_process_info.proc_type = ORTE_PROC_TYPE_NONE;
OBJ_RELEASE(orte_process_info.sync_buf);
orte_process_info.sync_buf = NULL;
init = false;
return ORTE_SUCCESS;
}