1
1
openmpi/orte/util/regex.c

405 строки
12 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.
2015-06-24 06:59:57 +03:00
* 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) 2013 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2017 Intel, Inc. All rights reserved.
* $COPYRIGHT$
2015-06-24 06:59:57 +03:00
*
* Additional copyrights may follow
2015-06-24 06:59:57 +03:00
*
* $HEADER$
*/
#include "orte_config.h"
#include "orte/types.h"
#include "orte/constants.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
#include "opal/util/argv.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/odls/odls_types.h"
#include "orte/mca/rml/base/rml_contact.h"
#include "orte/mca/rmaps/rmaps_types.h"
#include "orte/util/show_help.h"
#include "orte/util/name_fns.h"
#include "orte/util/nidmap.h"
#include "orte/runtime/orte_globals.h"
#include "orte/mca/ess/ess.h"
#include "orte/util/regex.h"
#define ORTE_MAX_NODE_PREFIX 50
static int regex_parse_node_ranges(char *base, char *ranges, int num_digits, char *suffix, char ***names);
static int regex_parse_node_range(char *base, char *range, int num_digits, char *suffix, char ***names);
int orte_regex_extract_node_names(char *regexp, char ***names)
{
int i, j, k, len, ret;
char *base;
char *orig, *suffix;
bool found_range = false;
bool more_to_come = false;
int num_digits;
if (NULL == regexp) {
*names = NULL;
return ORTE_SUCCESS;
}
2015-06-24 06:59:57 +03:00
orig = base = strdup(regexp);
if (NULL == base) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE;
}
2015-06-24 06:59:57 +03:00
OPAL_OUTPUT_VERBOSE((1, orte_debug_output,
"%s regex:extract:nodenames: checking nodelist: %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
regexp));
2015-06-24 06:59:57 +03:00
do {
/* Find the base */
len = strlen(base);
for (i = 0; i <= len; ++i) {
if (base[i] == '[') {
/* we found a range. this gets dealt with below */
base[i] = '\0';
found_range = true;
break;
}
if (base[i] == ',') {
/* we found a singleton node, and there are more to come */
base[i] = '\0';
found_range = false;
more_to_come = true;
break;
}
if (base[i] == '\0') {
/* we found a singleton node */
found_range = false;
more_to_come = false;
break;
}
}
if (i == 0 && !found_range) {
/* we found a special character at the beginning of the string */
orte_show_help("help-regex.txt", "regex:special-char", true, regexp);
free(orig);
return ORTE_ERR_BAD_PARAM;
}
2015-06-24 06:59:57 +03:00
if (found_range) {
/* If we found a range, get the number of digits in the numbers */
i++; /* step over the [ */
for (j=i; j < len; j++) {
if (base[j] == ':') {
base[j] = '\0';
break;
}
}
if (j >= len) {
/* we didn't find the number of digits */
orte_show_help("help-regex.txt", "regex:num-digits-missing", true, regexp);
free(orig);
return ORTE_ERR_BAD_PARAM;
}
num_digits = strtol(&base[i], NULL, 10);
i = j + 1; /* step over the : */
/* now find the end of the range */
for (j = i; j < len; ++j) {
if (base[j] == ']') {
base[j] = '\0';
break;
}
}
if (j >= len) {
/* we didn't find the end of the range */
orte_show_help("help-regex.txt", "regex:end-range-missing", true, regexp);
free(orig);
return ORTE_ERR_BAD_PARAM;
}
/* check for a suffix */
if (j+1 < len && base[j+1] != ',') {
/* find the next comma, if present */
for (k=j+1; k < len && base[k] != ','; k++);
if (k < len) {
base[k] = '\0';
}
suffix = strdup(&base[j+1]);
if (k < len) {
base[k] = ',';
}
j = k-1;
} else {
suffix = NULL;
}
OPAL_OUTPUT_VERBOSE((1, orte_debug_output,
"%s regex:extract:nodenames: parsing range %s %s %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
base, base + i, suffix));
ret = regex_parse_node_ranges(base, base + i, num_digits, suffix, names);
if (NULL != suffix) {
free(suffix);
}
if (ORTE_SUCCESS != ret) {
orte_show_help("help-regex.txt", "regex:bad-value", true, regexp);
free(orig);
return ret;
}
if (j+1 < len && base[j + 1] == ',') {
more_to_come = true;
base = &base[j + 2];
} else {
more_to_come = false;
}
} else {
/* If we didn't find a range, just add the node */
if(ORTE_SUCCESS != (ret = opal_argv_append_nosize(names, base))) {
ORTE_ERROR_LOG(ret);
free(orig);
return ret;
}
/* step over the comma */
i++;
/* set base equal to the (possible) next base to look at */
base = &base[i];
}
} while(more_to_come);
2015-06-24 06:59:57 +03:00
free(orig);
2015-06-24 06:59:57 +03:00
/* All done */
return ret;
}
/*
* Parse one or more ranges in a set
*
* @param base The base text of the node name
* @param *ranges A pointer to a range. This can contain multiple ranges
2015-06-24 06:59:57 +03:00
* (i.e. "1-3,10" or "5" or "9,0100-0130,250")
* @param ***names An argv array to add the newly discovered nodes to
*/
static int regex_parse_node_ranges(char *base, char *ranges, int num_digits, char *suffix, char ***names)
{
int i, len, ret;
char *start, *orig;
2015-06-24 06:59:57 +03:00
/* Look for commas, the separator between ranges */
2015-06-24 06:59:57 +03:00
len = strlen(ranges);
for (orig = start = ranges, i = 0; i < len; ++i) {
if (',' == ranges[i]) {
ranges[i] = '\0';
ret = regex_parse_node_range(base, start, num_digits, suffix, names);
if (ORTE_SUCCESS != ret) {
ORTE_ERROR_LOG(ret);
return ret;
}
start = ranges + i + 1;
}
}
2015-06-24 06:59:57 +03:00
/* Pick up the last range, if it exists */
2015-06-24 06:59:57 +03:00
if (start < orig + len) {
2015-06-24 06:59:57 +03:00
OPAL_OUTPUT_VERBOSE((1, orte_debug_output,
"%s regex:parse:ranges: parse range %s (2)",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), start));
2015-06-24 06:59:57 +03:00
ret = regex_parse_node_range(base, start, num_digits, suffix, names);
if (ORTE_SUCCESS != ret) {
ORTE_ERROR_LOG(ret);
return ret;
}
}
2015-06-24 06:59:57 +03:00
/* All done */
return ORTE_SUCCESS;
}
/*
* Parse a single range in a set and add the full names of the nodes
* found to the names argv
*
* @param base The base text of the node name
2015-06-24 06:59:57 +03:00
* @param *ranges A pointer to a single range. (i.e. "1-3" or "5")
* @param ***names An argv array to add the newly discovered nodes to
*/
static int regex_parse_node_range(char *base, char *range, int num_digits, char *suffix, char ***names)
{
char *str, tmp[132];
size_t i, k, start, end;
size_t base_len, len;
bool found;
int ret;
2015-06-24 06:59:57 +03:00
if (NULL == base || NULL == range) {
return ORTE_ERROR;
}
len = strlen(range);
base_len = strlen(base);
/* Silence compiler warnings; start and end are always assigned
properly, below */
start = end = 0;
2015-06-24 06:59:57 +03:00
/* Look for the beginning of the first number */
2015-06-24 06:59:57 +03:00
for (found = false, i = 0; i < len; ++i) {
if (isdigit((int) range[i])) {
if (!found) {
start = atoi(range + i);
found = true;
break;
}
}
}
if (!found) {
ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND);
return ORTE_ERR_NOT_FOUND;
}
2015-06-24 06:59:57 +03:00
/* Look for the end of the first number */
2015-06-24 06:59:57 +03:00
for (found = false; i < len; ++i) {
if (!isdigit(range[i])) {
break;
}
}
2015-06-24 06:59:57 +03:00
/* Was there no range, just a single number? */
2015-06-24 06:59:57 +03:00
if (i >= len) {
end = start;
found = true;
} else {
/* Nope, there was a range. Look for the beginning of the second
* number
*/
for (; i < len; ++i) {
if (isdigit(range[i])) {
end = strtol(range + i, NULL, 10);
found = true;
break;
}
}
}
if (!found) {
ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND);
return ORTE_ERR_NOT_FOUND;
}
2015-06-24 06:59:57 +03:00
/* Make strings for all values in the range */
2015-06-24 06:59:57 +03:00
len = base_len + num_digits + 32;
if (NULL != suffix) {
len += strlen(suffix);
}
str = (char *) malloc(len);
if (NULL == str) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return ORTE_ERR_OUT_OF_RESOURCE;
}
for (i = start; i <= end; ++i) {
memset(str, 0, len);
strcpy(str, base);
/* we need to zero-pad the digits */
for (k=0; k < (size_t)num_digits; k++) {
str[k+base_len] = '0';
}
memset(tmp, 0, 132);
snprintf(tmp, 132, "%lu", (unsigned long)i);
for (k=0; k < strlen(tmp); k++) {
str[base_len + num_digits - k - 1] = tmp[strlen(tmp)-k-1];
}
/* if there is a suffix, add it */
if (NULL != suffix) {
strcat(str, suffix);
}
ret = opal_argv_append_nosize(names, str);
if(ORTE_SUCCESS != ret) {
ORTE_ERROR_LOG(ret);
free(str);
return ret;
}
}
free(str);
2015-06-24 06:59:57 +03:00
/* All done */
return ORTE_SUCCESS;
}
Create an alternative mapping method that pushes responsibility onto the backend daemons. By default, let mpirun only pack the app_context info and send that to the backend daemons where the mapping will be done. This significantly reduces the computational time on mpirun as it isn't running up/down the topology tree computing thousands of binding locations, and it reduces the launch message to a very small number of bytes. When running -novm, fall back to the old way of doing things where mpirun computes the entire map and binding, and then sends the full info to the backend daemon. Add a new cmd line option/mca param --fwd-mpirun-port that allows mpirun to dynamically select a port, but then passes that back to all the other daemons so they will use that port as a static port for their own wireup. In this mode, we no longer "phone home" directly to mpirun, but instead use the static port to wireup at daemon start. We then use the routing tree to rollup the initial launch report, and limit the number of open sockets on mpirun's node. Update ras simulator to track the new nidmap code Cleanup some bugs in the nidmap regex code, and enhance the error message for not enough slots to include the host on which the problem is found. Update gadget platform file Initialize the range count when starting a new range Fix the no-np case in managed allocation Ensure DVM node usage gets cleaned up after each job Update scaling.pl script to use --fwd-mpirun-port. Pre-connect the daemon to its parent during launch while we are otherwise waiting for the daemon's children to send their "phone home" rollup messages Signed-off-by: Ralph Castain <rhc@open-mpi.org>
2017-02-02 03:33:14 +03:00
/***** CLASS INSTANTIATIONS ****/
static void range_construct(orte_regex_range_t *ptr)
{
ptr->vpid = 0;
ptr->cnt = 0;
}
OBJ_CLASS_INSTANCE(orte_regex_range_t,
opal_list_item_t,
range_construct, NULL);
static void orte_regex_node_construct(orte_regex_node_t *ptr)
{
ptr->prefix = NULL;
ptr->suffix = NULL;
ptr->num_digits = 0;
OBJ_CONSTRUCT(&ptr->ranges, opal_list_t);
}
static void orte_regex_node_destruct(orte_regex_node_t *ptr)
{
opal_list_item_t *item;
if (NULL != ptr->prefix) {
free(ptr->prefix);
}
if (NULL != ptr->suffix) {
free(ptr->suffix);
}
while (NULL != (item = opal_list_remove_first(&ptr->ranges))) {
OBJ_RELEASE(item);
}
OBJ_DESTRUCT(&ptr->ranges);
}
OBJ_CLASS_INSTANCE(orte_regex_node_t,
opal_list_item_t,
orte_regex_node_construct,
orte_regex_node_destruct);