1
1

Merge pull request #6306 from karasevb/regx_host_ordering_fix

regex: fixed host ordering for different prefixes
Этот коммит содержится в:
Ralph Castain 2019-02-08 11:09:55 -08:00 коммит произвёл GitHub
родитель 8bbd201029 46e38b9193
Коммит fcbc7ea298
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 107 добавлений и 86 удалений

Просмотреть файл

@ -154,38 +154,25 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
} }
/* is this node name already on our list? */ /* is this node name already on our list? */
found = false; found = false;
for (item = opal_list_get_first(&nodenms); if (0 != opal_list_get_size(&nodenms)) {
!found && item != opal_list_get_end(&nodenms); ndreg = (orte_regex_node_t*)opal_list_get_last(&nodenms);
item = opal_list_get_next(item)) {
ndreg = (orte_regex_node_t*)item; if ((0 < strlen(prefix) && NULL == ndreg->prefix) ||
if (0 < strlen(prefix) && NULL == ndreg->prefix) { (0 == strlen(prefix) && NULL != ndreg->prefix) ||
continue; (0 < strlen(prefix) && NULL != ndreg->prefix &&
} 0 != strcmp(prefix, ndreg->prefix)) ||
if (0 == strlen(prefix) && NULL != ndreg->prefix) { (NULL == suffix && NULL != ndreg->suffix) ||
continue; (NULL != suffix && NULL == ndreg->suffix) ||
} (NULL != suffix && NULL != ndreg->suffix &&
if (0 < strlen(prefix) && NULL != ndreg->prefix 0 != strcmp(suffix, ndreg->suffix)) ||
&& 0 != strcmp(prefix, ndreg->prefix)) { (numdigits != ndreg->num_digits)) {
continue; found = false;
} } else {
if (NULL == suffix && NULL != ndreg->suffix) {
continue;
}
if (NULL != suffix && NULL == ndreg->suffix) {
continue;
}
if (NULL != suffix && NULL != ndreg->suffix &&
0 != strcmp(suffix, ndreg->suffix)) {
continue;
}
if (numdigits != ndreg->num_digits) {
continue;
}
/* found a match - flag it */ /* found a match - flag it */
found = true; found = true;
/* get the last range on this nodeid - we do this }
* to preserve order }
*/ if (found) {
range = (orte_regex_range_t*)opal_list_get_last(&ndreg->ranges); range = (orte_regex_range_t*)opal_list_get_last(&ndreg->ranges);
if (NULL == range) { if (NULL == range) {
/* first range for this nodeid */ /* first range for this nodeid */
@ -193,22 +180,18 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
range->vpid = nodenum; range->vpid = nodenum;
range->cnt = 1; range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super); opal_list_append(&ndreg->ranges, &range->super);
break;
}
/* see if the node number is out of sequence */ /* see if the node number is out of sequence */
if (nodenum != (range->vpid + range->cnt)) { } else if (nodenum != (range->vpid + range->cnt)) {
/* start a new range */ /* start a new range */
range = OBJ_NEW(orte_regex_range_t); range = OBJ_NEW(orte_regex_range_t);
range->vpid = nodenum; range->vpid = nodenum;
range->cnt = 1; range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super); opal_list_append(&ndreg->ranges, &range->super);
break; } else {
}
/* everything matches - just increment the cnt */ /* everything matches - just increment the cnt */
range->cnt++; range->cnt++;
break;
} }
if (!found) { } else {
/* need to add it */ /* need to add it */
ndreg = OBJ_NEW(orte_regex_node_t); ndreg = OBJ_NEW(orte_regex_node_t);
if (0 < strlen(prefix)) { if (0 < strlen(prefix)) {

Просмотреть файл

@ -142,7 +142,9 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
for( j = 0; j <= i; ++j) { for( j = 0; j <= i; ++j) {
prefix[j] = node[j]; prefix[j] = node[j];
} }
if (numdigits) {
startnum = j; startnum = j;
}
break; break;
} }
} }
@ -168,35 +170,25 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
} }
/* is this node name already on our list? */ /* is this node name already on our list? */
found = false; found = false;
for (item = opal_list_get_first(&nodenms); if (0 != opal_list_get_size(&nodenms)) {
!found && item != opal_list_get_end(&nodenms); ndreg = (orte_regex_node_t*)opal_list_get_last(&nodenms);
item = opal_list_get_next(item)) {
ndreg = (orte_regex_node_t*)item; if ((0 < strlen(prefix) && NULL == ndreg->prefix) ||
if (0 < strlen(prefix) && NULL == ndreg->prefix) { (0 == strlen(prefix) && NULL != ndreg->prefix) ||
continue; (0 < strlen(prefix) && NULL != ndreg->prefix &&
} 0 != strcmp(prefix, ndreg->prefix)) ||
if (0 == strlen(prefix) && NULL != ndreg->prefix) { (NULL == suffix && NULL != ndreg->suffix) ||
continue; (NULL != suffix && NULL == ndreg->suffix) ||
} (NULL != suffix && NULL != ndreg->suffix &&
if (0 < strlen(prefix) && NULL != ndreg->prefix 0 != strcmp(suffix, ndreg->suffix)) ||
&& 0 != strcmp(prefix, ndreg->prefix)) { (numdigits != ndreg->num_digits)) {
continue; found = false;
} } else {
if (NULL == suffix && NULL != ndreg->suffix) {
continue;
}
if (NULL != suffix && NULL == ndreg->suffix) {
continue;
}
if (NULL != suffix && NULL != ndreg->suffix &&
0 != strcmp(suffix, ndreg->suffix)) {
continue;
}
if (numdigits != ndreg->num_digits) {
continue;
}
/* found a match - flag it */ /* found a match - flag it */
found = true; found = true;
}
}
if (found) {
/* get the last range on this nodeid - we do this /* get the last range on this nodeid - we do this
* to preserve order * to preserve order
*/ */
@ -207,22 +199,18 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
range->vpid = nodenum; range->vpid = nodenum;
range->cnt = 1; range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super); opal_list_append(&ndreg->ranges, &range->super);
break;
}
/* see if the node number is out of sequence */ /* see if the node number is out of sequence */
if (nodenum != (range->vpid + range->cnt)) { } else if (nodenum != (range->vpid + range->cnt)) {
/* start a new range */ /* start a new range */
range = OBJ_NEW(orte_regex_range_t); range = OBJ_NEW(orte_regex_range_t);
range->vpid = nodenum; range->vpid = nodenum;
range->cnt = 1; range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super); opal_list_append(&ndreg->ranges, &range->super);
break; } else {
}
/* everything matches - just increment the cnt */ /* everything matches - just increment the cnt */
range->cnt++; range->cnt++;
break;
} }
if (!found) { } else {
/* need to add it */ /* need to add it */
ndreg = OBJ_NEW(orte_regex_node_t); ndreg = OBJ_NEW(orte_regex_node_t);
if (0 < strlen(prefix)) { if (0 < strlen(prefix)) {

Просмотреть файл

@ -13,16 +13,19 @@
#include "opal/util/argv.h" #include "opal/util/argv.h"
#include "orte/util/proc_info.h" #include "orte/util/proc_info.h"
#include "orte/util/regex.h"
#include "orte/mca/errmgr/errmgr.h" #include "orte/mca/errmgr/errmgr.h"
#include "orte/runtime/runtime.h" #include "orte/runtime/runtime.h"
#include "orte/mca/regx/regx.h"
#include "orte/mca/regx/base/base.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int rc; int rc;
char *regex, *save; char *regex = NULL, **nodelist;
char **nodes=NULL; char **nodes=NULL;
int i; int i;
opal_pointer_array_t *node_pool;
orte_node_t *nptr;
if (argc < 1 || NULL == argv[1]) { if (argc < 1 || NULL == argv[1]) {
fprintf(stderr, "usage: regex <comma-separated list of nodes>\n"); fprintf(stderr, "usage: regex <comma-separated list of nodes>\n");
@ -31,10 +34,19 @@ int main(int argc, char **argv)
orte_init(&argc, &argv, ORTE_PROC_NON_MPI); orte_init(&argc, &argv, ORTE_PROC_NON_MPI);
if (ORTE_SUCCESS != (rc = mca_base_framework_open(&orte_regx_base_framework, 0))) {
ORTE_ERROR_LOG(rc);
return rc;
}
if (ORTE_SUCCESS != (rc = orte_regx_base_select())) {
ORTE_ERROR_LOG(rc);
return rc;
}
if (NULL != strchr(argv[1], '[')) { if (NULL != strchr(argv[1], '[')) {
/* given a regex to analyze */ /* given a regex to analyze */
fprintf(stderr, "ANALYZING REGEX: %s\n", argv[1]); fprintf(stderr, "ANALYZING REGEX: %s\n", argv[1]);
if (ORTE_SUCCESS != (rc = orte_regex_extract_node_names(argv[1], &nodes))) { if (ORTE_SUCCESS != (rc = orte_regx.extract_node_names(argv[1], &nodes))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
} }
for (i=0; NULL != nodes[i]; i++) { for (i=0; NULL != nodes[i]; i++) {
@ -45,23 +57,61 @@ int main(int argc, char **argv)
return 0; return 0;
} }
save = strdup(argv[1]); node_pool = OBJ_NEW(opal_pointer_array_t);
if (ORTE_SUCCESS != (rc = orte_regex_create(save, &regex))) { nodelist = opal_argv_split(argv[1], ',');
for (i=0; NULL != nodelist[i]; i++) {
orte_proc_t *daemon = NULL;
nptr = OBJ_NEW(orte_node_t);
nptr->name = strdup(nodelist[i]);
daemon = OBJ_NEW(orte_proc_t);
daemon->name.jobid = 123;
daemon->name.vpid = i;
nptr->daemon = daemon;
nptr->index = opal_pointer_array_add(node_pool, nptr);
}
if (ORTE_SUCCESS != (rc = orte_regx.nidmap_create(node_pool, &regex))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
} else { } else {
char *vpids = strchr(regex, '@');
vpids[0] = '\0';
fprintf(stderr, "REGEX: %s\n", regex); fprintf(stderr, "REGEX: %s\n", regex);
if (ORTE_SUCCESS != (rc = orte_regex_extract_node_names(regex, &nodes))) { if (ORTE_SUCCESS != (rc = orte_regx.extract_node_names(regex, &nodes))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
} }
free(regex); free(regex);
regex = opal_argv_join(nodes, ','); regex = opal_argv_join(nodes, ',');
opal_argv_free(nodes);
if (0 == strcmp(regex, argv[1])) { if (0 == strcmp(regex, argv[1])) {
fprintf(stderr, "EXACT MATCH\n"); fprintf(stderr, "EXACT MATCH\n");
} else { } else {
fprintf(stderr, "ERROR: %s\n", regex); fprintf(stderr, "ERROR: %s\n", regex);
if (opal_argv_count(nodes) != opal_argv_count(nodelist)) {
fprintf(stderr, "ERROR: number of nodes %d, expected %d\n",
opal_argv_count(nodes), opal_argv_count(nodelist));
goto exit;
}
for (i=0; NULL != nodelist[i]; i++) {
if (0 == strcmp(nodelist[i], nodes[i])) {
fprintf(stderr, "%s OK\n", nodelist[i]);
}
fprintf(stderr, "%s ERROR, expect %s\n", nodes[i], nodelist[i]);
}
} }
free(regex); free(regex);
regex = NULL;
} }
free(save); exit:
opal_argv_free(nodelist);
opal_argv_free(nodes);
for (i=0; (nptr = opal_pointer_array_get_item(node_pool, i)) != NULL; i++) {
free(nptr->name);
OBJ_RELEASE(nptr->daemon);
}
OBJ_RELEASE(node_pool);
} }