diff --git a/orte/mca/regx/fwd/regx_fwd.c b/orte/mca/regx/fwd/regx_fwd.c index 893b96e0ae..c5c4d5d903 100644 --- a/orte/mca/regx/fwd/regx_fwd.c +++ b/orte/mca/regx/fwd/regx_fwd.c @@ -154,38 +154,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 != 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; } - 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; - } - /* 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 */ @@ -193,22 +180,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)) { diff --git a/orte/mca/regx/reverse/regx_reverse.c b/orte/mca/regx/reverse/regx_reverse.c index b94a9be353..b6c3ba187a 100644 --- a/orte/mca/regx/reverse/regx_reverse.c +++ b/orte/mca/regx/reverse/regx_reverse.c @@ -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; } } @@ -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 != 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; } - 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; - } - /* found a match - flag it */ - found = true; + } + if (found) { /* get the last range on this nodeid - we do this * to preserve order */ @@ -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)) { diff --git a/orte/test/system/regex.c b/orte/test/system/regex.c index 1fb3496f3b..45d1c140ef 100644 --- a/orte/test/system/regex.c +++ b/orte/test/system/regex.c @@ -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 \n"); @@ -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++) { @@ -45,23 +57,61 @@ int main(int argc, char **argv) return 0; } - save = strdup(argv[1]); - if (ORTE_SUCCESS != (rc = orte_regex_create(save, ®ex))) { + 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, ®ex))) { 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; } - 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); }