Skip to content

Commit

Permalink
Merge pull request #6306 from karasevb/regx_host_ordering_fix
Browse files Browse the repository at this point in the history
regex: fixed host ordering for different prefixes
  • Loading branch information
rhc54 authored Feb 8, 2019
2 parents 8bbd201 + 46e38b9 commit fcbc7ea
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 86 deletions.
63 changes: 23 additions & 40 deletions orte/mca/regx/fwd/regx_fwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,61 +154,44 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
}
/* is this node name already on our list? */
found = false;
for (item = opal_list_get_first(&nodenms);
!found && item != opal_list_get_end(&nodenms);
item = opal_list_get_next(item)) {
ndreg = (orte_regex_node_t*)item;
if (0 < strlen(prefix) && NULL == ndreg->prefix) {
continue;
}
if (0 == strlen(prefix) && NULL != ndreg->prefix) {
continue;
}
if (0 < strlen(prefix) && NULL != ndreg->prefix
&& 0 != strcmp(prefix, ndreg->prefix)) {
continue;
}
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;
if (0 != opal_list_get_size(&nodenms)) {
ndreg = (orte_regex_node_t*)opal_list_get_last(&nodenms);

if ((0 < strlen(prefix) && NULL == ndreg->prefix) ||
(0 == strlen(prefix) && NULL != ndreg->prefix) ||
(0 < strlen(prefix) && NULL != ndreg->prefix &&
0 != strcmp(prefix, ndreg->prefix)) ||
(NULL == suffix && NULL != ndreg->suffix) ||
(NULL != suffix && NULL == ndreg->suffix) ||
(NULL != suffix && NULL != ndreg->suffix &&
0 != strcmp(suffix, ndreg->suffix)) ||
(numdigits != ndreg->num_digits)) {
found = false;
} else {
/* found a match - flag it */
found = true;
}
/* found a match - flag it */
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);
if (NULL == range) {
/* first range for this nodeid */
range = OBJ_NEW(orte_regex_range_t);
range->vpid = nodenum;
range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super);
break;
}
/* 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 */
range = OBJ_NEW(orte_regex_range_t);
range->vpid = nodenum;
range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super);
break;
} else {
/* everything matches - just increment the cnt */
range->cnt++;
}
/* everything matches - just increment the cnt */
range->cnt++;
break;
}
if (!found) {
} else {
/* need to add it */
ndreg = OBJ_NEW(orte_regex_node_t);
if (0 < strlen(prefix)) {
Expand Down
64 changes: 26 additions & 38 deletions orte/mca/regx/reverse/regx_reverse.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
for( j = 0; j <= i; ++j) {
prefix[j] = node[j];
}
startnum = j;
if (numdigits) {
startnum = j;
}
break;
}
}
Expand All @@ -168,35 +170,25 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
}
/* is this node name already on our list? */
found = false;
for (item = opal_list_get_first(&nodenms);
!found && item != opal_list_get_end(&nodenms);
item = opal_list_get_next(item)) {
ndreg = (orte_regex_node_t*)item;
if (0 < strlen(prefix) && NULL == ndreg->prefix) {
continue;
}
if (0 == strlen(prefix) && NULL != ndreg->prefix) {
continue;
}
if (0 < strlen(prefix) && NULL != ndreg->prefix
&& 0 != strcmp(prefix, ndreg->prefix)) {
continue;
}
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;
if (0 != opal_list_get_size(&nodenms)) {
ndreg = (orte_regex_node_t*)opal_list_get_last(&nodenms);

if ((0 < strlen(prefix) && NULL == ndreg->prefix) ||
(0 == strlen(prefix) && NULL != ndreg->prefix) ||
(0 < strlen(prefix) && NULL != ndreg->prefix &&
0 != strcmp(prefix, ndreg->prefix)) ||
(NULL == suffix && NULL != ndreg->suffix) ||
(NULL != suffix && NULL == ndreg->suffix) ||
(NULL != suffix && NULL != ndreg->suffix &&
0 != strcmp(suffix, ndreg->suffix)) ||
(numdigits != ndreg->num_digits)) {
found = false;
} else {
/* found a match - flag it */
found = true;
}
/* found a match - flag it */
found = true;
}
if (found) {
/* get the last range on this nodeid - we do this
* to preserve order
*/
Expand All @@ -207,22 +199,18 @@ static int nidmap_create(opal_pointer_array_t *pool, char **regex)
range->vpid = nodenum;
range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super);
break;
}
/* 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 */
range = OBJ_NEW(orte_regex_range_t);
range->vpid = nodenum;
range->cnt = 1;
opal_list_append(&ndreg->ranges, &range->super);
break;
} else {
/* everything matches - just increment the cnt */
range->cnt++;
}
/* everything matches - just increment the cnt */
range->cnt++;
break;
}
if (!found) {
} else {
/* need to add it */
ndreg = OBJ_NEW(orte_regex_node_t);
if (0 < strlen(prefix)) {
Expand Down
66 changes: 58 additions & 8 deletions orte/test/system/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
#include "opal/util/argv.h"

#include "orte/util/proc_info.h"
#include "orte/util/regex.h"
#include "orte/mca/errmgr/errmgr.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 rc;
char *regex, *save;
char *regex = NULL, **nodelist;
char **nodes=NULL;
int i;
opal_pointer_array_t *node_pool;
orte_node_t *nptr;

if (argc < 1 || NULL == argv[1]) {
fprintf(stderr, "usage: regex <comma-separated list of nodes>\n");
Expand All @@ -31,10 +34,19 @@ int main(int argc, char **argv)

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], '[')) {
/* given a regex to analyze */
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);
}
for (i=0; NULL != nodes[i]; i++) {
Expand All @@ -45,23 +57,61 @@ int main(int argc, char **argv)
return 0;
}

save = strdup(argv[1]);
if (ORTE_SUCCESS != (rc = orte_regex_create(save, &regex))) {
node_pool = OBJ_NEW(opal_pointer_array_t);
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);
} else {
char *vpids = strchr(regex, '@');
vpids[0] = '\0';
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);
}
free(regex);
regex = opal_argv_join(nodes, ',');
opal_argv_free(nodes);
if (0 == strcmp(regex, argv[1])) {
fprintf(stderr, "EXACT MATCH\n");
} else {
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);
regex = NULL;
}
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);
}
free(save);
OBJ_RELEASE(node_pool);
}

0 comments on commit fcbc7ea

Please sign in to comment.